Repository navigation
fix: render emphasis next to CJK text (CJK-friendly amendment) - #300
Merged
Merged
Conversation
markdown-it follows CommonMark's flanking rules, which decide whether `*`, `**` and `~~` can open or close from the punctuation next to the run. In Chinese, Japanese and Korean text written without spaces that fails: `**「括弧」**の直後` keeps its literal `**` on the page, because the closing run follows `」` and precedes a letter. Apply the CJK-friendly amendment (tats-u/markdown-cjk-friendly) through a CommonJS port of markdown-it-cjk-friendly 3.0.0 in lib/cjk-friendly-emphasis.js. The package and its get-east-asian-width dependency are ESM-only, which this CommonJS CLI cannot require under Jest or on Node 20 before 20.19. The East Asian Width ranges are generated into lib/east-asian-width-data.js by scripts/generate-east-asian-width.js; get-east-asian-width is a devDependency only, so the shipped dependency tree is unchanged. Both files keep the MIT notices of the code and data they derive from. The port reads characters as markdown-it 15's own scanDelims does (a lone surrogate reads as U+FFFD). `_` still never opens or closes inside a word. As in the original, a general-use variation selector right before a delimiter run is looked through to the character it modifies, so a few inputs such as `a**x”︀**b` change even without CJK; any other input without a CJK character next to a delimiter parses as before. Verified: - every CommonMark spec example (652) renders identically with and without the rule; - the plugin's own testcases (812 inputs incl. Korean, non-BMP, emoji and variation selectors) render byte-for-byte like markdown-it-cjk-friendly 3.0.0, except two lone-surrogate inputs where this port matches stock markdown-it instead; - the generated data matches get-east-asian-width 1.7.0 at all 1,114,112 code points; - new tests fail (10 of 23 at the time) with the CJK relaxation removed; the full jest suite and eslint pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Nov 16, 2026
## [2.31.2](v2.31.1...v2.31.2) (2026-11-16) ### Bug Fixes * render emphasis next to CJK text (CJK-friendly amendment) ([#300](#300)) ([d7ca4cb](d7ca4cb))
|
🎉 This PR is included in version 2.31.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Pull Request Template
Description
Closes #299
Markdown in Chinese, Japanese or Korean often loses its emphasis. CommonMark's flanking rules check the punctuation on each side of a
*/**/~~run. In**「括弧」**の直後, the closing**follows」and precedes a letter, so it cannot close. The page then shows the literal asterisks. Korean hits the same problem whenever a particle follows emphasis that ends in punctuation or code, for example**스크립트(script)**라고,**`npm publish`**를,**(주)**는and**100%**의. Japanese has the same problem without any spaces:**「括弧」**の直後,これは**私のやりたかったこと。**だから,税込**¥10,000**で.This PR applies the CJK-friendly amendment to CommonMark, the rule that
markdown-it-cjk-friendlyimplements, and adds no runtime dependency.Why a port instead of the package:
markdown-it-cjk-friendly2.x/3.x and itsget-east-asian-widthdependency are ESM-only. This CLI is CommonJS:require()them before Node 24.9 (I checked on Node 22).enginesallows, cannotrequire()them at runtime.So the change is:
lib/cjk-friendly-emphasis.js: a CommonJS port ofmarkdown-it-cjk-friendly3.0.0. It replacesscanDelimson a subclass ofmd.inline.State, the same way the plugin does. The file keeps that package's MIT notice (Tatsunori Uchino; markdown-it's authors).lib/east-asian-width-data.js: East Asian Width ranges, generated byscripts/generate-east-asian-width.jsfromget-east-asian-width1.7.0 through its public API. That package is a devDependency only, so the shipped dependency tree andnpm-shrinkwrap.jsondo not change. The generated file keeps that package's MIT notice.MacroConverteruses it:new MarkdownIt().use(cjkFriendlyEmphasis). That coversconvert,create,create-child,updateand the other Markdown inputs.Behaviour:
*,**and~~now open and close next to CJK characters._/__still never open or close inside a word.scanDelimsreads them, so a lone surrogate counts as U+FFFD.a**x”︀**bchanges.A known limitation that predates this PR: text in a page that contains literal emphasis markers is not escaped when the page is read as Markdown. Storage → Markdown → storage already turns
<p>**a**</p>and<p>~~x~~</p>into formatting onmain. With this change, the same applies next to CJK text. A literal**「…」**のleft on a page by the current behaviour will become bold when written back, which is usually what its author meant. Escaping literal markers inrenderTextwould change the output for every user, so I left it out of this PR.Type of Change
Testing
Beyond the new
tests/cjk-friendly-emphasis.test.js, I compared outputs offline:markdown-it-cjk-friendly3.0.0. The only exceptions are two lone-surrogate inputs, where this port matches stock markdown-it instead.get-east-asian-width1.7.0 at all 1,114,112 code points.npx eslint .pass on Node 22.Checklist
Additional Context
We use confluence-cli for Japanese pages, and this is the last gap that keeps us from using its Markdown conversion directly. I'm happy to switch to depending on the package instead, if you'd rather move toward ESM, or to put the rule behind an option.
🤖 Generated with Claude Code