securemark 0.296.4 → 0.297.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.
@@ -133,7 +133,7 @@ describe('Unit: parser/api/parse', () => {
133
133
  '<p><a class="index" href="#index::a">a</a></p>',
134
134
  '<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span><span class="figtext"></span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
135
135
  '<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
136
- '<p><sup class="annotation" id="annotation::ref:a:1" title="a"><span></span><a href="#annotation::def:a:1">*1</a></sup></p>',
136
+ '<p><sup class="annotation" id="annotation::ref:a:1" title="a"><a href="#annotation::def:a:1">*1</a></sup></p>',
137
137
  '<p><a class="url" href="https://source/x/a" target="_blank">a</a></p>',
138
138
  '<p><a class="url" href="https://source/a" target="_blank">/a</a></p>',
139
139
  '<p><a class="url" href="/z/a">^/a</a></p>',
@@ -216,8 +216,8 @@ describe('Unit: parser/api/parse', () => {
216
216
  [...parse('$-a\n$$\n$$\n\n(($-a[[^B]]))[[^B|$-a]]', { notes }).children].map(el => el.outerHTML),
217
217
  [
218
218
  '<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span><span class="figtext"></span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
219
- '<p><sup class="annotation" id="annotation::ref:[$-a]:1" title="(1)"><span></span><a href="#annotation::def:[$-a]:1">*1</a></sup><sup class="reference" data-abbr="B" id="reference::ref:B:1" title="(1)"><span></span><a href="#reference::def:B">[B]</a></sup></p>',
220
- '<ol class="annotations"><li id="annotation::def:[$-a]:1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B" id="reference::ref:B:2" title="(1)"><span></span><a href="#reference::def:B">[B]</a></sup></span><sup><a href="#annotation::ref:[$-a]:1">^1</a></sup></li></ol>',
219
+ '<p><sup class="annotation" id="annotation::ref:[$-a]:1" title="(1)"><a href="#annotation::def:[$-a]:1">*1</a></sup><sup class="reference" data-abbr="B" id="reference::ref:B:1" title="(1)"><a href="#reference::def:B">[B]</a></sup></p>',
220
+ '<ol class="annotations"><li id="annotation::def:[$-a]:1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B" id="reference::ref:B:2" title="(1)"><a href="#reference::def:B">[B]</a></sup></span><sup><a href="#annotation::ref:[$-a]:1">^1</a></sup></li></ol>',
221
221
  ]);
222
222
  assert.deepStrictEqual(
223
223
  notes.references.outerHTML,
@@ -256,36 +256,36 @@ describe('Unit: parser/api/parse', () => {
256
256
  '[[^Constitution, art. 2, sec. 1|b]]',
257
257
  ].join('\n\n'), { notes }).children].map(el => el.outerHTML),
258
258
  [
259
- '<p><sup class="reference" data-abbr="A 1" id="reference::ref:A_1:1" title="b"><span></span><a href="#reference::def:A_1">[A 1]</a></sup></p>',
260
- '<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:2" title="b"><span></span><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
261
- '<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:3" title="b"><span></span><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
262
- '<p><sup class="reference" data-abbr="Xyz 2020" id="reference::ref:Xyz_2020:1" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020]</a></sup></p>',
263
- '<p><sup class="reference" data-abbr="Xyz 2020, 1" id="reference::ref:Xyz_2020:2" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1]</a></sup></p>',
264
- '<p><sup class="reference" data-abbr="Xyz 2020, 1, 2" id="reference::ref:Xyz_2020:3" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, 2]</a></sup></p>',
265
- '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1" id="reference::ref:Xyz_2020:4" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1]</a></sup></p>',
266
- '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b" id="reference::ref:Xyz_2020:5" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1-2.1b]</a></sup></p>',
267
- '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b" id="reference::ref:Xyz_2020:6" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1a-b]</a></sup></p>',
268
- '<p><sup class="reference" data-abbr="Xyz 2020, 1-2" id="reference::ref:Xyz_2020:7" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1-2]</a></sup></p>',
269
- '<p><sup class="reference" data-abbr="Xyz 2020, 1:1-2" id="reference::ref:Xyz_2020:8" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1:1-2]</a></sup></p>',
270
- '<p><sup class="reference" data-abbr="Xyz 2020, 1n" id="reference::ref:Xyz_2020:9" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n]</a></sup></p>',
271
- '<p><sup class="reference" data-abbr="Xyz 2020, 1n1" id="reference::ref:Xyz_2020:10" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n1]</a></sup></p>',
272
- '<p><sup class="reference" data-abbr="Xyz 2020, 1nn1-2" id="reference::ref:Xyz_2020:11" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1nn1-2]</a></sup></p>',
273
- '<p><sup class="reference" data-abbr="Xyz 2020, i" id="reference::ref:Xyz_2020:12" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, i]</a></sup></p>',
274
- '<p><sup class="reference" data-abbr="Xyz 2020, capter 1" id="reference::ref:Xyz_2020:13" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, capter 1]</a></sup></p>',
275
- '<p><sup class="reference" data-abbr="Xyz 2020, cap. 1" id="reference::ref:Xyz_2020:14" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, cap. 1]</a></sup></p>',
276
- '<p><sup class="reference" data-abbr="Xyz 2020a" id="reference::ref:Xyz_2020a:1" title="b"><span></span><a href="#reference::def:Xyz_2020a">[Xyz 2020a]</a></sup></p>',
277
- '<p><sup class="reference" data-abbr="Xyz 2020a, 1" id="reference::ref:Xyz_2020a:2" title="b"><span></span><a href="#reference::def:Xyz_2020a">[Xyz 2020a, 1]</a></sup></p>',
278
- '<p><sup class="reference" data-abbr="Xyz 2020-2021a" id="reference::ref:Xyz_2020-2021a:1" title="b"><span></span><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a]</a></sup></p>',
279
- '<p><sup class="reference" data-abbr="Xyz 2020-2021a, 1" id="reference::ref:Xyz_2020-2021a:2" title="b"><span></span><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a, 1]</a></sup></p>',
280
- '<p><sup class="reference" data-abbr="Xyz, April 1, 2020" id="reference::ref:Xyz,_April_1,_2020:1" title="b"><span></span><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020]</a></sup></p>',
281
- '<p><sup class="reference" data-abbr="Xyz, April 1, 2020, 1" id="reference::ref:Xyz,_April_1,_2020:2" title="b"><span></span><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020, 1]</a></sup></p>',
282
- '<p><sup class="reference" data-abbr="Xyz n.d." id="reference::ref:Xyz_n.d.:1" title="b"><span></span><a href="#reference::def:Xyz_n.d.">[Xyz n.d.]</a></sup></p>',
283
- '<p><sup class="reference" data-abbr="Xyz n.d., 1" id="reference::ref:Xyz_n.d.:2" title="b"><span></span><a href="#reference::def:Xyz_n.d.">[Xyz n.d., 1]</a></sup></p>',
284
- '<p><sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2" id="reference::ref:X._Y.,_and_Z_et_al._2020:1" title="b"><span></span><a href="#reference::def:X._Y.,_and_Z_et_al._2020">[X. Y., and Z et al. 2020, 1-2]</a></sup></p>',
285
- '<p><sup class="reference" data-abbr="A title 2020" id="reference::ref:A_title_2020:1" title="b"><span></span><a href="#reference::def:A_title_2020">[A title 2020]</a></sup></p>',
286
- '<p><sup class="reference" data-abbr="A title 2020, 1" id="reference::ref:A_title_2020:2" title="b"><span></span><a href="#reference::def:A_title_2020">[A title 2020, 1]</a></sup></p>',
287
- '<p><sup class="reference" data-abbr="Constitution, art. 2" id="reference::ref:Constitution:1" title="b"><span></span><a href="#reference::def:Constitution">[Constitution, art. 2]</a></sup></p>',
288
- '<p><sup class="reference" data-abbr="Constitution, art. 2, sec. 1" id="reference::ref:Constitution:2" title="b"><span></span><a href="#reference::def:Constitution">[Constitution, art. 2, sec. 1]</a></sup></p>',
259
+ '<p><sup class="reference" data-abbr="A 1" id="reference::ref:A_1:1" title="b"><a href="#reference::def:A_1">[A 1]</a></sup></p>',
260
+ '<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:2" title="b"><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
261
+ '<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:3" title="b"><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
262
+ '<p><sup class="reference" data-abbr="Xyz 2020" id="reference::ref:Xyz_2020:1" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020]</a></sup></p>',
263
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1" id="reference::ref:Xyz_2020:2" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1]</a></sup></p>',
264
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, 2" id="reference::ref:Xyz_2020:3" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, 2]</a></sup></p>',
265
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1" id="reference::ref:Xyz_2020:4" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1]</a></sup></p>',
266
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b" id="reference::ref:Xyz_2020:5" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1-2.1b]</a></sup></p>',
267
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b" id="reference::ref:Xyz_2020:6" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1a-b]</a></sup></p>',
268
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1-2" id="reference::ref:Xyz_2020:7" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1-2]</a></sup></p>',
269
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1:1-2" id="reference::ref:Xyz_2020:8" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1:1-2]</a></sup></p>',
270
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1n" id="reference::ref:Xyz_2020:9" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n]</a></sup></p>',
271
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1n1" id="reference::ref:Xyz_2020:10" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n1]</a></sup></p>',
272
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1nn1-2" id="reference::ref:Xyz_2020:11" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, 1nn1-2]</a></sup></p>',
273
+ '<p><sup class="reference" data-abbr="Xyz 2020, i" id="reference::ref:Xyz_2020:12" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, i]</a></sup></p>',
274
+ '<p><sup class="reference" data-abbr="Xyz 2020, capter 1" id="reference::ref:Xyz_2020:13" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, capter 1]</a></sup></p>',
275
+ '<p><sup class="reference" data-abbr="Xyz 2020, cap. 1" id="reference::ref:Xyz_2020:14" title="b"><a href="#reference::def:Xyz_2020">[Xyz 2020, cap. 1]</a></sup></p>',
276
+ '<p><sup class="reference" data-abbr="Xyz 2020a" id="reference::ref:Xyz_2020a:1" title="b"><a href="#reference::def:Xyz_2020a">[Xyz 2020a]</a></sup></p>',
277
+ '<p><sup class="reference" data-abbr="Xyz 2020a, 1" id="reference::ref:Xyz_2020a:2" title="b"><a href="#reference::def:Xyz_2020a">[Xyz 2020a, 1]</a></sup></p>',
278
+ '<p><sup class="reference" data-abbr="Xyz 2020-2021a" id="reference::ref:Xyz_2020-2021a:1" title="b"><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a]</a></sup></p>',
279
+ '<p><sup class="reference" data-abbr="Xyz 2020-2021a, 1" id="reference::ref:Xyz_2020-2021a:2" title="b"><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a, 1]</a></sup></p>',
280
+ '<p><sup class="reference" data-abbr="Xyz, April 1, 2020" id="reference::ref:Xyz,_April_1,_2020:1" title="b"><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020]</a></sup></p>',
281
+ '<p><sup class="reference" data-abbr="Xyz, April 1, 2020, 1" id="reference::ref:Xyz,_April_1,_2020:2" title="b"><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020, 1]</a></sup></p>',
282
+ '<p><sup class="reference" data-abbr="Xyz n.d." id="reference::ref:Xyz_n.d.:1" title="b"><a href="#reference::def:Xyz_n.d.">[Xyz n.d.]</a></sup></p>',
283
+ '<p><sup class="reference" data-abbr="Xyz n.d., 1" id="reference::ref:Xyz_n.d.:2" title="b"><a href="#reference::def:Xyz_n.d.">[Xyz n.d., 1]</a></sup></p>',
284
+ '<p><sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2" id="reference::ref:X._Y.,_and_Z_et_al._2020:1" title="b"><a href="#reference::def:X._Y.,_and_Z_et_al._2020">[X. Y., and Z et al. 2020, 1-2]</a></sup></p>',
285
+ '<p><sup class="reference" data-abbr="A title 2020" id="reference::ref:A_title_2020:1" title="b"><a href="#reference::def:A_title_2020">[A title 2020]</a></sup></p>',
286
+ '<p><sup class="reference" data-abbr="A title 2020, 1" id="reference::ref:A_title_2020:2" title="b"><a href="#reference::def:A_title_2020">[A title 2020, 1]</a></sup></p>',
287
+ '<p><sup class="reference" data-abbr="Constitution, art. 2" id="reference::ref:Constitution:1" title="b"><a href="#reference::def:Constitution">[Constitution, art. 2]</a></sup></p>',
288
+ '<p><sup class="reference" data-abbr="Constitution, art. 2, sec. 1" id="reference::ref:Constitution:2" title="b"><a href="#reference::def:Constitution">[Constitution, art. 2, sec. 1]</a></sup></p>',
289
289
  ]);
290
290
  });
291
291
 
@@ -362,30 +362,30 @@ describe('Unit: parser/api/parse', () => {
362
362
 
363
363
  it('backtrack 1', () => {
364
364
  // 最悪計算量での実行速度はCommonMarkの公式JS実装の32nに対して50-400%程度。
365
- // 6n = annotation + reference + link + url/math + ruby + text
365
+ // 5n = reference + link + url/math + ruby + text
366
366
  assert.deepStrictEqual(
367
- [...parse(`((([[[[#$[${'.'.repeat(16665)}`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
367
+ [...parse(`((([[[[#$[${'.'.repeat(19998)}`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
368
368
  .map(el => el.tagName),
369
369
  ['P']);
370
370
  });
371
371
 
372
372
  it('backtrack 1 error', () => {
373
373
  assert.deepStrictEqual(
374
- [...parse(`((([[[[#$[${'.'.repeat(16665 + 1)}`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
374
+ [...parse(`((([[[[#$[${'.'.repeat(19998 + 1)}`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
375
375
  .map(el => el.tagName),
376
376
  ['H1', 'PRE']);
377
377
  });
378
378
 
379
379
  it('backtrack 2', () => {
380
380
  assert.deepStrictEqual(
381
- [...parse(`((([[[[#$[${'.'.repeat(16664)}]]]`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
381
+ [...parse(`((([[[[#$[${'.'.repeat(19998)}]]]`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
382
382
  .map(el => el.tagName),
383
383
  ['P', 'OL']);
384
384
  });
385
385
 
386
386
  it('backtrack 2 error', () => {
387
387
  assert.deepStrictEqual(
388
- [...parse(`((([[[[#$[${'.'.repeat(16664 + 1)}]]]`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
388
+ [...parse(`((([[[[#$[${'.'.repeat(19998 + 1)}]]]`, {}, new Context({ resources: { clock: 100000, recursions: [100] } })).children]
389
389
  .map(el => el.tagName),
390
390
  ['H1', 'PRE']);
391
391
  });
@@ -94,7 +94,7 @@ describe('Unit: parser/block/blockquote', () => {
94
94
  assert.deepStrictEqual(inspect(parser, input('!>> ## a\n> ## a', new Context())), [['<blockquote><blockquote><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></blockquote><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
95
95
  assert.deepStrictEqual(inspect(parser, input('!>> ~ a\n> ~ a', new Context())), [['<blockquote><blockquote><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
96
96
  assert.deepStrictEqual(inspect(parser, input('!>> ~~~figure $test-a\n>> > \n>>\n~~~\n> ~~~figure $test-a\n> > \n>\n[#a]\n~~~', new Context())), [['<blockquote><blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span><span class="figtext"></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span><span class="figtext"><a class="index">a</a></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
97
- assert.deepStrictEqual(inspect(parser, input('!>> ((a))\n> ((a))', new Context())), [['<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
97
+ assert.deepStrictEqual(inspect(parser, input('!>> ((a))\n> ((a))', new Context())), [['<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="a"><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
98
98
  });
99
99
 
100
100
  });
@@ -7,7 +7,7 @@ import { unwrap, invalid } from '../../util';
7
7
  import { parse } from '../../api/parse';
8
8
  import { html } from 'typed-dom/dom';
9
9
 
10
- export const aside: ExtensionParser.AsideParser = recursion(Recursion.block, block(fmap(
10
+ export const aside: ExtensionParser.AsideParser = block(recursion(Recursion.block, fmap(
11
11
  fence(/(~{3,})aside(?!\S)([^\n]*)(?:$|\n)/y, 300),
12
12
  // Bug: Type mismatch between outer and inner.
13
13
  (nodes: List<Node<string>>, context) => {
@@ -25,7 +25,7 @@ describe('Unit: parser/block/extension/example', () => {
25
25
  assert.deepStrictEqual(inspect(parser, input('~~~example/markdown\n[$fig-a]\n!https://host\n~~~', new Context())), [['<aside class="example" data-type="markdown"><pre translate="no">[$fig-a]\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
26
26
  assert.deepStrictEqual(inspect(parser, input('~~~example/markdown\n## a\n~~~', new Context())), [['<aside class="example" data-type="markdown"><pre translate="no">## a</pre><hr><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
27
27
  assert.deepStrictEqual(inspect(parser, input('~~~example/markdown\n~ a\n~~~', new Context())), [['<aside class="example" data-type="markdown"><pre translate="no">~ a</pre><hr><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
28
- assert.deepStrictEqual(inspect(parser, input('~~~example/markdown\n((a))[[b]]\n~~~', new Context())), [['<aside class="example" data-type="markdown"><pre translate="no">((a))[[b]]</pre><hr><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup><sup class="reference disabled" title="b"><span></span><a>[1]</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"><li><span>b</span><sup><a>^1</a></sup></li></ol></section></aside>'], '']);
28
+ assert.deepStrictEqual(inspect(parser, input('~~~example/markdown\n((a))[[b]]\n~~~', new Context())), [['<aside class="example" data-type="markdown"><pre translate="no">((a))[[b]]</pre><hr><section><p><sup class="annotation disabled" title="a"><a>*1</a></sup><sup class="reference disabled" title="b"><a>[1]</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"><li><span>b</span><sup><a>^1</a></sup></li></ol></section></aside>'], '']);
29
29
  assert.deepStrictEqual(inspect(parser, input('~~~~example/markdown\na\n~~~~', new Context())), [['<aside class="example" data-type="markdown"><pre translate="no">a</pre><hr><section><p>a</p><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
30
30
  assert.deepStrictEqual(inspect(parser, input('~~~example/math\na\n~~~', new Context())), [['<aside class="example" data-type="math"><pre translate="no">a</pre><hr><div class="math" translate="no">$$\na\n$$</div></aside>'], '']);
31
31
  assert.deepStrictEqual(inspect(parser, input(`~~~example/math\n0${'\n'.repeat(100)}~~~`, new Context()), '>'), [['<aside class="example" data-type="math">'], '']);
@@ -7,7 +7,7 @@ import { unwrap, invalid } from '../../util';
7
7
  import { parse } from '../../api/parse';
8
8
  import { html } from 'typed-dom/dom';
9
9
 
10
- export const example: ExtensionParser.ExampleParser = recursion(Recursion.block, block(fmap(
10
+ export const example: ExtensionParser.ExampleParser = block(recursion(Recursion.block, fmap(
11
11
  fence(/(~{3,})(?:example\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/y, 300),
12
12
  // Bug: Type mismatch between outer and inner.
13
13
  (nodes: List<Node<string>>, context) => {
@@ -12,12 +12,12 @@ describe('Unit: parser/inline/annotation', () => {
12
12
  assert.deepStrictEqual(inspect(parser, input('', new Context())), undefined);
13
13
  assert.deepStrictEqual(inspect(parser, input('(', new Context())), undefined);
14
14
  assert.deepStrictEqual(inspect(parser, input('()', new Context())), undefined);
15
- assert.deepStrictEqual(inspect(parser, input('((', new Context())), undefined);
16
- assert.deepStrictEqual(inspect(parser, input('(())', new Context())), undefined);
17
- assert.deepStrictEqual(inspect(parser, input('(()))', new Context())), undefined);
18
- assert.deepStrictEqual(inspect(parser, input('(("))', new Context())), undefined);
19
- assert.deepStrictEqual(inspect(parser, input('(([))', new Context())), undefined);
20
- assert.deepStrictEqual(inspect(parser, input('(([%))', new Context())), undefined);
15
+ assert.deepStrictEqual(inspect(parser, input('((', new Context())), [['<span class="paren">(<span class="paren">(</span></span>'], '']);
16
+ assert.deepStrictEqual(inspect(parser, input('(())', new Context())), [['<span class="paren">(<span class="paren">(</span></span>'], '))']);
17
+ assert.deepStrictEqual(inspect(parser, input('(()))', new Context())), [['<span class="paren">(<span class="paren">(</span></span>'], ')))']);
18
+ assert.deepStrictEqual(inspect(parser, input('(("))', new Context())), [['<span class="paren">(<span class="paren">("))</span></span>'], '']);
19
+ assert.deepStrictEqual(inspect(parser, input('(([))', new Context())), [['<span class="paren">(<span class="paren">([))</span></span>'], '']);
20
+ assert.deepStrictEqual(inspect(parser, input('(([%))', new Context())), [['<span class="paren">(<span class="paren">([%))</span></span>'], '']);
21
21
  assert.deepStrictEqual(inspect(parser, input('(( ))', new Context())), undefined);
22
22
  assert.deepStrictEqual(inspect(parser, input('(( a))', new Context())), undefined);
23
23
  assert.deepStrictEqual(inspect(parser, input('(( a ))', new Context())), undefined);
@@ -26,14 +26,16 @@ describe('Unit: parser/inline/annotation', () => {
26
26
  assert.deepStrictEqual(inspect(parser, input('((\n))', new Context())), undefined);
27
27
  assert.deepStrictEqual(inspect(parser, input('((\na))', new Context())), undefined);
28
28
  assert.deepStrictEqual(inspect(parser, input('((\\\na))', new Context())), undefined);
29
- assert.deepStrictEqual(inspect(parser, input('((a\n))', new Context())), undefined);
30
- assert.deepStrictEqual(inspect(parser, input('((a\\\n))', new Context())), undefined);
31
- assert.deepStrictEqual(inspect(parser, input('((a\nb))', new Context())), undefined);
32
- assert.deepStrictEqual(inspect(parser, input('((a\\\nb))', new Context())), undefined);
33
- assert.deepStrictEqual(inspect(parser, input('((*a\nb*))', new Context())), undefined);
34
- assert.deepStrictEqual(inspect(parser, input('((\\))', new Context())), undefined);
35
- assert.deepStrictEqual(inspect(parser, input('((a)b))', new Context())), undefined);
36
- assert.deepStrictEqual(inspect(parser, input('(((a))', new Context())), undefined);
29
+ assert.deepStrictEqual(inspect(parser, input('((a\n))', new Context())), [['<span class="paren">(<span class="paren">(a<br>)</span>)</span>'], '']);
30
+ assert.deepStrictEqual(inspect(parser, input('((a\\\n))', new Context())), [['<span class="paren">(<span class="paren">(a<br>)</span>)</span>'], '']);
31
+ assert.deepStrictEqual(inspect(parser, input('((a\nb))', new Context())), [['<span class="paren">(<span class="paren">(a<br>b)</span>)</span>'], '']);
32
+ assert.deepStrictEqual(inspect(parser, input('((a\\\nb))', new Context())), [['<span class="paren">(<span class="paren">(a<br>b)</span>)</span>'], '']);
33
+ assert.deepStrictEqual(inspect(parser, input('((*a\nb*))', new Context())), [['<span class="paren">(<span class="paren">(<em>a<br>b</em>)</span>)</span>'], '']);
34
+ assert.deepStrictEqual(inspect(parser, input('((\\))', new Context())), [['<span class="paren">(<span class="paren">()</span></span>'], ')']);
35
+ assert.deepStrictEqual(inspect(parser, input('((a)b))', new Context())), [['<span class="paren">((a</span>'], ')b))']);
36
+ assert.deepStrictEqual(inspect(parser, input('((!)b))', new Context())), [['<span class="paren">(<span class="paren">(!</span></span>'], ')b))']);
37
+ assert.deepStrictEqual(inspect(parser, input('(((a))', new Context())), [['<span class="paren">(<sup class="annotation"><span>a</span></sup></span>'], '']);
38
+ assert.deepStrictEqual(inspect(parser, input('(((!))', new Context())), [['<span class="paren">(<sup class="annotation"><span>!</span></sup></span>'], '']);
37
39
  assert.deepStrictEqual(inspect(parser, input(' ((a))', new Context())), undefined);
38
40
  });
39
41
 
@@ -53,7 +55,7 @@ describe('Unit: parser/inline/annotation', () => {
53
55
  assert.deepStrictEqual(inspect(parser, input('((![]{a}))', new Context())), [['<sup class="annotation"><span>!<a class="url" href="a">a</a></span></sup>'], '']);
54
56
  assert.deepStrictEqual(inspect(parser, input('(([[a] ]))', new Context())), [['<sup class="annotation"><span>[[a] ]</span></sup>'], '']);
55
57
  assert.deepStrictEqual(inspect(parser, input('(((a)))', new Context())), [['<sup class="annotation"><span>(a)</span></sup>'], '']);
56
- assert.deepStrictEqual(inspect(parser, input('((((a))))', new Context())), [['<sup class="annotation"><span><span class="paren">((a))</span></span></sup>'], '']);
58
+ assert.deepStrictEqual(inspect(parser, input('((((a))))', new Context())), [['<sup class="annotation"><span><sup class="annotation"><span>a</span></sup></span></sup>'], '']);
57
59
  assert.deepStrictEqual(inspect(parser, input('(([[a]]))', new Context())), [['<sup class="annotation"><span><sup class="reference"><span>a</span></sup></span></sup>'], '']);
58
60
  });
59
61
 
@@ -1,30 +1,57 @@
1
1
  import { AnnotationParser } from '../inline';
2
- import { State, Backtrack } from '../context';
2
+ import { State, Recursion } from '../context';
3
3
  import { List, Node } from '../../combinator/data/parser';
4
- import { union, some, precedence, state, constraint, surround, close, setBacktrack, lazy } from '../../combinator';
4
+ import { union, some, recursion, precedence, constraint, surround, close, lazy } from '../../combinator';
5
5
  import { inline } from '../inline';
6
+ import { indexA } from './bracket';
6
7
  import { beforeNonblank, trimBlankNodeEnd } from '../visibility';
7
8
  import { unwrap } from '../util';
8
9
  import { html, defrag } from 'typed-dom/dom';
9
10
 
10
11
  export const annotation: AnnotationParser = lazy(() => constraint(State.annotation, surround(
11
12
  close('((', beforeNonblank),
12
- precedence(1, state(State.annotation,
13
- some(union([inline]), ')', [[')', 1]]))),
13
+ precedence(1, recursion(Recursion.inline, recursion(Recursion.bracket, recursion(Recursion.bracket,
14
+ some(union([inline]), ')', [[')', 1]]))))),
14
15
  '))',
15
- false,
16
- [2, 1 | Backtrack.common, 3 | Backtrack.doublebracket],
17
- ([, ns], context) =>
18
- context.linebreak === 0
19
- ? new List([new Node(html('sup', { class: 'annotation' }, [html('span', defrag(unwrap(trimBlankNodeEnd(ns))))]))])
20
- : undefined,
21
- (_, context): undefined => {
16
+ false, [],
17
+ ([, ns], context) => {
18
+ const { linebreak } = context;
19
+ if (linebreak === 0) {
20
+ return new List([new Node(html('sup', { class: 'annotation' }, [html('span', defrag(unwrap(trimBlankNodeEnd(ns))))]))]);
21
+ }
22
+ ns.unshift(new Node('('));
23
+ ns.push(new Node(')'));
24
+ return new List([new Node(html('span', { class: 'paren' }, ['(', html('span', { class: 'paren' }, defrag(unwrap(ns))), ')']))]);
25
+ },
26
+ ([, bs = new List()], context) => {
22
27
  const { source, position, range, linebreak } = context;
23
- const head = position - range;
24
- if (source[position] !== ')') {
25
- setBacktrack(context, 2 | Backtrack.common, head + 1);
28
+ if (linebreak === 0 && bs.length === 1 && source[position] === ')' && typeof bs.head?.value === 'object' && bs.head.value.className === 'paren') {
29
+ const { firstChild, lastChild } = bs.head.value;
30
+ assert(firstChild instanceof Text);
31
+ if (firstChild!.nodeValue!.length === 1) {
32
+ firstChild!.remove();
33
+ }
34
+ else {
35
+ firstChild!.nodeValue = firstChild!.nodeValue!.slice(1);
36
+ }
37
+ assert(lastChild instanceof Text);
38
+ if (lastChild!.nodeValue!.length === 1) {
39
+ lastChild!.remove();
40
+ }
41
+ else {
42
+ lastChild!.nodeValue = lastChild!.nodeValue!.slice(0, -1);
43
+ }
44
+ context.position += 1;
45
+ return new List([new Node(html('span', { class: 'paren' }, ['(', html('sup', { class: 'annotation' }, [html('span', bs.head.value.childNodes)])]))]);
46
+ }
47
+ if (linebreak === 0 && bs.length === 3 && source[position - range + 2] === '(' && source[position] === ')' && source[position - 1] === ')' && source[position - 2] !== '\\') {
48
+ context.position += 1;
49
+ return new List([new Node(html('span', { class: 'paren' }, ['(', html('sup', { class: 'annotation' }, [html('span', [bs.head!.next!.value])])]))]);
26
50
  }
27
- else if (linebreak !== 0) {
28
- setBacktrack(context, 2 | Backtrack.doublebracket, head + 1);
51
+ const str = linebreak === 0 ? source.slice(position - range + 2, position) : '';
52
+ if (linebreak === 0 && indexA.test(str)) {
53
+ return new List([new Node(html('span', { class: 'paren' }, ['((' + str]))]);
29
54
  }
55
+ bs.unshift(new Node('('));
56
+ return new List([new Node(html('span', { class: 'paren' }, ['(', html('span', { class: 'paren' }, defrag(unwrap(bs)))]))]);
30
57
  })));
@@ -13,7 +13,7 @@ import { define } from 'typed-dom/dom';
13
13
  export const account: AutolinkParser.AccountParser = lazy(() => constraint(State.autolink, state(State.autolink,
14
14
  surround(
15
15
  surround(
16
- /(?<![0-9a-z])@/yi,
16
+ /(?<![0-9a-z@#])@/yi,
17
17
  str(/[0-9a-z](?:[.-](?=[0-9a-z])|[0-9a-z]){0,254}\/|/yi),
18
18
  str(/[a-z][0-9a-z]*(?:[.-][0-9a-z]+)*(?![_.-]?[0-9a-z@]|>>|:\S)/yi),
19
19
  false,
@@ -18,7 +18,7 @@ import { define } from 'typed-dom/dom';
18
18
 
19
19
  export const anchor: AutolinkParser.AnchorParser = lazy(() => constraint(State.autolink, state(State.autolink,
20
20
  surround(
21
- /(?<![0-9a-z])>>/yi,
21
+ /(?<![0-9a-z@#])>>/yi,
22
22
  str(/[0-9a-z]+(?:-[0-9a-z]+)*(?![_.-]?[0-9a-z@#]|>>|:\S)/yi),
23
23
  '',
24
24
  false,
@@ -10,7 +10,7 @@ import { define } from 'typed-dom/dom';
10
10
  export const hashnum: AutolinkParser.HashnumParser = lazy(() => constraint(State.autolink, state(State.autolink,
11
11
  surround(
12
12
  new RegExp([
13
- /(?<![^\p{C}\p{S}\p{P}\s]|emoji)#/yu.source,
13
+ /(?<![^\p{C}\p{S}\p{P}\s]|emoji|[@#])#/yu.source,
14
14
  ].join('|').replace(/emoji/g, emoji.source), 'yu'),
15
15
  str(new RegExp([
16
16
  /[0-9]{1,9}(?![_.-]?[0-9a-z@#]|>>|:\S|[^\p{C}\p{S}\p{P}\s]|emoji)/yu.source,
@@ -14,7 +14,7 @@ export const emoji = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presen
14
14
  export const hashtag: AutolinkParser.HashtagParser = lazy(() => constraint(State.autolink, state(State.autolink,
15
15
  surround(
16
16
  new RegExp([
17
- /(?<![^\p{C}\p{S}\p{P}\s]|emoji)#/yu.source,
17
+ /(?<![^\p{C}\p{S}\p{P}\s]|emoji|[@#])#/yu.source,
18
18
  ].join('|').replace(/emoji/g, emoji.source), 'yu'),
19
19
  verify(
20
20
  str(new RegExp([
@@ -8,7 +8,7 @@ import { str } from '../source';
8
8
  import { unwrap } from '../util';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
 
11
- const indexA = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*$/;
11
+ export const indexA = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*$/;
12
12
  const indexF = new RegExp(indexA.source.replace(', ', '[,、]')
13
13
  .replace(/[09AZaz.]|\-(?!\w)/g, c => String.fromCodePoint(c.codePointAt(0)! + 0xFEE0)));
14
14
 
@@ -38,25 +38,17 @@ const p1 = lazy(() => surround(
38
38
  str('('),
39
39
  precedence(1, recursion(Recursion.bracket, some(inline, ')', [[')', 1]]))),
40
40
  str(')'),
41
- // 唯一の参照者であるAnnotation構文に対してのみバックトラックを記録しその他は記録しない。
42
- // 二重括弧構文の内括弧のバックトラックは二重括弧構文自身が記録するため記録不要。
43
- // Ruby構文の丸括弧は常にRuby構文が先に到達し記録するため記録不要。
44
41
  true, [],
45
- ([as, bs = new List(), cs], context) => {
46
- const { source, position, range } = context;
47
- const head = position - range;
48
- if (source[head + 1] === '(' && (context.linebreak !== 0 || source[position - 2] !== ')')) {
49
- setBacktrack(context, 2 | Backtrack.doublebracket, head);
50
- }
51
- const str = source.slice(position - range + 1, position - 1);
52
- return indexA.test(str)
42
+ ([as, bs = [], cs], { source, position, range, linebreak }) => {
43
+ const str = linebreak === 0 ? source.slice(position - range + 1, position - 1) : '';
44
+ return linebreak === 0 && indexA.test(str)
53
45
  ? new List([new Node(as.head!.value), new Node(str), new Node(cs.head!.value)])
54
46
  : new List([new Node(html('span', { class: 'paren' }, defrag(unwrap(as.import(bs as List<Node<string>>).import(cs)))))]);
55
47
  },
56
48
  ([as, bs = new List()], context) => {
57
- const { source, position, range } = context;
58
- const str = source.slice(position - range + 1, position);
59
- return indexA.test(str)
49
+ const { source, position, range, linebreak } = context;
50
+ const str = linebreak === 0 ? source.slice(position - range + 1, position) : '';
51
+ return linebreak === 0 && indexA.test(str)
60
52
  ? new List([new Node(as.head!.value), new Node(str)])
61
53
  : new List([new Node(html('span', { class: 'paren' }, defrag(unwrap(as.import(bs as List<Node<string>>)))))]);
62
54
  }));
@@ -66,16 +58,16 @@ const p2 = lazy(() => surround(
66
58
  precedence(1, recursion(Recursion.bracket, some(inline, ')', [[')', 1]]))),
67
59
  str(')'),
68
60
  true, [],
69
- ([as, bs = [], cs], { source, position, range }) => {
70
- const str = source.slice(position - range + 1, position - 1);
71
- return indexF.test(str)
61
+ ([as, bs = [], cs], { source, position, range, linebreak }) => {
62
+ const str = linebreak === 0 ? source.slice(position - range + 1, position - 1) : '';
63
+ return linebreak === 0 && indexF.test(str)
72
64
  ? new List([new Node(as.head!.value), new Node(str), new Node(cs.head!.value)])
73
65
  : new List([new Node(html('span', { class: 'paren' }, defrag(unwrap(as.import(bs as List<Node<string>>).import(cs)))))]);
74
66
  },
75
67
  ([as, bs = new List()], context) => {
76
- const { source, position, range } = context;
77
- const str = source.slice(position - range + 1, position);
78
- return indexF.test(str)
68
+ const { source, position, range, linebreak } = context;
69
+ const str = linebreak === 0 ? source.slice(position - range + 1, position) : '';
70
+ return linebreak === 0 && indexF.test(str)
79
71
  ? new List([new Node(as.head!.value), new Node(str)])
80
72
  : new List([new Node(html('span', { class: 'paren' }, defrag(unwrap(as.import(bs as List<Node<string>>)))))]);
81
73
  }));
@@ -87,13 +79,13 @@ const s1 = lazy(() => surround(
87
79
  true,
88
80
  [2 | Backtrack.common],
89
81
  ([as, bs = new List(), cs], context) => {
90
- const { source, position, range } = context;
82
+ const { source, position, range, linebreak } = context;
91
83
  const head = position - range;
92
- if (source[head + 1] === '[' && (context.linebreak !== 0 || source[position - 2] !== ']')) {
84
+ if (source[head + 1] === '[' && (linebreak !== 0 || source[position - 2] !== ']')) {
93
85
  setBacktrack(context, 2 | Backtrack.doublebracket, head);
94
86
  }
95
87
  if (context.state & State.link) {
96
- if (context.linebreak !== 0) {
88
+ if (linebreak !== 0) {
97
89
  setBacktrack(context, 2 | Backtrack.link | Backtrack.ruby, head);
98
90
  }
99
91
  else if (source[position] !== '{') {
@@ -8,7 +8,7 @@ import { unwrap, repeat } from '../util';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
 
10
10
  export const deletion: DeletionParser = lazy(() =>
11
- precedence(0, recursion(Recursion.inline, repeat('~~', '', surround(
11
+ precedence(0, repeat('~~', '', recursion(Recursion.inline, surround(
12
12
  '',
13
13
  some(union([
14
14
  some(inline, blankWith('\n', '~~')),
@@ -17,5 +17,5 @@ export const deletion: DeletionParser = lazy(() =>
17
17
  '~~',
18
18
  false, [],
19
19
  ([, bs], { buffer }) => buffer.import(bs),
20
- ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
21
- nodes => new List([new Node(html('del', defrag(unwrap(nodes))))])))));
20
+ ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer)),
21
+ nodes => new List([new Node(html('del', defrag(unwrap(nodes))))]))));
@@ -23,7 +23,7 @@ const subemphasis: Parser.IntermediateParser<EmphasisParser> = lazy(() => some(u
23
23
  // 可能な限り早く閉じるよう解析しなければならない。
24
24
  // このため終端記号の後ろを見て終端を中止し同じ構文を再帰的に適用してはならない。
25
25
  export const emstrong: EmStrongParser = lazy(() =>
26
- precedence(0, recursion(Recursion.inline, repeat('***', beforeNonblank, surround(
26
+ precedence(0, repeat('***', beforeNonblank, recursion(Recursion.inline, surround(
27
27
  '',
28
28
  some(union([some(inline, '*', afterNonblank)])),
29
29
  strs('*', 1, 3),
@@ -75,7 +75,7 @@ export const emstrong: EmStrongParser = lazy(() =>
75
75
  }
76
76
  assert(false);
77
77
  },
78
- ([, bs], { buffer }) => bs && buffer.import(bs) && buffer.push(new Node(Command.Cancel)) && buffer),
78
+ ([, bs], { buffer }) => bs && buffer.import(bs) && buffer.push(new Node(Command.Cancel)) && buffer)),
79
79
  // 3以上の`*`に対してemの適用を保証する
80
80
  nodes => new List([new Node(html('em', [html('strong', defrag(unwrap(nodes)))]))]),
81
81
  (nodes, context, prefix, postfix, state) => {
@@ -137,7 +137,7 @@ export const emstrong: EmStrongParser = lazy(() =>
137
137
  nodes = prepend('*'.repeat(prefix - postfix), nodes);
138
138
  }
139
139
  return nodes;
140
- }))));
140
+ })));
141
141
 
142
142
  function prepend<N>(prefix: string, nodes: List<Node<N>>): List<Node<N>> {
143
143
  if (typeof nodes.head?.value === 'string') {
@@ -33,7 +33,7 @@ export function identity(
33
33
  if (index === '' && text.tagName === 'LI') return undefined;
34
34
  return index
35
35
  ? `${type}:${id ?? ''}:${index}`
36
- : identity(type, id, signature(text));
36
+ : identity(type, id, signature(text.cloneNode(true)));
37
37
  }
38
38
  text = text.trim();
39
39
  if (text === '') return undefined;
@@ -106,10 +106,10 @@ assert(baseR(~0 >>> 0, 36) === (~0 >>> 0).toString(36));
106
106
  assert(baseR(61, 62) === 'Z');
107
107
  assert(baseR(62, 62) === '10');
108
108
 
109
- export function signature(source: Element | DocumentFragment): string {
110
- assert(!navigator.userAgent.includes('Chrome') || !source.querySelector('br:not(:has(+ :is(ul, ol)))') || source.nodeName === 'MARK');
111
- const target = source.cloneNode(true) as typeof source;
112
- for (let es = target.querySelectorAll('code[data-src], .math[data-src], .label[data-label], .remark, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'),
109
+ export function signature(target: Element | DocumentFragment): string {
110
+ assert(!target.parentNode);
111
+ assert(!target.querySelector('br:not(:has(+ :is(ul, ol)))') || target.nodeName === 'MARK');
112
+ for (let es = target.querySelectorAll('code[data-src], .math[data-src], .remark, rt, rp, br, .annotation, .reference, .checkbox, ul, ol, .label[data-label]'),
113
113
  len = es.length, i = 0; i < len; ++i) {
114
114
  const el = es[i];
115
115
  switch (el.tagName) {
@@ -144,9 +144,9 @@ export function signature(source: Element | DocumentFragment): string {
144
144
  return target.textContent!.trim();
145
145
  }
146
146
 
147
- export function text(source: Element | DocumentFragment): string {
148
- assert(!navigator.userAgent.includes('Chrome') || !source.querySelector('br:not(:has(+ :is(ul, ol)))'));
149
- const target = source.cloneNode(true) as typeof source;
147
+ export function text(target: Element | DocumentFragment): string {
148
+ assert(!target.parentNode);
149
+ assert(!target.querySelector('br:not(:has(+ :is(ul, ol)))'));
150
150
  for (let es = target.querySelectorAll('code[data-src], .math[data-src], .remark, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'),
151
151
  len = es.length, i = 0; i < len; ++i) {
152
152
  const el = es[i];
@@ -8,7 +8,7 @@ import { unwrap, repeat } from '../util';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
 
10
10
  export const insertion: InsertionParser = lazy(() =>
11
- precedence(0, recursion(Recursion.inline, repeat('++', '', surround(
11
+ precedence(0, repeat('++', '', recursion(Recursion.inline, surround(
12
12
  '',
13
13
  some(union([
14
14
  some(inline, blankWith('\n', '++')),
@@ -17,5 +17,5 @@ export const insertion: InsertionParser = lazy(() =>
17
17
  '++',
18
18
  false, [],
19
19
  ([, bs], { buffer }) => buffer.import(bs),
20
- ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
21
- nodes => new List([new Node(html('ins', defrag(unwrap(nodes))))])))));
20
+ ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer)),
21
+ nodes => new List([new Node(html('ins', defrag(unwrap(nodes))))]))));
@@ -11,11 +11,11 @@ import { html, defrag } from 'typed-dom/dom';
11
11
  // 斜体は単語に使うとかえって見づらく読み飛ばしやすくなるため使わないべきであり
12
12
  // ある程度の長さのある文に使うのが望ましい。
13
13
  export const italic: ItalicParser = lazy(() =>
14
- precedence(0, recursion(Recursion.inline, repeat('///', beforeNonblank, surround(
14
+ precedence(0, repeat('///', beforeNonblank, recursion(Recursion.inline, surround(
15
15
  '',
16
16
  some(union([inline]), '///', afterNonblank),
17
17
  '///',
18
18
  false, [],
19
19
  ([, bs], { buffer }) => buffer.import(bs),
20
- ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
21
- nodes => new List([new Node(html('i', defrag(unwrap(nodes))))])))));
20
+ ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer)),
21
+ nodes => new List([new Node(html('i', defrag(unwrap(nodes))))]))));