securemark 0.292.0 → 0.293.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.js +597 -416
  3. package/markdown.d.ts +35 -60
  4. package/package.json +1 -1
  5. package/src/combinator/control/constraint/contract.ts +6 -15
  6. package/src/combinator/control/manipulation/clear.ts +3 -4
  7. package/src/combinator/control/manipulation/fence.ts +3 -1
  8. package/src/combinator/control/manipulation/indent.ts +5 -11
  9. package/src/combinator/control/manipulation/match.ts +3 -2
  10. package/src/combinator/control/manipulation/recovery.ts +1 -1
  11. package/src/combinator/control/manipulation/scope.ts +3 -10
  12. package/src/combinator/control/manipulation/surround.ts +4 -24
  13. package/src/combinator/data/parser/context/delimiter.ts +10 -9
  14. package/src/combinator/data/parser/context.ts +31 -0
  15. package/src/combinator/data/parser/inits.ts +1 -1
  16. package/src/combinator/data/parser/sequence.ts +1 -1
  17. package/src/combinator/data/parser/some.test.ts +1 -1
  18. package/src/combinator/data/parser/some.ts +4 -5
  19. package/src/combinator/data/parser.ts +0 -1
  20. package/src/combinator.ts +0 -1
  21. package/src/parser/api/parse.test.ts +16 -8
  22. package/src/parser/api/parse.ts +1 -2
  23. package/src/parser/autolink.test.ts +7 -7
  24. package/src/parser/autolink.ts +2 -4
  25. package/src/parser/block/blockquote.test.ts +1 -1
  26. package/src/parser/block/blockquote.ts +7 -7
  27. package/src/parser/block/codeblock.ts +8 -8
  28. package/src/parser/block/dlist.test.ts +1 -1
  29. package/src/parser/block/dlist.ts +5 -6
  30. package/src/parser/block/extension/aside.ts +4 -4
  31. package/src/parser/block/extension/example.ts +4 -4
  32. package/src/parser/block/extension/fig.ts +5 -5
  33. package/src/parser/block/extension/figbase.ts +1 -1
  34. package/src/parser/block/extension/figure.test.ts +1 -1
  35. package/src/parser/block/extension/figure.ts +6 -6
  36. package/src/parser/block/extension/message.ts +4 -4
  37. package/src/parser/block/extension/placeholder.ts +8 -8
  38. package/src/parser/block/extension/table.test.ts +1 -1
  39. package/src/parser/block/extension/table.ts +32 -22
  40. package/src/parser/block/extension.ts +3 -3
  41. package/src/parser/block/heading.test.ts +1 -1
  42. package/src/parser/block/heading.ts +2 -2
  43. package/src/parser/block/ilist.test.ts +3 -3
  44. package/src/parser/block/ilist.ts +5 -5
  45. package/src/parser/block/mathblock.ts +8 -8
  46. package/src/parser/block/mediablock.ts +6 -6
  47. package/src/parser/block/olist.test.ts +16 -14
  48. package/src/parser/block/olist.ts +13 -13
  49. package/src/parser/block/pagebreak.ts +1 -1
  50. package/src/parser/block/paragraph.test.ts +3 -4
  51. package/src/parser/block/paragraph.ts +1 -2
  52. package/src/parser/block/reply/cite.ts +7 -9
  53. package/src/parser/block/reply/quote.ts +6 -6
  54. package/src/parser/block/reply.ts +3 -3
  55. package/src/parser/block/sidefence.ts +3 -3
  56. package/src/parser/block/table.ts +13 -13
  57. package/src/parser/block/ulist.test.ts +8 -7
  58. package/src/parser/block/ulist.ts +6 -7
  59. package/src/parser/block.ts +48 -15
  60. package/src/parser/context.ts +4 -4
  61. package/src/parser/header.ts +3 -3
  62. package/src/parser/inline/annotation.ts +1 -1
  63. package/src/parser/inline/autolink/account.test.ts +8 -7
  64. package/src/parser/inline/autolink/account.ts +11 -8
  65. package/src/parser/inline/autolink/anchor.test.ts +1 -1
  66. package/src/parser/inline/autolink/anchor.ts +21 -17
  67. package/src/parser/inline/autolink/channel.test.ts +8 -8
  68. package/src/parser/inline/autolink/channel.ts +40 -15
  69. package/src/parser/inline/autolink/email.test.ts +15 -15
  70. package/src/parser/inline/autolink/email.ts +5 -7
  71. package/src/parser/inline/autolink/hashnum.test.ts +4 -9
  72. package/src/parser/inline/autolink/hashnum.ts +8 -4
  73. package/src/parser/inline/autolink/hashtag.test.ts +9 -10
  74. package/src/parser/inline/autolink/hashtag.ts +9 -6
  75. package/src/parser/inline/autolink/url.test.ts +72 -74
  76. package/src/parser/inline/autolink/url.ts +19 -24
  77. package/src/parser/inline/autolink.ts +21 -24
  78. package/src/parser/inline/bracket.ts +3 -3
  79. package/src/parser/inline/code.ts +2 -2
  80. package/src/parser/inline/deletion.test.ts +2 -2
  81. package/src/parser/inline/deletion.ts +1 -1
  82. package/src/parser/inline/emphasis.test.ts +5 -5
  83. package/src/parser/inline/emphasis.ts +2 -7
  84. package/src/parser/inline/emstrong.test.ts +14 -14
  85. package/src/parser/inline/emstrong.ts +4 -16
  86. package/src/parser/inline/extension/index.test.ts +5 -3
  87. package/src/parser/inline/extension/index.ts +8 -10
  88. package/src/parser/inline/extension/indexer.test.ts +1 -2
  89. package/src/parser/inline/extension/indexer.ts +3 -3
  90. package/src/parser/inline/extension/label.ts +1 -1
  91. package/src/parser/inline/extension/placeholder.ts +1 -1
  92. package/src/parser/inline/html.test.ts +2 -2
  93. package/src/parser/inline/html.ts +21 -20
  94. package/src/parser/inline/htmlentity.ts +4 -4
  95. package/src/parser/inline/insertion.test.ts +2 -2
  96. package/src/parser/inline/insertion.ts +1 -1
  97. package/src/parser/inline/italic.test.ts +9 -9
  98. package/src/parser/inline/italic.ts +1 -1
  99. package/src/parser/inline/link.ts +14 -19
  100. package/src/parser/inline/mark.test.ts +5 -5
  101. package/src/parser/inline/mark.ts +1 -1
  102. package/src/parser/inline/math.test.ts +6 -6
  103. package/src/parser/inline/math.ts +9 -13
  104. package/src/parser/inline/media.ts +9 -14
  105. package/src/parser/inline/reference.test.ts +4 -4
  106. package/src/parser/inline/reference.ts +5 -5
  107. package/src/parser/inline/remark.test.ts +19 -23
  108. package/src/parser/inline/remark.ts +17 -19
  109. package/src/parser/inline/ruby.ts +5 -3
  110. package/src/parser/inline/shortmedia.ts +6 -9
  111. package/src/parser/inline/strong.test.ts +5 -5
  112. package/src/parser/inline/strong.ts +2 -7
  113. package/src/parser/inline.test.ts +25 -23
  114. package/src/parser/inline.ts +21 -9
  115. package/src/parser/segment.ts +23 -5
  116. package/src/parser/source/escapable.test.ts +6 -6
  117. package/src/parser/source/escapable.ts +20 -5
  118. package/src/parser/source/line.ts +28 -4
  119. package/src/parser/source/str.ts +5 -27
  120. package/src/parser/source/text.test.ts +60 -60
  121. package/src/parser/source/text.ts +121 -6
  122. package/src/parser/source/unescapable.test.ts +8 -8
  123. package/src/parser/source/unescapable.ts +19 -3
  124. package/src/parser/util.ts +3 -3
  125. package/src/parser/visibility.ts +45 -40
  126. package/src/combinator/control/manipulation/trim.test.ts +0 -23
  127. package/src/combinator/control/manipulation/trim.ts +0 -17
@@ -4,13 +4,21 @@ import { html } from 'typed-dom/dom';
4
4
  describe('Unit: parser/api/parse', () => {
5
5
  describe('parse', () => {
6
6
  it('huge input', () => {
7
- assert.throws(() =>
8
- parse(`${'\n'.repeat(10 * 1000 ** 2)}`));
7
+ assert.deepStrictEqual(
8
+ [...parse(`${'\n'.repeat(10 * 1000 ** 2)}`, { id: '' }).children].map(el => el.outerHTML),
9
+ [
10
+ '<h1 class="error">Error: Too large input over 1,000,000 bytes.</h1>',
11
+ `<pre class="error" translate="no">${'\n'.repeat(997)}...</pre>`,
12
+ ]);
9
13
  });
10
14
 
11
15
  it('huge segment', () => {
12
- assert.throws(() =>
13
- parse(`${'\n'.repeat(100 * 1000 + 1)}`));
16
+ assert.deepStrictEqual(
17
+ [...parse(`${'\n'.repeat(100 * 1000 + 1)}`, { id: '' }).children].map(el => el.outerHTML),
18
+ [
19
+ '<h1 class="error">Error: Too large segment over 100,000 bytes.</h1>',
20
+ `<pre class="error" translate="no">${'\n'.repeat(997)}...</pre>`,
21
+ ]);
14
22
  });
15
23
 
16
24
  it('result', () => {
@@ -74,7 +82,7 @@ describe('Unit: parser/api/parse', () => {
74
82
  ['<p>a<br>b</p>']);
75
83
  assert.deepStrictEqual(
76
84
  [...parse('a\n\\ \nb').children].map(el => el.outerHTML),
77
- ['<p>a<br>\\ <br>b</p>']);
85
+ ['<p>a<br>\\<br>b</p>']);
78
86
  assert.deepStrictEqual(
79
87
  [...parse('a\n\\\nb').children].map(el => el.outerHTML),
80
88
  ['<p>a<br>\\<br>b</p>']);
@@ -353,9 +361,9 @@ describe('Unit: parser/api/parse', () => {
353
361
 
354
362
  it('backtrack', function () {
355
363
  this.timeout(5000);
356
- // 最悪計算量での実行速度はCommonMarkの公式JS実装の32nに対して5倍遅い程度。
364
+ // 最悪計算量での実行速度はCommonMarkの公式JS実装の32nに対して3倍遅い程度。
357
365
  // 5n = annotation/reference + link + url/math + ruby + text
358
- const source = `${'.'.repeat(5 + 0)}((([[[[#$[${'.'.repeat(19997)}`;
366
+ const source = `${'.'.repeat(0 + 0)}((([[[[#$[${'.'.repeat(19998)}`;
359
367
  assert.deepStrictEqual(
360
368
  [...parse(source, {}, { resources: { clock: 100000, recursions: [100] } }).children]
361
369
  .map(el => el.tagName),
@@ -364,7 +372,7 @@ describe('Unit: parser/api/parse', () => {
364
372
 
365
373
  it('backtrack error', function () {
366
374
  this.timeout(5000);
367
- const source = `${'.'.repeat(5 + 1)}((([[[[#$[${'.'.repeat(19997)}`;
375
+ const source = `${'.'.repeat(0 + 1)}((([[[[#$[${'.'.repeat(19998)}`;
368
376
  assert.deepStrictEqual(
369
377
  [...parse(source, {}, { resources: { clock: 100000, recursions: [100] } }).children]
370
378
  .map(el => el.tagName),
@@ -1,7 +1,7 @@
1
1
  import { ParserOptions } from '../../..';
2
2
  import { MarkdownParser } from '../../../markdown';
3
3
  import { input, eval } from '../../combinator/data/parser';
4
- import { segment, validate, MAX_SEGMENT_SIZE } from '../segment';
4
+ import { segment } from '../segment';
5
5
  import { header } from '../header';
6
6
  import { block } from '../block';
7
7
  import { normalize } from './normalize';
@@ -16,7 +16,6 @@ interface Options extends ParserOptions {
16
16
  }
17
17
 
18
18
  export function parse(source: string, opts: Options = {}, context?: MarkdownParser.Options | MarkdownParser.Context): DocumentFragment {
19
- if (!validate(source, MAX_SEGMENT_SIZE)) throw new Error(`Too large input over ${MAX_SEGMENT_SIZE.toLocaleString('en')} bytes`);
20
19
  const url = headers(source).find(field => field.toLowerCase().startsWith('url:'))?.slice(4).trim() ?? '';
21
20
  source = !context ? normalize(source) : source;
22
21
  context = {
@@ -15,15 +15,15 @@ describe('Unit: parser/autolink', () => {
15
15
  assert.deepStrictEqual(inspect(parser('#a'), ctx), [['<a class="hashtag" href="/hashtags/a">#a</a>'], '']);
16
16
  assert.deepStrictEqual(inspect(parser('@a#b'), ctx), [['<a class="channel" href="/@a?ch=b">@a#b</a>'], '']);
17
17
  assert.deepStrictEqual(inspect(parser('\\\n'), ctx), [['\\', '<br>'], '']);
18
- assert.deepStrictEqual(inspect(parser('a#b'), ctx), [['a#b'], '']);
19
- assert.deepStrictEqual(inspect(parser('0a#b'), ctx), [['0a#b'], '']);
20
- assert.deepStrictEqual(inspect(parser('あ#b'), ctx), [['あ#b'], '']);
21
- assert.deepStrictEqual(inspect(parser('あい#b'), ctx), [['', 'い#b'], '']);
22
- assert.deepStrictEqual(inspect(parser('0aあ#b'), ctx), [['0aあ#b'], '']);
23
- assert.deepStrictEqual(inspect(parser('0aあい#b'), ctx), [['0a', '', 'い#b'], '']);
18
+ assert.deepStrictEqual(inspect(parser('a#b'), ctx), [['a', '#b'], '']);
19
+ assert.deepStrictEqual(inspect(parser('0a#b'), ctx), [['0a', '#b'], '']);
20
+ assert.deepStrictEqual(inspect(parser('あ#b'), ctx), [['あ', '#b'], '']);
21
+ assert.deepStrictEqual(inspect(parser('あい#b'), ctx), [['あい', '#b'], '']);
22
+ assert.deepStrictEqual(inspect(parser('0aあ#b'), ctx), [['0a', 'あ', '#b'], '']);
23
+ assert.deepStrictEqual(inspect(parser('0aあい#b'), ctx), [['0a', 'あい', '#b'], '']);
24
24
  assert.deepStrictEqual(inspect(parser('a\n#b'), ctx), [['a', '<br>', '<a class="hashtag" href="/hashtags/b">#b</a>'], '']);
25
25
  assert.deepStrictEqual(inspect(parser('a\\\n#b'), ctx), [['a', '\\', '<br>', '<a class="hashtag" href="/hashtags/b">#b</a>'], '']);
26
- assert.deepStrictEqual(inspect(parser('0a>>b'), ctx), [['0a>>b'], '']);
26
+ assert.deepStrictEqual(inspect(parser('0a>>b'), ctx), [['0a', '>', '>b'], '']);
27
27
  });
28
28
 
29
29
  });
@@ -1,15 +1,13 @@
1
1
  import { MarkdownParser } from '../../markdown';
2
- import { union, some, convert, lazy } from '../combinator';
2
+ import { union, some, lazy } from '../combinator';
3
3
  import { autolink as autolink_ } from './inline/autolink';
4
4
  import { linebreak, unescsource } from './source';
5
5
 
6
6
  export import AutolinkParser = MarkdownParser.AutolinkParser;
7
7
 
8
8
  export const autolink: AutolinkParser = lazy(() =>
9
- convert(source => `\r${source}`,
10
9
  some(union([
11
10
  autolink_,
12
11
  linebreak,
13
12
  unescsource,
14
- ])),
15
- false));
13
+ ])));
@@ -76,7 +76,7 @@ describe('Unit: parser/block/blockquote', () => {
76
76
  assert.deepStrictEqual(inspect(parser('!> a\\\nb'), ctx), [['<blockquote><section><p>a<br>b</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
77
77
  assert.deepStrictEqual(inspect(parser('!> ++a\nb++'), ctx), [['<blockquote><section><p><ins>a<br>b</ins></p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
78
78
  assert.deepStrictEqual(inspect(parser('!> ++a\n> b++'), ctx), [['<blockquote><section><p><ins>a<br>b</ins></p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
79
- assert.deepStrictEqual(inspect(parser('!> a \n b c '), ctx), [['<blockquote><section><p> a <br> b c</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
79
+ assert.deepStrictEqual(inspect(parser('!> a \n b c '), ctx), [['<blockquote><section><p> a<br> b c</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
80
80
  assert.deepStrictEqual(inspect(parser('!>> a'), ctx), [['<blockquote><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote></blockquote>'], '']);
81
81
  assert.deepStrictEqual(inspect(parser('!>> a\n> b'), ctx), [['<blockquote><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote><section><p>b</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
82
82
  assert.deepStrictEqual(inspect(parser('!> - a'), ctx), [['<blockquote><section><ul><li>a</li></ul><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
@@ -6,17 +6,17 @@ import { contentline } from '../source';
6
6
  import { parse } from '../api/parse';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
 
9
- export const segment: BlockquoteParser.SegmentParser = block(validate(['!>', '>'], union([
10
- validate(/^!?>+(?=[^\S\n]|\n[^\S\n]*\S)/, some(contentline)),
11
- ])));
9
+ export const segment: BlockquoteParser.SegmentParser = block(union([
10
+ validate(/!?>+(?=[^\S\n]|\n[^\S\n]*\S)/y, some(contentline)),
11
+ ]));
12
12
 
13
13
  export const blockquote: BlockquoteParser = lazy(() => block(rewrite(segment, union([
14
- open(/^(?=>)/, source),
15
- open(/^!(?=>)/, markdown),
14
+ open(/(?=>)/y, source),
15
+ open(/!(?=>)/y, markdown),
16
16
  ]))));
17
17
 
18
- const opener = /^(?=>>+(?:$|\s))/;
19
- const indent = block(open(opener, some(contentline, /^>(?:$|\s)/)), false);
18
+ const opener = /(?=>>+(?:$|\s))/y;
19
+ const indent = block(open(opener, some(contentline, />(?:$|\s)/y)), false);
20
20
  const unindent = (source: string) => source.replace(/(?<=^|\n)>(?:[^\S\n]|(?=>*(?:$|\s)))|\n$/g, '');
21
21
 
22
22
  const source: BlockquoteParser.SourceParser = lazy(() => fmap(
@@ -1,20 +1,20 @@
1
1
  import { CodeBlockParser } from '../block';
2
2
  import { input, eval } from '../../combinator/data/parser';
3
- import { block, validate, fence, clear, fmap } from '../../combinator';
3
+ import { block, fence, clear, fmap } from '../../combinator';
4
4
  import { autolink } from '../autolink';
5
5
  import { invalid } from '../util';
6
6
  import { html, defrag } from 'typed-dom/dom';
7
7
 
8
- const opener = /^(`{3,})(?!`)([^\n]*)(?:$|\n)/;
8
+ const opener = /(`{3,})(?!`)([^\n]*)(?:$|\n)/y;
9
9
  const language = /^[0-9a-z]+(?:-[a-z][0-9a-z]*)*$/i;
10
10
 
11
- export const segment: CodeBlockParser.SegmentParser = block(validate('```',
12
- clear(fence(opener, 300))));
11
+ export const segment: CodeBlockParser.SegmentParser = block(
12
+ clear(fence(opener, 300)));
13
13
 
14
- export const segment_: CodeBlockParser.SegmentParser = block(validate('```',
15
- clear(fence(opener, 300, false))), false);
14
+ export const segment_: CodeBlockParser.SegmentParser = block(
15
+ clear(fence(opener, 300, false)), false);
16
16
 
17
- export const codeblock: CodeBlockParser = block(validate('```', fmap(
17
+ export const codeblock: CodeBlockParser = block(fmap(
18
18
  fence(opener, 300),
19
19
  // Bug: Type mismatch between outer and inner.
20
20
  ([body, overflow, closer, opener, delim, param]: string[], context) => {
@@ -74,4 +74,4 @@ export const codeblock: CodeBlockParser = block(validate('```', fmap(
74
74
  body.slice(0, -1) || undefined
75
75
  : defrag(eval(autolink(input(body.slice(0, -1), { ...context })), [])));
76
76
  return [el];
77
- })));
77
+ }));
@@ -54,7 +54,7 @@ describe('Unit: parser/block/dlist', () => {
54
54
  assert.deepStrictEqual(inspect(parser('~ a\n: b\n\\\nc'), ctx), [['<dl><dt id="index::a">a</dt><dd>b<br>\\<br>c</dd></dl>'], '']);
55
55
  assert.deepStrictEqual(inspect(parser('~ a~ b'), ctx), [['<dl><dt id="index::a~_b">a~ b</dt><dd></dd></dl>'], '']);
56
56
  assert.deepStrictEqual(inspect(parser('~ a: b'), ctx), [['<dl><dt id="index::a:_b">a: b</dt><dd></dd></dl>'], '']);
57
- assert.deepStrictEqual(inspect(parser('~ a \n: b \nc '), ctx), [['<dl><dt id="index::a">a</dt><dd>b <br>c</dd></dl>'], '']);
57
+ assert.deepStrictEqual(inspect(parser('~ a \n: b\nc '), ctx), [['<dl><dt id="index::a">a</dt><dd>b<br>c</dd></dl>'], '']);
58
58
  assert.deepStrictEqual(inspect(parser('~ a \n: b\n c '), ctx), [['<dl><dt id="index::a">a</dt><dd>b<br> c</dd></dl>'], '']);
59
59
  });
60
60
 
@@ -3,13 +3,12 @@ import { State } from '../context';
3
3
  import { union, inits, some, state, block, line, validate, rewrite, open, lazy, fmap } from '../../combinator';
4
4
  import { inline, indexee, indexer, dataindex } from '../inline';
5
5
  import { anyline } from '../source';
6
- import { lineable } from '../util';
7
6
  import { visualize, trimBlank, trimBlankEnd } from '../visibility';
8
7
  import { push } from 'spica/array';
9
8
  import { html, defrag } from 'typed-dom/dom';
10
9
 
11
10
  export const dlist: DListParser = lazy(() => block(fmap(validate(
12
- /^~[^\S\n]+(?=\S)/,
11
+ /~[^\S\n]+(?=\S)/y,
13
12
  some(inits([
14
13
  state(State.annotation | State.reference | State.index | State.label | State.link,
15
14
  some(term)),
@@ -18,16 +17,16 @@ export const dlist: DListParser = lazy(() => block(fmap(validate(
18
17
  es => [html('dl', fillTrailingDescription(es))])));
19
18
 
20
19
  const term: DListParser.TermParser = line(indexee(fmap(open(
21
- /^~[^\S\n]+(?=\S)/,
20
+ /~[^\S\n]+(?=\S)/y,
22
21
  visualize(trimBlank(some(union([indexer, inline])))),
23
22
  true),
24
23
  ns => [html('dt', { 'data-index': dataindex(ns) }, defrag(ns))])));
25
24
 
26
25
  const desc: DListParser.DescriptionParser = block(fmap(open(
27
- /^:[^\S\n]+(?=\S)|/,
26
+ /:[^\S\n]+(?=\S)|/y,
28
27
  rewrite(
29
- some(anyline, /^[~:][^\S\n]+\S/),
30
- visualize(trimBlankEnd(lineable(some(union([inline])))))),
28
+ some(anyline, /[~:][^\S\n]+\S/y),
29
+ visualize(trimBlankEnd(some(union([inline]))))),
31
30
  true),
32
31
  ns => [html('dd', defrag(ns))]),
33
32
  false);
@@ -1,13 +1,13 @@
1
1
  import { ExtensionParser } from '../../block';
2
2
  import { Recursion } from '../../context';
3
- import { recursion, block, validate, fence, fmap } from '../../../combinator';
3
+ import { recursion, block, fence, fmap } from '../../../combinator';
4
4
  import { identity } from '../../inline/extension/indexee';
5
5
  import { invalid } from '../../util';
6
6
  import { parse } from '../../api/parse';
7
7
  import { html } from 'typed-dom/dom';
8
8
 
9
- export const aside: ExtensionParser.AsideParser = recursion(Recursion.block, block(validate('~~~', fmap(
10
- fence(/^(~{3,})aside(?!\S)([^\n]*)(?:$|\n)/, 300),
9
+ export const aside: ExtensionParser.AsideParser = recursion(Recursion.block, block(fmap(
10
+ fence(/(~{3,})aside(?!\S)([^\n]*)(?:$|\n)/y, 300),
11
11
  // Bug: Type mismatch between outer and inner.
12
12
  ([body, overflow, closer, opener, delim, param]: string[], context) => {
13
13
  if (!closer || overflow || param.trimStart()) return [html('pre', {
@@ -42,4 +42,4 @@ export const aside: ExtensionParser.AsideParser = recursion(Recursion.block, blo
42
42
  references,
43
43
  ]),
44
44
  ];
45
- }))));
45
+ })));
@@ -1,15 +1,15 @@
1
1
  import { ExtensionParser } from '../../block';
2
2
  import { Recursion } from '../../context';
3
3
  import { input, eval } from '../../../combinator/data/parser';
4
- import { recursion, block, validate, fence, fmap } from '../../../combinator';
4
+ import { recursion, block, fence, fmap } from '../../../combinator';
5
5
  import { mathblock } from '../mathblock';
6
6
  import { invalid } from '../../util';
7
7
  import { parse } from '../../api/parse';
8
8
  import { html } from 'typed-dom/dom';
9
9
 
10
- const opener = /^(~{3,})(?:example\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/;
10
+ const opener = /(~{3,})(?:example\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/y;
11
11
 
12
- export const example: ExtensionParser.ExampleParser = recursion(Recursion.block, block(validate('~~~', fmap(
12
+ export const example: ExtensionParser.ExampleParser = recursion(Recursion.block, block(fmap(
13
13
  fence(opener, 300),
14
14
  // Bug: Type mismatch between outer and inner.
15
15
  ([body, overflow, closer, opener, delim, type = 'markdown', param]: string[], context) => {
@@ -58,4 +58,4 @@ export const example: ExtensionParser.ExampleParser = recursion(Recursion.block,
58
58
  }, `${opener}${body}${closer}`),
59
59
  ];
60
60
  }
61
- }))));
61
+ })));
@@ -8,13 +8,13 @@ import { segment as seg_math } from '../mathblock';
8
8
  import { segment as seg_table } from './table';
9
9
  import { segment as seg_blockquote } from '../blockquote';
10
10
  import { segment as seg_placeholder } from './placeholder';
11
- import { media, shortmedia } from '../../inline';
11
+ import { media, lineshortmedia } from '../../inline';
12
12
 
13
13
  import FigParser = ExtensionParser.FigParser;
14
14
 
15
- export const segment: FigParser.SegmentParser = block(validate(['[$', '$'],
15
+ export const segment: FigParser.SegmentParser = block(validate(/\[?\$/y,
16
16
  sequence([
17
- line(close(seg_label, /^(?=\s).*\n/)),
17
+ line(close(seg_label, /(?=\s).*\n/y)),
18
18
  union([
19
19
  seg_code,
20
20
  seg_math,
@@ -39,10 +39,10 @@ export const fig: FigParser = block(rewrite(segment, verify(convert(
39
39
  ([el]) => el.tagName === 'FIGURE')));
40
40
 
41
41
  const parser = sequence([
42
- line(close(seg_label, /^(?=\s).*\n/)),
42
+ line(close(seg_label, /(?=\s).*\n/y)),
43
43
  line(union([
44
44
  media,
45
- shortmedia,
45
+ lineshortmedia,
46
46
  ])),
47
47
  some(contentline),
48
48
  ]);
@@ -4,7 +4,7 @@ import { label } from '../../inline/extension/label';
4
4
  import { html } from 'typed-dom/dom';
5
5
 
6
6
  export const figbase: ExtensionParser.FigbaseParser = block(fmap(
7
- validate(/^\[?\$-(?:[0-9]+\.)*0\]?[^\S\n]*(?!\S|\n[^\S\n]*\S)/,
7
+ validate(/\[?\$-(?:[0-9]+\.)*0\]?[^\S\n]*(?!\S|\n[^\S\n]*\S)/y,
8
8
  line(union([label]))),
9
9
  ([el]) => {
10
10
  const label = el.getAttribute('data-label')!;
@@ -13,7 +13,6 @@ describe('Unit: parser/block/extension/figure', () => {
13
13
  assert.deepStrictEqual(inspect(parser('~~~figure $group-name]\n!https://host\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure $group-name]\n!https://host\n~~~</pre>'], '']);
14
14
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name\n!https://host\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure [$group-name\n!https://host\n~~~</pre>'], '']);
15
15
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\nhttps://host\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure [$group-name]\nhttps://host\n~~~</pre>'], '']);
16
- assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\\\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\\\n~~~</pre>'], '']);
17
16
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n\\\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\n\\\n~~~</pre>'], '']);
18
17
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\na\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\na\n~~~</pre>'], '']);
19
18
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n\n\n\n~~~'), ctx), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\n\n\n\n~~~</pre>'], '']);
@@ -60,6 +59,7 @@ describe('Unit: parser/block/extension/figure', () => {
60
59
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n~~~table\n~~~\n\ncaption\n~~~'), ctx), [['<figure data-type="table" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><table></table></div></figure>'], '']);
61
60
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n> \n~~~\n\n~~~'), ctx), [['<figure data-type="quote" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><blockquote><pre><br>~~~</pre></blockquote></div></figure>'], '']);
62
61
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n> \n~~~\n\ncaption\n~~~'), ctx), [['<figure data-type="quote" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><blockquote><pre><br>~~~</pre></blockquote></div></figure>'], '']);
62
+ assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\\\n~~~'), ctx), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></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>'], '']);
63
63
  assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n![]{https://host}\n~~~'), ctx), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></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>'], '']);
64
64
  assert.deepStrictEqual(inspect(parser('~~~~figure [$group-name]\n!https://host\n~~~~'), ctx), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></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>'], '']);
65
65
  assert.deepStrictEqual(inspect(parser('~~~figure $group-name\n!https://host\n~~~'), ctx), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></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>'], '']);
@@ -12,7 +12,7 @@ import { example } from './example';
12
12
  import { table, segment_ as seg_table } from './table';
13
13
  import { blockquote, segment as seg_blockquote } from '../blockquote';
14
14
  import { placeholder, segment_ as seg_placeholder } from './placeholder';
15
- import { inline, media, shortmedia } from '../../inline';
15
+ import { inline, media, lineshortmedia } from '../../inline';
16
16
  import { visualize, trimBlank } from '../../visibility';
17
17
  import { invalid } from '../../util';
18
18
  import { memoize } from 'spica/memoize';
@@ -21,9 +21,9 @@ import { html, defrag } from 'typed-dom/dom';
21
21
  import FigureParser = ExtensionParser.FigureParser;
22
22
 
23
23
  export const segment: FigureParser.SegmentParser = block(match(
24
- /^(~{3,})(?:figure[^\S\n])?(?=\[?\$)/,
24
+ /(~{3,})(?:figure[^\S\n])?(?=\[?\$)/y,
25
25
  memoize(
26
- ([, fence], closer = new RegExp(String.raw`^${fence}[^\S\n]*(?:$|\n)`)) => close(
26
+ ([, fence], closer = new RegExp(String.raw`${fence}[^\S\n]*(?:$|\n)`, 'y')) => close(
27
27
  sequence([
28
28
  contentline,
29
29
  inits([
@@ -49,7 +49,7 @@ export const segment: FigureParser.SegmentParser = block(match(
49
49
  export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
50
50
  convert(source => source.slice(source.match(/^~+(?:\w+\s+)?/)![0].length, source.trimEnd().lastIndexOf('\n')),
51
51
  sequence([
52
- line(sequence([label, str(/^(?=\s).*\n/)])),
52
+ line(sequence([label, str(/(?=\s).*\n/y)])),
53
53
  inits([
54
54
  block(union([
55
55
  ulist,
@@ -62,7 +62,7 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
62
62
  blockquote,
63
63
  placeholder,
64
64
  line(media),
65
- line(shortmedia),
65
+ line(lineshortmedia),
66
66
  ])),
67
67
  emptyline,
68
68
  block(visualize(trimBlank(some(inline)))),
@@ -80,7 +80,7 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
80
80
  ])
81
81
  ])),
82
82
  fmap(
83
- fence(/^(~{3,})(?:figure|\[?\$\S*)(?!\S)[^\n]*(?:$|\n)/, 300),
83
+ fence(/(~{3,})(?:figure|\[?\$\S*)(?!\S)[^\n]*(?:$|\n)/y, 300),
84
84
  ([body, overflow, closer, opener, delim]: string[], context) => {
85
85
  const violation =
86
86
  !closer && [
@@ -1,6 +1,6 @@
1
1
  import { ExtensionParser } from '../../block';
2
2
  import { input, eval } from '../../../combinator/data/parser';
3
- import { union, block, validate, fence, fmap } from '../../../combinator';
3
+ import { union, block, fence, fmap } from '../../../combinator';
4
4
  import { segment } from '../../segment';
5
5
  import { emptyline } from '../../source';
6
6
  import { ulist } from '../ulist';
@@ -19,8 +19,8 @@ import { html } from 'typed-dom/dom';
19
19
 
20
20
  import MessageParser = ExtensionParser.MessageParser;
21
21
 
22
- export const message: MessageParser = block(validate('~~~', fmap(
23
- fence(/^(~{3,})message\/(\S+)([^\n]*)(?:$|\n)/, 300),
22
+ export const message: MessageParser = block(fmap(
23
+ fence(/(~{3,})message\/(\S+)([^\n]*)(?:$|\n)/y, 300),
24
24
  // Bug: Type mismatch between outer and inner.
25
25
  ([body, overflow, closer, opener, delim, type, param]: string[], context) => {
26
26
  if (!closer || overflow || param.trimStart()) return [html('pre', {
@@ -50,7 +50,7 @@ export const message: MessageParser = block(validate('~~~', fmap(
50
50
  [html('h1', title(type))],
51
51
  [...segment(body)].reduce((acc, seg) => push(acc, eval(content(input(seg, { ...context })), [])), []))),
52
52
  ];
53
- })));
53
+ }));
54
54
 
55
55
  function title(type: string): string {
56
56
  switch (type) {
@@ -1,17 +1,17 @@
1
1
  import { ExtensionParser } from '../../block';
2
- import { block, validate, fence, clear, fmap } from '../../../combinator';
2
+ import { block, fence, clear, fmap } from '../../../combinator';
3
3
  import { invalid } from '../../util';
4
4
  import { html } from 'typed-dom/dom';
5
5
 
6
- const opener = /^(~{3,})(?!~)[^\n]*(?:$|\n)/;
6
+ const opener = /(~{3,})(?!~)[^\n]*(?:$|\n)/y;
7
7
 
8
- export const segment: ExtensionParser.PlaceholderParser.SegmentParser = block(validate('~~~',
9
- clear(fence(opener, 300))));
8
+ export const segment: ExtensionParser.PlaceholderParser.SegmentParser = block(
9
+ clear(fence(opener, 300)));
10
10
 
11
- export const segment_: ExtensionParser.PlaceholderParser.SegmentParser = block(validate('~~~',
12
- clear(fence(opener, 300, false))), false);
11
+ export const segment_: ExtensionParser.PlaceholderParser.SegmentParser = block(
12
+ clear(fence(opener, 300, false)), false);
13
13
 
14
- export const placeholder: ExtensionParser.PlaceholderParser = block(validate('~~~', fmap(
14
+ export const placeholder: ExtensionParser.PlaceholderParser = block(fmap(
15
15
  fence(opener, Infinity),
16
16
  ([body, overflow, closer, opener, delim]) => [
17
17
  html('pre', {
@@ -24,4 +24,4 @@ export const placeholder: ExtensionParser.PlaceholderParser = block(validate('~~
24
24
  overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
25
25
  'Invalid argument'),
26
26
  }, `${opener}${body}${overflow || closer}`),
27
- ])));
27
+ ]));
@@ -147,7 +147,7 @@ describe('Unit: parser/block/extension/table', () => {
147
147
  [[html('table', [
148
148
  html('thead'),
149
149
  html('tbody', [
150
- html('tr', [html('td', ['\\ ', html('br'), '\\ ', html('br'), '0'])]),
150
+ html('tr', [html('td', ['\\', html('br'), '\\', html('br'), '0'])]),
151
151
  ]),
152
152
  html('tfoot'),
153
153
  ]).outerHTML], '']);
@@ -2,9 +2,9 @@ import { max, min, isArray } from 'spica/alias';
2
2
  import { ExtensionParser } from '../../block';
3
3
  import { Node, eval, input } from '../../../combinator/data/parser';
4
4
  import { union, subsequence, inits, some, block, line, validate, fence, rewrite, clear, surround, open, convert, dup, lazy, fmap } from '../../../combinator';
5
- import { inline, medialink, media, shortmedia } from '../../inline';
5
+ import { inline, medialink, media, lineshortmedia } from '../../inline';
6
6
  import { str, anyline, emptyline, contentline } from '../../source';
7
- import { lineable, invalid } from '../../util';
7
+ import { invalid } from '../../util';
8
8
  import { visualize, trimBlank, trimBlankEnd } from '../../visibility';
9
9
  import { unshift, splice } from 'spica/array';
10
10
  import { html, define, defrag } from 'typed-dom/dom';
@@ -14,15 +14,15 @@ import RowParser = TableParser.RowParser;
14
14
  import AlignParser = TableParser.AlignParser;
15
15
  import CellParser = TableParser.CellParser;
16
16
 
17
- const opener = /^(~{3,})table(?:\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/;
17
+ const opener = /(~{3,})table(?:\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/y;
18
18
 
19
- export const segment: TableParser.SegmentParser = block(validate('~~~',
20
- clear(fence(opener, 10000))));
19
+ export const segment: TableParser.SegmentParser = block(
20
+ clear(fence(opener, 10000)));
21
21
 
22
- export const segment_: TableParser.SegmentParser = block(validate('~~~',
23
- clear(fence(opener, 10000, false))), false);
22
+ export const segment_: TableParser.SegmentParser = block(
23
+ clear(fence(opener, 10000, false)), false);
24
24
 
25
- export const table: TableParser = block(validate('~~~', fmap(
25
+ export const table: TableParser = block(fmap(
26
26
  fence(opener, 10000),
27
27
  // Bug: Type mismatch between outer and inner.
28
28
  ([body, overflow, closer, opener, delim, type, param]: string[], context) => {
@@ -48,7 +48,7 @@ export const table: TableParser = block(validate('~~~', fmap(
48
48
  ...invalid('table', 'argument', 'Invalid table type'),
49
49
  }, `${opener}${body}${closer}`)];
50
50
  }
51
- })));
51
+ }));
52
52
 
53
53
  const parser: TableParser = lazy(() => block(fmap(
54
54
  some(union([row])),
@@ -68,43 +68,53 @@ const row: RowParser = lazy(() => dup(fmap(
68
68
  ]),
69
69
  ns => !isArray(ns[0]) ? unshift([[[]]], ns) : ns)));
70
70
 
71
- const alignment = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)/;
71
+ const alignment = /[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)/y;
72
72
 
73
73
  const align: AlignParser = line(fmap(
74
74
  union([str(alignment)]),
75
75
  ([s]) => s.split('/').map(s => s.split(''))));
76
76
 
77
- const delimiter = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)|^[#:](?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/;
77
+ const delimiter = /[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)|[#:](?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/y;
78
78
 
79
79
  const head: CellParser.HeadParser = block(fmap(open(
80
- str(/^#(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/),
80
+ str(/#(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/y),
81
81
  rewrite(
82
82
  inits([
83
83
  anyline,
84
84
  some(contentline, delimiter),
85
85
  ]),
86
86
  union([
87
- block(surround(/^[^\n]/, medialink, /^\s*$/)),
88
- block(surround(/^[^\n]/, media, /^\s*$/)),
89
- block(surround(/^[^\n]/, shortmedia, /^\s*$/)),
90
- open(/^(?:\s*\n|\s)/, visualize(trimBlank(some(inline))), true),
87
+ block(surround(
88
+ /\s/y,
89
+ union([
90
+ medialink,
91
+ media,
92
+ lineshortmedia,
93
+ ]),
94
+ /\s*$/y)),
95
+ open(/(?:[^\S\n]*\n|\s)/y, visualize(trimBlank(some(inline))), true),
91
96
  ])),
92
97
  true),
93
98
  ns => [html('th', attributes(ns.shift()! as string), defrag(ns))]),
94
99
  false);
95
100
 
96
101
  const data: CellParser.DataParser = block(fmap(open(
97
- str(/^:(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/),
102
+ str(/:(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/y),
98
103
  rewrite(
99
104
  inits([
100
105
  anyline,
101
106
  some(contentline, delimiter),
102
107
  ]),
103
108
  union([
104
- block(surround(/^[^\n]/, medialink, /^\s*$/)),
105
- block(surround(/^[^\n]/, media, /^\s*$/)),
106
- block(surround(/^[^\n]/, shortmedia, /^\s*$/)),
107
- open(/^(?:\s*\n|\s)/, visualize(trimBlankEnd(lineable(some(inline)))), true),
109
+ block(surround(
110
+ /\s/y,
111
+ union([
112
+ medialink,
113
+ media,
114
+ lineshortmedia,
115
+ ]),
116
+ /\s*$/y)),
117
+ open(/(?:[^\S\n]*\n|\s)/y, visualize(trimBlankEnd(some(inline))), true),
108
118
  ])),
109
119
  true),
110
120
  ns => [html('td', attributes(ns.shift()! as string), defrag(ns))]),
@@ -114,7 +124,7 @@ const dataline: CellParser.DatalineParser = line(
114
124
  rewrite(
115
125
  contentline,
116
126
  union([
117
- validate(/^!+\s/, convert(source => `:${source}`, data, false)),
127
+ validate(/!+\s/y, convert(source => `:${source}`, data, false)),
118
128
  convert(source => `: ${source}`, data, false),
119
129
  ])));
120
130
 
@@ -1,5 +1,5 @@
1
1
  import { ExtensionParser } from '../block';
2
- import { union, validate } from '../../combinator';
2
+ import { union } from '../../combinator';
3
3
  import { figbase } from './extension/figbase';
4
4
  import { fig, segment as seg_fig } from './extension/fig';
5
5
  import { figure, segment as seg_figure } from './extension/figure';
@@ -9,12 +9,12 @@ import { aside } from './extension/aside';
9
9
  import { example } from './extension/example';
10
10
  import { placeholder, segment as seg_placeholder } from './extension/placeholder';
11
11
 
12
- export const segment: ExtensionParser.SegmentParser = validate(['~~~', '[$', '$'], validate(/^~{3,}|^\[?\$[A-Za-z-]\S+[^\S\n]*(?:$|\n)/, union([
12
+ export const segment: ExtensionParser.SegmentParser = union([
13
13
  seg_fig,
14
14
  seg_figure,
15
15
  seg_table,
16
16
  seg_placeholder,
17
- ])));
17
+ ]);
18
18
 
19
19
  export const extension: ExtensionParser = union([
20
20
  figbase,
@@ -35,7 +35,7 @@ describe('Unit: parser/block/heading', () => {
35
35
  it('basic', () => {
36
36
  assert.deepStrictEqual(inspect(parser('# a'), ctx), [['<h1 id="index::a">a</h1>'], '']);
37
37
  assert.deepStrictEqual(inspect(parser('# a '), ctx), [['<h1 id="index::a">a</h1>'], '']);
38
- assert.deepStrictEqual(inspect(parser('# a b c \n'), ctx), [['<h1 id="index::a_b__c">a b c</h1>'], '']);
38
+ assert.deepStrictEqual(inspect(parser('# a b c \n'), ctx), [['<h1 id="index::a_b_c">a b c</h1>'], '']);
39
39
  assert.deepStrictEqual(inspect(parser('# a\n'), ctx), [['<h1 id="index::a">a</h1>'], '']);
40
40
  assert.deepStrictEqual(inspect(parser('# *a*`b`${c}$'), ctx), [['<h1 id="index::a`b`${c}$"><em>a</em><code data-src="`b`">b</code><span class="math" translate="no" data-src="${c}$">${c}$</span></h1>'], '']);
41
41
  assert.deepStrictEqual(inspect(parser('# a\\'), ctx), [['<h1 id="index::a">a</h1>'], '']);