OpenProgram Docs

Markdown in Chinese

CommonMark was written for languages that put a space between words. Chinese does not, and models writing Chinese break its rules in a few fixed ways, so the marks show as text. Every renderer adds the same extensions to marked (lib/markdown/prose.ts); each takes only what the stock rules leave as text.

WrittenStock CommonMarkShown
这是**重点。**下一句Asterisks as textBold, closed after the full stop
这是*斜体。*后面, ~~原价,~~, __粗体__Marks as textItalic, struck, bold
访问 https://a.com/x。下一句The link takes 。下一句The link ends before 。
[文档](https://a.com)Brackets as textA link
[deck](/Users/me/ICDM 2026/deck.pptx)Text: a space ends the targetA file link
##标题, 1.第一项, -第一项Markers as textA heading, a list
价格 $5,折后 $3One formula from $5 to $Text

Rules

PartRule
Emphasis*, **, ***, ~~: taken when punctuation touches the inside of a mark, a non-space its outside, and CJK is on one side. _, __: taken when CJK touches the outside and the text inside has CJK, so snake_case stays (cjk-emphasis.ts)
Bare addressesEnd at the first full-width punctuation mark, and at CJK still in the host name. CJK in a path stays: zh.wikipedia.org/wiki/中文 (cjk-links.ts)
Link targetsFull-width parentheses count when the target is an address or a local path. A root, home, file:// or drive path may have spaces (spaced-path-links.ts)
MarkersA line starting with #–######, 1., 1), - or + directly followed by CJK is read with the space put back. Block tokens, so code is never touched (cjk-blocks.ts)
FormulasLexer tokens that render as .md-math holding their source; KaTeX draws only those and never scans text. $ opens before a non-space; the closing $ follows a non-space and is not followed by a digit, as in Pandoc. \(…\), \[…\], $$…$$ always count (math.ts)

Left as written

WrittenWhy
#话题#今天A hashtag: one # closed by another
1.5倍A digit follows the dot
1、, (1), •Plain text that already reads as numbering
*强调* at a line startEmphasis, not a bullet
Tables with |Rare, and a full-width bar is also ordinary text
Web addresses with spacesA space ends them, as everywhere

The user's own messages and A2UI text get the same extensions without formulas: what a person types stays literal.

Code
  • apps/web/lib/markdown/prose.ts, cjk-emphasis.ts, cjk-links.ts, cjk-blocks.ts, spaced-path-links.ts, math.ts
  • apps/web/lib/runtime-bridge/dom/markdown-render.ts (renderMd, typesetMath)
  • apps/web/components/chat/messages/bubbles/markdown.ts, apps/web/lib/format-utils/markdown.tsx, document-markdown.ts
  • apps/web/tests/chat/markdown/chinese-prose.test.mjs

Chat attachments

Last updated · 2026-11-25