开发者发布 LLX Markdown 流式渲染器
AI 总结
开发者 rsaryev 发布零依赖渲染器 LLX Markdown,可在 AI 对话回复流式输出时增量解析并修复未完成的 Markdown 语法。它加入面向智能体的内容块,并支持 Mermaid 和 KaTeX,但不支持 remark 或 rehype 插件。在开发者自测中,处理 10 万字符回复累计占用主线程 0.25 秒,测试脚本已开放供检查。
深度见解
该软件瞄准流式聊天界面的常见问题,但速度优势及 CommonMark、GFM 测试结果均为开发者自报,尚无独立验证。
I've been building chat UIs for agents and kept running into the same issues with react-markdown: it re-parses the whole reply on every token, so long answers get noticeably slower, and you see raw ** and half-typed [links](htt until the token that closes them arrives.
So I wrote my own renderer. It parses incrementally and repairs unfinished syntax while the reply streams: <Markdown streaming={!done}>{text}</Markdown>
On a 100k-character reply it takes 0.25 s of main-thread time in total. markdown-to-jsx takes 2.4 s, Streamdown 6.3 s, and react-markdown didn't finish within the 30 s budget. The benchmark scripts are in the repo if you want to check them.
The other part is the syntax. Agents often want to show steps, alternatives or pros and cons, and plain Markdown flattens all of that into bullet lists. So on top of GFM I added a few blocks in the same style as GitHub alerts: > [!STEPS] 1. **Back up the database** 2. **Run the migration**
There are also tabs, stats, pros/cons, sources, file trees, and Mermaid and KaTeX support. The source still reads fine as plain Markdown when it isn't rendered. The package exports a system-prompt snippet that teaches the model this syntax.
It has no dependencies and comes in at 30 KB gzipped. Its parser passes the CommonMark and GFM spec tests. It doesn't support remark/rehype plugins, so if you rely on those, react-markdown is still the better choice.
https://github.com/rsaryev/llx-markdown submitted by /u/Awkward-Let-4628
[link] [comments] |
#LLX Markdown#react-markdown#markdown-to-jsx#Streamdown#Mermaid#KaTeX