Skip to content

fix(feishu): render markdown tables as monospace code blocks - #20580

Closed
mytangyh wants to merge 1 commit into
NousResearch:mainfrom
mytangyh:fix/feishu-table-codeblock
Closed

fix(feishu): render markdown tables as monospace code blocks#20580
mytangyh wants to merge 1 commit into
NousResearch:mainfrom
mytangyh:fix/feishu-table-codeblock

Conversation

@mytangyh

@mytangyh mytangyh commented May 6, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes broken markdown table rendering in the Feishu platform adapter. Instead of falling back to plain text mode (which loses all formatting), markdown tables are now converted to Unicode box-drawing characters inside fenced code blocks, rendering in monospace with proper column alignment.

Related Issue

Fixes the issue where Feishu messages containing markdown tables were sent as unformatted plain text, causing tables to appear misaligned and unreadable.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/feishu.py: Add _convert_md_tables() function that parses markdown tables and renders them with Unicode box-drawing characters (\u250c\u2500\u252c\u2500\u2510 etc.) wrapped in fenced code blocks
  • gateway/platforms/feishu.py: Handle CJK characters correctly using unicodedata.east_asian_width for proper column width calculation
  • gateway/platforms/feishu.py: Update _MARKDOWN_TABLE_RE regex to capture full tables including body rows (not just header + separator)
  • gateway/platforms/feishu.py: Modify _build_outbound_payload to convert tables through the post (md) pipeline instead of falling back to text mode
  • tests/gateway/test_feishu.py: Add 7 unit tests for _convert_md_tables covering simple tables, CJK alignment, surrounding text, no-table passthrough, multiple tables, alignment markers, and empty cells

How to Test

  1. Send a message through Feishu containing a markdown table (e.g. | Name | Value |\n|---|---|\n| foo | bar |)
  2. Verify the table renders in monospace with proper box-drawing borders
  3. Test with CJK content to verify alignment
  4. Run pytest tests/gateway/test_feishu.py::TestConvertMdTables -v

Checklist

  • I have read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix
  • I have run pytest tests/gateway/test_feishu.py -q and all 204 tests pass
  • I have added tests for my changes

Feishu md tag does not render markdown tables. The previous approach
fell back to plain text mode for messages containing tables, which lost
all formatting. Instead, convert markdown tables to box-drawing
characters inside fenced code blocks so the md renderer displays them
in monospace with proper column alignment.

Changes:
- Add _convert_md_tables() that parses markdown tables and renders
  them with Unicode box-drawing characters wrapped in code fences
- Handle CJK characters correctly using unicodedata.east_asian_width
  for proper column width calculation
- Update _MARKDOWN_TABLE_RE to capture full tables including body rows
- Modify _build_outbound_payload to convert tables before sending
  through the post (md) pipeline instead of falling back to text mode
- Add 7 unit tests covering simple tables, CJK alignment, surrounding
  text, no-table passthrough, multiple tables, alignment markers,
  and empty cells
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter P2 Medium — degraded but workaround exists labels May 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing with #19015 — both fix Feishu markdown table rendering. This PR converts to Unicode box-drawing characters in code blocks; #19015 wraps tables in plain code fences.

@mytangyh

mytangyh commented May 6, 2026

Copy link
Copy Markdown
Author

Closing this PR — upstream already has commit 8e18d10 (fix(feishu): force text mode for markdown tables) by WuTianyi, which solves the same problem with a better approach (space-aligned monospace columns instead of box-drawing characters). The current code works well. No need for this redundant fix.

@mytangyh mytangyh closed this May 6, 2026
@mytangyh
mytangyh deleted the fix/feishu-table-codeblock branch May 8, 2026 12:32
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.

2 participants