markdown-it-cjk-friendly 0.3.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -13
- package/dist/index.cjs +11 -6
- package/dist/index.js +11 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
# markdown-it-cjk-friendly
|
|
2
2
|
|
|
3
|
-
[](https://npmjs.com/package/markdown-it-cjk-friendly)
|
|
3
|
+
[](https://npmjs.com/package/markdown-it-cjk-friendly) [](https://npmjs.com/package/markdown-it-cjk-friendly) [](https://npmjs.com/package/markdown-it-cjk-friendly)
|
|
4
4
|
|
|
5
|
-
A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to make Markdown emphasis (`**`) in CommonMark compatible with Chinese, Japanese, and Korean.
|
|
5
|
+
A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to make Markdown emphasis (`**`) in CommonMark compatible with Chinese, Japanese, and Korean (CJK).
|
|
6
6
|
|
|
7
|
-
<span lang="ja">CommonMarkの強調記号(`**`)
|
|
7
|
+
<span lang="ja">CommonMarkの強調記号(`**`)を日本語・中国語・韓国語にきちんと対応させるための[markdown-it](https://github.com/markdown-it/markdown-it)プラグイン</span>
|
|
8
8
|
|
|
9
9
|
<span lang="zh-Hans-CN">一个 [markdown-it](https://github.com/markdown-it/markdown-it) 插件,用于使 CommonMark 的强调标记(`**`)能够正确支持中文、日语和韩语文本。</span>
|
|
10
10
|
|
|
11
|
-
<span lang="ko">CommonMark의 강조 표시(
|
|
11
|
+
<span lang="ko">CommonMark의 강조 표시(`**`) 를 한국어, 중국어, 일본어와 호환되도록 만드는 [markdown-it](https://github.com/markdown-it/markdown-it) 플러그인</span>
|
|
12
12
|
|
|
13
13
|
## Problem / <span lang="ja">問題</span> / <span lang="zh-Hans-CN">问题</span> / <span lang="ko">문제점</span>
|
|
14
14
|
|
|
15
|
-
CommonMark has a problem that the following emphasis marks `**` are not recognized as emphasis marks in Japanese and
|
|
15
|
+
CommonMark has a problem that the following emphasis marks `**` are not recognized as emphasis marks in Japanese, Chinese, and Korean.
|
|
16
16
|
|
|
17
|
-
<span lang="ja">CommonMark
|
|
17
|
+
<span lang="ja">CommonMarkには、日本語・中国語・韓国語内の次のような強調記号(`**`)が強調記号として認識されない問題があります。</span>
|
|
18
18
|
|
|
19
|
-
<span lang="zh-Hans-CN">CommonMark
|
|
19
|
+
<span lang="zh-Hans-CN">CommonMark存在以下问题:在中文、日语和韩语文本中,强调标记`**`不会被识别为强调标记。</span>
|
|
20
20
|
|
|
21
|
-
<span lang="ko">CommonMark는 일본어와 중국어에서 다음과 같은 강조 표시
|
|
21
|
+
<span lang="ko">CommonMark는 일본어와 중국어에서 다음과 같은 강조 표시 `**`가 강조 표시로 인식되지 않는 문제가 있습니다.</span>
|
|
22
22
|
|
|
23
23
|
```md
|
|
24
24
|
**このアスタリスクは強調記号として認識されず、そのまま表示されます。**この文のせいで。
|
|
@@ -46,6 +46,29 @@ Of course, not only the end side but also the start side has the same issue.
|
|
|
46
46
|
|
|
47
47
|
CommonMark issue: https://github.com/commonmark/commonmark-spec/issues/650
|
|
48
48
|
|
|
49
|
+
## Runtime Requirements / <span lang="ja">実行環境の要件</span> / <span lang="zh-Hans-CN">运行环境要求</span> / <span lang="ko">업데이트 전략</span>
|
|
50
|
+
|
|
51
|
+
This package uses the [`v` flag of the regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) introduced in ES2024 to determine whether the character is an emoji or not.
|
|
52
|
+
|
|
53
|
+
<span lang="ja">本パッケージは文字が絵文字かどうかを判定するために、ES2024で導入された[正規表現の`v`フラグ](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)を使用しています。</span>
|
|
54
|
+
|
|
55
|
+
<span lang="zh-CN">本包使用 ES2024 引入的[`v` 标志](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) 来判断字符是否为 emoji。</span>
|
|
56
|
+
|
|
57
|
+
<span lang="ko">이 패키지는 ES2024에서 도입된 [`v` 플래그](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)를 사용하여 문자가 이모지인지 여부를 판단합니다.</span>
|
|
58
|
+
|
|
59
|
+
It makes this package compatible only with relatively recent browsers and Node.js:
|
|
60
|
+
|
|
61
|
+
<span lang="ja">このため、本パッケージは、次のような比較的新しいブラウザやNode.jsでしか動作しません。</span>
|
|
62
|
+
|
|
63
|
+
<span lang="zh-CN">因此,本包只兼容比较新的浏览器和 Node.js:</span>
|
|
64
|
+
|
|
65
|
+
<span lang="ko">따라서, 이 패키지는 비교적 최신 브라우저와 Node.js에서만 작동합니다.</span>
|
|
66
|
+
|
|
67
|
+
- Chrome / Edge 112 or later
|
|
68
|
+
- Firefox 116 or later
|
|
69
|
+
- Safari 17 or later
|
|
70
|
+
- Node.js 20 or later
|
|
71
|
+
|
|
49
72
|
## Installation / <span lang="ja">インストール</span> / <span lang="zh-Hans-CN">安装</span> / <span lang="ko">설치</span>
|
|
50
73
|
|
|
51
74
|
Install `markdown-it-cjk-friendly` via [npm](https://www.npmjs.com/):
|
|
@@ -56,18 +79,17 @@ Install `markdown-it-cjk-friendly` via [npm](https://www.npmjs.com/):
|
|
|
56
79
|
|
|
57
80
|
<span lang="ko">`markdown-it-cjk-friendly`를 [npm](https://www.npmjs.com/)으로 설치하세요.</span>
|
|
58
81
|
|
|
59
|
-
|
|
60
82
|
```bash
|
|
61
83
|
npm install markdown-it-cjk-friendly
|
|
62
84
|
```
|
|
63
85
|
|
|
64
|
-
If you use another package manager, please replace `npm` with the command of the package manager you use (e.g. `pnpm`).
|
|
86
|
+
If you use another package manager, please replace `npm install` with the command of the package manager you use (e.g. `pnpm add` or `yarn add`).
|
|
65
87
|
|
|
66
|
-
<span lang="ja">npm以外のパッケージマネージャを使う場合は、`npm`を当該パッケージマネージャのコマンド(例:`pnpm`)に置き換えてください。</span>
|
|
88
|
+
<span lang="ja">npm以外のパッケージマネージャを使う場合は、`npm install`を当該パッケージマネージャのコマンド(例:`pnpm add`・`yarn add`)に置き換えてください。</span>
|
|
67
89
|
|
|
68
|
-
<span lang="zh-Hans-CN">如果使用其他包管理器,请将 `npm` 替换为当时包管理器的命令(例如:`pnpm`)。</span>
|
|
90
|
+
<span lang="zh-Hans-CN">如果使用其他包管理器,请将 `npm install` 替换为当时包管理器的命令(例如:`pnpm add`、`yarn add`)。</span>
|
|
69
91
|
|
|
70
|
-
<span lang="ko">다른 패키지 매니저를 사용하는 경우 `npm`을 해당 패키지 매니저의 명령어(예: `pnpm`)로 바꾸어 주세요.</span>
|
|
92
|
+
<span lang="ko">다른 패키지 매니저를 사용하는 경우 `npm install`을 해당 패키지 매니저의 명령어(예: `pnpm add`, `yarn add`)로 바꾸어 주세요.</span>
|
|
71
93
|
|
|
72
94
|
## Usage / <span lang="ja">使い方</span> / <span lang="zh-Hans-CN">用法</span> / <span lang="ko">사용법</span>
|
|
73
95
|
|
|
@@ -87,6 +109,10 @@ const md = MarkdownIt();
|
|
|
87
109
|
md.use(markdownItCjkFriendly);
|
|
88
110
|
```
|
|
89
111
|
|
|
112
|
+
## Specification / <span lang="ja">規格書</span> / <span lang="zh-Hans-CN">规范</span> / <span lang="ko">규정서</span>
|
|
113
|
+
|
|
114
|
+
https://github.com/tats-u/markdown-cjk-friendly/blob/main/specification.md (English)
|
|
115
|
+
|
|
90
116
|
## Contributing / <span lang="ja">貢献</span> / <span lang="zh-Hans-CN">贡献</span> / <span lang="ko">기여</span>
|
|
91
117
|
|
|
92
118
|
### Setup
|
package/dist/index.cjs
CHANGED
|
@@ -63,20 +63,25 @@ function markdownItCjFriendlyPlugin(md) {
|
|
|
63
63
|
const max = this.posMax;
|
|
64
64
|
const marker = this.src.charCodeAt(start);
|
|
65
65
|
let [lastChar, lastCharPos] = getLastCharCode(this.src, start);
|
|
66
|
-
|
|
66
|
+
let isLastActuallyTwoPrev = false;
|
|
67
|
+
if (maybeHanSVS(lastChar)) {
|
|
68
|
+
[lastChar, lastCharPos] = getLastCharCode(this.src, lastCharPos);
|
|
69
|
+
isLastActuallyTwoPrev = true;
|
|
70
|
+
}
|
|
67
71
|
let pos = start;
|
|
68
72
|
while(pos < max && this.src.charCodeAt(pos) === marker)pos++;
|
|
69
73
|
const count = pos - start;
|
|
70
74
|
const nextChar = pos < max ? this.src.codePointAt(pos) : 0x20;
|
|
75
|
+
const isLastCJKChar = (isLastActuallyTwoPrev ? isCjk : isCjkOrIvs)(lastChar);
|
|
76
|
+
const isNextCJKChar = isCjk(nextChar);
|
|
71
77
|
const isLastPunctChar = (0, utils_mjs_namespaceObject.isMdAsciiPunct)(lastChar) || (0, utils_mjs_namespaceObject.isPunctChar)(String.fromCodePoint(lastChar));
|
|
72
78
|
const isNextPunctChar = (0, utils_mjs_namespaceObject.isMdAsciiPunct)(nextChar) || (0, utils_mjs_namespaceObject.isPunctChar)(String.fromCodePoint(nextChar));
|
|
79
|
+
const isLastNonCjkPunctChar = isLastPunctChar && !isLastCJKChar;
|
|
80
|
+
const isNextNonCjkPunctChar = isNextPunctChar && !isNextCJKChar;
|
|
73
81
|
const isLastWhiteSpace = (0, utils_mjs_namespaceObject.isWhiteSpace)(lastChar);
|
|
74
82
|
const isNextWhiteSpace = (0, utils_mjs_namespaceObject.isWhiteSpace)(nextChar);
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const adjacentToCjChar = isLastCJKChar || isNextCJKChar;
|
|
78
|
-
const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar || adjacentToCjChar);
|
|
79
|
-
const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar || adjacentToCjChar);
|
|
83
|
+
const left_flanking = !isNextWhiteSpace && (!isNextNonCjkPunctChar || isLastNonCjkPunctChar || isLastWhiteSpace || isLastCJKChar);
|
|
84
|
+
const right_flanking = !isLastWhiteSpace && (!isLastNonCjkPunctChar || isNextWhiteSpace || isNextNonCjkPunctChar || isNextCJKChar);
|
|
80
85
|
const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
|
|
81
86
|
const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
|
|
82
87
|
return {
|
package/dist/index.js
CHANGED
|
@@ -33,20 +33,25 @@ function markdownItCjFriendlyPlugin(md) {
|
|
|
33
33
|
const max = this.posMax;
|
|
34
34
|
const marker = this.src.charCodeAt(start);
|
|
35
35
|
let [lastChar, lastCharPos] = getLastCharCode(this.src, start);
|
|
36
|
-
|
|
36
|
+
let isLastActuallyTwoPrev = false;
|
|
37
|
+
if (maybeHanSVS(lastChar)) {
|
|
38
|
+
[lastChar, lastCharPos] = getLastCharCode(this.src, lastCharPos);
|
|
39
|
+
isLastActuallyTwoPrev = true;
|
|
40
|
+
}
|
|
37
41
|
let pos = start;
|
|
38
42
|
while(pos < max && this.src.charCodeAt(pos) === marker)pos++;
|
|
39
43
|
const count = pos - start;
|
|
40
44
|
const nextChar = pos < max ? this.src.codePointAt(pos) : 0x20;
|
|
45
|
+
const isLastCJKChar = (isLastActuallyTwoPrev ? isCjk : isCjkOrIvs)(lastChar);
|
|
46
|
+
const isNextCJKChar = isCjk(nextChar);
|
|
41
47
|
const isLastPunctChar = (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isMdAsciiPunct)(lastChar) || (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isPunctChar)(String.fromCodePoint(lastChar));
|
|
42
48
|
const isNextPunctChar = (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isMdAsciiPunct)(nextChar) || (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isPunctChar)(String.fromCodePoint(nextChar));
|
|
49
|
+
const isLastNonCjkPunctChar = isLastPunctChar && !isLastCJKChar;
|
|
50
|
+
const isNextNonCjkPunctChar = isNextPunctChar && !isNextCJKChar;
|
|
43
51
|
const isLastWhiteSpace = (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isWhiteSpace)(lastChar);
|
|
44
52
|
const isNextWhiteSpace = (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isWhiteSpace)(nextChar);
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const adjacentToCjChar = isLastCJKChar || isNextCJKChar;
|
|
48
|
-
const left_flanking = !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar || adjacentToCjChar);
|
|
49
|
-
const right_flanking = !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar || adjacentToCjChar);
|
|
53
|
+
const left_flanking = !isNextWhiteSpace && (!isNextNonCjkPunctChar || isLastNonCjkPunctChar || isLastWhiteSpace || isLastCJKChar);
|
|
54
|
+
const right_flanking = !isLastWhiteSpace && (!isLastNonCjkPunctChar || isNextWhiteSpace || isNextNonCjkPunctChar || isNextCJKChar);
|
|
50
55
|
const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
|
|
51
56
|
const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
|
|
52
57
|
return {
|