forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson-feishu-markdown-table-not-rendered.json
More file actions
16 lines (16 loc) · 1.44 KB
/
Copy pathlesson-feishu-markdown-table-not-rendered.json
File metadata and controls
16 lines (16 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"task_id": "lesson-feishu-markdown-table-not-rendered",
"title": "飞书 post 消息中 Markdown 表格不渲染",
"domain": "development",
"tags": [
"feishu",
"markdown",
"table",
"post",
"lark"
],
"problem": "在飞书 IM 消息中使用 `post` 类型的富文本消息发送 Markdown 表格,表格显示为空白或原始分隔线(`|------|`),而不是渲染后的表格。",
"solution": "在发送前,用 `<br>` 标签替换表格的分隔符 `|`,打断表格行连续性,使飞书客户端能够渲染:\n\n```python\nimport re\n\ndef _optimize_markdown_style(content: str) -> str:\n \"\"\"飞书 post 中表格渲染修复:用 <br> 替换 | 分隔\"\"\"\n lines = content.split('\\n')\n result = []\n in_table = False\n \n for line in lines:\n is_table_line = bool(re.match(r'^\\s*\\|.*\\|\\s*$', line))\n if is_table_line:\n # 表格行:替换 | 为 <br> 分隔符\n line = re.sub(r'\\|', '<br>', line)\n # 清理多余的 <br> 前后空格\n line = re.sub(r'\\s*<br>\\s*', ' | ', line).strip()\n line = f'<br>{line}<br>'\n in_table = True\n else:\n in_table = False\n result.append(line)\n \n return '\\n'.join(result)\n```",
"source": "lessons/contrib/feishu-markdown-table-not-rendered.md",
"test_cmd": "python3 scripts/verify_task.py lesson-feishu-markdown-table-not-rendered"
}