From 26bb3312bf09244544b249e666a0faba4a0b82f5 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 6 Apr 2026 06:03:54 +0000 Subject: [PATCH] Fix CJK emphasis delimiter detection in scanDelims MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- markdown_it/rules_inline/state_inline.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/markdown_it/rules_inline/state_inline.py b/markdown_it/rules_inline/state_inline.py index de35287d..6301e044 100644 --- a/markdown_it/rules_inline/state_inline.py +++ b/markdown_it/rules_inline/state_inline.py @@ -148,6 +148,14 @@ def scanDelims(self, start: int, canSplitWord: bool) -> Scanned: isLastWhiteSpace = isWhiteSpace(ord(lastChar)) isNextWhiteSpace = isWhiteSpace(ord(nextChar)) + # Treat CJK ideographs as punctuation for flanking delimiter checks + # so that emphasis works correctly in mixed CJK/ASCII contexts. + # e.g. 湾岸の**46%**を should render 46% + if not isNextPunctChar and ord(nextChar) > 0x2E7F: + isNextPunctChar = True + if not isLastPunctChar and ord(lastChar) > 0x2E7F: + isLastPunctChar = True + left_flanking = not ( isNextWhiteSpace or (isNextPunctChar and not (isLastWhiteSpace or isLastPunctChar))