Skip to content

feat(im): support Markdown image rendering in post content#893

Merged
YangJunzhou-01 merged 2 commits into
mainfrom
feat/markdown_image
May 22, 2026
Merged

feat(im): support Markdown image rendering in post content#893
YangJunzhou-01 merged 2 commits into
mainfrom
feat/markdown_image

Conversation

@liujiashu-shiro

@liujiashu-shiro liujiashu-shiro commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Leverage underlying URL compatibility and remove redundant URL conversion logic to simplify the Markdown-to-Post element processing pipeline. Also add documentation for sending Markdown images, and align image handling guidance with actual runtime behavior.

Changes

  • Remove buildPostElements, buildPostElementNodes, scanPostToken, scanBareURLToken, scanMarkdownLinkToken, scanBalancedParenToken, trimBareURLToken, appendMDPostNode, marshalJSONNoEscape, marshalStringNoEscape and related constants
  • Revert buildSingleMDPost / buildSegmentedPost to single {"tag":"md"} serialization
  • Replace marshalJSONNoEscape with standard json.Marshal
  • Remove corresponding unit tests
  • Add Markdown image instructions in lark-im-messages-send.md and lark-im-messages-reply.md
  • Align Markdown image documentation with runtime behavior: clarify that img_xxx keys are the most reliable input, local paths are not supported, and remote URLs are auto-resolved at runtime (removed with a warning on failure); recommend pre-uploading via images.create for reliability

Test Plan

  • Unit tests pass (go test ./shortcuts/im/)
  • Verify lark im send --markdown with bare URLs renders correctly
  • Verify sending images via Markdown image syntax displays properly

Summary by CodeRabbit

  • Bug Fixes
    • Markdown content is now serialized and sent as single markdown blocks, preserving original markdown and changing how special characters are escaped; bare URLs and markdown links are no longer split into separate elements.
  • Documentation
    • Updated Markdown image guidance: local file paths in Markdown are not supported; pre-upload via images.create is recommended; remote URLs may be auto-downloaded/uploaded and can be removed on failure; added examples and common-mistakes notes.

Review Change Stack

@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 May 14, 2026
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56c30dea-9692-4187-817f-2b540db04b1d

📥 Commits

Reviewing files that changed from the base of the PR and between ec827b6 and 12f6fb9.

📒 Files selected for processing (2)
  • shortcuts/im/helpers.go
  • shortcuts/im/helpers_test.go
💤 Files with no reviewable changes (2)
  • shortcuts/im/helpers_test.go
  • shortcuts/im/helpers.go

📝 Walkthrough

Walkthrough

This PR consolidates Feishu markdown wrapping to emit single md nodes via standard json.Marshal, removes inline tokenization/link-splitting helpers, updates tests to the plain-markdown case, and clarifies --markdown image constraints (prefer pre-uploaded img_xxx, no local-path support, remote URLs may be auto-resolved).

Changes

Markdown wrapping simplification and image documentation

Layer / File(s) Summary
Markdown wrapping simplification
shortcuts/im/helpers.go
Replaces custom no-escape JSON marshaling with json.Marshal, consolidates segmented post construction from multi-element decomposition to single md elements, and removes tokenization/splitting helpers for URL and code-block preservation.
Test validation for plain markdown wrapping
shortcuts/im/helpers_test.go
Rewrites TestWrapMarkdownAsPost to validate only the simplified plain markdown wrapping case, removing prior sub-tests for URL-to-link transformation and code-block URL preservation.
Image constraint documentation for messages-reply and messages-send
skills/lark-im/references/lark-im-messages-reply.md, skills/lark-im/references/lark-im-messages-send.md
Clarifies markdown image handling across both skill references: recommends pre-uploaded img_xxx keys, states local file paths in markdown syntax are not supported, notes remote URLs may be auto-downloaded/uploaded at runtime with removal on failure, and adds examples plus common-mistake warnings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#206: Both PRs modify shortcuts/im/helpers.go markdown-to-Feishu post wrapping (wrapMarkdownAsPost), with this PR consolidating to single md elements via standard json.Marshal, whereas PR #206 tokenizes into mixed md/a elements with no-escape marshaling.
  • larksuite/cli#338: Both PRs modify shortcuts/im/helpers.go's markdown-to-Feishu wrapping pipeline (e.g., wrapMarkdownAsPost and content builders), with this PR removing tokenization/splitting behavior compared to the segmentation refactoring in #338.

Suggested labels

domain/im, size/L

Suggested reviewers

  • YangJunzhou-01
  • haozhenghua-code
  • liangshuo-1

Poem

🐰 I wrap up markdown neat and slight,
One md node now, no split in sight,
Upload your pics before you send,
Local paths won't find a friend,
Simpler posts hop on through the night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% 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 accurately summarizes the main change: adding support for Markdown image rendering in post content, which is the primary feature objective.
Description check ✅ Passed The PR description includes all required sections from the template: Summary, Changes (detailed list), and Test Plan (with completed checkboxes). No required sections are missing.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/markdown_image

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 commented May 14, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@12f6fb9b1890517543baf3f240bc10bcd604a7d0

🧩 Skill update

npx skills add larksuite/cli#feat/markdown_image -y -g

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.59%. Comparing base (56749e7) to head (12f6fb9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #893      +/-   ##
==========================================
- Coverage   67.61%   67.59%   -0.03%     
==========================================
  Files         575      575              
  Lines       54347    54244     -103     
==========================================
- Hits        36747    36664      -83     
+ Misses      14555    14543      -12     
+ Partials     3045     3037       -8     

☔ 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.

Leverage underlying URL compatibility and remove redundant URL conversion logic. Add the ability to send Markdown images.
Clarify that remote URLs are auto-resolved at runtime and only removed
on failure, rather than being unsupported. Recommend pre-uploading via
images.create for reliability. Update caveats, common mistakes, and
notes in both messages-send and messages-reply references.
@YangJunzhou-01
YangJunzhou-01 merged commit fbe4cc6 into main May 22, 2026
30 of 32 checks passed
@YangJunzhou-01
YangJunzhou-01 deleted the feat/markdown_image branch May 22, 2026 02:44
@liangshuo-1 liangshuo-1 mentioned this pull request May 22, 2026
3 tasks
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
…#893)

add documentation for sending Markdown images, and align image handling guidance with actual runtime behavior
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