securemark 0.258.0 → 0.258.3

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 (64) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.js +200 -196
  3. package/package.json +1 -1
  4. package/src/combinator/control/manipulation/convert.ts +7 -7
  5. package/src/combinator/control/manipulation/scope.ts +4 -4
  6. package/src/combinator/data/parser/context/memo.ts +20 -11
  7. package/src/combinator/data/parser/context.test.ts +3 -3
  8. package/src/combinator/data/parser/context.ts +22 -31
  9. package/src/combinator/data/parser/inits.ts +3 -2
  10. package/src/combinator/data/parser/sequence.ts +3 -2
  11. package/src/combinator/data/parser/some.ts +4 -2
  12. package/src/combinator/data/parser/subsequence.ts +3 -3
  13. package/src/combinator/data/parser/tails.ts +3 -3
  14. package/src/combinator/data/parser.ts +1 -2
  15. package/src/parser/api/bind.ts +1 -1
  16. package/src/parser/api/parse.test.ts +15 -12
  17. package/src/parser/api/parse.ts +1 -1
  18. package/src/parser/block/blockquote.ts +4 -4
  19. package/src/parser/block/dlist.ts +3 -3
  20. package/src/parser/block/extension/table.ts +4 -4
  21. package/src/parser/block/ilist.ts +2 -2
  22. package/src/parser/block/olist.ts +2 -2
  23. package/src/parser/block/reply/cite.ts +2 -2
  24. package/src/parser/block/reply/quote.ts +2 -2
  25. package/src/parser/block/sidefence.ts +2 -2
  26. package/src/parser/block/table.ts +5 -5
  27. package/src/parser/block/ulist.ts +2 -2
  28. package/src/parser/block.ts +2 -2
  29. package/src/parser/context.ts +7 -7
  30. package/src/parser/inline/annotation.test.ts +5 -5
  31. package/src/parser/inline/annotation.ts +6 -5
  32. package/src/parser/inline/autolink/email.ts +2 -2
  33. package/src/parser/inline/autolink/url.ts +2 -2
  34. package/src/parser/inline/autolink.ts +2 -2
  35. package/src/parser/inline/bracket.ts +13 -13
  36. package/src/parser/inline/code.ts +2 -2
  37. package/src/parser/inline/comment.ts +2 -2
  38. package/src/parser/inline/deletion.ts +5 -4
  39. package/src/parser/inline/emphasis.ts +5 -4
  40. package/src/parser/inline/emstrong.ts +5 -4
  41. package/src/parser/inline/extension/index.ts +8 -7
  42. package/src/parser/inline/extension/indexer.ts +2 -2
  43. package/src/parser/inline/extension/label.ts +2 -2
  44. package/src/parser/inline/extension/placeholder.ts +5 -4
  45. package/src/parser/inline/html.ts +2 -2
  46. package/src/parser/inline/htmlentity.ts +2 -2
  47. package/src/parser/inline/insertion.ts +5 -4
  48. package/src/parser/inline/link.test.ts +2 -1
  49. package/src/parser/inline/link.ts +26 -17
  50. package/src/parser/inline/mark.ts +5 -4
  51. package/src/parser/inline/math.ts +3 -3
  52. package/src/parser/inline/media.test.ts +1 -0
  53. package/src/parser/inline/media.ts +7 -6
  54. package/src/parser/inline/reference.test.ts +5 -5
  55. package/src/parser/inline/reference.ts +7 -6
  56. package/src/parser/inline/ruby.test.ts +1 -0
  57. package/src/parser/inline/ruby.ts +4 -4
  58. package/src/parser/inline/strong.ts +5 -4
  59. package/src/parser/inline/template.ts +6 -6
  60. package/src/parser/inline.test.ts +4 -1
  61. package/src/parser/source/escapable.ts +2 -2
  62. package/src/parser/source/str.ts +5 -5
  63. package/src/parser/source/text.ts +2 -2
  64. package/src/parser/source/unescapable.ts +2 -2
@@ -1,6 +1,6 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { MarkdownParser } from '../../markdown';
3
- import { union, reset, creator, open, fallback, recover } from '../combinator';
3
+ import { union, reset, creation, open, fallback, recover } from '../combinator';
4
4
  import { emptyline } from './source';
5
5
  import { horizontalrule } from './block/horizontalrule';
6
6
  import { heading } from './block/heading';
@@ -35,7 +35,7 @@ export import BlockquoteParser = BlockParser.BlockquoteParser;
35
35
  export import ReplyParser = BlockParser.ReplyParser;
36
36
  export import ParagraphParser = BlockParser.ParagraphParser;
37
37
 
38
- export const block: BlockParser = creator(error(
38
+ export const block: BlockParser = creation(error(
39
39
  reset({ resources: { budget: 50 * 1000, recursion: 20 } },
40
40
  union([
41
41
  emptyline,
@@ -1,4 +1,4 @@
1
- export const enum Rule {
1
+ export const enum Syntax {
2
2
  reference = 1 << 12,
3
3
  comment = 1 << 11,
4
4
  index = 1 << 10,
@@ -14,12 +14,6 @@ export const enum Rule {
14
14
  quote = 1 << 0,
15
15
  none = 0,
16
16
  }
17
- export const backtrackable = 0
18
- | Rule.annotation
19
- | Rule.reference
20
- | Rule.index
21
- | Rule.link
22
- | Rule.media;
23
17
 
24
18
  export const enum State {
25
19
  annotation = 1 << 6,
@@ -30,3 +24,9 @@ export const enum State {
30
24
  media = 1 << 1,
31
25
  autolink = 1 << 0,
32
26
  }
27
+ export const backtrackable = 0
28
+ | State.annotation
29
+ | State.reference
30
+ | State.index
31
+ | State.link
32
+ | State.media;
@@ -18,11 +18,11 @@ describe('Unit: parser/inline/annotation', () => {
18
18
  assert.deepStrictEqual(inspect(parser('((\n))')), undefined);
19
19
  assert.deepStrictEqual(inspect(parser('((\na))')), undefined);
20
20
  assert.deepStrictEqual(inspect(parser('((\\\na))')), undefined);
21
- assert.deepStrictEqual(inspect(parser('((a\n))')), [['', '(('], 'a\n))']);
22
- assert.deepStrictEqual(inspect(parser('((a\\\n))')), [['', '(('], 'a\\\n))']);
23
- assert.deepStrictEqual(inspect(parser('((a\nb))')), [['', '(('], 'a\nb))']);
24
- assert.deepStrictEqual(inspect(parser('((a\\\nb))')), [['', '(('], 'a\\\nb))']);
25
- assert.deepStrictEqual(inspect(parser('((*a\nb*))')), [['', '(('], '*a\nb*))']);
21
+ assert.deepStrictEqual(inspect(parser('((a\n))')), undefined);
22
+ assert.deepStrictEqual(inspect(parser('((a\\\n))')), undefined);
23
+ assert.deepStrictEqual(inspect(parser('((a\nb))')), undefined);
24
+ assert.deepStrictEqual(inspect(parser('((a\\\nb))')), undefined);
25
+ assert.deepStrictEqual(inspect(parser('((*a\nb*))')), undefined);
26
26
  assert.deepStrictEqual(inspect(parser('((\\))')), undefined);
27
27
  assert.deepStrictEqual(inspect(parser('((a)b))')), undefined);
28
28
  assert.deepStrictEqual(inspect(parser('(((a))')), undefined);
@@ -1,20 +1,21 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { AnnotationParser } from '../inline';
3
- import { union, some, guard, context, syntax, state, validate, surround, lazy } from '../../combinator';
3
+ import { union, some, guard, context, syntax, state, surround, lazy } from '../../combinator';
4
4
  import { inline } from '../inline';
5
5
  import { optimize } from './link';
6
- import { Rule, State } from '../context';
6
+ import { Syntax, State } from '../context';
7
7
  import { startLoose, trimNode } from '../visibility';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
 
10
- export const annotation: AnnotationParser = lazy(() => validate('((', syntax(Rule.annotation, 6, surround(
10
+ export const annotation: AnnotationParser = lazy(() => surround(
11
11
  '((',
12
12
  guard(context => ~context.state! & State.annotation,
13
+ syntax(Syntax.annotation, 6, 1,
13
14
  state(State.annotation | State.media,
14
15
  startLoose(
15
16
  context({ delimiters: undefined },
16
- some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')'))),
17
+ some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')')))),
17
18
  '))',
18
19
  false,
19
20
  ([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNode(defrag(ns)))])], rest],
20
- ([, ns, rest], next) => next[0] === ')' ? undefined : optimize('((', ns, rest)))));
21
+ ([, ns, rest], next) => next[0] === ')' ? undefined : optimize('((', ns, rest, next)));
@@ -1,11 +1,11 @@
1
1
  import { AutolinkParser } from '../../inline';
2
- import { creator, verify, rewrite } from '../../../combinator';
2
+ import { creation, verify, rewrite } from '../../../combinator';
3
3
  import { str } from '../../source';
4
4
  import { html } from 'typed-dom/dom';
5
5
 
6
6
  // https://html.spec.whatwg.org/multipage/input.html
7
7
 
8
- export const email: AutolinkParser.EmailParser = creator(rewrite(verify(
8
+ export const email: AutolinkParser.EmailParser = creation(rewrite(verify(
9
9
  str(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*@[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*(?![0-9A-Za-z])/),
10
10
  ([source]) => source.indexOf('@') <= 64 && source.length <= 255),
11
11
  source => [[html('a', { class: 'email', href: `mailto:${source}` }, source)], '']));
@@ -1,5 +1,5 @@
1
1
  import { AutolinkParser } from '../../inline';
2
- import { union, some, creator, precedence, validate, focus, rewrite, convert, surround, open, lazy } from '../../../combinator';
2
+ import { union, some, creation, precedence, validate, focus, rewrite, convert, surround, open, lazy } from '../../../combinator';
3
3
  import { textlink } from '../link';
4
4
  import { unescsource } from '../../source';
5
5
 
@@ -13,7 +13,7 @@ export const url: AutolinkParser.UrlParser = lazy(() => validate(['http://', 'ht
13
13
  url => `{ ${url} }`,
14
14
  union([textlink])))));
15
15
 
16
- const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() => creator(precedence(2, union([
16
+ const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() => creation(precedence(2, union([
17
17
  surround('(', some(union([bracket, unescsource]), ')'), ')', true),
18
18
  surround('[', some(union([bracket, unescsource]), ']'), ']', true),
19
19
  surround('{', some(union([bracket, unescsource]), '}'), '}', true),
@@ -8,13 +8,13 @@ import { hashtag, emoji } from './autolink/hashtag';
8
8
  import { hashnum } from './autolink/hashnum';
9
9
  import { anchor } from './autolink/anchor';
10
10
  import { str } from '../source';
11
- import { Rule, State } from '../context';
11
+ import { Syntax, State } from '../context';
12
12
  import { stringify } from '../util';
13
13
 
14
14
  export const autolink: AutolinkParser = fmap(
15
15
  validate(/^(?:[@#>0-9A-Za-z]|\S#)/,
16
16
  guard(context => ~context.state! & State.autolink,
17
- syntax(Rule.autolink, 1,
17
+ syntax(Syntax.autolink, 1, 1,
18
18
  some(union([
19
19
  url,
20
20
  email,
@@ -3,29 +3,29 @@ import { BracketParser } from '../inline';
3
3
  import { union, some, syntax, surround, lazy } from '../../combinator';
4
4
  import { inline } from '../inline';
5
5
  import { str } from '../source';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift, push } from 'spica/array';
9
9
 
10
10
  const index = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*/;
11
11
 
12
12
  export const bracket: BracketParser = lazy(() => union([
13
- syntax(Rule.none, 2, surround(str('('), str(index), str(')'))),
14
- syntax(Rule.bracket, 2, surround(str('('), some(inline, ')', [[')', 2]]), str(')'), true,
13
+ surround(str('('), syntax(Syntax.none, 2, 1, str(index)), str(')')),
14
+ surround(str('('), syntax(Syntax.bracket, 2, 1, some(inline, ')', [[')', 2]])), str(')'), true,
15
15
  ([as, bs = [], cs], rest) => [[html('span', { class: 'paren' }, defrag(push(unshift(as, bs), cs)))], rest],
16
- ([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest])),
17
- syntax(Rule.none, 2, surround(str('('), str(new RegExp(index.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => c.trimStart() && String.fromCharCode(c.charCodeAt(0) + 0xFEE0)))), str(')'))),
18
- syntax(Rule.bracket, 2, surround(str('('), some(inline, ')', [[')', 2]]), str(')'), true,
16
+ ([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
17
+ surround(str('('), syntax(Syntax.none, 2, 1, str(new RegExp(index.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => c.trimStart() && String.fromCharCode(c.charCodeAt(0) + 0xFEE0))))), str(')')),
18
+ surround(str('('), syntax(Syntax.bracket, 2, 1, some(inline, ')', [[')', 2]])), str(')'), true,
19
19
  ([as, bs = [], cs], rest) => [[html('span', { class: 'paren' }, defrag(push(unshift(as, bs), cs)))], rest],
20
- ([as, bs = []], rest) => [unshift(as, bs), rest])),
21
- syntax(Rule.bracket, 2, surround(str('['), some(inline, ']', [[']', 2]]), str(']'), true,
20
+ ([as, bs = []], rest) => [unshift(as, bs), rest]),
21
+ surround(str('['), syntax(Syntax.bracket, 2, 1, some(inline, ']', [[']', 2]])), str(']'), true,
22
22
  undefined,
23
- ([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest])),
24
- syntax(Rule.bracket, 2, surround(str('{'), some(inline, '}', [['}', 2]]), str('}'), true,
23
+ ([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
24
+ surround(str('{'), syntax(Syntax.bracket, 2, 1, some(inline, '}', [['}', 2]])), str('}'), true,
25
25
  undefined,
26
- ([as, bs = []], rest) => [unshift(as, bs), rest])),
26
+ ([as, bs = []], rest) => [unshift(as, bs), rest]),
27
27
  // Control media blinking in editing rather than control confusion of pairs of quote marks.
28
- syntax(Rule.quote, 8, surround(str('"'), some(inline, '"', [['"', 8]]), str('"'), true,
28
+ surround(str('"'), syntax(Syntax.quote, 8, 1, some(inline, '"', [['"', 8]])), str('"'), true,
29
29
  undefined,
30
- ([as, bs = []], rest) => [unshift(as, bs), rest])),
30
+ ([as, bs = []], rest) => [unshift(as, bs), rest]),
31
31
  ]));
@@ -1,8 +1,8 @@
1
1
  import { CodeParser } from '../inline';
2
- import { creator, validate, match } from '../../combinator';
2
+ import { creation, validate, match } from '../../combinator';
3
3
  import { html } from 'typed-dom/dom';
4
4
 
5
- export const code: CodeParser = creator(validate('`', match(
5
+ export const code: CodeParser = creation(validate('`', match(
6
6
  /^(`+)(?!`)([^\n]*?[^`\n])\1(?!`)/,
7
7
  ([whole, , body]) => rest =>
8
8
  [[html('code', { 'data-src': whole }, format(body))], rest.slice(whole.length)])));
@@ -2,12 +2,12 @@ import { CommentParser } from '../inline';
2
2
  import { union, some, syntax, validate, surround, open, close, match, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { text, str } from '../source';
5
- import { Rule } from '../context';
5
+ import { Syntax } from '../context';
6
6
  import { html, defrag } from 'typed-dom/dom';
7
7
  import { memoize } from 'spica/memoize';
8
8
  import { unshift, push } from 'spica/array';
9
9
 
10
- export const comment: CommentParser = lazy(() => validate('[%', syntax(Rule.none, 4, match(
10
+ export const comment: CommentParser = lazy(() => validate('[%', syntax(Syntax.none, 4, 1, match(
11
11
  /^\[(%+)\s/,
12
12
  memoize(
13
13
  ([, fence]) =>
@@ -2,17 +2,18 @@ import { DeletionParser } from '../inline';
2
2
  import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
- import { Rule } from '../context';
5
+ import { Syntax } from '../context';
6
6
  import { blankWith } from '../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const deletion: DeletionParser = lazy(() => syntax(Rule.none, 1, surround(
10
+ export const deletion: DeletionParser = lazy(() => surround(
11
11
  str('~~'),
12
+ syntax(Syntax.none, 1, 1,
12
13
  some(union([
13
14
  some(inline, blankWith('\n', '~~')),
14
15
  open('\n', some(inline, '~'), true),
15
- ])),
16
+ ]))),
16
17
  str('~~'), false,
17
18
  ([, bs], rest) => [[html('del', defrag(bs))], rest],
18
- ([as, bs], rest) => [unshift(as, bs), rest])));
19
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -4,13 +4,14 @@ import { inline } from '../inline';
4
4
  import { emstrong } from './emstrong';
5
5
  import { strong } from './strong';
6
6
  import { str } from '../source';
7
- import { Rule } from '../context';
7
+ import { Syntax } from '../context';
8
8
  import { startTight, blankWith } from '../visibility';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
  import { unshift } from 'spica/array';
11
11
 
12
- export const emphasis: EmphasisParser = lazy(() => syntax(Rule.none, 1, surround(
12
+ export const emphasis: EmphasisParser = lazy(() => surround(
13
13
  str('*'),
14
+ syntax(Syntax.none, 1, 1,
14
15
  startTight(some(union([
15
16
  strong,
16
17
  some(inline, blankWith('*')),
@@ -19,7 +20,7 @@ export const emphasis: EmphasisParser = lazy(() => syntax(Rule.none, 1, surround
19
20
  strong,
20
21
  emphasis,
21
22
  ])),
22
- ])), '*'),
23
+ ])), '*')),
23
24
  str('*'), false,
24
25
  ([, bs], rest) => [[html('em', defrag(bs))], rest],
25
- ([as, bs], rest) => [unshift(as, bs), rest])));
26
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -5,7 +5,7 @@ import { inline } from '../inline';
5
5
  import { strong } from './strong';
6
6
  import { emphasis } from './emphasis';
7
7
  import { str } from '../source';
8
- import { Rule } from '../context';
8
+ import { Syntax } from '../context';
9
9
  import { startTight, blankWith } from '../visibility';
10
10
  import { html, defrag } from 'typed-dom/dom';
11
11
  import { unshift } from 'spica/array';
@@ -27,12 +27,13 @@ const subemphasis: IntermediateParser<EmphasisParser> = lazy(() => some(union([
27
27
  ])),
28
28
  ])));
29
29
 
30
- export const emstrong: EmStrongParser = lazy(() => syntax(Rule.none, 1, surround(
30
+ export const emstrong: EmStrongParser = lazy(() => surround(
31
31
  str('***'),
32
+ syntax(Syntax.none, 1, 1,
32
33
  startTight(some(union([
33
34
  some(inline, blankWith('*')),
34
35
  open(some(inline, '*'), inline),
35
- ]))),
36
+ ])))),
36
37
  str(/^\*{1,3}/), false,
37
38
  ([, bs, cs], rest, context): Result<HTMLElement | string, typeof context> => {
38
39
  assert(cs.length === 1);
@@ -58,4 +59,4 @@ export const emstrong: EmStrongParser = lazy(() => syntax(Rule.none, 1, surround
58
59
  }
59
60
  assert(false);
60
61
  },
61
- ([as, bs], rest) => [unshift(as, bs), rest])));
62
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -1,24 +1,25 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { ExtensionParser } from '../../inline';
3
- import { union, some, syntax, creator, precedence, guard, state, validate, surround, open, lazy, fmap } from '../../../combinator';
3
+ import { union, some, syntax, creation, precedence, guard, state, validate, surround, open, lazy, fmap } from '../../../combinator';
4
4
  import { inline } from '../../inline';
5
5
  import { indexee, identity } from './indexee';
6
6
  import { txt, str, stropt } from '../../source';
7
- import { Rule, State } from '../../context';
7
+ import { Syntax, State } from '../../context';
8
8
  import { startTight, trimBlankEnd } from '../../visibility';
9
9
  import { html, define, defrag } from 'typed-dom/dom';
10
10
 
11
11
  import IndexParser = ExtensionParser.IndexParser;
12
12
 
13
- export const index: IndexParser = lazy(() => validate('[#', syntax(Rule.index, 2, fmap(indexee(surround(
13
+ export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surround(
14
14
  '[#',
15
15
  guard(context => ~context.state! & State.index,
16
+ syntax(Syntax.index, 2, 1,
16
17
  state(State.annotation | State.reference | State.index | State.label | State.link | State.media | State.autolink,
17
18
  startTight(
18
19
  open(stropt(/^\|?/), trimBlankEnd(some(union([
19
20
  signature,
20
21
  inline,
21
- ]), ']', [[/^\\?\n/, 9], [']', 2]])), true)))),
22
+ ]), ']', [[/^\\?\n/, 9], [']', 2]])), true))))),
22
23
  ']',
23
24
  false,
24
25
  ([, ns], rest) => [[html('a', defrag(ns))], rest])),
@@ -30,16 +31,16 @@ export const index: IndexParser = lazy(() => validate('[#', syntax(Rule.index, 2
30
31
  href: el.id ? `#${el.id}` : undefined,
31
32
  },
32
33
  el.childNodes),
33
- ]))));
34
+ ])));
34
35
 
35
- const signature: IndexParser.SignatureParser = lazy(() => creator(fmap(open(
36
+ const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
36
37
  '|#',
37
38
  startTight(some(union([bracket, txt]), ']'))),
38
39
  ns => [
39
40
  html('span', { class: 'indexer', 'data-index': identity(ns.join('')).slice(6) }),
40
41
  ])));
41
42
 
42
- const bracket: IndexParser.SignatureParser.BracketParser = lazy(() => creator(union([
43
+ const bracket: IndexParser.SignatureParser.BracketParser = lazy(() => creation(union([
43
44
  surround(str('('), some(union([bracket, txt]), ')'), str(')'), true),
44
45
  surround(str('['), some(union([bracket, txt]), ']'), str(']'), true),
45
46
  surround(str('{'), some(union([bracket, txt]), '}'), str('}'), true),
@@ -1,10 +1,10 @@
1
1
  import { ExtensionParser } from '../../inline';
2
- import { union, creator, state, verify, focus, surround, fmap } from '../../../combinator';
2
+ import { union, creation, state, verify, focus, surround, fmap } from '../../../combinator';
3
3
  import { index } from './index';
4
4
  import { State } from '../../context';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
- export const indexer: ExtensionParser.IndexerParser = creator(fmap(verify(surround(
7
+ export const indexer: ExtensionParser.IndexerParser = creation(fmap(verify(surround(
8
8
  /^\s+(?=\[#\S)/,
9
9
  state(State.index, false,
10
10
  union([
@@ -1,6 +1,6 @@
1
1
  import { Array } from 'spica/global';
2
2
  import { ExtensionParser } from '../../inline';
3
- import { union, guard, creator, validate, surround, clear, fmap } from '../../../combinator';
3
+ import { union, guard, creation, validate, surround, clear, fmap } from '../../../combinator';
4
4
  import { str } from '../../source';
5
5
  import { State } from '../../context';
6
6
  import { html } from 'typed-dom/dom';
@@ -12,7 +12,7 @@ export const segment: ExtensionParser.LabelParser.SegmentParser = clear(validate
12
12
  body,
13
13
  ])));
14
14
 
15
- export const label: ExtensionParser.LabelParser = validate(['[$', '$'], creator(fmap(
15
+ export const label: ExtensionParser.LabelParser = validate(['[$', '$'], creation(fmap(
16
16
  guard(context => ~context.state! & State.label,
17
17
  union([
18
18
  surround('[', body, ']'),
@@ -2,7 +2,7 @@ import { ExtensionParser } from '../../inline';
2
2
  import { union, some, syntax, validate, surround, lazy } from '../../../combinator';
3
3
  import { inline } from '../../inline';
4
4
  import { str } from '../../source';
5
- import { Rule } from '../../context';
5
+ import { Syntax } from '../../context';
6
6
  import { startTight } from '../../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
@@ -11,9 +11,10 @@ import { unshift } from 'spica/array';
11
11
 
12
12
  // All syntax surrounded by square brackets shouldn't contain line breaks.
13
13
 
14
- export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], syntax(Rule.none, 2, surround(
14
+ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], surround(
15
15
  str(/^\[[:^]/),
16
- startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]])),
16
+ syntax(Syntax.none, 2, 1,
17
+ startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]))),
17
18
  str(']'), false,
18
19
  ([as, bs], rest) => [[
19
20
  html('span', {
@@ -23,4 +24,4 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validat
23
24
  'data-invalid-message': `Reserved start symbol "${as[0][1]}" cannot be used in "[]"`,
24
25
  }, defrag(bs)),
25
26
  ], rest],
26
- ([as, bs], rest) => [unshift(as, bs), rest]))));
27
+ ([as, bs], rest) => [unshift(as, bs), rest])));
@@ -3,7 +3,7 @@ import { HTMLParser } from '../inline';
3
3
  import { union, subsequence, some, syntax, validate, focus, surround, open, match, lazy } from '../../combinator';
4
4
  import { inline } from '../inline';
5
5
  import { str } from '../source';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { isStartLooseNodes, blankWith } from '../visibility';
8
8
  import { html as h, defrag } from 'typed-dom/dom';
9
9
  import { memoize } from 'spica/memoize';
@@ -19,7 +19,7 @@ const attrspecs = {
19
19
  Object.setPrototypeOf(attrspecs, null);
20
20
  Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
21
21
 
22
- export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(Rule.none, 5, union([
22
+ export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(Syntax.none, 5, 1, union([
23
23
  focus(
24
24
  '<wbr>',
25
25
  () => [[h('wbr')], '']),
@@ -1,10 +1,10 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
3
- import { union, creator, validate, focus, fmap } from '../../combinator';
3
+ import { union, creation, validate, focus, fmap } from '../../combinator';
4
4
  import { html } from 'typed-dom/dom';
5
5
  import { reduce } from 'spica/memoize';
6
6
 
7
- export const unsafehtmlentity: UnsafeHTMLEntityParser = creator(validate('&', focus(
7
+ export const unsafehtmlentity: UnsafeHTMLEntityParser = creation(validate('&', focus(
8
8
  /^&[0-9A-Za-z]+;/,
9
9
  entity => [[parse(entity) ?? `\x1B${entity}`], ''])));
10
10
 
@@ -2,17 +2,18 @@ import { InsertionParser } from '../inline';
2
2
  import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
- import { Rule } from '../context';
5
+ import { Syntax } from '../context';
6
6
  import { blankWith } from '../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const insertion: InsertionParser = lazy(() => syntax(Rule.none, 1, surround(
10
+ export const insertion: InsertionParser = lazy(() => surround(
11
11
  str('++'),
12
+ syntax(Syntax.none, 1, 1,
12
13
  some(union([
13
14
  some(inline, blankWith('\n', '++')),
14
15
  open('\n', some(inline, '+'), true),
15
- ])),
16
+ ]))),
16
17
  str('++'), false,
17
18
  ([, bs], rest) => [[html('ins', defrag(bs))], rest],
18
- ([as, bs], rest) => [unshift(as, bs), rest])));
19
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -45,6 +45,7 @@ describe('Unit: parser/inline/link', () => {
45
45
  it('invalid', () => {
46
46
  assert.deepStrictEqual(inspect(parser('')), undefined);
47
47
  assert.deepStrictEqual(inspect(parser('{}')), undefined);
48
+ assert.deepStrictEqual(inspect(parser('[{b}')), [['', '[', '<a href="b">b</a>'], '']);
48
49
  assert.deepStrictEqual(inspect(parser('[]')), undefined);
49
50
  assert.deepStrictEqual(inspect(parser('[]{}')), undefined);
50
51
  assert.deepStrictEqual(inspect(parser('[]{ }')), undefined);
@@ -64,7 +65,7 @@ describe('Unit: parser/inline/link', () => {
64
65
  assert.deepStrictEqual(inspect(parser('[\\ ]{b}')), undefined);
65
66
  assert.deepStrictEqual(inspect(parser('[\\\n]{b}')), undefined);
66
67
  assert.deepStrictEqual(inspect(parser('[&Tab;]{b}')), undefined);
67
- assert.deepStrictEqual(inspect(parser('[[]{b}')), undefined);
68
+ assert.deepStrictEqual(inspect(parser('[[]{b}')), [['', '[', '<a href="b">b</a>'], '']);
68
69
  assert.deepStrictEqual(inspect(parser('[]]{b}')), undefined);
69
70
  assert.deepStrictEqual(inspect(parser('[a]{}')), undefined);
70
71
  assert.deepStrictEqual(inspect(parser('[a\nb]{b}')), undefined);
@@ -1,12 +1,12 @@
1
1
  import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
2
2
  import { LinkParser, TextLinkParser } from '../inline';
3
- import { Result, eval } from '../../combinator/data/parser';
4
- import { union, inits, tails, subsequence, some, guard, syntax, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
3
+ import { Result, eval, exec } from '../../combinator/data/parser';
4
+ import { union, inits, tails, subsequence, some, guard, syntax, creation, precedence, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
5
5
  import { inline, media, shortmedia } from '../inline';
6
6
  import { attributes } from './html';
7
7
  import { autolink } from '../autolink';
8
8
  import { unescsource, str } from '../source';
9
- import { Rule, State } from '../context';
9
+ import { Syntax, State } from '../context';
10
10
  import { trimNode } from '../visibility';
11
11
  import { stringify } from '../util';
12
12
  import { html, define, defrag } from 'typed-dom/dom';
@@ -17,8 +17,9 @@ const optspec = {
17
17
  } as const;
18
18
  Object.setPrototypeOf(optspec, null);
19
19
 
20
- export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link, 2, 10, bind(
20
+ export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
21
21
  guard(context => ~context.state! & State.link,
22
+ syntax(Syntax.link, 2, 10,
22
23
  fmap(subsequence([
23
24
  state(State.link,
24
25
  dup(union([
@@ -31,19 +32,22 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link
31
32
  ']',
32
33
  true,
33
34
  undefined,
34
- ([, ns = [], rest], next) => next[0] === ']' ? undefined : optimize('[', ns, rest)),
35
+ ([, ns = [], rest], next) => next[0] === ']' ? undefined : optimize('[', ns, rest, next)),
35
36
  ]))),
36
- // 全体の失敗が確定した時も解析し予算を浪費している
37
37
  dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
38
- ]),
39
- ([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []])),
38
+ ], nodes => nodes[0][0] !== ''),
39
+ ([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []]))),
40
40
  ([content, params]: [(HTMLElement | string)[], string[]], rest, context) => {
41
- if (params.length === 0) return;
42
41
  assert(content[0] !== '' || params.length === 0);
43
42
  if (content[0] === '') return [content, rest];
43
+ if (params.length === 0) return;
44
44
  assert(params.every(p => typeof p === 'string'));
45
45
  if (content.length !== 0 && trimNode(content).length === 0) return;
46
- if (eval(some(autolink)(stringify(content), context))?.some(node => typeof node === 'object')) return;
46
+ for (let source = stringify(content); source;) {
47
+ const result = autolink(source, context);
48
+ if (typeof eval(result!)[0] === 'object') return;
49
+ source = exec(result!);
50
+ }
47
51
  assert(!html('div', content).querySelector('a, .media, .annotation, .reference') || (content[0] as HTMLElement).matches('.media'));
48
52
  const INSECURE_URI = params.shift()!;
49
53
  assert(INSECURE_URI === INSECURE_URI.trim());
@@ -58,13 +62,14 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link
58
62
  if (el.classList.contains('invalid')) return [[el], rest];
59
63
  assert(el.classList.length === 0);
60
64
  return [[define(el, attributes('link', [], optspec, params))], rest];
61
- }))));
65
+ })));
62
66
 
63
- export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link, 2, 10, bind(
67
+ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], bind(
68
+ creation(10, precedence(2,
64
69
  reverse(tails([
65
70
  dup(surround('[', some(union([unescsource]), ']'), ']')),
66
71
  dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
67
- ])),
72
+ ])))),
68
73
  ([params, content = []], rest, context) => {
69
74
  assert(params[0] === '\r');
70
75
  params.shift();
@@ -83,7 +88,7 @@ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], syntax(R
83
88
  assert(!el.classList.contains('invalid'));
84
89
  assert(el.classList.length === 0);
85
90
  return [[define(el, attributes('link', [], optspec, params))], rest];
86
- }))));
91
+ })));
87
92
 
88
93
  export const uri: LinkParser.ParameterParser.UriParser = fmap(union([
89
94
  open(/^[^\S\n]+/, str(/^\S+/)),
@@ -187,11 +192,15 @@ function decode(uri: string): string {
187
192
  }
188
193
  }
189
194
 
190
- export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string): Result<string> {
195
+ export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string, next: string): Result<string> {
196
+ if (next[+(next[0] === '\\')] === '\n') return;
191
197
  let count = 0;
192
198
  for (let i = 0; i < ns.length - 1; i += 2) {
193
- if (ns[i] !== '' || ns[i + 1] !== opener[0]) break;
194
- ++count;
199
+ const fst = ns[i];
200
+ const snd = ns[i + 1] as string;
201
+ assert(typeof snd === 'string');
202
+ if (fst !== '' || snd[0] !== opener[0]) break;
203
+ count += snd.length;
195
204
  }
196
205
  return [['', opener[0].repeat(opener.length + count)], rest.slice(count)];
197
206
  }
@@ -3,16 +3,17 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
5
  import { startTight, blankWith } from '../visibility';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const mark: MarkParser = lazy(() => syntax(Rule.none, 1, surround(
10
+ export const mark: MarkParser = lazy(() => surround(
11
11
  str('=='),
12
+ syntax(Syntax.none, 1, 1,
12
13
  startTight(some(union([
13
14
  some(inline, blankWith('==')),
14
15
  open(some(inline, '='), mark),
15
- ]))),
16
+ ])))),
16
17
  str('=='), false,
17
18
  ([, bs], rest) => [[html('mark', defrag(bs))], rest],
18
- ([as, bs], rest) => [unshift(as, bs), rest])));
19
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -1,11 +1,11 @@
1
1
  import { MathParser } from '../inline';
2
- import { union, some, creator, precedence, validate, focus, rewrite, surround, lazy } from '../../combinator';
2
+ import { union, some, creation, precedence, validate, focus, rewrite, surround, lazy } from '../../combinator';
3
3
  import { escsource, unescsource } from '../source';
4
4
  import { html } from 'typed-dom/dom';
5
5
 
6
6
  const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
7
7
 
8
- export const math: MathParser = lazy(() => validate('$', creator(rewrite(
8
+ export const math: MathParser = lazy(() => validate('$', creation(rewrite(
9
9
  union([
10
10
  surround('$', precedence(6, bracket), '$'),
11
11
  surround(
@@ -31,7 +31,7 @@ export const math: MathParser = lazy(() => validate('$', creator(rewrite(
31
31
  source)
32
32
  ], '']))));
33
33
 
34
- const bracket: MathParser.BracketParser = lazy(() => creator(surround(
34
+ const bracket: MathParser.BracketParser = lazy(() => creation(surround(
35
35
  '{',
36
36
  some(union([
37
37
  bracket,