markdown-it-cjk-friendly 1.0.2 → 1.1.0

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/LICENSE CHANGED
@@ -1,4 +1,8 @@
1
- Copyright (c) 2024 Tatsunori Uchino, and authors and contributors of original packages
1
+ Copyright (c) 2024 Tatsunori Uchino
2
+
3
+ markdown-it:
4
+
5
+ Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
2
6
 
3
7
  Permission is hereby granted, free of charge, to any person
4
8
  obtaining a copy of this software and associated documentation
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # markdown-it-cjk-friendly
2
2
 
3
- [![Version](https://img.shields.io/npm/v/markdown-it-cjk-friendly)](https://npmjs.com/package/markdown-it-cjk-friendly) [![NPM Downloads](https://img.shields.io/npm/dw/markdown-it-cjk-friendly)](https://npmjs.com/package/markdown-it-cjk-friendly) [![NPM Last Update](https://img.shields.io/npm/last-update/markdown-it-cjk-friendly)](https://npmjs.com/package/markdown-it-cjk-friendly)
3
+ [![Version](https://img.shields.io/npm/v/markdown-it-cjk-friendly)](https://npmjs.com/package/markdown-it-cjk-friendly) ![Node Current](https://img.shields.io/node/v/markdown-it-cjk-friendly) [![NPM Downloads](https://img.shields.io/npm/dm/markdown-it-cjk-friendly)](https://npmjs.com/package/markdown-it-cjk-friendly) [![NPM Last Update](https://img.shields.io/npm/last-update/markdown-it-cjk-friendly)](https://npmjs.com/package/markdown-it-cjk-friendly)
4
4
 
5
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
 
@@ -46,23 +46,61 @@ 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
+ ## When should I use this? / <span lang="ja">このパッケージを使うべき場合</span> / <span lang="zh-Hans-CN">何时使用此包</span> / <span lang="ko">이 패키지를 사용하는 시저</span>
50
+
51
+ If you are an engineer who must handle Chinese, Japanese, and Korean content that cannot be fully supervised, it is strongly recommended to use this package (adopt this specification instead of plain CommonMark or GFM). "Cannot be fully supervised" refers to situations such as:
52
+
53
+ 1. When you need to display user-generated or AI-generated content as-is
54
+ 2. When many translators do not understand this CommonMark behavior, and you cannot provide real-time rendering previews similar to production, and `<strong>` tags are not allowed
55
+ - When using translation services like Crowdin or Transifex
56
+ - When the person responsible for translation quality is not an engineer or does not understand this CommonMark behavior
57
+
58
+ Additionally, if you are creating Markdown-related software or services primarily targeting Chinese, Japanese, or Korean users (or all of them), it is strongly recommended to use this package (adopt this specification).
59
+
60
+ <span lang="ja">もしエンジニアであるあなたが全てに監修を入れられない日本語・中国語・韓国語のコンテンツを扱わなければならない場合、このパッケージを使う(素のCommonMarkやGFMではなく、この仕様を採用する)ことを強く推奨します。「全てに監修を入れられない」というのは、例えば次のようなものを指します。</span>
61
+
62
+ 1. <span lang="ja">ユーザまたはAIが作成したコンテンツをそのまま表示する必要がある場合</span>
63
+ 2. <span lang="ja">翻訳者に、このCommonMarkの仕様を理解していない人も多く、なおかつリアルタイムで本番同様の描画プレビューを提供できず、`<strong>`タグを許可していない場合</span>
64
+ - <span lang="ja">翻訳にCrowdin・Transifexなどの翻訳サービスを使っている場合</span>
65
+ - <span lang="ja">翻訳の品質に責任を負っている人が非エンジニアである、またはComonMarkのこの挙動を理解していない場合</span>
66
+
67
+ <span lang="ja">また、あなたが主に日本人・中国人・韓国人のいずれかまたは全てを対象としたMarkdown関連のソフトウェアやサービスを作成する場合も、このパッケージを使う(この仕様を採用する)ことを強く推奨します。</span>
68
+
69
+ <span lang="zh">如果作为工程师的您必须处理无法全面监督的中文、日文和韩文内容,强烈建议使用这个包装(采用此规范,而不是普通的CommonMark或GFM)。"无法全面监督"指的是以下情况:</span>
70
+
71
+ 1. <span lang="zh">当需要按原样显示用户生成或AI生成的内容时</span>
72
+ 2. <span lang="zh">当许多翻译人员不理解这个CommonMark行为,而且无法提供类似生产环境的实时渲染预览,并且不允许使用`<strong>`标签时</span>
73
+ - <span lang="zh">当使用Crowdin或Transifex等翻译服务时</span>
74
+ - <span lang="zh">当负责翻译质量的人不是工程师或不理解这个CommonMark行为时</span>
75
+
76
+ <span lang="zh">此外,如果您正在创建主要面向中国人、日本人或韩国人(或全部)的Markdown相关软件或服务,也强烈建议采用此规范。</span>
77
+
78
+ <span lang="ko">엔지니어로서 완전히 감독할 수 없는 일본어, 중국어, 한국어 콘텐츠를 다뤄야 하는 경우, 이 패키지를 사용하세요 (일반 CommonMark나 GFM 대신 이 사양을 채택할 것을 강력히 권장합니다). "완전히 감독할 수 없는"이란 다음과 같은 상황을 의미합니다:</span>
79
+
80
+ 1. <span lang="ko">사용자 또는 AI가 생성한 콘텐츠를 그대로 표시해야 하는 경우</span>
81
+ 2. <span lang="ko">많은 번역자가 이 CommonMark 동작을 이해하지 못하고, 실시간으로 실제 환경과 유사한 렌더링 미리보기를 제공할 수 없으며, `<strong>` 태그가 허용되지 않는 경우</span>
82
+ - <span lang="ko">Crowdin이나 Transifex 같은 번역 서비스를 사용하는 경우</span>
83
+ - <span lang="ko">번역 품질에 책임을 지는 사람이 엔지니어가 아니거나 이 CommonMark 동작을 이해하지 못하는 경우</span>
84
+
85
+ <span lang="ko">또한, 주로 일본어, 중국어, 한국어 사용자(또는 모두)를 대상으로 하는 Markdown 관련 소프트웨어나 서비스를 만들고 있다면, 이 패키지를 사용하세요 (이 사양을 채택할 것을 강력히 권장합니다).</span>
86
+
49
87
  ## Runtime Requirements / <span lang="ja">実行環境の要件</span> / <span lang="zh-Hans-CN">运行环境要求</span> / <span lang="ko">업데이트 전략</span>
50
88
 
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.
89
+ If you require() this package in a CommonJS environment, it will load another ESM-only package internally. Because of it, Node.js version 20.19, 22.12, 23 or later, and a bundler will be required. If you import this package as ESM, there will be no additional requirements.
52
90
 
53
- <span lang="ja">本パッケージは文字が絵文字かどうかを判定するために、ES2024で導入された[正規表現の`v`フラグ](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)を使用しています。</span>
91
+ <span lang="ja">本パッケージをCommonJS環境でrequire()する場合、内部で別のESM専用パッケージを読み込みます。そのため、require(ESM)に対応したNode.jsのバージョン(20.19 / 22.12 / 23 以上)やバンドラが必要になります。ESMとしてインポートする場合は特に追加の要件はありません。</span>
54
92
 
55
- <span lang="zh-CN">本包使用 ES2024 引入的[`v` 标志](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) 来判断字符是否为 emoji。</span>
93
+ <span lang="zh-Hans-CN">如果您在CommonJS环境中require()此包,它将内部加载另一个仅支持ESM的包。因此,需要使用Node.js版本20.19、22.12、23或更高版本,以及打包工具。如果您以ESM方式导入此包,则没有额外要求。</span>
56
94
 
57
- <span lang="ko">이 패키지는 ES2024에서 도입된 [`v` 플래그](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)를 사용하여 문자가 이모지인지 여부를 판단합니다.</span>
95
+ <span lang="ko">이 패키지를 CommonJS 환경에서 require()할 경우, 내부적으로 ESM 전용 패키지를 로드하게 됩니다. 이로 인해 Node.js 버전 20.19, 22.12, 23 이상 번들러가 필요합니다. ESM으로 이 패키지를 가져올 경우에는 추가 요구사항이 없습니다.</span>
58
96
 
59
- It makes this package compatible only with relatively recent browsers and Node.js:
97
+ This package uses the [`v` flag for regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets) introduced in ES2024, if available, to determine whether a character is an emoji. In the following compatible environments, it will comply with the Unicode version supported by the runtime. Otherwise, it will fall back to the snapshot as of Unicode 16.
60
98
 
61
- <span lang="ja">このため、本パッケージは、次のような比較的新しいブラウザやNode.jsでしか動作しません。</span>
99
+ <span lang="ja">本パッケージは文字が絵文字かどうかを判定するために、ES2024で導入された[正規表現の`v`フラグ](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)が利用可能であれば使用します。以下の対応環境の場合、ランタイムが対応しているUnicodeバージョンに準拠します。それ以外の場合、Unicode 16時点のスナップショットにフォールバックします。</span>
62
100
 
63
- <span lang="zh-CN">因此,本包只兼容比较新的浏览器和 Node.js:</span>
101
+ <span lang="zh-Hans-CN">本包使用ES2024引入的[正则表达式`v`标志](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)(如果可用)来判断字符是否为表情符号。在以下兼容环境中,将遵循运行时支持的Unicode版本。否则,将回退到Unicode 16的快照。</span>
64
102
 
65
- <span lang="ko">따라서, 패키지는 비교적 최신 브라우저와 Node.js에서만 작동합니다.</span>
103
+ <span lang="ko">이 패키지는 문자가 이모지인지 판단하기 위해 ES2024에서 도입된 [정규표현식 `v` 플래그](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicodeSets)를 사용할 수 있다면 사용합니다. 다음 호환 환경에서는 런타임이 지원하는 Unicode 버전을 따릅니다. 그렇지 않은 경우, Unicode 16 시점의 스냅샷으로 폴백합니다.</span>
66
104
 
67
105
  - Chrome / Edge 112 or later
68
106
  - Firefox 116 or later
@@ -109,10 +147,28 @@ const md = MarkdownIt();
109
147
  md.use(markdownItCjkFriendly);
110
148
  ```
111
149
 
150
+ ## Compatibility with the other languages / <span lang="ja">他言語との互換性</span> / <span lang="zh-Hans-CN">与其他语言的兼容性</span> / <span lang="ko">다른 언어와의 호환성</span>
151
+
152
+ This modification of the specification does not affect the other languages than Chinese, Japanese, and Korean. Even if your application or document has translations or content in other languages, it will not be affected, so please feel free to use this packages. I assure that even with this package (amendment suggestion), markdown-it still outputs the same HTML for all CommonMark test cases as of 0.31.2.
153
+
154
+ <span lang="ja">この仕様変更提案は、日本語・中国語・韓国語以外の言語には影響しません。アプリケーションやドキュメントに他言語の翻訳やコンテンツが含まれていても影響はありませんので、安心して本パッケージをご利用ください。本パッケージ(修正案)を使用しても、0.31.2時点の全てのCommonMarkテストケースで、markdown-itが同じHTMLを出力することを保証しています。</span>
155
+
156
+ <span lang="zh-Hans-CN">除中文、日文和韩文外,建议的规范变更不会影响其他语言。请放心使用此软件包,因为如果您的应用程序或文档包含其他语言的翻译或内容,也不会受到影响。我保证,即使使用此软件包(修正建议),markdown-it 仍然会为 0.31.2 版本的所有 CommonMark 测试用例输出相同的 HTML。</span>
157
+
158
+ <span lang="ko">이번 사양 변경 제안은 한국어, 중국어, 일본어 이외의 언어에는 영향을 미치지 않습니다. 애플리케이션이나 문서에 다른 언어의 번역이나 콘텐츠가 포함되어 있어도 영향을 받지 않으므로 안심하고 본 패키지를 사용하시기 바랍니다. 본 패키지(수정안)를 사용해도 0.31.2 시점의 모든 CommonMark 테스트케이스에서 markdown-it가 동일한 HTML을 출력하는 것을 보장합니다.</span>
159
+
112
160
  ## Specification / <span lang="ja">規格書</span> / <span lang="zh-Hans-CN">规范</span> / <span lang="ko">규정서</span>
113
161
 
114
162
  https://github.com/tats-u/markdown-cjk-friendly/blob/main/specification.md (English)
115
163
 
164
+ ## Related packages / <span lang="ja">関連パッケージ</span> / <span lang="zh-Hans-CN">相关包</span> / <span lang="ko">관련 패키지</span>
165
+
166
+ - [remark-cjk-friendly](https://npmjs.com/package/remark-cjk-friendly) [![Version](https://img.shields.io/npm/v/remark-cjk-friendly)](https://npmjs.com/package/remark-cjk-friendly) ![Node Current](https://img.shields.io/node/v/remark-cjk-friendly) [![NPM Downloads](https://img.shields.io/npm/dm/remark-cjk-friendly)](https://npmjs.com/package/remark-cjk-friendly) [![NPM Last Update](https://img.shields.io/npm/last-update/remark-cjk-friendly)](https://npmjs.com/package/remark-cjk-friendly)
167
+ - [micromark-extension-cjk-friendly](https://npmjs.com/package/micromark-extension-cjk-friendly) [![Version](https://img.shields.io/npm/v/micromark-extension-cjk-friendly)](https://npmjs.com/package/micromark-extension-cjk-friendly) ![Node Current](https://img.shields.io/node/v/micromark-extension-cjk-friendly) [![NPM Downloads](https://img.shields.io/npm/dm/micromark-extension-cjk-friendly)](https://npmjs.com/package/micromark-extension-cjk-friendly) [![NPM Last Update](https://img.shields.io/npm/last-update/micromark-extension-cjk-friendly)](https://npmjs.com/package/micromark-extension-cjk-friendly)
168
+ - [remark-cjk-friendly-gfm-strikethrough](https://npmjs.com/package/remark-cjk-friendly-gfm-strikethrough) [![Version](https://img.shields.io/npm/v/remark-cjk-friendly-gfm-strikethrough)](https://npmjs.com/package/remark-cjk-friendly-gfm-strikethrough) ![Node Current](https://img.shields.io/node/v/remark-cjk-friendly-gfm-strikethrough) [![NPM Downloads](https://img.shields.io/npm/dm/remark-cjk-friendly-gfm-strikethrough)](https://npmjs.com/package/remark-cjk-friendly-gfm-strikethrough) [![NPM Last Update](https://img.shields.io/npm/last-update/remark-cjk-friendly-gfm-strikethrough)](https://npmjs.com/package/remark-cjk-friendly-gfm-strikethrough)
169
+ - [micromark-extension-cjk-friendly-gfm-strikethrough](https://npmjs.com/package/micromark-extension-cjk-friendly-gfm-strikethrough) [![Version](https://img.shields.io/npm/v/micromark-extension-cjk-friendly-gfm-strikethrough)](https://npmjs.com/package/micromark-extension-cjk-friendly-gfm-strikethrough) ![Node Current](https://img.shields.io/node/v/micromark-extension-cjk-friendly-gfm-strikethrough) [![NPM Downloads](https://img.shields.io/npm/dm/micromark-extension-cjk-friendly-gfm-strikethrough)](https://npmjs.com/package/micromark-extension-cjk-friendly-gfm-strikethrough) [![NPM Last Update](https://img.shields.io/npm/last-update/micromark-extension-cjk-friendly-gfm-strikethrough)](https://npmjs.com/package/micromark-extension-cjk-friendly-gfm-strikethrough)
170
+
171
+
116
172
  ## Contributing / <span lang="ja">貢献</span> / <span lang="zh-Hans-CN">贡献</span> / <span lang="ko">기여</span>
117
173
 
118
174
  ### Setup
package/dist/index.cjs CHANGED
@@ -1,119 +1,122 @@
1
1
  "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = function(exports1, definition) {
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = function(obj, prop) {
13
- return Object.prototype.hasOwnProperty.call(obj, prop);
14
- };
15
- })();
16
- (()=>{
17
- __webpack_require__.r = function(exports1) {
18
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
19
- value: 'Module'
20
- });
21
- Object.defineProperty(exports1, '__esModule', {
22
- value: true
23
- });
24
- };
25
- })();
26
- var __webpack_exports__ = {};
27
- __webpack_require__.r(__webpack_exports__);
28
- __webpack_require__.d(__webpack_exports__, {
29
- default: ()=>markdownItCjFriendlyPlugin
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => markdownItCjFriendlyPlugin
30
24
  });
31
- const external_get_east_asian_width_namespaceObject = require("get-east-asian-width");
32
- const utils_mjs_namespaceObject = require("markdown-it/lib/common/utils.mjs");
33
- function isCjkBase(uc) {
34
- const eaw = (0, external_get_east_asian_width_namespaceObject.eastAsianWidthType)(uc);
35
- switch(eaw){
36
- case "fullwidth":
37
- case "halfwidth":
38
- return true;
39
- case "wide":
40
- return !/^\p{RGI_Emoji}/v.test(String.fromCodePoint(uc));
41
- case "narrow":
42
- return false;
43
- case "ambiguous":
44
- return 0xe0100 <= uc && uc <= 0xe01ef && null;
45
- case "neutral":
46
- return /^\p{sc=Hangul}/u.test(String.fromCodePoint(uc));
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_get_east_asian_width = require("get-east-asian-width");
27
+ var import_utils = require("markdown-it/lib/common/utils.mjs");
28
+ var isEmoji = function(uc) {
29
+ if (this.fn !== null) {
30
+ return this.fn(uc);
31
+ }
32
+ try {
33
+ const regex = new RegExp("^\\p{RGI_Emoji}", "v");
34
+ this.fn = (uc_) => regex.test(String.fromCodePoint(uc_));
35
+ } catch (e) {
36
+ if (!(e instanceof SyntaxError)) {
37
+ throw e;
47
38
  }
39
+ this.fn = (cp) => 8986 <= cp && cp <= 8987 || 9193 <= cp && cp <= 9196 || cp === 9200 || cp === 9203 || 9725 <= cp && cp <= 9726 || 9748 <= cp && cp <= 9749 || 9800 <= cp && cp <= 9811 || cp === 9855 || cp === 9875 || cp === 9889 || 9898 <= cp && cp <= 9899 || 9917 <= cp && cp <= 9918 || 9924 <= cp && cp <= 9925 || cp === 9934 || cp === 9940 || cp === 9962 || 9970 <= cp && cp <= 9971 || cp === 9973 || cp === 9978 || cp === 9981 || cp === 9989 || 9994 <= cp && cp <= 9995 || cp === 10024 || cp === 10060 || cp === 10062 || 10067 <= cp && cp <= 10069 || cp === 10071 || 10133 <= cp && cp <= 10135 || cp === 10160 || cp === 10175 || 11035 <= cp && cp <= 11036 || cp === 11088 || cp === 11093 || cp === 126980 || cp === 127183 || cp === 127374 || 127377 <= cp && cp <= 127386 || cp === 127489 || cp === 127514 || cp === 127535 || 127538 <= cp && cp <= 127542 || 127544 <= cp && cp <= 127546 || 127568 <= cp && cp <= 127569 || 127744 <= cp && cp <= 127756 || 127757 <= cp && cp <= 127758 || cp === 127759 || cp === 127760 || cp === 127761 || cp === 127762 || 127763 <= cp && cp <= 127765 || 127766 <= cp && cp <= 127768 || cp === 127769 || cp === 127770 || cp === 127771 || cp === 127772 || 127773 <= cp && cp <= 127774 || 127775 <= cp && cp <= 127776 || 127789 <= cp && cp <= 127791 || 127792 <= cp && cp <= 127793 || 127794 <= cp && cp <= 127795 || 127796 <= cp && cp <= 127797 || 127799 <= cp && cp <= 127818 || cp === 127819 || 127820 <= cp && cp <= 127823 || cp === 127824 || 127825 <= cp && cp <= 127867 || cp === 127868 || 127870 <= cp && cp <= 127871 || 127872 <= cp && cp <= 127891 || 127904 <= cp && cp <= 127940 || cp === 127941 || cp === 127942 || cp === 127943 || cp === 127944 || cp === 127945 || cp === 127946 || 127951 <= cp && cp <= 127955 || 127968 <= cp && cp <= 127971 || cp === 127972 || 127973 <= cp && cp <= 127984 || cp === 127988 || 127992 <= cp && cp <= 128007 || cp === 128008 || 128009 <= cp && cp <= 128011 || 128012 <= cp && cp <= 128014 || 128015 <= cp && cp <= 128016 || 128017 <= cp && cp <= 128018 || cp === 128019 || cp === 128020 || cp === 128021 || cp === 128022 || 128023 <= cp && cp <= 128041 || cp === 128042 || 128043 <= cp && cp <= 128062 || cp === 128064 || 128066 <= cp && cp <= 128100 || cp === 128101 || 128102 <= cp && cp <= 128107 || 128108 <= cp && cp <= 128109 || 128110 <= cp && cp <= 128172 || cp === 128173 || 128174 <= cp && cp <= 128181 || 128182 <= cp && cp <= 128183 || 128184 <= cp && cp <= 128235 || 128236 <= cp && cp <= 128237 || cp === 128238 || cp === 128239 || 128240 <= cp && cp <= 128244 || cp === 128245 || 128246 <= cp && cp <= 128247 || cp === 128248 || 128249 <= cp && cp <= 128252 || 128255 <= cp && cp <= 128258 || cp === 128259 || 128260 <= cp && cp <= 128263 || cp === 128264 || cp === 128265 || 128266 <= cp && cp <= 128276 || cp === 128277 || 128278 <= cp && cp <= 128299 || 128300 <= cp && cp <= 128301 || 128302 <= cp && cp <= 128317 || 128331 <= cp && cp <= 128334 || 128336 <= cp && cp <= 128347 || 128348 <= cp && cp <= 128359 || cp === 128378 || 128405 <= cp && cp <= 128406 || cp === 128420 || 128507 <= cp && cp <= 128511 || cp === 128512 || 128513 <= cp && cp <= 128518 || 128519 <= cp && cp <= 128520 || 128521 <= cp && cp <= 128525 || cp === 128526 || cp === 128527 || cp === 128528 || cp === 128529 || 128530 <= cp && cp <= 128532 || cp === 128533 || cp === 128534 || cp === 128535 || cp === 128536 || cp === 128537 || cp === 128538 || cp === 128539 || 128540 <= cp && cp <= 128542 || cp === 128543 || 128544 <= cp && cp <= 128549 || 128550 <= cp && cp <= 128551 || 128552 <= cp && cp <= 128555 || cp === 128556 || cp === 128557 || 128558 <= cp && cp <= 128559 || 128560 <= cp && cp <= 128563 || cp === 128564 || cp === 128565 || cp === 128566 || 128567 <= cp && cp <= 128576 || 128577 <= cp && cp <= 128580 || 128581 <= cp && cp <= 128591 || cp === 128640 || 128641 <= cp && cp <= 128642 || 128643 <= cp && cp <= 128645 || cp === 128646 || cp === 128647 || cp === 128648 || cp === 128649 || 128650 <= cp && cp <= 128651 || cp === 128652 || cp === 128653 || cp === 128654 || cp === 128655 || cp === 128656 || 128657 <= cp && cp <= 128659 || cp === 128660 || cp === 128661 || cp === 128662 || cp === 128663 || cp === 128664 || 128665 <= cp && cp <= 128666 || 128667 <= cp && cp <= 128673 || cp === 128674 || cp === 128675 || 128676 <= cp && cp <= 128677 || cp === 128678 || 128679 <= cp && cp <= 128685 || 128686 <= cp && cp <= 128689 || cp === 128690 || 128691 <= cp && cp <= 128693 || cp === 128694 || 128695 <= cp && cp <= 128696 || 128697 <= cp && cp <= 128702 || cp === 128703 || cp === 128704 || 128705 <= cp && cp <= 128709 || cp === 128716 || cp === 128720 || 128721 <= cp && cp <= 128722 || cp === 128725 || 128726 <= cp && cp <= 128727 || cp === 128732 || 128733 <= cp && cp <= 128735 || 128747 <= cp && cp <= 128748 || 128756 <= cp && cp <= 128758 || 128759 <= cp && cp <= 128760 || cp === 128761 || cp === 128762 || 128763 <= cp && cp <= 128764 || 128992 <= cp && cp <= 129003 || cp === 129008 || cp === 129292 || 129293 <= cp && cp <= 129295 || 129296 <= cp && cp <= 129304 || 129305 <= cp && cp <= 129310 || cp === 129311 || 129312 <= cp && cp <= 129319 || 129320 <= cp && cp <= 129327 || cp === 129328 || 129329 <= cp && cp <= 129330 || 129331 <= cp && cp <= 129338 || 129340 <= cp && cp <= 129342 || cp === 129343 || 129344 <= cp && cp <= 129349 || 129351 <= cp && cp <= 129355 || cp === 129356 || 129357 <= cp && cp <= 129359 || 129360 <= cp && cp <= 129374 || 129375 <= cp && cp <= 129387 || 129388 <= cp && cp <= 129392 || cp === 129393 || cp === 129394 || 129395 <= cp && cp <= 129398 || 129399 <= cp && cp <= 129400 || cp === 129401 || cp === 129402 || cp === 129403 || 129404 <= cp && cp <= 129407 || 129408 <= cp && cp <= 129412 || 129413 <= cp && cp <= 129425 || 129426 <= cp && cp <= 129431 || 129432 <= cp && cp <= 129442 || 129443 <= cp && cp <= 129444 || 129445 <= cp && cp <= 129450 || 129451 <= cp && cp <= 129453 || 129454 <= cp && cp <= 129455 || 129456 <= cp && cp <= 129465 || 129466 <= cp && cp <= 129471 || cp === 129472 || 129473 <= cp && cp <= 129474 || 129475 <= cp && cp <= 129482 || cp === 129483 || cp === 129484 || 129485 <= cp && cp <= 129487 || 129488 <= cp && cp <= 129510 || 129511 <= cp && cp <= 129535 || 129648 <= cp && cp <= 129651 || cp === 129652 || 129653 <= cp && cp <= 129655 || 129656 <= cp && cp <= 129658 || 129659 <= cp && cp <= 129660 || 129664 <= cp && cp <= 129666 || 129667 <= cp && cp <= 129670 || 129671 <= cp && cp <= 129672 || cp === 129673 || cp === 129679 || 129680 <= cp && cp <= 129685 || 129686 <= cp && cp <= 129704 || 129705 <= cp && cp <= 129708 || 129709 <= cp && cp <= 129711 || 129712 <= cp && cp <= 129718 || 129719 <= cp && cp <= 129722 || 129723 <= cp && cp <= 129725 || cp === 129726 || cp === 129727 || 129728 <= cp && cp <= 129730 || 129731 <= cp && cp <= 129733 || cp === 129734 || 129742 <= cp && cp <= 129743 || 129744 <= cp && cp <= 129750 || 129751 <= cp && cp <= 129753 || 129754 <= cp && cp <= 129755 || cp === 129756 || cp === 129759 || 129760 <= cp && cp <= 129767 || cp === 129768 || cp === 129769 || 129776 <= cp && cp <= 129782 || 129783 <= cp && cp <= 129784;
40
+ }
41
+ return this.fn(uc);
42
+ }.bind({
43
+ fn: null
44
+ });
45
+ function isCjkBase(uc) {
46
+ const eaw = (0, import_get_east_asian_width.eastAsianWidthType)(uc);
47
+ switch (eaw) {
48
+ case "fullwidth":
49
+ case "halfwidth":
50
+ return true;
51
+ // never be emoji
52
+ case "wide":
53
+ return !isEmoji(uc);
54
+ case "narrow":
55
+ return false;
56
+ case "ambiguous":
57
+ return 917760 <= uc && uc <= 917999 ? null : false;
58
+ case "neutral":
59
+ return /^\p{sc=Hangul}/u.test(String.fromCodePoint(uc));
60
+ }
48
61
  }
49
62
  function isCjk(uc) {
50
- return isCjkBase(uc) ?? false;
63
+ return isCjkBase(uc) ?? false;
51
64
  }
52
65
  function isCjkOrIvs(uc) {
53
- const raw = isCjkBase(uc);
54
- return null === raw || raw;
66
+ const raw = isCjkBase(uc);
67
+ return raw === null ? true : raw;
55
68
  }
56
69
  function maybeHanSVS(uc) {
57
- return (0xfff0 & uc) === 0xfe00 && (uc >= 0xfe00 && uc <= 0xfe02 || 0xfe0e === uc);
70
+ return (uc & 65520) === 65024 && (uc >= 65024 && uc <= 65026 || uc === 65038);
58
71
  }
59
72
  function markdownItCjFriendlyPlugin(md) {
60
- const PreviousState = md.inline.State;
61
- class CjFriendlyState extends PreviousState {
62
- scanDelims(start, canSplitWord) {
63
- const max = this.posMax;
64
- const marker = this.src.charCodeAt(start);
65
- let [lastChar, lastCharPos] = getLastCharCode(this.src, start);
66
- let isLastActuallyTwoPrev = false;
67
- if (maybeHanSVS(lastChar)) {
68
- [lastChar, lastCharPos] = getLastCharCode(this.src, lastCharPos);
69
- isLastActuallyTwoPrev = true;
70
- }
71
- let pos = start;
72
- while(pos < max && this.src.charCodeAt(pos) === marker)pos++;
73
- const count = pos - start;
74
- const nextChar = pos < max ? this.src.codePointAt(pos) : 0x20;
75
- const isLastCJKChar = (isLastActuallyTwoPrev ? isCjk : isCjkOrIvs)(lastChar);
76
- const isNextCJKChar = isCjk(nextChar);
77
- const isLastPunctChar = (0, utils_mjs_namespaceObject.isMdAsciiPunct)(lastChar) || (0, utils_mjs_namespaceObject.isPunctChar)(String.fromCodePoint(lastChar));
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;
81
- const isLastWhiteSpace = (0, utils_mjs_namespaceObject.isWhiteSpace)(lastChar);
82
- const isNextWhiteSpace = (0, utils_mjs_namespaceObject.isWhiteSpace)(nextChar);
83
- const left_flanking = !isNextWhiteSpace && (!isNextNonCjkPunctChar || isLastNonCjkPunctChar || isLastWhiteSpace || isLastCJKChar);
84
- const right_flanking = !isLastWhiteSpace && (!isLastNonCjkPunctChar || isNextWhiteSpace || isNextNonCjkPunctChar || isNextCJKChar);
85
- const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
86
- const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
87
- return {
88
- can_open,
89
- can_close,
90
- length: count
91
- };
92
- function getLastCharCode(str, pos) {
93
- if (pos <= 0) return [
94
- 0x20,
95
- -1
96
- ];
97
- const charCode = str.charCodeAt(pos - 1);
98
- if ((0xfc00 & charCode) !== 0xdc00) return [
99
- charCode,
100
- pos - 1
101
- ];
102
- const codePoint = str.codePointAt(pos - 2);
103
- return codePoint > 0xffff ? [
104
- codePoint,
105
- pos - 2
106
- ] : [
107
- charCode,
108
- pos - 1
109
- ];
110
- }
73
+ const PreviousState = md.inline.State;
74
+ class CjFriendlyState extends PreviousState {
75
+ scanDelims(start, canSplitWord) {
76
+ const max = this.posMax;
77
+ const marker = this.src.charCodeAt(start);
78
+ let [lastChar, lastCharPos] = getLastCharCode(this.src, start);
79
+ let isLastActuallyTwoPrev = false;
80
+ if (maybeHanSVS(lastChar)) {
81
+ [lastChar, lastCharPos] = getLastCharCode(this.src, lastCharPos);
82
+ isLastActuallyTwoPrev = true;
83
+ }
84
+ let pos = start;
85
+ while (pos < max && this.src.charCodeAt(pos) === marker) {
86
+ pos++;
87
+ }
88
+ const count = pos - start;
89
+ const nextChar = pos < max ? this.src.codePointAt(pos) : 32;
90
+ const isLastCJKChar = (isLastActuallyTwoPrev ? isCjk : isCjkOrIvs)(
91
+ lastChar
92
+ );
93
+ const isNextCJKChar = isCjk(nextChar);
94
+ const isLastPunctChar = (0, import_utils.isMdAsciiPunct)(lastChar) || (0, import_utils.isPunctChar)(String.fromCodePoint(lastChar));
95
+ const isNextPunctChar = (0, import_utils.isMdAsciiPunct)(nextChar) || (0, import_utils.isPunctChar)(String.fromCodePoint(nextChar));
96
+ const isLastNonCjkPunctChar = isLastPunctChar && !isLastCJKChar;
97
+ const isNextNonCjkPunctChar = isNextPunctChar && !isNextCJKChar;
98
+ const isLastWhiteSpace = (0, import_utils.isWhiteSpace)(lastChar);
99
+ const isNextWhiteSpace = (0, import_utils.isWhiteSpace)(nextChar);
100
+ const left_flanking = !isNextWhiteSpace && (!isNextNonCjkPunctChar || isLastNonCjkPunctChar || isLastWhiteSpace || isLastCJKChar);
101
+ const right_flanking = !isLastWhiteSpace && (!isLastNonCjkPunctChar || isNextWhiteSpace || isNextNonCjkPunctChar || isNextCJKChar);
102
+ const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
103
+ const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
104
+ return { can_open, can_close, length: count };
105
+ function getLastCharCode(str, pos2) {
106
+ if (pos2 <= 0) {
107
+ return [32, -1];
111
108
  }
109
+ const charCode = str.charCodeAt(pos2 - 1);
110
+ if ((charCode & 64512) !== 56320) {
111
+ return [charCode, pos2 - 1];
112
+ }
113
+ const codePoint = str.codePointAt(pos2 - 2);
114
+ return codePoint > 65535 ? (
115
+ // biome-ignore lint/style/noNonNullAssertion: ditto
116
+ [codePoint, pos2 - 2]
117
+ ) : [charCode, pos2 - 1];
118
+ }
112
119
  }
113
- md.inline.State = CjFriendlyState;
120
+ }
121
+ md.inline.State = CjFriendlyState;
114
122
  }
115
- var __webpack_export_target__ = exports;
116
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
117
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
118
- value: true
119
- });
@@ -0,0 +1,5 @@
1
+ import MarkdownIt from 'markdown-it';
2
+
3
+ declare function markdownItCjFriendlyPlugin(md: MarkdownIt): void;
4
+
5
+ export { markdownItCjFriendlyPlugin as default };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- import type MarkdownIt from "markdown-it";
2
- export default function markdownItCjFriendlyPlugin(md: MarkdownIt): void;
1
+ import MarkdownIt from 'markdown-it';
2
+
3
+ declare function markdownItCjFriendlyPlugin(md: MarkdownIt): void;
4
+
5
+ export { markdownItCjFriendlyPlugin as default };
package/dist/index.js CHANGED
@@ -1,85 +1,105 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_get_east_asian_width_c890dec0__ from "get-east-asian-width";
2
- import * as __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__ from "markdown-it/lib/common/utils.mjs";
3
- function isCjkBase(uc) {
4
- const eaw = (0, __WEBPACK_EXTERNAL_MODULE_get_east_asian_width_c890dec0__.eastAsianWidthType)(uc);
5
- switch(eaw){
6
- case "fullwidth":
7
- case "halfwidth":
8
- return true;
9
- case "wide":
10
- return !/^\p{RGI_Emoji}/v.test(String.fromCodePoint(uc));
11
- case "narrow":
12
- return false;
13
- case "ambiguous":
14
- return 0xe0100 <= uc && uc <= 0xe01ef && null;
15
- case "neutral":
16
- return /^\p{sc=Hangul}/u.test(String.fromCodePoint(uc));
1
+ // src/index.ts
2
+ import { eastAsianWidthType } from "get-east-asian-width";
3
+ import {
4
+ isMdAsciiPunct,
5
+ isPunctChar,
6
+ isWhiteSpace
7
+ } from "markdown-it/lib/common/utils.mjs";
8
+ var isEmoji = function(uc) {
9
+ if (this.fn !== null) {
10
+ return this.fn(uc);
11
+ }
12
+ try {
13
+ const regex = new RegExp("^\\p{RGI_Emoji}", "v");
14
+ this.fn = (uc_) => regex.test(String.fromCodePoint(uc_));
15
+ } catch (e) {
16
+ if (!(e instanceof SyntaxError)) {
17
+ throw e;
17
18
  }
19
+ this.fn = (cp) => 8986 <= cp && cp <= 8987 || 9193 <= cp && cp <= 9196 || cp === 9200 || cp === 9203 || 9725 <= cp && cp <= 9726 || 9748 <= cp && cp <= 9749 || 9800 <= cp && cp <= 9811 || cp === 9855 || cp === 9875 || cp === 9889 || 9898 <= cp && cp <= 9899 || 9917 <= cp && cp <= 9918 || 9924 <= cp && cp <= 9925 || cp === 9934 || cp === 9940 || cp === 9962 || 9970 <= cp && cp <= 9971 || cp === 9973 || cp === 9978 || cp === 9981 || cp === 9989 || 9994 <= cp && cp <= 9995 || cp === 10024 || cp === 10060 || cp === 10062 || 10067 <= cp && cp <= 10069 || cp === 10071 || 10133 <= cp && cp <= 10135 || cp === 10160 || cp === 10175 || 11035 <= cp && cp <= 11036 || cp === 11088 || cp === 11093 || cp === 126980 || cp === 127183 || cp === 127374 || 127377 <= cp && cp <= 127386 || cp === 127489 || cp === 127514 || cp === 127535 || 127538 <= cp && cp <= 127542 || 127544 <= cp && cp <= 127546 || 127568 <= cp && cp <= 127569 || 127744 <= cp && cp <= 127756 || 127757 <= cp && cp <= 127758 || cp === 127759 || cp === 127760 || cp === 127761 || cp === 127762 || 127763 <= cp && cp <= 127765 || 127766 <= cp && cp <= 127768 || cp === 127769 || cp === 127770 || cp === 127771 || cp === 127772 || 127773 <= cp && cp <= 127774 || 127775 <= cp && cp <= 127776 || 127789 <= cp && cp <= 127791 || 127792 <= cp && cp <= 127793 || 127794 <= cp && cp <= 127795 || 127796 <= cp && cp <= 127797 || 127799 <= cp && cp <= 127818 || cp === 127819 || 127820 <= cp && cp <= 127823 || cp === 127824 || 127825 <= cp && cp <= 127867 || cp === 127868 || 127870 <= cp && cp <= 127871 || 127872 <= cp && cp <= 127891 || 127904 <= cp && cp <= 127940 || cp === 127941 || cp === 127942 || cp === 127943 || cp === 127944 || cp === 127945 || cp === 127946 || 127951 <= cp && cp <= 127955 || 127968 <= cp && cp <= 127971 || cp === 127972 || 127973 <= cp && cp <= 127984 || cp === 127988 || 127992 <= cp && cp <= 128007 || cp === 128008 || 128009 <= cp && cp <= 128011 || 128012 <= cp && cp <= 128014 || 128015 <= cp && cp <= 128016 || 128017 <= cp && cp <= 128018 || cp === 128019 || cp === 128020 || cp === 128021 || cp === 128022 || 128023 <= cp && cp <= 128041 || cp === 128042 || 128043 <= cp && cp <= 128062 || cp === 128064 || 128066 <= cp && cp <= 128100 || cp === 128101 || 128102 <= cp && cp <= 128107 || 128108 <= cp && cp <= 128109 || 128110 <= cp && cp <= 128172 || cp === 128173 || 128174 <= cp && cp <= 128181 || 128182 <= cp && cp <= 128183 || 128184 <= cp && cp <= 128235 || 128236 <= cp && cp <= 128237 || cp === 128238 || cp === 128239 || 128240 <= cp && cp <= 128244 || cp === 128245 || 128246 <= cp && cp <= 128247 || cp === 128248 || 128249 <= cp && cp <= 128252 || 128255 <= cp && cp <= 128258 || cp === 128259 || 128260 <= cp && cp <= 128263 || cp === 128264 || cp === 128265 || 128266 <= cp && cp <= 128276 || cp === 128277 || 128278 <= cp && cp <= 128299 || 128300 <= cp && cp <= 128301 || 128302 <= cp && cp <= 128317 || 128331 <= cp && cp <= 128334 || 128336 <= cp && cp <= 128347 || 128348 <= cp && cp <= 128359 || cp === 128378 || 128405 <= cp && cp <= 128406 || cp === 128420 || 128507 <= cp && cp <= 128511 || cp === 128512 || 128513 <= cp && cp <= 128518 || 128519 <= cp && cp <= 128520 || 128521 <= cp && cp <= 128525 || cp === 128526 || cp === 128527 || cp === 128528 || cp === 128529 || 128530 <= cp && cp <= 128532 || cp === 128533 || cp === 128534 || cp === 128535 || cp === 128536 || cp === 128537 || cp === 128538 || cp === 128539 || 128540 <= cp && cp <= 128542 || cp === 128543 || 128544 <= cp && cp <= 128549 || 128550 <= cp && cp <= 128551 || 128552 <= cp && cp <= 128555 || cp === 128556 || cp === 128557 || 128558 <= cp && cp <= 128559 || 128560 <= cp && cp <= 128563 || cp === 128564 || cp === 128565 || cp === 128566 || 128567 <= cp && cp <= 128576 || 128577 <= cp && cp <= 128580 || 128581 <= cp && cp <= 128591 || cp === 128640 || 128641 <= cp && cp <= 128642 || 128643 <= cp && cp <= 128645 || cp === 128646 || cp === 128647 || cp === 128648 || cp === 128649 || 128650 <= cp && cp <= 128651 || cp === 128652 || cp === 128653 || cp === 128654 || cp === 128655 || cp === 128656 || 128657 <= cp && cp <= 128659 || cp === 128660 || cp === 128661 || cp === 128662 || cp === 128663 || cp === 128664 || 128665 <= cp && cp <= 128666 || 128667 <= cp && cp <= 128673 || cp === 128674 || cp === 128675 || 128676 <= cp && cp <= 128677 || cp === 128678 || 128679 <= cp && cp <= 128685 || 128686 <= cp && cp <= 128689 || cp === 128690 || 128691 <= cp && cp <= 128693 || cp === 128694 || 128695 <= cp && cp <= 128696 || 128697 <= cp && cp <= 128702 || cp === 128703 || cp === 128704 || 128705 <= cp && cp <= 128709 || cp === 128716 || cp === 128720 || 128721 <= cp && cp <= 128722 || cp === 128725 || 128726 <= cp && cp <= 128727 || cp === 128732 || 128733 <= cp && cp <= 128735 || 128747 <= cp && cp <= 128748 || 128756 <= cp && cp <= 128758 || 128759 <= cp && cp <= 128760 || cp === 128761 || cp === 128762 || 128763 <= cp && cp <= 128764 || 128992 <= cp && cp <= 129003 || cp === 129008 || cp === 129292 || 129293 <= cp && cp <= 129295 || 129296 <= cp && cp <= 129304 || 129305 <= cp && cp <= 129310 || cp === 129311 || 129312 <= cp && cp <= 129319 || 129320 <= cp && cp <= 129327 || cp === 129328 || 129329 <= cp && cp <= 129330 || 129331 <= cp && cp <= 129338 || 129340 <= cp && cp <= 129342 || cp === 129343 || 129344 <= cp && cp <= 129349 || 129351 <= cp && cp <= 129355 || cp === 129356 || 129357 <= cp && cp <= 129359 || 129360 <= cp && cp <= 129374 || 129375 <= cp && cp <= 129387 || 129388 <= cp && cp <= 129392 || cp === 129393 || cp === 129394 || 129395 <= cp && cp <= 129398 || 129399 <= cp && cp <= 129400 || cp === 129401 || cp === 129402 || cp === 129403 || 129404 <= cp && cp <= 129407 || 129408 <= cp && cp <= 129412 || 129413 <= cp && cp <= 129425 || 129426 <= cp && cp <= 129431 || 129432 <= cp && cp <= 129442 || 129443 <= cp && cp <= 129444 || 129445 <= cp && cp <= 129450 || 129451 <= cp && cp <= 129453 || 129454 <= cp && cp <= 129455 || 129456 <= cp && cp <= 129465 || 129466 <= cp && cp <= 129471 || cp === 129472 || 129473 <= cp && cp <= 129474 || 129475 <= cp && cp <= 129482 || cp === 129483 || cp === 129484 || 129485 <= cp && cp <= 129487 || 129488 <= cp && cp <= 129510 || 129511 <= cp && cp <= 129535 || 129648 <= cp && cp <= 129651 || cp === 129652 || 129653 <= cp && cp <= 129655 || 129656 <= cp && cp <= 129658 || 129659 <= cp && cp <= 129660 || 129664 <= cp && cp <= 129666 || 129667 <= cp && cp <= 129670 || 129671 <= cp && cp <= 129672 || cp === 129673 || cp === 129679 || 129680 <= cp && cp <= 129685 || 129686 <= cp && cp <= 129704 || 129705 <= cp && cp <= 129708 || 129709 <= cp && cp <= 129711 || 129712 <= cp && cp <= 129718 || 129719 <= cp && cp <= 129722 || 129723 <= cp && cp <= 129725 || cp === 129726 || cp === 129727 || 129728 <= cp && cp <= 129730 || 129731 <= cp && cp <= 129733 || cp === 129734 || 129742 <= cp && cp <= 129743 || 129744 <= cp && cp <= 129750 || 129751 <= cp && cp <= 129753 || 129754 <= cp && cp <= 129755 || cp === 129756 || cp === 129759 || 129760 <= cp && cp <= 129767 || cp === 129768 || cp === 129769 || 129776 <= cp && cp <= 129782 || 129783 <= cp && cp <= 129784;
20
+ }
21
+ return this.fn(uc);
22
+ }.bind({
23
+ fn: null
24
+ });
25
+ function isCjkBase(uc) {
26
+ const eaw = eastAsianWidthType(uc);
27
+ switch (eaw) {
28
+ case "fullwidth":
29
+ case "halfwidth":
30
+ return true;
31
+ // never be emoji
32
+ case "wide":
33
+ return !isEmoji(uc);
34
+ case "narrow":
35
+ return false;
36
+ case "ambiguous":
37
+ return 917760 <= uc && uc <= 917999 ? null : false;
38
+ case "neutral":
39
+ return /^\p{sc=Hangul}/u.test(String.fromCodePoint(uc));
40
+ }
18
41
  }
19
42
  function isCjk(uc) {
20
- return isCjkBase(uc) ?? false;
43
+ return isCjkBase(uc) ?? false;
21
44
  }
22
45
  function isCjkOrIvs(uc) {
23
- const raw = isCjkBase(uc);
24
- return null === raw || raw;
46
+ const raw = isCjkBase(uc);
47
+ return raw === null ? true : raw;
25
48
  }
26
49
  function maybeHanSVS(uc) {
27
- return (0xfff0 & uc) === 0xfe00 && (uc >= 0xfe00 && uc <= 0xfe02 || 0xfe0e === uc);
50
+ return (uc & 65520) === 65024 && (uc >= 65024 && uc <= 65026 || uc === 65038);
28
51
  }
29
52
  function markdownItCjFriendlyPlugin(md) {
30
- const PreviousState = md.inline.State;
31
- class CjFriendlyState extends PreviousState {
32
- scanDelims(start, canSplitWord) {
33
- const max = this.posMax;
34
- const marker = this.src.charCodeAt(start);
35
- let [lastChar, lastCharPos] = getLastCharCode(this.src, start);
36
- let isLastActuallyTwoPrev = false;
37
- if (maybeHanSVS(lastChar)) {
38
- [lastChar, lastCharPos] = getLastCharCode(this.src, lastCharPos);
39
- isLastActuallyTwoPrev = true;
40
- }
41
- let pos = start;
42
- while(pos < max && this.src.charCodeAt(pos) === marker)pos++;
43
- const count = pos - start;
44
- const nextChar = pos < max ? this.src.codePointAt(pos) : 0x20;
45
- const isLastCJKChar = (isLastActuallyTwoPrev ? isCjk : isCjkOrIvs)(lastChar);
46
- const isNextCJKChar = isCjk(nextChar);
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));
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;
51
- const isLastWhiteSpace = (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isWhiteSpace)(lastChar);
52
- const isNextWhiteSpace = (0, __WEBPACK_EXTERNAL_MODULE_markdown_it_lib_common_utils_mjs_c48a6852__.isWhiteSpace)(nextChar);
53
- const left_flanking = !isNextWhiteSpace && (!isNextNonCjkPunctChar || isLastNonCjkPunctChar || isLastWhiteSpace || isLastCJKChar);
54
- const right_flanking = !isLastWhiteSpace && (!isLastNonCjkPunctChar || isNextWhiteSpace || isNextNonCjkPunctChar || isNextCJKChar);
55
- const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
56
- const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
57
- return {
58
- can_open,
59
- can_close,
60
- length: count
61
- };
62
- function getLastCharCode(str, pos) {
63
- if (pos <= 0) return [
64
- 0x20,
65
- -1
66
- ];
67
- const charCode = str.charCodeAt(pos - 1);
68
- if ((0xfc00 & charCode) !== 0xdc00) return [
69
- charCode,
70
- pos - 1
71
- ];
72
- const codePoint = str.codePointAt(pos - 2);
73
- return codePoint > 0xffff ? [
74
- codePoint,
75
- pos - 2
76
- ] : [
77
- charCode,
78
- pos - 1
79
- ];
80
- }
53
+ const PreviousState = md.inline.State;
54
+ class CjFriendlyState extends PreviousState {
55
+ scanDelims(start, canSplitWord) {
56
+ const max = this.posMax;
57
+ const marker = this.src.charCodeAt(start);
58
+ let [lastChar, lastCharPos] = getLastCharCode(this.src, start);
59
+ let isLastActuallyTwoPrev = false;
60
+ if (maybeHanSVS(lastChar)) {
61
+ [lastChar, lastCharPos] = getLastCharCode(this.src, lastCharPos);
62
+ isLastActuallyTwoPrev = true;
63
+ }
64
+ let pos = start;
65
+ while (pos < max && this.src.charCodeAt(pos) === marker) {
66
+ pos++;
67
+ }
68
+ const count = pos - start;
69
+ const nextChar = pos < max ? this.src.codePointAt(pos) : 32;
70
+ const isLastCJKChar = (isLastActuallyTwoPrev ? isCjk : isCjkOrIvs)(
71
+ lastChar
72
+ );
73
+ const isNextCJKChar = isCjk(nextChar);
74
+ const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(String.fromCodePoint(lastChar));
75
+ const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(String.fromCodePoint(nextChar));
76
+ const isLastNonCjkPunctChar = isLastPunctChar && !isLastCJKChar;
77
+ const isNextNonCjkPunctChar = isNextPunctChar && !isNextCJKChar;
78
+ const isLastWhiteSpace = isWhiteSpace(lastChar);
79
+ const isNextWhiteSpace = isWhiteSpace(nextChar);
80
+ const left_flanking = !isNextWhiteSpace && (!isNextNonCjkPunctChar || isLastNonCjkPunctChar || isLastWhiteSpace || isLastCJKChar);
81
+ const right_flanking = !isLastWhiteSpace && (!isLastNonCjkPunctChar || isNextWhiteSpace || isNextNonCjkPunctChar || isNextCJKChar);
82
+ const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar);
83
+ const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar);
84
+ return { can_open, can_close, length: count };
85
+ function getLastCharCode(str, pos2) {
86
+ if (pos2 <= 0) {
87
+ return [32, -1];
88
+ }
89
+ const charCode = str.charCodeAt(pos2 - 1);
90
+ if ((charCode & 64512) !== 56320) {
91
+ return [charCode, pos2 - 1];
81
92
  }
93
+ const codePoint = str.codePointAt(pos2 - 2);
94
+ return codePoint > 65535 ? (
95
+ // biome-ignore lint/style/noNonNullAssertion: ditto
96
+ [codePoint, pos2 - 2]
97
+ ) : [charCode, pos2 - 1];
98
+ }
82
99
  }
83
- md.inline.State = CjFriendlyState;
100
+ }
101
+ md.inline.State = CjFriendlyState;
84
102
  }
85
- export { markdownItCjFriendlyPlugin as default };
103
+ export {
104
+ markdownItCjFriendlyPlugin as default
105
+ };
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "markdown-it-cjk-friendly",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
8
- "import": "./dist/index.js",
9
8
  "module-sync": "./dist/index.js",
10
- "require": "./dist/index.cjs"
9
+ "import": "./dist/index.js",
10
+ "node": "./dist/index.cjs",
11
+ "default": "./dist/index.js"
11
12
  }
12
13
  },
13
14
  "main": "./dist/index.cjs",
14
15
  "module": "./dist/index.js",
15
16
  "types": "./dist/index.d.ts",
16
- "files": ["dist", "LICENSE", "README.md"],
17
+ "files": [
18
+ "dist",
19
+ "LICENSE",
20
+ "README.md"
21
+ ],
17
22
  "repository": {
18
23
  "url": "https://github.com/tats-u/markdown-cjk-friendly"
19
24
  },
@@ -31,17 +36,7 @@
31
36
  ],
32
37
  "description": "markdown-it plugin to make Markdown emphasis (`**`) in CommonMark more friendly with Chinese, Japanese, and Korean (CJK)",
33
38
  "sideEffects": false,
34
- "scripts": {
35
- "build": "rslib build",
36
- "dev": "rslib build --watch",
37
- "test": "vitest --run",
38
- "test:up": "vitest -u",
39
- "test:watch": "vitest watch",
40
- "lint:type": "tsc --noEmit",
41
- "prepack": "node -e \"require('fs').cpSync('../../LICENSE', './LICENSE')\""
42
- },
43
39
  "devDependencies": {
44
- "@rslib/core": "^0.3.1",
45
40
  "@types/markdown-it": "^14.1.2",
46
41
  "markdown-it": "^14.1.0"
47
42
  },
@@ -58,6 +53,22 @@
58
53
  "get-east-asian-width": "^1.3.0"
59
54
  },
60
55
  "engines": {
61
- "node": ">=20"
56
+ "node": ">=16"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "build:lib": "tsup",
61
+ "build:rslib": "rslib build",
62
+ "dev": "tsup --watch",
63
+ "dev:lib": "tsup --watch",
64
+ "dev:rslib": "rslib build --watch",
65
+ "test": "vitest run",
66
+ "test:lib": "vitest run",
67
+ "test:up": "vitest -u",
68
+ "test:watch": "vitest watch",
69
+ "test:lib:watch": "vitest watch",
70
+ "bench": "vitest bench --run",
71
+ "bench:watch": "vitest bench",
72
+ "lint:type": "tsc --noEmit"
62
73
  }
63
- }
74
+ }