fix(feishu): render markdown tables as aligned code fences - #21872
Open
mytangyh wants to merge 1 commit into
Open
fix(feishu): render markdown tables as aligned code fences#21872mytangyh wants to merge 1 commit into
mytangyh wants to merge 1 commit into
Conversation
Feishu's post-type 'md' elements do not render markdown tables. The current approach forces plain text mode for any content containing a table, which loses all markdown formatting (bold, links, etc.) in the same message. Instead, convert markdown tables to space-padded rows inside code fences. The monospace rendering preserves column alignment while allowing the rest of the message to use normal markdown formatting. Changes: - Enhance _MARKDOWN_TABLE_RE to capture full table including body rows - Add _display_width() for CJK / emoji / zero-width char width measurement - Add _convert_md_tables() to parse, align, and wrap tables in code fences - Replace force-text-mode early return with _convert_md_tables() call
3 tasks
8 tasks
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for preserving rich Markdown around Feishu tables. The underlying problem remains on current main, but this needs a targeted salvage rather than a direct apply.
Problems
- The active adapter moved from
gateway/platforms/feishu.pytoplugins/platforms/feishu/adapter.pyin552adbe0827c32df8ed9bb19e908c26eff43add7; current plain-text fallback remains atplugins/platforms/feishu/adapter.py:4524-4534. gateway/platforms/feishu.py:220globally substitutes table-shaped blocks, including tables inside existing fenced code blocks. The current post builder deliberately tracks fence state atplugins/platforms/feishu/adapter.py:577-623.- This payload-routing change has no regression tests;
tests/gateway/test_feishu.pycurrently has no table or_build_outbound_payloadcoverage.
Suggested changes
- Port the fix to
plugins/platforms/feishu/adapter.py. - Make conversion fence-aware, then add mixed-markdown, fenced-table, and CJK/emoji payload tests.
Automated hermes-sweeper review.
| def _replace(match: re.Match) -> str: | ||
| return "```\n" + _table_to_simple(match.group(0)) + "\n```" | ||
|
|
||
| return _MARKDOWN_TABLE_RE.sub(_replace, text) |
Contributor
There was a problem hiding this comment.
This global substitution also matches a table-shaped example already inside a fenced code block, inserting a second pair of fences and breaking the fence state consumed by the post builder. Please scan line-by-line while tracking fence state and leave existing fenced blocks unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Replace the force-plain-text fallback for markdown tables with a code-fence conversion that preserves monospace column alignment.
Why
Feishu's
mdrenderer does not render markdown tables. The current approach (8e18d103) detects tables and forces the entire message to plain text mode, which loses all markdown formatting (bold, links, inline code, etc.) in the same message.This PR instead converts markdown tables to space-padded rows inside code fences. The monospace rendering preserves column alignment while the rest of the message retains normal markdown formatting.
How
_MARKDOWN_TABLE_REto capture full tables including body rows (not just header + separator)_display_width()— CJK / emoji / zero-width character aware width measurement for column alignment_convert_md_tables()— parses markdown tables, measures column widths, pads cells, and wraps in code fences_build_outbound_payload()with a_convert_md_tables()callBefore / After
Before: A message containing a markdown table + bold text → entire message sent as plain text (no formatting at all).
After: Table converted to aligned code fence, rest of message rendered with full markdown support.
Testing
Tested with mixed-content messages containing markdown tables alongside bold, links, and CJK text. Verified column alignment in Feishu client.