@peaceroad/markdown-it-strong-ja 0.6.1 → 0.7.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/README.md CHANGED
@@ -18,80 +18,65 @@ md.render('HTMLは*「HyperText Markup Language」*の略です。')
18
18
  // <p>HTMLは<em>「HyperText Markup Language」</em>の略です。</p>
19
19
  ```
20
20
 
21
- Notice. Basically, it is assumed that you will use markdown-it-attrs in conjunction with this. If you do not use it, please use `use(mditStrongJa, {mditAttrs: false})`.
21
+ Note: this plugin assumes `markdown-it-attrs` is used. If you do not use it, pass `use(mditStrongJa, { mditAttrs: false })`.
22
22
 
23
23
  ### How this differs from vanilla markdown-it
24
24
 
25
- Default output pairs `*` / `**` as it scans left-to-right: when a line contains Japanese (hiragana / katakana / kanji / fullwidth punctuation), japanese-only mode treats the leading `**` aggressively; English-only lines follow markdown-it style pairing. Pick one mode for the examples below:
25
+ Default output pairs `*` / `**` as it scans left-to-right: when a line contains Japanese (hiragana / katakana / kanji (Han) / fullwidth punctuation), japanese mode treats the leading `**` aggressively; English-only lines follow markdown-it style pairing. Pick one mode for the examples below:
26
26
 
27
- - `mode: 'japanese-only'` (default) … Japanese ⇒ aggressive, English-only ⇒ markdown-it compatible
27
+ - `mode: 'japanese'` (default, alias: `'japanese-only'`) … Japanese ⇒ aggressive, English-only ⇒ markdown-it compatible
28
28
  - `mode: 'aggressive'` … always aggressive (lead `**` pairs greedily)
29
29
  - `mode: 'compatible'` … markdown-it compatible (lead `**` stays literal)
30
30
 
31
31
  ```js
32
- const mdDefault = mdit().use(mditStrongJa) // mode: 'japanese-only'
32
+ const mdDefault = mdit().use(mditStrongJa) // mode: 'japanese'
33
33
  const mdCompat = mdit().use(mditStrongJa, { mode: 'compatible' }) // markdown-it pairing
34
34
  const mdAggressive = mdit().use(mditStrongJa, { mode: 'aggressive' }) // always pair leading **
35
35
  ```
36
36
 
37
- Default (japanese-only) pairs aggressively only when Japanese is present. Aggressive always pairs the leading `**`, and compatible matches markdown-it.
37
+ Default (japanese) pairs aggressively only when Japanese is present in the paragraph (the full inline content); detection is not line-by-line. Aggressive always pairs the leading `**`, and compatible matches markdown-it. Detection keys off hiragana/katakana/kanji (Han) and fullwidth punctuation; it does not treat Hangul as Japanese, so it is not full CJK detection.
38
38
 
39
- Japanese-first pairing around punctuation and mixed sentences: leading/trailing Japanese quotes or brackets (`「`, `」`, `(`, `、` etc.) are wrapped even when the same pattern would stay literal in markdown-it. Mixed sentences here mean one line that contains multiple `*` runs; Japanese text keeps the leading `**` aggressive, while English-only stays compatible unless you pick aggressive mode.
39
+ Quick mode guide:
40
+ - Pick `compatible` for markdown-it behavior everywhere.
41
+ - Pick `japanese` to be aggressive only when Japanese text is present.
42
+ - Pick `aggressive` if you want leading `**` to always pair.
40
43
 
41
- - Punctuation:
44
+ Japanese-first pairing around punctuation and mixed sentences: leading/trailing Japanese quotes or brackets (`「`, `」`, `(`, `、` etc.) are wrapped in Japanese paragraphs. Mixed sentences here mean one paragraph that contains multiple `*` runs; Japanese text keeps the leading `**` aggressive, while English-only stays compatible unless you pick aggressive mode.
45
+
46
+ - Punctuation (Japanese quotes / fullwidth punctuation):
42
47
  - Input: `**「test」**`
43
- - Output (default): `<p><strong>「test」</strong></p>`
44
- - Output (aggressive): `<p><strong>「test」</strong></p>`
45
- - Output (compatible): `<p>**「test」**</p>`
48
+ - Output (default/aggressive/compatible/markdown-it): `<p><strong>「test」</strong></p>`
49
+ - Input: `これは**「test」**です`
50
+ - Output (default/aggressive): `<p>これは<strong>「test」</strong>です</p>`
51
+ - Output (compatible/markdown-it): `<p>これは**「test」**です</p>`
46
52
 
47
53
  - Mixed sentence (multiple `*` runs): English-only stays markdown-it compatible unless you pick aggressive mode; earlier `**` runs can remain literal while later ones pair.
48
54
  - Input (Japanese mixed): `**あああ。**iii**`
49
- - Output (default): `<p><strong>あああ。</strong>iii**</p>`
50
- - Output (aggressive): `<p><strong>あああ。</strong>iii**</p>`
51
- - Output (compatible): `<p>**あああ。<strong>iii</strong></p>`
55
+ - Output (default/aggressive): `<p><strong>あああ。</strong>iii**</p>`
56
+ - Output (compatible/markdown-it): `<p>**あああ。<strong>iii</strong></p>`
52
57
  - Input (English-only): `**aaa.**iii**`
53
- - Output (default): `<p>**aaa.<strong>iii</strong></p>`
54
58
  - Output (aggressive): `<p><strong>aaa.</strong>iii**</p>`
55
- - Output (compatible): `<p>**aaa.<strong>iii</strong></p>`
59
+ - Output (default/compatible/markdown-it): `<p>**aaa.<strong>iii</strong></p>`
56
60
  - Input (English-only, two `**` runs): `**aaa.**eee.**eeee**`
57
- - Output (default): `<p>**aaa.**eee.<strong>eeee</strong></p>`
58
61
  - Output (aggressive): `<p><strong>aaa.</strong>eee.<strong>eeee</strong></p>`
59
- - Output (compatible): `<p>**aaa.**eee.<strong>eeee</strong></p>`
62
+ - Output (default/compatible/markdown-it): `<p>**aaa.**eee.<strong>eeee</strong></p>`
60
63
 
61
64
  Inline link/HTML/code blocks stay intact (see Link / Inline code examples above): the plugin re-wraps `[label](url)` / `[label][]` after pairing to avoid broken emphasis tokens around anchors, inline HTML, or inline code. This also covers clusters of `*` with no spaces around the link or code span.
62
65
 
63
66
  - Link (cluster of `*` without spaces):
64
67
  - Input (English-only): `string**[text](url)**`
65
- - Output (default): `<p>string**<a href="url">text</a>**</p>`
66
68
  - Output (aggressive): `<p>string<strong><a href="url">text</a></strong></p>`
67
- - Output (compatible): `<p>string**<a href="url">text</a>**</p>`
69
+ - Output (default/compatible/markdown-it): `<p>string**<a href="url">text</a>**</p>`
68
70
  - Input (Japanese mixed): `これは**[text](url)**です`
69
71
  - Output (default/aggressive): `<p>これは<strong><a href="url">text</a></strong>です</p>`
70
- - Output (compatible): `<p>これは**<a href="url">text</a>**です</p>`
72
+ - Output (compatible/markdown-it): `<p>これは**<a href="url">text</a>**です</p>`
71
73
  - Inline code (cluster of `*` without spaces):
72
74
  - Input (English-only): `` **aa`code`**aa ``
73
- - Output (default): `<p>**aa<code>code</code>**aa</p>`
74
75
  - Output (aggressive): `<p><strong>aa<code>code</code></strong>aa</p>`
75
- - Output (compatible): `<p>**aa<code>code</code>**aa</p>`
76
+ - Output (default/compatible/markdown-it): `<p>**aa<code>code</code>**aa</p>`
76
77
  - Input (Japanese mixed): `` これは**`code`**です ``
77
78
  - Output (default/aggressive): `<p>これは<strong><code>code</code></strong>です</p>`
78
- - Output (compatible): `<p>これは**<code>code</code>**です</p>`
79
-
80
- ### Known differences from vanilla markdown-it
81
-
82
- This section collects other cases that diverge from vanilla markdown-it.
83
-
84
- The plugin keeps pairing aggressively in Japanese contexts, which can diverge from markdown-it when markup spans newlines or mixes nested markers.
85
-
86
- - Multiline + nested emphasis (markdown-it leaves trailing `**`):
87
-
88
- ```markdown
89
- ***強調と*入れ子*の検証***を行う。
90
- ```
91
-
92
- - markdown-it: `<p><em><em><em>強調と</em>入れ子</em>の検証</em>**を行う。</p>`
93
- - markdown-it-strong-ja (default/aggressive): `<p><em><strong>強調と<em>入れ子</em>の検証</strong></em>を行う。</p>`
94
- - If you want markdown-it behavior here, use `mode: 'compatible'`.
79
+ - Output (compatible/markdown-it): `<p>これは**<code>code</code>**です</p>`
95
80
 
96
81
  Notice. The plugin keeps inline HTML / angle-bracket regions intact so rendered HTML keeps correct nesting (for example, it avoids mis-nesting in inputs like `**aaa<code>**bbb</code>` when HTML output is enabled).
97
82
 
@@ -99,7 +84,7 @@ Notice. The plugin keeps inline HTML / angle-bracket regions intact so rendered
99
84
 
100
85
  ## Example
101
86
 
102
- The following examples is for strong. The process for em is roughly the same.
87
+ The following examples are for strong. The process for em is roughly the same.
103
88
 
104
89
  ````markdown
105
90
  [Markdown]
@@ -220,6 +205,11 @@ HTMLは**「HyperText Markup Language」**。
220
205
  [HTML]
221
206
  <p>HTMLは<strong>「HyperText Markup Language」</strong>。</p>
222
207
 
208
+ [Markdown]
209
+ ***強調と*入れ子*の検証***を行う。
210
+ [HTML]
211
+ <p><em><em><em>強調と</em>入れ子</em>の検証</em>**を行う。</p>
212
+
223
213
  [Markdown]
224
214
  ****
225
215
  [HTML]
@@ -237,13 +227,9 @@ a****
237
227
  ````
238
228
 
239
229
 
240
- ### disallowMixed (legacy)
241
-
242
- `disallowMixed: true` is kept for back-compat: it forces compatible pairing for English/mixed contexts that contain markdown links, HTML tags, inline code, or math expressions while staying aggressive for Japanese-only text. Prefer `mode` for new setups; enable this only if you need the legacy compat-first behavior in mixed English.
243
-
244
230
  ### coreRulesBeforePostprocess
245
231
 
246
- `strong_ja_postprocess` runs inside the markdown-it core pipeline. When other plugins register core rules, you can keep their rules ahead of `strong_ja_postprocess` by listing them in `coreRulesBeforePostprocess`. Each name is normalized, deduplicated, and re-ordered once during plugin setup.
232
+ `strong_ja_token_postprocess` runs inside the markdown-it core pipeline. When other plugins register core rules, you can keep their rules ahead of `strong_ja_token_postprocess` by listing them in `coreRulesBeforePostprocess`. Each name is normalized, deduplicated, and re-ordered once during plugin setup.
247
233
 
248
234
  ```js
249
235
  const md = mdit()
@@ -257,4 +243,32 @@ const md = mdit()
257
243
  - Specify `['cjk_breaks']` (or other rule names) when you rely on plugins such as `@peaceroad/markdown-it-cjk-breaks-mod` and need them to run first.
258
244
  - Pass an empty array if you do not want `mditStrongJa` to reorder any core rules.
259
245
 
260
- Most setups can leave this option untouched; use it only when you must keep another plugin's core rule ahead of `strong_ja_postprocess`.
246
+ Most setups can leave this option untouched; use it only when you must keep another plugin's core rule ahead of `strong_ja_token_postprocess`.
247
+
248
+ ### postprocess
249
+
250
+ Toggle the link/reference reconstruction pass and the link-adjacent mark cleanup that runs after inline parsing.
251
+
252
+ ```js
253
+ const md = mdit().use(mditStrongJa, {
254
+ postprocess: false
255
+ })
256
+ ```
257
+
258
+ - Default: `true`
259
+ - Set `false` when you want to minimize core-rule interference and accept that some link/reference + emphasis combinations remain literal (for example, `**[text](url)**`, `[**Text**][]`).
260
+
261
+ ### patchCorePush
262
+
263
+ Controls whether `mditStrongJa` patches `md.core.ruler.push` to keep `strong_ja_restore_softbreaks` ordered after `cjk_breaks` when other plugins register their core rules after `mditStrongJa` (used only when `mditAttrs: false`).
264
+
265
+ ```js
266
+ const md = mdit().use(mditStrongJa, {
267
+ mditAttrs: false,
268
+ patchCorePush: false
269
+ })
270
+ ```
271
+
272
+ - Default: `true`
273
+ - Disable if you want to avoid monkey-patching core rule registration and can guarantee rule ordering (or you do not use `cjk_breaks`).
274
+ - If disabled and `cjk_breaks` is registered later, softbreak normalization can run too early and spacing around CJK punctuation can differ in no-attrs mode.