Esc

comark-cjk

CJK

Bold and italics that end in 。 or 」 right before the next word, where CommonMark leaves the asterisks on the page.

Playground

この文は太字。次の文は普通です。

会議は「金曜日」に移りました。

鳩の数を数える。もう数えません。

Without the plugin, every line above shows its asterisks. CommonMark decides whether ** opens or closes bold by the characters around it, and a closing ** between 。 and the next word counts as neither, because Chinese, Japanese, and Korean put no space there. The plugin relaxes that rule next to those scripts only, so English and other text parses as before.

The syntax is CommonMark's: **bold**, *italics*, and ~~strikethrough~~. Only the rule for where they start and end changes.

CommonMark lets ** close bold only when it is right-flanking. Roughly, that means it comes after text and not before more of it, unless punctuation sits on its left and a space or punctuation on its right. **太字。**次 breaks that: 。 is punctuation and 次 is a letter, so the closing ** is left as text and the whole line shows its asterisks.

English puts a space after a full stop, so it never hits this. Chinese, Japanese, and Korean put no space after 。, 、, 」, or .. With the plugin, a delimiter next to a character from those scripts may open or close as if a space were there:

**この文は太字。**次の文
*「強調」*です
~~削除。~~次
**이 문장은 굵게.**다음 문장
md

Text with no Chinese, Japanese, or Korean on either side of a delimiter parses as CommonMark says, so **foo.**bar still shows its asterisks. _ and __ still don't open or close in the middle of a word, so write ** and * in these languages.

The plugin runs markdown-it-cjk-friendly by tats-u unchanged. Its repository holds the specification, a proposal for CommonMark, and versions of the same fix for remark and micromark, so a site that renders some pages with another Markdown tool can read them the same way.

Comark closes the bold a stream leaves open before parsing, so **太字。 shows as bold while the rest arrives. Write ** rather than __ there too: an unmatched __ is closed at the end of the line, not where you meant.

GitHub's Markdown follows CommonMark here, so a README in Japanese still shows the asterisks there. Move the closing ** before the punctuation, **太字**。, for text that has to read the same on GitHub.

The plugin takes no options. In comarkUi(), cjk: false turns it off.

comark-ui brings comark-cjk and registers it. To use it alone, install it and register the plugin:

pnpm add comark @comark/html comark-cjk
import { parseMarkdown } from "comark";
import cjk from "comark-cjk";

const document = await parseMarkdown(markdown, {
  plugins: [cjk()],
});
ts

It has no components and no styles, because it only changes where *, _, and ~~ start and end. It works with registerDefaultPlugins: false and in streaming parses.