Fix CJK emphasis delimiter detection in scanDelims#387
Open
awoni wants to merge 1 commit intoexecutablebooks:masterfrom
Open
Fix CJK emphasis delimiter detection in scanDelims#387awoni wants to merge 1 commit intoexecutablebooks:masterfrom
awoni wants to merge 1 commit intoexecutablebooks:masterfrom
Conversation
Treat CJK ideographs (codepoints > 0x2E7F) as punctuation in flanking delimiter checks so that emphasis markers work correctly in mixed CJK/ASCII contexts (e.g. 湾岸の**46%**を now renders bold correctly). https://claude.ai/code/session_01RzF12DUuSS8R6Zw1NKwv9o
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.
Summary
Fix emphasis delimiter detection for mixed CJK/ASCII text.
In CommonMark's
scanDelims, when an emphasis closing marker**is preceded by ASCII punctuation (e.g.%) and followed by a CJK character,right_flankingevaluates toFalse— causing bold to silently fail.Example:
湾岸の**46%**をrenders as plain text instead of<strong>46%</strong>.Root Cause
CJK characters (e.g.
を,の,は) are not classified as whitespace or punctuation by the spec. WhenlastChar='%'(punctuation) andnextChar='を'(neither whitespace nor punctuation):right_flanking = not (isLastPunctChar and not (isNextWhiteSpace or isNextPunctChar))evaluates to
False, so the closing**is rejected.Fix
Treat characters above U+2E7F as punctuation for flanking delimiter checks (6 lines added to
scanDelimsinstate_inline.py). This covers CJK Unified Ideographs, Hiragana, Katakana, Hangul, and other East Asian scripts.Test Cases
All pass. Existing English-only behavior is unchanged.
Note
The same bug likely exists in the JavaScript version of markdown-it.