Skip to content

feat: resolve markdown blank-line formatting inconsistency in post me…#1216

Merged
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
91-enjoy:feat/resolve-markdown-blank-line
Jun 2, 2026
Merged

feat: resolve markdown blank-line formatting inconsistency in post me…#1216
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
91-enjoy:feat/resolve-markdown-blank-line

Conversation

@91-enjoy

@91-enjoy 91-enjoy commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Simplifies the markdown-to-post rendering pipeline in the IM shortcut. The previous
implementation split markdown at blank-line boundaries into multiple post paragraphs,
using zero-width space (\u200B) sentinel characters to preserve visual spacing.
While well-intentioned, this approach introduced fragility around edge cases such as
blank lines inside fenced code blocks, messages with only blank lines, and interactions
with the heading-normalization pass. This change consolidates rendering back into a
single {"tag":"md"} segment, making the output more predictable, the code significantly
easier to follow, and the test surface easier to maintain.

Changes

  • Consolidate wrapMarkdownAsPost and resolveMarkdownAsPost to produce a single-segment
    post payload directly, without dispatching through a multi-step segmentation pipeline
  • Inline the code-block protection logic (placeholder substitution and restoration)
    directly into optimizeMarkdownStyle, removing the need for standalone
    protectMarkdownCodeBlocks / restoreMarkdownCodeBlocks helpers
  • Remove intermediate abstractions that were only required by the multi-segment path:
    markdownPart struct, shouldUseSegmentedPost, splitMarkdownByBlankLines,
    marshalMarkdownPostContent, buildSingleMDPost, buildSegmentedPost,
    buildMarkdownPostContent
  • Remove reBlankLineSeparator regex and the postBlankLinePlaceholder /
    markdownCodeBlockPlaceholder package-level constants
  • Clean up test helpers (decodePostContentForTest, decodePostParagraphForTest)
    and all test cases that covered the removed multi-segment behavior; simplify
    the remaining TestWrapMarkdownAsPost to assert on the raw JSON structure

Test Plan

  • go test ./shortcuts/im/... -race passes
  • go build ./... passes with no errors
  • TestOptimizeMarkdownStyle (heading normalization, table formatting, code-block
    protection, excess-newline compression) remains fully covered and unchanged
  • Manual local verification confirms the lark im message send --markdown flow
    works as expected

Related Issues

  • None

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved markdown content formatting—posts now render as optimized single blocks instead of segmented content blocks.
  • Tests

    • Updated test cases to validate refined markdown rendering behavior.

…ssages

Change-Id: Ic2870ecbcb31ae7d36121f120102f2ff964f5169
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR consolidates markdown-to-Feishu post rendering. Instead of emitting segmented "text" paragraphs split on blank lines, both DryRun and Execute paths now return a single unified "md" block with optimized markdown content. Code-block handling is inlined within optimizeMarkdownStyle. Tests are simplified to validate the new unified format.

Changes

Markdown-to-Feishu Post Rendering Consolidation

Layer / File(s) Summary
Markdown optimization refactoring
shortcuts/im/helpers.go
Regex patterns consolidate into a var block. optimizeMarkdownStyle inlines code-block placeholder extraction and restoration using a local marker constant, eliminating external helper logic.
Post rendering consolidation to single "md" block
shortcuts/im/helpers.go
wrapMarkdownAsPost and resolveMarkdownAsPost are simplified to emit a single Feishu post JSON with one "md" paragraph and optimized markdown, removing blank-line segmentation and multi-block generation.
Test alignment and cleanup
shortcuts/im/helpers_test.go, shortcuts/im/coverage_additional_test.go
encoding/json import and JSON-decoding helpers removed. Segmented-paragraph test deleted. Assertions updated to validate consolidated "md" block output via substring checks instead of JSON unmarshaling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#338: Both PRs modify markdown post rendering in shortcuts/im/helpers.go; this PR consolidates the segmented "text" blocks introduced in that PR back to a single "md" format.
  • larksuite/cli#893: Both PRs refactor wrapMarkdownAsPost/resolveMarkdownAsPost to emit a single "md" block and update test expectations accordingly.
  • larksuite/cli#206: Both PRs modify markdown-to-Feishu post rendering; this PR standardizes to single "md" block while the other PR explores alternative link tokenization paths.

Suggested labels

domain/im, size/M

Suggested reviewers

  • YangJunzhou-01

Poem

🐰 Segmented posts once split like carrot sticks,
Now unified as one smooth markdown mix—
Code blocks tucked safely, optimization clicks,
A single "md" block, where simplicity sticks!
The tests sing in harmony, no more tricks. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is truncated (70 chars) but clearly refers to the main change: simplifying markdown blank-line formatting in post messages, which directly aligns with the changeset's core objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description provides a comprehensive summary, detailed list of changes, and completed test plan matching the required template structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact labels Jun 2, 2026
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.19%. Comparing base (70081f6) to head (91c17e3).
⚠️ Report is 32 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/im/helpers.go 64.28% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1216      +/-   ##
==========================================
+ Coverage   68.23%   69.19%   +0.96%     
==========================================
  Files         617      633      +16     
  Lines       57176    59492    +2316     
==========================================
+ Hits        39013    41166    +2153     
- Misses      14933    15010      +77     
- Partials     3230     3316      +86     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@91c17e35239a131f6e84823e8a62e39b716db144

🧩 Skill update

npx skills add 91-enjoy/cli#feat/resolve-markdown-blank-line -y -g

@YangJunzhou-01
YangJunzhou-01 merged commit 0aa9e96 into larksuite:main Jun 2, 2026
22 checks passed
@liangshuo-1 liangshuo-1 mentioned this pull request Jun 2, 2026
1 task
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
…ssages (larksuite#1216)

Simplifies the markdown-to-post rendering pipeline in the IM shortcut. The previous
implementation split markdown at blank-line boundaries into multiple post paragraphs,
using zero-width space (\u200B) sentinel characters to preserve visual spacing.
While well-intentioned, this approach introduced fragility around edge cases such as
blank lines inside fenced code blocks, messages with only blank lines, and interactions
with the heading-normalization pass. This change consolidates rendering back into a
single {"tag":"md"} segment, making the output more predictable, the code significantly
easier to follow, and the test surface easier to maintain.
Change-Id: Ic2870ecbcb31ae7d36121f120102f2ff964f5169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants