Skip to content

feat: markdown support line breaks#338

Merged
YangJunzhou-01 merged 1 commit intolarksuite:mainfrom
91-enjoy:feat/markdown_support_line_breaks
Apr 10, 2026
Merged

feat: markdown support line breaks#338
YangJunzhou-01 merged 1 commit intolarksuite:mainfrom
91-enjoy:feat/markdown_support_line_breaks

Conversation

@91-enjoy
Copy link
Copy Markdown
Contributor

@91-enjoy 91-enjoy commented Apr 8, 2026

Change-Id: Ie6b56b6302027f42e869d087d7ca4e94b99afda9

Summary

im +messages-send and im +messages-reply currently wrap --markdown into a single post md paragraph. When the input contains blank-line-separated paragraphs, the rendered
Feishu 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:

    • Extract code-block protection and restore helpers so markdown analysis can safely ignore fenced code blocks
    • Add shouldUseSegmentedPost() to detect blank-line separators outside code blocks
    • Add splitMarkdownByBlankLines() and markdownPart to split markdown into content and separator parts
    • Add marshalMarkdownPostContent(), buildSingleMDPost(), buildSegmentedPost(), and buildMarkdownPostContent() to centralize post payload generation
    • Preserve blank lines in post payloads by inserting tag: "text" paragraphs containing a zero-width placeholder between md paragraphs
    • Route both wrapMarkdownAsPost() and resolveMarkdownAsPost() through the same builder so dry-run and execute follow the same structure
  • shortcuts/im/helpers_test.go:

    • Add JSON decode helpers for asserting post paragraph structure instead of only checking string fragments
    • Add tests for segmented markdown with a single blank line, multiple blank lines, and blank lines that contain spaces
    • Add coverage to ensure blank lines inside fenced code blocks do not trigger segmented post mode
    • Add dry-run coverage for segmented markdown that also rewrites remote image URLs to placeholder image keys
  • shortcuts/im/coverage_additional_test.go:

    • Update TestResolveMarkdownAsPost to assert segmented post output for markdown containing blank-line-separated sections
    • Keep verification that heading normalization still applies in the execute path

Test Plan

  • go test ./shortcuts/im/...
  • make unit-test
  • Manual local verification confirms ./lark-cli im +messages-send --markdown ... preserves blank lines in rendered post messages
  • Manual local verification confirms ./lark-cli im +messages-reply --markdown ... preserves blank lines in rendered post replies

Related Issues

  • None

Summary by CodeRabbit

New Features

  • Markdown processing now intelligently segments content with proper blank line preservation in converted posts
  • Code blocks within markdown are protected during the conversion process

Tests

  • Added comprehensive test coverage for segmented post layouts and blank line rendering
  • Enhanced validation of post content structure and markdown text preservation

Change-Id: Ie6b56b6302027f42e869d087d7ca4e94b99afda9
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

The changes refactor markdown-to-Feishu post conversion logic to support segmented content arrays with blank-line separators. A new pipeline enables producing either single md blocks or multiple paragraphs with alternating md and text tags. Code block handling was extracted into reusable helpers, and comprehensive test coverage validates the new segmentation behavior.

Changes

Cohort / File(s) Summary
Segmented Post Implementation
shortcuts/im/helpers.go
Refactored markdown wrapping pipeline to support segmentation. Extracted code block protection/restoration into protectMarkdownCodeBlocks and restoreMarkdownCodeBlocks helpers. Added shouldUseSegmentedPost, splitMarkdownByBlankLines, and JSON builders (buildSingleMDPost, buildSegmentedPost, buildMarkdownPostContent) to handle blank-line-separated content with text tags containing zero-width placeholders.
Test Coverage for Segmentation
shortcuts/im/helpers_test.go
Added JSON decoding helpers (decodePostContentForTest, decodePostParagraphForTest) and refactored existing assertions from substring checks to structured content validation. Added test cases for segmented post behavior: dry-run blank-line handling, segmentation detection logic, and validation that blank lines produce "tag":"text" paragraphs while text blocks remain "tag":"md".
Resolved Payload Validation
shortcuts/im/coverage_additional_test.go
Updated TestResolveMarkdownAsPost to validate that resolved payload includes both "tag":"md" and "tag":"text" entries in the segmented output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit's ode to blank-line grace,
Code blocks tucked in a safer place,
Segments dance where blanks appear,
Text tags bloom, the output's clear!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding markdown support for line breaks (blank-line preservation) in Feishu posts.
Description check ✅ Passed The pull request description comprehensively covers all required template sections: a clear Summary explaining the motivation, detailed Changes listing modifications to each file, a thorough Test Plan with checkboxes showing completed testing, and a Related Issues section.

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

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

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 Apr 8, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 8, 2026

Greptile Summary

This PR adds segmented post building for --markdown messages in im +messages-send and im +messages-reply. When the input contains blank-line-separated sections outside fenced code blocks, the content is now split into multiple md post paragraphs with zero-width-space text paragraphs inserted as visual spacers, preserving the intended spacing in Feishu's rich-text post format.

The only finding is a P2 dead-code nit in wrapMarkdownAsPostForDryRun where a FindStringSubmatch result (sub) is computed but never read, and both branches of the resulting if return identical output.

Confidence Score: 5/5

Safe 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

Vulnerabilities

No security concerns identified.

Important Files Changed

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]
Loading

Comments Outside Diff (1)

  1. shortcuts/im/helpers.go, line 814-824 (link)

    P2 Dead code — both branches of if len(sub) < 2 return the same string

    sub is computed via FindStringSubmatch but its captured groups are never read; both the if and the fallthrough arm produce identical output. This looks like a copy-paste from resolveMarkdownImageURLs where sub[1] is actually used. The entire sub variable and the conditional can be dropped:

Reviews (1): Last reviewed commit: "feat: markdown support line breaks" | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@9d69ad7990042c2c2e0d8a59c8e7847a59a3306d

🧩 Skill update

npx skills add 91-enjoy/cli#feat/markdown_support_line_breaks -y -g

@YangJunzhou-01 YangJunzhou-01 merged commit d7262b7 into larksuite:main Apr 10, 2026
15 checks passed
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