Skip to content

fix(feishu): route tables and multi-line code blocks to CardKit 2.0#19038

Closed
shiping430 wants to merge 1 commit into
NousResearch:mainfrom
shiping430:fix/feishu-card-tables-codeblocks
Closed

fix(feishu): route tables and multi-line code blocks to CardKit 2.0#19038
shiping430 wants to merge 1 commit into
NousResearch:mainfrom
shiping430:fix/feishu-card-tables-codeblocks

Conversation

@shiping430

Copy link
Copy Markdown

Summary

Feishu's post/md tag has two rendering limitations that this PR fixes:

  1. Tables — GFM table syntax (| col1 | col2 | ... |) is silently dropped; rows after the separator line don't appear
  2. Code blocks — Fenced code blocks longer than ~6 lines are truncated with no way to expand

Both are fixed by detecting these patterns in _build_outbound_payload and routing them to CardKit 2.0 interactive message format instead of post. CardKit 2.0's tag: markdown element natively supports GFM tables and fenced code blocks with scrollable rendering and a Copy button.

Changes

gateway/platforms/feishu.py:

  • Added _TABLE_MARKDOWN_RE — matches GFM tables (| cells | rows + |---| separator)
  • Added _CODE_BLOCK_RE — matches fenced code blocks with 2+ content lines (1-2 line blocks are unaffected; they render fine in post/md)
  • Modified _build_outbound_payload to check these patterns before the generic markdown hint and route matching content to _build_card_payloadmsg_type: interactive
  • Added _build_card_payload — builds a CardKit 2.0 card with tag: markdown element

Why CardKit 2.0

CardKit 2.0's markdown element is the officially recommended way to render markdown that Feishu's post/md tag doesn't support. It handles tables natively and renders code blocks with scroll + copy — no custom parsing needed.

Testing

Regex patterns tested:

  • _TABLE_MARKDOWN_RE → matches tables, does not false-positive on non-table content
  • _CODE_BLOCK_RE → matches 3-line+ code blocks, does not match inline code or 2-line blocks

Related Issues

Feishu's post/md tag silently drops GFM table rows and truncates
fenced code blocks after ~6 lines with no way to expand. Fix by
detecting these patterns in _build_outbound_payload and routing them
to CardKit 2.0 interactive cards instead:

- Tables: detect via _TABLE_MARKDOWN_RE (|cells| + |---| separator)
- Code blocks: detect via _CODE_BLOCK_RE (opening fence + 2+ content
  lines + closing fence); 1-2 line blocks render fine in post/md and
  are left unchanged

CardKit 2.0's tag=markdown element natively supports GFM tables
and fenced code blocks with scrollable rendering and a Copy button.

Fixes NousResearch#19035 (code block truncation)
Fixes NousResearch#9549 (table rendering)
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter comp/gateway Gateway runner, session dispatch, delivery labels May 3, 2026
@teknium1

teknium1 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR. Closing because the immediate user-visible bug (tables rendering as blank in Feishu) was already fixed on main via #20275 (salvage of #13723) — tables now fall back to plain text, which is readable if not pretty.

The CardKit 2.0 upgrade would be a real improvement for both tables and code blocks, but landing it without a live Feishu bot to validate — and without a fallback when a bot doesn't have card permission — is a risk we aren't in a position to accept right now. If you're able to test this against a real Feishu bot and add a _POST_CONTENT_INVALID_RE-style fallback to post when the card send fails, I'd be happy to revisit.

Fixes #19035 / #9549 remain open for future revisit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feishu] Code blocks cannot be expanded — only first ~2 lines visible [Feishu] Markdown tables not rendering in Feishu messages

3 participants