fix(feishu): render markdown tables correctly via post+md instead of downgrading to text#31056
fix(feishu): render markdown tables correctly via post+md instead of downgrading to text#31056luochonglie wants to merge 4 commits into
Conversation
…downgrading to text The Feishu gateway adapter had two bugs causing markdown tables to display as raw pipe-delimited text instead of rendered tables: 1. _build_outbound_payload() forced text mode for content matching _MARKDOWN_TABLE_RE, based on the incorrect assumption that post+md would render tables as blank messages. Tested and proven wrong — Feishu's post+md renders tables correctly (verified with Lark CLI --markdown which uses the same post+md format). 2. _MARKDOWN_HINT_RE did not include a table pattern, so content containing ONLY a table (without other markdown like headings, bold, etc.) would not match and fall through to plain text mode. Fixes: - Remove the _MARKDOWN_TABLE_RE downgrade logic in _build_outbound_payload() - Add table pattern (^\|.*\|\n\|[-|: ]+\|) to _MARKDOWN_HINT_RE so pure-table content is correctly routed to post format
Review: fix(feishu): render markdown tables correctly via post+md instead of downgrading to textSummaryTwo-part fix: (1) removes an incorrect downgrade that forced AnalysisCorrectness: The behavioral change is sound. Removing the Edge cases checked:
Issues FoundWARNING (2)
INFO (2)
Points Positifs
RecommendationCOMMENT -- The fix is correct and safe to merge functionally. The two WARNINGs (dead |
…ne formatting in table cells
…LF handling - Remove dead _MARKDOWN_TABLE_RE constant and stale comment (WARNING NousResearch#1) - Fix CRLF line ending handling in _MARKDOWN_HINT_RE pattern (WARNING NousResearch#2) - Fix CRLF handling in _escape_markdown_text() - use re.split(r'\r?\n') - Preserve original line ending style when rejoining lines Addresses review feedback from jsboige in PR NousResearch#31056
🔧 WARNINGs Fixed - PR UpdatedThanks @jsboige for the detailed review! I've addressed both WARNINGs: ✅ WARNING #1: Dead Code Removed
✅ WARNING #2: CRLF Line Ending SupportFixed in 3 places:
📝 Commit Info
🙏 Additional Notes
Ready for re-review! 🚀 @alt-glitch Thanks for noting this is in the "feishu markdown table rendering family" - this PR was developed independently but I'll review #29552 to see if there are any improvements we can incorporate. |
Add comprehensive unit tests for the Feishu markdown table rendering fix: - Test _MARKDOWN_HINT_RE table pattern detection (LF, CRLF, alignment) - Test _escape_markdown_text() smart table detection and preservation - Test CRLF (Windows line ending) handling throughout - Test edge cases: emoji, special chars, wide tables, code blocks - Test regression scenarios from reported issues (Zhipu usage, Feishu seen messages) 25 test cases covering all aspects of the fix to prevent regression. Addresses INFO NousResearch#2 from jsboige review in PR NousResearch#31056: adds unit tests for table routing.
✅ Unit Tests Added!Thanks for the review feedback @jsboige! I've addressed the INFO #2 - unit tests are now included. 📝 Test CoverageCreated 25 comprehensive unit tests in
🧪 Test Results📦 New Files
🎯 What the Tests Verify
All WARNINGs and INFOs from the review have been addressed! 🚀 |
|
Gentle ping 🎯 This PR fixes a Feishu/Lark markdown table rendering bug affecting all markdown tables sent to the platform. Verified fixes:
Would be great if someone could review when time permits. Thanks! 🙏 |
Summary
The Feishu gateway adapter had two bugs causing markdown tables to display as raw pipe-delimited text (
| A | B |) instead of rendered tables:Bug 1: Incorrect table downgrade in
_build_outbound_payload()The code forced
textmode for content matching_MARKDOWN_TABLE_RE, based on the assumption thatpost+mdwould render tables as blank messages:This assumption is incorrect. Tested and verified that Feishu
post+mdrenders tables correctly. Lark CLI--markdownuses the samepost+mdformat ({"zh_cn":{"content":[[{"tag":"md","text":"..."}]]}}) and tables render perfectly.Bug 2:
_MARKDOWN_HINT_REmissing table pattern_MARKDOWN_HINT_REdetermines whether content should be sent aspost(rich text) ortext(plain text). It matches headings, bold, code blocks, lists, links, etc. — but not tables.This means content containing ONLY a table (without other markdown elements like headings or bold) would not match
_MARKDOWN_HINT_REand fall through to plaintextmode, displaying raw pipe characters.Changes
_MARKDOWN_TABLE_REdowngrade logic in_build_outbound_payload()— tables now correctly route topostformat(^\|.*\|\n\|[-|: ]+\|)to_MARKDOWN_HINT_RE— pure-table content is now correctly detected and sent aspostTesting
Verified on Feishu mobile client (dark mode):
textmodepostmodepost(worked by accident)post(works by design)Also verified with Lark CLI that both
--as botand--as useridentities render tables correctly viapost+mdformat.