securemark 0.234.3 → 0.235.2

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/securemark.js +210 -171
  3. package/markdown.d.ts +5 -2
  4. package/package-lock.json +40 -37
  5. package/package.json +1 -1
  6. package/src/combinator/control/constraint/block.ts +0 -2
  7. package/src/combinator/control/constraint/contract.ts +1 -1
  8. package/src/combinator/control/manipulation/context.test.ts +4 -4
  9. package/src/combinator/control/manipulation/context.ts +7 -0
  10. package/src/combinator/control/manipulation/match.ts +1 -1
  11. package/src/combinator/control/manipulation/resource.ts +6 -3
  12. package/src/combinator/control/manipulation/scope.ts +1 -1
  13. package/src/combinator/control/manipulation/surround.ts +3 -4
  14. package/src/combinator/data/parser/inits.ts +1 -1
  15. package/src/combinator/data/parser/sequence.ts +1 -1
  16. package/src/combinator/data/parser/some.ts +41 -21
  17. package/src/combinator/data/parser.ts +33 -7
  18. package/src/parser/api/bind.test.ts +3 -3
  19. package/src/parser/api/parse.test.ts +12 -5
  20. package/src/parser/block/blockquote.test.ts +1 -1
  21. package/src/parser/block/extension/aside.test.ts +1 -1
  22. package/src/parser/block/extension/example.test.ts +2 -2
  23. package/src/parser/block/extension/fig.test.ts +20 -20
  24. package/src/parser/block/extension/figure.test.ts +31 -28
  25. package/src/parser/block/extension/figure.ts +5 -3
  26. package/src/parser/block/extension/table.ts +6 -6
  27. package/src/parser/block/heading.test.ts +1 -1
  28. package/src/parser/block.ts +1 -2
  29. package/src/parser/inline/annotation.ts +3 -3
  30. package/src/parser/inline/bracket.test.ts +10 -10
  31. package/src/parser/inline/bracket.ts +5 -8
  32. package/src/parser/inline/deletion.test.ts +4 -1
  33. package/src/parser/inline/deletion.ts +7 -4
  34. package/src/parser/inline/emphasis.ts +3 -6
  35. package/src/parser/inline/emstrong.ts +7 -8
  36. package/src/parser/inline/extension/index.test.ts +19 -18
  37. package/src/parser/inline/extension/index.ts +3 -4
  38. package/src/parser/inline/extension/indexer.test.ts +1 -0
  39. package/src/parser/inline/extension/indexer.ts +1 -0
  40. package/src/parser/inline/html.test.ts +25 -17
  41. package/src/parser/inline/html.ts +39 -15
  42. package/src/parser/inline/insertion.test.ts +4 -1
  43. package/src/parser/inline/insertion.ts +7 -4
  44. package/src/parser/inline/link.test.ts +3 -0
  45. package/src/parser/inline/link.ts +9 -11
  46. package/src/parser/inline/mark.ts +3 -6
  47. package/src/parser/inline/media.test.ts +3 -0
  48. package/src/parser/inline/media.ts +9 -6
  49. package/src/parser/inline/reference.ts +6 -6
  50. package/src/parser/inline/ruby.ts +3 -4
  51. package/src/parser/inline/strong.test.ts +1 -1
  52. package/src/parser/inline/strong.ts +3 -6
  53. package/src/parser/inline.test.ts +2 -3
  54. package/src/parser/processor/figure.test.ts +28 -28
  55. package/src/parser/processor/figure.ts +1 -1
  56. package/src/parser/util.ts +43 -39
@@ -28,7 +28,7 @@ describe('Unit: parser/processor/figure', () => {
28
28
  assert.deepStrictEqual(
29
29
  [...target.children].map(el => el.outerHTML),
30
30
  [
31
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
31
+ '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
32
32
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
33
33
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
34
34
  ]);
@@ -47,10 +47,10 @@ describe('Unit: parser/processor/figure', () => {
47
47
  assert.deepStrictEqual(
48
48
  [...target.children].map(el => el.outerHTML),
49
49
  [
50
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
50
+ '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
51
51
  '<h2 id="index:0">0</h2>',
52
- '<figure data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2. </span><figcaption></figcaption></figure>',
53
- '<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Table 1. </span><figcaption></figcaption></figure>',
52
+ '<figure data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
53
+ '<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Table 1. </span></figcaption></figure>',
54
54
  ]);
55
55
  }
56
56
  });
@@ -65,7 +65,7 @@ describe('Unit: parser/processor/figure', () => {
65
65
  assert.deepStrictEqual(
66
66
  [...target.children].map(el => el.outerHTML),
67
67
  [
68
- '<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><span class="figindex">(1)</span><figcaption></figcaption></figure>',
68
+ '<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
69
69
  '<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
70
70
  ]);
71
71
  }
@@ -87,11 +87,11 @@ describe('Unit: parser/processor/figure', () => {
87
87
  assert.deepStrictEqual(
88
88
  [...target.children].map(el => el.outerHTML),
89
89
  [
90
- '<figure data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2. </span><figcaption></figcaption></figure>',
91
- '<figure data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 3.1. </span><figcaption></figcaption></figure>',
92
- '<figure data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><span class="figindex">(4.1.1)</span><figcaption></figcaption></figure>',
93
- '<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><span class="figindex">(1)</span><figcaption></figcaption></figure>',
94
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
90
+ '<figure data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
91
+ '<figure data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
92
+ '<figure data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(4.1.1)</span></figcaption></figure>',
93
+ '<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
94
+ '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
95
95
  '<p><a class="label" data-label="fig-2" href="#label:fig-2">Fig. 2</a></p>',
96
96
  '<p><a class="label" data-label="$-4.1.1" href="#label:$-4.1.1">(4.1.1)</a></p>',
97
97
  '<p><a class="label disabled invalid" data-label="fig-1" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-description="Missing the reference.">$fig-1</a></p>',
@@ -111,10 +111,10 @@ describe('Unit: parser/processor/figure', () => {
111
111
  assert.deepStrictEqual(
112
112
  [...target.children].map(el => el.outerHTML),
113
113
  [
114
- '<blockquote><blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
115
- '<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n&gt; \n\n~~~\n\n$fig-a</pre><hr><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure><p><a class="label disabled" data-label="fig-a">Fig. 1</a></p><ol class="annotations"></ol><ol class="references"></ol></section></aside>',
116
- '<figure data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
117
- '<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2. </span><figcaption></figcaption></figure>',
114
+ '<blockquote><blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
115
+ '<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n&gt; \n\n~~~\n\n$fig-a</pre><hr><section><figure data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><p><a class="label disabled" data-label="fig-a">Fig. 1</a></p><ol class="annotations"></ol><ol class="references"></ol></section></aside>',
116
+ '<figure data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
117
+ '<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
118
118
  ]);
119
119
  }
120
120
  });
@@ -163,16 +163,16 @@ describe('Unit: parser/processor/figure', () => {
163
163
  '<h1 id="index:0">0</h1>',
164
164
  '<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
165
165
  '<h2 id="index:0">0</h2>',
166
- '<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
166
+ '<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
167
167
  '<h2 id="index:0">0</h2>',
168
168
  '<blockquote><section><h2>0</h2><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
169
- '<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2.1. </span><figcaption></figcaption></figure>',
169
+ '<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></figcaption></figure>',
170
170
  '<h2 id="index:0">0</h2>',
171
171
  '<figure data-label="$-0.0.0" data-group="$" hidden=""></figure>',
172
- '<figure data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 3.1. </span><figcaption></figcaption></figure>',
172
+ '<figure data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
173
173
  '<h2 id="index:0">0</h2>',
174
174
  '<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
175
- '<figure data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 4.1. </span><figcaption></figcaption></figure>',
175
+ '<figure data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 4.1. </span></figcaption></figure>',
176
176
  '<figure data-label="$-0.0" data-group="$" hidden=""></figure>',
177
177
  '<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
178
178
  '<figure data-label="$-0.4.0" data-group="$" hidden=""></figure>',
@@ -180,19 +180,19 @@ describe('Unit: parser/processor/figure', () => {
180
180
  '<h2 id="index:0">0</h2>',
181
181
  '<h2 id="index:0">0</h2>',
182
182
  '<figure data-label="$-0.0" data-group="$" hidden="" data-number="6.0"></figure>',
183
- '<figure data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 6.1. </span><figcaption></figcaption></figure>',
183
+ '<figure data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></figcaption></figure>',
184
184
  '<h2 id="index:0">0</h2>',
185
185
  '<figure data-label="$-5.0" data-group="$" hidden="" data-number="5.0"></figure>',
186
- '<figure data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.1. </span><figcaption></figcaption></figure>',
186
+ '<figure data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.1. </span></figcaption></figure>',
187
187
  '<figure data-label="$-0" data-group="$" hidden=""></figure>',
188
- '<figure data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.2. </span><figcaption></figcaption></figure>',
188
+ '<figure data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.2. </span></figcaption></figure>',
189
189
  '<h3 id="index:0">0</h3>',
190
190
  '<figure data-label="$-0.0.0" data-group="$" hidden=""></figure>',
191
- '<figure data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.3. </span><figcaption></figcaption></figure>',
191
+ '<figure data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.3. </span></figcaption></figure>',
192
192
  '<h3 id="index:0">0</h3>',
193
- '<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.4. </span><figcaption></figcaption></figure>',
193
+ '<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.4. </span></figcaption></figure>',
194
194
  '<h1 id="index:0">0</h1>',
195
- '<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 6.1. </span><figcaption></figcaption></figure>',
195
+ '<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></figcaption></figure>',
196
196
  ]);
197
197
  }
198
198
  });
@@ -219,10 +219,10 @@ describe('Unit: parser/processor/figure', () => {
219
219
  '<h2 id="index:0">0</h2>',
220
220
  '<h2 id="index:0">0</h2>',
221
221
  '<figure data-label="$-1.0" data-group="$" hidden="" data-number="1.0"></figure>',
222
- '<figure data-label="fig-a" data-group="fig" data-number="1.1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1.1. </span><figcaption></figcaption></figure>',
222
+ '<figure data-label="fig-a" data-group="fig" data-number="1.1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1.1. </span></figcaption></figure>',
223
223
  '<h2 id="index:0">0</h2>',
224
224
  '<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
225
- '<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2.1. </span><figcaption></figcaption></figure>',
225
+ '<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></figcaption></figure>',
226
226
  ]);
227
227
  }
228
228
  });
@@ -238,7 +238,7 @@ describe('Unit: parser/processor/figure', () => {
238
238
  assert.deepStrictEqual(
239
239
  [...target.children].map(el => el.outerHTML),
240
240
  [
241
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
241
+ '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
242
242
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
243
243
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
244
244
  ]);
@@ -255,7 +255,7 @@ describe('Unit: parser/processor/figure', () => {
255
255
  assert.deepStrictEqual(
256
256
  [...target.children].map(el => el.outerHTML),
257
257
  [
258
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
258
+ '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
259
259
  '<p><a class="label" data-label="fig-a" href="#label:0:fig-a">Fig. 1</a></p>',
260
260
  ]);
261
261
  }
@@ -85,7 +85,7 @@ export function* figure(
85
85
  ? `(${number})`
86
86
  : `${capitalize(group)}${group === 'fig' ? '.' : ''} ${number}`;
87
87
  define(
88
- def.querySelector(':scope > .figindex')!,
88
+ def.querySelector(':scope > figcaption > .figindex')!,
89
89
  group === '$' ? figindex : `${figindex}. `);
90
90
  for (const ref of refs.take(label, Infinity)) {
91
91
  if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
@@ -5,15 +5,23 @@ import { union, some, verify, convert } from '../combinator';
5
5
  import { unsafehtmlentity } from './inline/htmlentity';
6
6
  import { linebreak, unescsource } from './source';
7
7
  import { invisibleHTMLEntityNames } from './api/normalize';
8
- import { push, pop } from 'spica/array';
8
+ import { reduce } from 'spica/memoize';
9
+ import { push } from 'spica/array';
9
10
 
10
- export function delimiter(opener: string): RegExp {
11
- return new RegExp(String.raw`^(?:\s+|\\\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)?${opener}`);
11
+ export function blank(prefix: '' | RegExp, suffix: string | RegExp): RegExp {
12
+ return new RegExp(String.raw
13
+ `^${
14
+ prefix && prefix.source
15
+ }(?:\\\s|[^\S\n]+|\n|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)?${
16
+ typeof suffix === 'string' ? suffix : suffix.source
17
+ }`);
12
18
  }
13
19
 
14
20
  export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
15
21
  export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
16
- const blankline = new RegExp(String.raw`^(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`, 'gm');
22
+ const blankline = new RegExp(String.raw
23
+ `^(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`,
24
+ 'gm');
17
25
  return union([
18
26
  convert(
19
27
  source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
@@ -45,11 +53,9 @@ export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, ex
45
53
  ? parser(source, context)
46
54
  : undefined;
47
55
  }
48
- export function isStartLoose(source: string, context: MarkdownParser.Context, except?: string): boolean {
49
- source &&= source.replace(/^[^\S\n]+/, '');
50
- if (source === '') return true;
51
- return isStartTight(source, context, except);
52
- }
56
+ export const isStartLoose = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
57
+ return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
58
+ }, (source, _, except = '') => `${source}\0${except}`);
53
59
  export function startTight<P extends Parser<unknown>>(parser: P, except?: string): P;
54
60
  export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
55
61
  return (source, context) =>
@@ -57,7 +63,7 @@ export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
57
63
  ? parser(source, context)
58
64
  : undefined;
59
65
  }
60
- function isStartTight(source: string, context: MarkdownParser.Context, except?: string): boolean {
66
+ const isStartTight = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
61
67
  if (source === '') return true;
62
68
  if (except && source.slice(0, except.length) === except) return false;
63
69
  switch (source[0]) {
@@ -87,15 +93,15 @@ function isStartTight(source: string, context: MarkdownParser.Context, except?:
87
93
  default:
88
94
  return source[0].trimStart() !== '';
89
95
  }
90
- }
96
+ }, (source, _, except = '') => `${source}\0${except}`);
91
97
  export function isStartTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
92
98
  if (nodes.length === 0) return true;
93
99
  return isVisible(nodes[0], 0);
94
100
  }
95
- export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
96
- if (nodes.length === 0) return true;
97
- return isVisible(nodes[nodes.length - 1], -1);
98
- }
101
+ //export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
102
+ // if (nodes.length === 0) return true;
103
+ // return isVisible(nodes[nodes.length - 1], -1);
104
+ //}
99
105
  function isVisible(node: HTMLElement | string, strpos?: number): boolean {
100
106
  switch (typeof node) {
101
107
  case 'string':
@@ -124,23 +130,29 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
124
130
  }
125
131
  }
126
132
 
127
- export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
128
- return trimNodeStart(trimNodeEnd(nodes));
129
- }
130
- function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
131
- for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
132
- if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
133
- if (typeof node === 'string') {
134
- const pos = node.length - node.trimStart().length;
135
- if (pos > 0) {
136
- nodes[0] = node.slice(pos);
137
- break;
138
- }
139
- }
140
- nodes.shift();
141
- }
142
- return nodes;
133
+ export function trimSpaceStart<P extends Parser<unknown>>(parser: P): P;
134
+ export function trimSpaceStart<T>(parser: Parser<T>): Parser<T> {
135
+ return convert(
136
+ reduce(source => source.replace(/^[^\S\n]+/, '')),
137
+ parser);
143
138
  }
139
+ //export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
140
+ // return trimNodeStart(trimNodeEnd(nodes));
141
+ //}
142
+ //function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
143
+ // for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
144
+ // if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
145
+ // if (typeof node === 'string') {
146
+ // const pos = node.length - node.trimStart().length;
147
+ // if (pos > 0) {
148
+ // nodes[0] = node.slice(pos);
149
+ // break;
150
+ // }
151
+ // }
152
+ // nodes.shift();
153
+ // }
154
+ // return nodes;
155
+ //}
144
156
  export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
145
157
  const skip = nodes.length > 0 &&
146
158
  typeof nodes[nodes.length - 1] === 'object' &&
@@ -159,14 +171,6 @@ export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | str
159
171
  }
160
172
  return push(nodes, skip);
161
173
  }
162
- export function trimNodeEndBR<T extends HTMLElement | string>(nodes: T[]): T[];
163
- export function trimNodeEndBR(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
164
- if (nodes.length === 0) return nodes;
165
- const node = nodes[nodes.length - 1];
166
- return typeof node === 'object' && node.tagName === 'BR'
167
- ? pop(nodes)[0]
168
- : nodes;
169
- }
170
174
 
171
175
  export function stringify(nodes: readonly (HTMLElement | string)[]): string {
172
176
  let acc = '';