Skip to content

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

Closed
liujiashu-shiro wants to merge 1 commit into
mainfrom
feat/markdown_image
Closed

feat(im): support Markdown image rendering in post content#874
liujiashu-shiro wants to merge 1 commit 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 a new skill for sending Markdown images.

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 skill instructions in lark-im-messages-send.md and lark-im-messages-reply.md

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

  • Documentation
    • Clarified image handling constraints for markdown-formatted messages: only pre-uploaded images are supported; local paths and remote URLs must be uploaded first via the image upload endpoint before referencing in markdown.
    • Added examples demonstrating proper image pre-upload workflow before use in markdown messages.

Review Change Stack

Leverage underlying URL compatibility and remove redundant URL conversion logic. Add the ability to send Markdown images.
@CLAassistant

CLAassistant commented May 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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
📝 Walkthrough

Walkthrough

The PR simplifies Feishu markdown post JSON construction by removing custom marshaling and element tokenization, then documents the resulting constraints around image handling in markdown for send and reply operations.

Changes

Markdown Post Simplification and Image Handling

Layer / File(s) Summary
Markdown post JSON and element simplification
shortcuts/im/helpers.go, shortcuts/im/helpers_test.go
Replaces custom marshalStringNoEscape with standard json.Marshal, removes URL/markdown tokenization helpers (buildPostElementNodes), and wraps markdown directly as single {tag:"md", text:<markdown>} nodes in both single-post and segmented-post construction. Test coverage is simplified to assert single md-node output.
Image handling constraints for markdown send and reply
skills/lark-im/references/lark-im-messages-send.md, skills/lark-im/references/lark-im-messages-reply.md
Adds explicit "Image Constraint for --markdown" sections documenting that images must be pre-uploaded via images.create to obtain an image_key. Includes step-by-step examples and strengthens "Common Mistakes" and "Notes" sections warning that local paths and remote URLs cannot be used directly in --markdown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#206: Reverses markdown/URL tokenization removal and custom no-HTML-escape marshaling in shortcuts/im/helpers.go by consolidating multi-element post construction into a single md node via standard json.Marshal.
  • larksuite/cli#338: Introduced the URL tokenization and segmented-blank-line behavior in markdown post building that this PR simplifies away; changes to both helpers.go element construction logic and test coverage.

Suggested labels

enhancement, domain/im, size/M

Suggested reviewers

  • YangJunzhou-01

Poem

🐰 From tangled tokens to a single node so clean,
Markdown flows direct, no elements in between.
Images upload first—a lesson in the docs,
The simplest path to Feishu's message blocks! ✨

🚥 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 describes the main change: simplifying Markdown processing by removing URL conversion logic and enabling Markdown image rendering.
Description check ✅ Passed The description covers all required sections: Summary explains motivation, Changes lists main modifications, and Test Plan confirms verification steps with checkmarks.
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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills/lark-im/references/lark-im-messages-reply.md`:
- Around line 67-69: Update the Markdown guidance lines that currently state
remote Markdown image URLs are unsupported to instead recommend pre-uploading
for reliability and retain the actual runtime behavior that attempts to
download/upload remote URLs and removes failed images with a warning;
specifically replace the sentences like "Only already-uploaded `img_xxx`
Markdown images are kept reliably." and "Local paths (e.g. `![x](./a.png)`) and
remote URLs are **not** supported..." with wording such as "Pre-uploading images
(use `image_key` like `img_xxx`) is recommended for reliability; the runtime
will still attempt to download and upload remote Markdown image URLs and will
remove any image that fails with a warning." Apply the same phrasing at the
other occurrences referenced (the blocks around the text matching those lines).

In `@skills/lark-im/references/lark-im-messages-send.md`:
- Around line 67-69: Update the contradictory Markdown-image bullets so they
consistently reflect runtime behavior: state that already-uploaded `img_xxx`
images are preserved, local file paths like `![x](./a.png)` are not supported,
remote image URLs will be attempted (downloaded and uploaded) but if remote
download/upload fails the image is removed and a warning is emitted; apply this
same corrected wording to the other occurrences referenced (lines around the
other instances).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 277249e5-3e27-4646-adb6-e939d15ad417

📥 Commits

Reviewing files that changed from the base of the PR and between a18504b and 4686676.

📒 Files selected for processing (4)
  • shortcuts/im/helpers.go
  • shortcuts/im/helpers_test.go
  • skills/lark-im/references/lark-im-messages-reply.md
  • skills/lark-im/references/lark-im-messages-send.md

Comment on lines +67 to 69
- Only already-uploaded `img_xxx` Markdown images are kept reliably.
- Local paths (e.g. `![x](./a.png)`) and remote URLs are **not** supported as image links — all images must be downloaded and uploaded via `images.create`, provided as an `image_key`.
- If remote Markdown image handling fails, that image is removed with a warning.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align Markdown image guidance with current runtime behavior.

These lines now say remote Markdown image URLs are unsupported and may become placeholder text, but current runtime still tries to download/upload remote image URLs and removes failed images with a warning. Please update wording to “pre-upload is recommended for reliability” and keep failure behavior consistent with actual execution.

Suggested wording update
-- Only already-uploaded `img_xxx` Markdown images are kept reliably.
-- Local paths (e.g. `![x](./a.png)`) and remote URLs are **not** supported as image links — all images must be downloaded and uploaded via `images.create`, provided as an `image_key`.
+- Already-uploaded `img_xxx` image keys are the most reliable Markdown image input.
+- Local paths (e.g. `![x](./a.png)`) are **not** supported directly in `--markdown`.
+- Remote URLs may be auto-downloaded and uploaded during execution; if that step fails, the image is removed with a warning.

-- When using `--markdown` and the reply content includes images, you **must** first upload the image via `images.create` to obtain an `image_key`, then reference it as `![alt](img_xxx)`.
+- When using `--markdown` with images, prefer pre-uploading via `images.create` and referencing `![alt](img_xxx)` for predictable results.

-- **Using `--markdown` with images without first uploading via `images.create`.** All images must be pre-uploaded to obtain an `image_key`. Neither local paths nor remote URLs can be used directly — otherwise the image will be replaced with placeholder text.
+- **Using local file paths inside Markdown image syntax** (for example `![x](./a.png)`) with `--markdown`. This is not auto-uploaded and will not render as an image.

Also applies to: 75-76, 189-190, 244-245

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/lark-im/references/lark-im-messages-reply.md` around lines 67 - 69,
Update the Markdown guidance lines that currently state remote Markdown image
URLs are unsupported to instead recommend pre-uploading for reliability and
retain the actual runtime behavior that attempts to download/upload remote URLs
and removes failed images with a warning; specifically replace the sentences
like "Only already-uploaded `img_xxx` Markdown images are kept reliably." and
"Local paths (e.g. `![x](./a.png)`) and remote URLs are **not** supported..."
with wording such as "Pre-uploading images (use `image_key` like `img_xxx`) is
recommended for reliability; the runtime will still attempt to download and
upload remote Markdown image URLs and will remove any image that fails with a
warning." Apply the same phrasing at the other occurrences referenced (the
blocks around the text matching those lines).

Comment on lines +67 to 69
- Only already-uploaded `img_xxx` Markdown images are kept reliably.
- Local paths in Markdown image syntax like `![x](./a.png)` are **not** supported.
- If remote Markdown image download/upload fails, that image is removed with a warning.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix contradictory Markdown-image behavior statements.

This file now mixes two incompatible claims: remote URLs are auto-resolved vs remote URLs are unsupported. The new “placeholder text” wording is also inconsistent with runtime, which drops failed images with a warning. Please align these lines with the implemented behavior.

Also applies to: 75-76, 195-196, 245-245

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/lark-im/references/lark-im-messages-send.md` around lines 67 - 69,
Update the contradictory Markdown-image bullets so they consistently reflect
runtime behavior: state that already-uploaded `img_xxx` images are preserved,
local file paths like `![x](./a.png)` are not supported, remote image URLs will
be attempted (downloaded and uploaded) but if remote download/upload fails the
image is removed and a warning is emitted; apply this same corrected wording to
the other occurrences referenced (lines around the other instances).

@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 65.87%. Comparing base (b0c9a4d) to head (4686676).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #874      +/-   ##
==========================================
- Coverage   65.90%   65.87%   -0.03%     
==========================================
  Files         518      518              
  Lines       48830    48731      -99     
==========================================
- Hits        32181    32102      -79     
+ Misses      13882    13870      -12     
+ Partials     2767     2759       -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.

@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@4686676405c01e7d9ad643708e9468de87eeb433

🧩 Skill update

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

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