feat: markdown support line breaks#338
Conversation
Change-Id: Ie6b56b6302027f42e869d087d7ca4e94b99afda9
📝 WalkthroughWalkthroughThe changes refactor markdown-to-Feishu post conversion logic to support segmented content arrays with blank-line separators. A new pipeline enables producing either single Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR adds segmented post building for The only finding is a P2 dead-code nit in Confidence Score: 5/5Safe to merge; the single finding is a cosmetic dead-code nit with no behavioral impact. All production logic (splitting, separator counting, code-block protection, optimization, fallback) is correct and exercised by targeted tests. The only issue is P2 dead code that does not affect output. shortcuts/im/helpers.go — minor dead-code cleanup in wrapMarkdownAsPostForDryRun
|
| Filename | Overview |
|---|---|
| shortcuts/im/helpers.go | Adds segmented post building (split on blank lines, placeholder paragraphs) with one dead-code issue in wrapMarkdownAsPostForDryRun; core logic is correct |
| shortcuts/im/helpers_test.go | Adds well-structured tests for segmented post (single blank line, multiple blank lines, spaces-only lines, code-block protection, dry-run image URL rewriting) |
| shortcuts/im/coverage_additional_test.go | Updates TestResolveMarkdownAsPost to assert segmented output and heading normalization; straightforward and correct |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[markdown input] --> B{shouldUseSegmentedPost?}
B -- "no blank lines outside code blocks" --> C[buildSingleMDPost]
B -- "blank-line separator found" --> D[buildSegmentedPost]
C --> E["single md paragraph {tag:md, text:optimized}"]
D --> F[splitMarkdownByBlankLines]
F --> G["content parts + separator parts (code blocks protected/restored)"]
G --> H{for each part}
H -- "content" --> I["optimizeMarkdownStyle + Trim newlines"]
H -- "separator newlineCount=N" --> J["insert N-1 placeholder paragraphs {tag:text, text:zero-width-space}"]
I --> K[md paragraph]
J --> K
K --> L[marshalMarkdownPostContent to JSON]
Comments Outside Diff (1)
-
shortcuts/im/helpers.go, line 814-824 (link)Dead code — both branches of
if len(sub) < 2return the same stringsubis computed viaFindStringSubmatchbut its captured groups are never read; both theifand the fallthrough arm produce identical output. This looks like a copy-paste fromresolveMarkdownImageURLswheresub[1]is actually used. The entiresubvariable and the conditional can be dropped:
Reviews (1): Last reviewed commit: "feat: markdown support line breaks" | Re-trigger Greptile
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@9d69ad7990042c2c2e0d8a59c8e7847a59a3306d🧩 Skill updatenpx skills add 91-enjoy/cli#feat/markdown_support_line_breaks -y -g |
Change-Id: Ie6b56b6302027f42e869d087d7ca4e94b99afda9
Summary
im +messages-sendandim +messages-replycurrently wrap--markdowninto a single postmdparagraph. When the input contains blank-line-separated paragraphs, the renderedFeishu post may lose the intended spacing between sections.
This PR adds segmented post building for markdown that contains blank-line separators outside fenced code blocks. It preserves visual blank lines by splitting markdown into
multiple post paragraphs and inserting placeholder text paragraphs between them, while keeping the existing markdown style normalization and image-resolution behavior.
Changes
shortcuts/im/helpers.go:shouldUseSegmentedPost()to detect blank-line separators outside code blockssplitMarkdownByBlankLines()andmarkdownPartto split markdown into content and separator partsmarshalMarkdownPostContent(),buildSingleMDPost(),buildSegmentedPost(), andbuildMarkdownPostContent()to centralize post payload generationtag: "text"paragraphs containing a zero-width placeholder betweenmdparagraphswrapMarkdownAsPost()andresolveMarkdownAsPost()through the same builder so dry-run and execute follow the same structureshortcuts/im/helpers_test.go:shortcuts/im/coverage_additional_test.go:TestResolveMarkdownAsPostto assert segmented post output for markdown containing blank-line-separated sectionsTest Plan
go test ./shortcuts/im/...make unit-test./lark-cli im +messages-send --markdown ...preserves blank lines in rendered post messages./lark-cli im +messages-reply --markdown ...preserves blank lines in rendered post repliesRelated Issues
Summary by CodeRabbit
New Features
Tests