Repository navigation
fix(render): render CJK emphasis and wrap CJK text per character - #135
Merged
Merged
Conversation
CommonMark's flanking rule leaves `**` literal when punctuation sits inside and a CJK letter outside, which is common in Chinese text. A zero-width mark inserted before parsing makes the delimiter valid; it is removed from the output and alignment still uses the original source. Break CJK runs per character with basic kinsoku and keep Latin words whole.
…eds repair Blocks without `*` return at once, and the literal-range parse runs only after a repairable delimiter is found. Text that was not protected skips the mark stripping.
backnotprop
force-pushed
the
fix/cjk-markdown-rendering
branch
from
November 15, 2026 15:51
353b25e to
62b8f91
Compare
Contributor
|
Thanks @Manho, this is great work! I split it so the CJK part could land now: I rebased your commit, added an early return in |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chinese Markdown shows raw
**on screen because of one CommonMark rule, and long CJK runs wrap badly. This PR fixes both.What was wrong
改造成**“最强妖怪”**。shows the**. CommonMark refuses a delimiter with punctuation on its inner side and a letter on its outer side. Chinese has no spaces to satisfy that, and the leftover**can then pair with the wrong partner further along the line.-, leaving the marker alone on a row.What changed
cjk_emphasis.rs: puts a U+200B on the inner side of a refused delimiter before parsing, then strips it from the rendered text.tui-markdownruns its own parser and has no option for this, so the repair happens in its input. Alignment still runs against the original source, so offsets don't move. Delimiters in code, math and raw HTML are left alone. A block with no*returns at once, and the extra parse for literal ranges runs only when a delimiter needs repair.wrap/breaks.rs: breaks CJK per character with basic kinsoku (opening punctuation stays with the text after it, closing punctuation with the text before it), and keeps Latin words whole.wrap.rsonly calls it.Results
**, and list items no longer leave the-alone on a row.--annotateon quotes inside repaired bold and across a wrapped CJK list item stores exactoriginalText, with no U+200B in it.--bench samples/big.md, 5 interleaved runs againstmain: render+align+wrap 339–407 ms (main 349–413 ms), and reflow overlaps. No measurable cost.Testing
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(545 passed, 10 new), andpython3 herdr/test-manifest.py, on macOS.Known limits
protectdoesn't exclude*inside link destinations or titles.strip_marksalso removes a U+200B that was already in the source, but only in a block that needed repair.Not in this PR
The decoration part of the original PR (bullets, task boxes, quote bars, rules, hanging indents) moved to #152. That PR builds it from the parsed document instead of the rendered text.