@mdit/plugin-cjk-friendly
Plugin to make emphasis and strong emphasis friendly to Chinese, Japanese and Korean text.
Usage
import { cjkFriendly } from "@mdit/plugin-cjk-friendly";
import MarkdownIt from "markdown-it";
const mdIt = new MarkdownIt().use(cjkFriendly);
mdIt.render(
"**このアスタリスクは強調記号として認識されず、そのまま表示されます。**この文のせいで。",
);
// <p><strong>このアスタリスクは強調記号として認識されず、そのまま表示されます。</strong>この文のせいで。</p>Tips
This plugin implements the CJK-friendly CommonMark amendments. It only affects delimiter runs adjacent to CJK characters, so documents in other languages keep the plain markdown-it output.
VuePress 2's @vuepress/plugin-markdown-ext already depends on the reference implementation markdown-it-cjk-friendly.
Syntax
CommonMark only lets ** open emphasis when it is not followed by punctuation, unless the character before it is whitespace or punctuation. Since CJK punctuation is commonly placed right before the closing marker, many CJK emphasis markers are left unrecognized:
Input
これは**私のやりたかったこと。**だからするの。Output with plain markdown-it
<p>これは**私のやりたかったこと。**だからするの。</p>Output with this plugin
<p>これは<strong>私のやりたかったこと。</strong>だからするの。</p>CJK characters, CJK punctuation and variation selector sequences are treated as valid neighbors of *, ** and GFM ~~ delimiter runs. markdown-it keeps the intraword restrictions for _ and __, so the amendment does not change underscore emphasis. Characters with a default emoji presentation, such as 😀, are not treated as CJK characters.
Demo
Input
**这些星号不会被识别为强调标记,而是就这么原样显示出来。**都是因为这个句子。Output
<p><strong>这些星号不会被识别为强调标记,而是就这么原样显示出来。</strong>都是因为这个句子。</p>