securemark 0.299.4 → 0.300.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/design.md +0 -6
  3. package/dist/index.js +2749 -1979
  4. package/index.d.ts +2 -1
  5. package/markdown.d.ts +209 -183
  6. package/package.json +1 -1
  7. package/src/api/bind.test.ts +0 -22
  8. package/src/api/bind.ts +15 -10
  9. package/src/api/header.ts +8 -5
  10. package/src/api/parse.test.ts +118 -122
  11. package/src/api/parse.ts +13 -31
  12. package/src/api/run.ts +6 -0
  13. package/src/api.ts +1 -0
  14. package/src/combinator/control/inits.ts +26 -0
  15. package/src/combinator/control/sequence.test.ts +38 -0
  16. package/src/combinator/control/sequence.ts +17 -0
  17. package/src/combinator/control/some.test.ts +41 -0
  18. package/src/combinator/{data/parser → control}/some.ts +39 -26
  19. package/src/combinator/control/state.ts +42 -0
  20. package/src/combinator/control/subsequence.test.ts +47 -0
  21. package/src/combinator/control/subsequence.ts +16 -0
  22. package/src/combinator/control/tails.ts +8 -0
  23. package/src/combinator/control/union.test.ts +37 -0
  24. package/src/combinator/control/union.ts +18 -0
  25. package/src/combinator/{data/delimiter.ts → delimiter.ts} +40 -60
  26. package/src/combinator/effect/backtrack.ts +64 -0
  27. package/src/combinator/effect/clock.ts +10 -0
  28. package/src/combinator/effect/precedence.ts +50 -0
  29. package/src/combinator/effect/recursion.ts +30 -0
  30. package/src/combinator/effect/scope.ts +100 -0
  31. package/src/combinator/effect/state.ts +72 -0
  32. package/src/combinator/{data/list → parser}/list.ts +35 -10
  33. package/src/combinator/parser.ts +293 -0
  34. package/src/combinator/process/bind.ts +34 -0
  35. package/src/combinator/process/block.test.ts +20 -0
  36. package/src/combinator/process/block.ts +33 -0
  37. package/src/combinator/process/clear.ts +16 -0
  38. package/src/combinator/process/contract.ts +35 -0
  39. package/src/combinator/process/duplicate.ts +7 -0
  40. package/src/combinator/process/error.ts +13 -0
  41. package/src/combinator/{control/manipulation → process}/fallback.ts +3 -3
  42. package/src/combinator/process/fence.ts +59 -0
  43. package/src/combinator/process/fmap.ts +10 -0
  44. package/src/combinator/process/indent.test.ts +31 -0
  45. package/src/combinator/process/indent.ts +51 -0
  46. package/src/combinator/process/lazy.ts +8 -0
  47. package/src/combinator/process/line.test.ts +21 -0
  48. package/src/combinator/process/line.ts +55 -0
  49. package/src/combinator/process/match.ts +37 -0
  50. package/src/combinator/process/reverse.ts +7 -0
  51. package/src/combinator/process/scope.ts +102 -0
  52. package/src/combinator/process/surround.ts +271 -0
  53. package/src/combinator.ts +28 -24
  54. package/src/debug.test.ts +11 -8
  55. package/src/parser/autolink.test.ts +17 -18
  56. package/src/parser/block/blockquote.test.ts +78 -79
  57. package/src/parser/block/blockquote.ts +32 -25
  58. package/src/parser/block/codeblock.test.ts +56 -57
  59. package/src/parser/block/codeblock.ts +44 -26
  60. package/src/parser/block/dlist.test.ts +56 -57
  61. package/src/parser/block/dlist.ts +5 -5
  62. package/src/parser/block/extension/aside.test.ts +8 -9
  63. package/src/parser/block/extension/aside.ts +76 -47
  64. package/src/parser/block/extension/example.test.ts +18 -19
  65. package/src/parser/block/extension/example.ts +88 -48
  66. package/src/parser/block/extension/fig.test.ts +37 -36
  67. package/src/parser/block/extension/fig.ts +20 -25
  68. package/src/parser/block/extension/figbase.test.ts +18 -19
  69. package/src/parser/block/extension/figbase.ts +3 -3
  70. package/src/parser/block/extension/figure.test.ts +62 -63
  71. package/src/parser/block/extension/figure.ts +23 -21
  72. package/src/parser/block/extension/message.test.ts +13 -14
  73. package/src/parser/block/extension/message.ts +52 -39
  74. package/src/parser/block/extension/placeholder.test.ts +13 -13
  75. package/src/parser/block/extension/placeholder.ts +23 -21
  76. package/src/parser/block/extension/table.test.ts +70 -71
  77. package/src/parser/block/extension/table.ts +43 -31
  78. package/src/parser/block/extension.test.ts +24 -24
  79. package/src/parser/block/extension.ts +3 -3
  80. package/src/parser/block/heading.test.ts +58 -59
  81. package/src/parser/block/heading.ts +19 -18
  82. package/src/parser/block/ilist.test.ts +8 -8
  83. package/src/parser/block/ilist.ts +9 -7
  84. package/src/parser/block/mathblock.test.ts +31 -32
  85. package/src/parser/block/mathblock.ts +24 -23
  86. package/src/parser/block/mediablock.ts +7 -7
  87. package/src/parser/block/olist.test.ts +102 -103
  88. package/src/parser/block/olist.ts +11 -12
  89. package/src/parser/block/pagebreak.test.ts +15 -16
  90. package/src/parser/block/pagebreak.ts +5 -5
  91. package/src/parser/block/paragraph.test.ts +57 -58
  92. package/src/parser/block/paragraph.ts +1 -1
  93. package/src/parser/block/reply/cite.test.ts +39 -40
  94. package/src/parser/block/reply/cite.ts +5 -5
  95. package/src/parser/block/reply/quote.test.ts +50 -51
  96. package/src/parser/block/reply/quote.ts +8 -7
  97. package/src/parser/block/reply.test.ts +19 -20
  98. package/src/parser/block/reply.ts +2 -2
  99. package/src/parser/block/sidefence.test.ts +41 -48
  100. package/src/parser/block/sidefence.ts +17 -11
  101. package/src/parser/block/table.test.ts +48 -49
  102. package/src/parser/block/table.ts +10 -9
  103. package/src/parser/block/ulist.test.ts +52 -53
  104. package/src/parser/block/ulist.ts +9 -8
  105. package/src/parser/block.ts +63 -51
  106. package/src/parser/context.ts +35 -32
  107. package/src/parser/document.ts +48 -0
  108. package/src/parser/header.test.ts +19 -20
  109. package/src/parser/header.ts +31 -25
  110. package/src/parser/inline/annotation.test.ts +49 -50
  111. package/src/parser/inline/annotation.ts +14 -16
  112. package/src/parser/inline/autolink/account.test.ts +32 -33
  113. package/src/parser/inline/autolink/account.ts +18 -19
  114. package/src/parser/inline/autolink/anchor.test.ts +21 -22
  115. package/src/parser/inline/autolink/anchor.ts +7 -8
  116. package/src/parser/inline/autolink/channel.test.ts +14 -15
  117. package/src/parser/inline/autolink/email.test.ts +36 -37
  118. package/src/parser/inline/autolink/email.ts +6 -6
  119. package/src/parser/inline/autolink/hashnum.test.ts +32 -33
  120. package/src/parser/inline/autolink/hashnum.ts +7 -8
  121. package/src/parser/inline/autolink/hashtag.test.ts +59 -60
  122. package/src/parser/inline/autolink/hashtag.ts +8 -9
  123. package/src/parser/inline/autolink/url.test.ts +75 -76
  124. package/src/parser/inline/autolink/url.ts +13 -14
  125. package/src/parser/inline/autolink.ts +24 -11
  126. package/src/parser/inline/bracket.test.ts +73 -74
  127. package/src/parser/inline/bracket.ts +88 -63
  128. package/src/parser/inline/code.test.ts +30 -31
  129. package/src/parser/inline/code.ts +6 -6
  130. package/src/parser/inline/deletion.test.ts +27 -28
  131. package/src/parser/inline/deletion.ts +5 -5
  132. package/src/parser/inline/emphasis.test.ts +39 -40
  133. package/src/parser/inline/emphasis.ts +5 -5
  134. package/src/parser/inline/emstrong.test.ts +101 -102
  135. package/src/parser/inline/emstrong.ts +103 -85
  136. package/src/parser/inline/extension/index.test.ts +91 -92
  137. package/src/parser/inline/extension/index.ts +17 -13
  138. package/src/parser/inline/extension/indexee.ts +4 -4
  139. package/src/parser/inline/extension/indexer.test.ts +23 -24
  140. package/src/parser/inline/extension/indexer.ts +6 -5
  141. package/src/parser/inline/extension/label.test.ts +32 -33
  142. package/src/parser/inline/extension/label.ts +14 -5
  143. package/src/parser/inline/extension/placeholder.test.ts +42 -43
  144. package/src/parser/inline/extension/placeholder.ts +8 -9
  145. package/src/parser/inline/html.test.ts +109 -109
  146. package/src/parser/inline/html.ts +27 -27
  147. package/src/parser/inline/htmlentity.test.ts +37 -38
  148. package/src/parser/inline/htmlentity.ts +6 -7
  149. package/src/parser/inline/insertion.test.ts +27 -28
  150. package/src/parser/inline/insertion.ts +5 -5
  151. package/src/parser/inline/italic.test.ts +55 -56
  152. package/src/parser/inline/italic.ts +5 -5
  153. package/src/parser/inline/link.test.ts +186 -187
  154. package/src/parser/inline/link.ts +29 -30
  155. package/src/parser/inline/mark.test.ts +31 -32
  156. package/src/parser/inline/mark.ts +6 -6
  157. package/src/parser/inline/math.test.ts +140 -141
  158. package/src/parser/inline/math.ts +6 -7
  159. package/src/parser/inline/media.test.ts +92 -93
  160. package/src/parser/inline/media.ts +31 -37
  161. package/src/parser/inline/reference.test.ts +111 -112
  162. package/src/parser/inline/reference.ts +61 -32
  163. package/src/parser/inline/remark.test.ts +49 -50
  164. package/src/parser/inline/remark.ts +13 -13
  165. package/src/parser/inline/ruby.test.ts +49 -50
  166. package/src/parser/inline/ruby.ts +60 -49
  167. package/src/parser/inline/shortmedia.test.ts +9 -10
  168. package/src/parser/inline/shortmedia.ts +11 -9
  169. package/src/parser/inline/strong.test.ts +36 -37
  170. package/src/parser/inline/strong.ts +5 -5
  171. package/src/parser/inline/template.test.ts +22 -23
  172. package/src/parser/inline/template.ts +13 -16
  173. package/src/parser/inline.test.ts +225 -226
  174. package/src/parser/inline.ts +68 -34
  175. package/src/parser/parser.ts +51 -0
  176. package/src/parser/repeat.ts +118 -91
  177. package/src/parser/segment.test.ts +0 -11
  178. package/src/parser/segment.ts +25 -28
  179. package/src/parser/source/escapable.test.ts +23 -24
  180. package/src/parser/source/escapable.ts +20 -20
  181. package/src/parser/source/line.test.ts +17 -18
  182. package/src/parser/source/line.ts +19 -24
  183. package/src/parser/source/str.ts +17 -10
  184. package/src/parser/source/text.test.ts +88 -89
  185. package/src/parser/source/text.ts +19 -20
  186. package/src/parser/source/unescapable.test.ts +23 -24
  187. package/src/parser/source/unescapable.ts +16 -16
  188. package/src/parser/util.ts +1 -1
  189. package/src/parser/visibility.ts +35 -14
  190. package/src/processor/figure.test.ts +20 -20
  191. package/src/processor/figure.ts +18 -10
  192. package/src/processor/note.test.ts +13 -13
  193. package/src/processor/note.ts +4 -2
  194. package/src/renderer/render/media/pdf.ts +2 -2
  195. package/src/renderer/render/media/twitter.ts +2 -2
  196. package/src/renderer/render/media.test.ts +12 -12
  197. package/src/renderer/render.test.ts +11 -11
  198. package/src/util/info.test.ts +2 -2
  199. package/src/util/quote.test.ts +3 -3
  200. package/src/util/quote.ts +6 -5
  201. package/src/util/toc.test.ts +12 -12
  202. package/src/combinator/control/constraint/block.test.ts +0 -20
  203. package/src/combinator/control/constraint/block.ts +0 -28
  204. package/src/combinator/control/constraint/contract.ts +0 -27
  205. package/src/combinator/control/constraint/line.test.ts +0 -21
  206. package/src/combinator/control/constraint/line.ts +0 -42
  207. package/src/combinator/control/manipulation/clear.ts +0 -5
  208. package/src/combinator/control/manipulation/convert.ts +0 -22
  209. package/src/combinator/control/manipulation/duplicate.ts +0 -7
  210. package/src/combinator/control/manipulation/fence.ts +0 -54
  211. package/src/combinator/control/manipulation/indent.test.ts +0 -31
  212. package/src/combinator/control/manipulation/indent.ts +0 -39
  213. package/src/combinator/control/manipulation/lazy.ts +0 -8
  214. package/src/combinator/control/manipulation/match.ts +0 -27
  215. package/src/combinator/control/manipulation/recovery.ts +0 -18
  216. package/src/combinator/control/manipulation/reverse.ts +0 -8
  217. package/src/combinator/control/manipulation/scope.ts +0 -61
  218. package/src/combinator/control/manipulation/surround.ts +0 -223
  219. package/src/combinator/control/monad/bind.ts +0 -26
  220. package/src/combinator/control/monad/fmap.ts +0 -10
  221. package/src/combinator/data/parser/context.ts +0 -96
  222. package/src/combinator/data/parser/inits.ts +0 -20
  223. package/src/combinator/data/parser/sequence.test.ts +0 -33
  224. package/src/combinator/data/parser/sequence.ts +0 -20
  225. package/src/combinator/data/parser/some.test.ts +0 -37
  226. package/src/combinator/data/parser/subsequence.test.ts +0 -41
  227. package/src/combinator/data/parser/subsequence.ts +0 -13
  228. package/src/combinator/data/parser/tails.ts +0 -8
  229. package/src/combinator/data/parser/union.test.ts +0 -33
  230. package/src/combinator/data/parser/union.ts +0 -18
  231. package/src/combinator/data/parser.ts +0 -144
@@ -1,30 +1,30 @@
1
1
  import { UnescapableSourceParser } from '../source';
2
+ import { Result, Node } from '../../combinator/parser';
3
+ import { spend } from '../../combinator';
2
4
  import { State, Command } from '../context';
3
5
  import { Flag } from '../node';
4
- import { List, Node } from '../../combinator/data/parser';
5
- import { spend } from '../../combinator';
6
6
  import { nonWhitespace, canSkip, backToUrlHead, backToEmailHead } from './text';
7
7
  import { html } from 'typed-dom/dom';
8
8
 
9
- export const unescsource: UnescapableSourceParser = context => {
10
- const { source, position, state } = context;
9
+ export const unescsource: UnescapableSourceParser = (input, output) => {
10
+ const { source, position, state } = input;
11
11
  if (position === source.length) return;
12
12
  const char = source[position];
13
- spend(context, 1);
14
- context.position += 1;
13
+ spend(input, output, 1);
14
+ input.position += 1;
15
15
  switch (char) {
16
16
  case Command.Escape:
17
- spend(context, 1);
18
- context.position += 1;
19
- return new List([new Node(source.slice(position + 1, position + 2))]);
17
+ spend(input, output, 1);
18
+ input.position += 1;
19
+ return output.append(new Node(source.slice(position + 1, position + 2)));
20
20
  case '\r':
21
- return new List();
21
+ return Result.succ;
22
22
  case '\n':
23
- context.linebreak ||= source.length - position;
24
- return new List([new Node(html('br'), Flag.blank)]);
23
+ input.linebreak ||= source.length - position;
24
+ return output.append(new Node(html('br'), Flag.blank));
25
25
  default:
26
26
  assert(char !== '\n');
27
- if (context.sequential) return new List([new Node(char)]);
27
+ if (input.sequential) return output.append(new Node(char));
28
28
  nonWhitespace.lastIndex = position + 1;
29
29
  let i = canSkip(source, position)
30
30
  ? nonWhitespace.test(source)
@@ -33,9 +33,9 @@ export const unescsource: UnescapableSourceParser = context => {
33
33
  : next(source, position, state);
34
34
  assert(i > position);
35
35
  i -= position;
36
- spend(context, i - 1);
37
- context.position += i - 1;
38
- return new List([new Node(source.slice(position, context.position))]);
36
+ spend(input, output, i - 1);
37
+ input.position += i - 1;
38
+ return output.append(new Node(source.slice(position, input.position)));
39
39
  }
40
40
  };
41
41
 
@@ -1,4 +1,4 @@
1
- import { List, Node } from '../combinator/data/parser';
1
+ import { List, Node } from '../combinator/parser';
2
2
  import { rnd0Z } from 'spica/random';
3
3
  import { define } from 'typed-dom/dom';
4
4
 
@@ -1,7 +1,7 @@
1
- import { Parser, List, Node } from '../combinator/data/parser';
2
- import { Command } from './context';
1
+ import { Parser, List, Node } from '../combinator/parser';
2
+ import { Input, Command } from './context';
3
3
  import { Flag } from './node';
4
- import { convert, fmap } from '../combinator';
4
+ import { always, fmap } from '../combinator';
5
5
  import { invisibleBlankHTMLEntityNames } from '../api/normalize';
6
6
 
7
7
  namespace blank {
@@ -19,10 +19,32 @@ namespace blank {
19
19
  'y');
20
20
  }
21
21
 
22
- export function visualize<P extends Parser>(parser: P): P {
23
- return convert(
24
- source => source.replace(blank.line, `$1${Command.Escape}$2`),
25
- parser);
22
+ export function visualize<P extends Parser>(parser: P): P;
23
+ export function visualize<T>(parser: Parser<T>): Parser<T> {
24
+ interface Memory {
25
+ readonly scope: boolean;
26
+ }
27
+ return always<Parser<T, Input<Memory>>>([
28
+ (input, output) => {
29
+ const { source, position } = input;
30
+ const src = source.slice(position).replace(blank.line, `$1${Command.Escape}$2`);
31
+ input.memory = {
32
+ scope: src.length !== source.length - position,
33
+ };
34
+ if (input.memory.scope) {
35
+ input.scope.push(src);
36
+ }
37
+ return output.context;
38
+ },
39
+ parser,
40
+ (input, output) => {
41
+ if (input.memory.scope) {
42
+ input = input.scope.pop();
43
+ }
44
+ input.position = input.source.length;
45
+ return output.context;
46
+ },
47
+ ]);
26
48
  }
27
49
 
28
50
  export const beforeNonblank = beforeNonblankWith('');
@@ -91,17 +113,16 @@ export function trimBlank<N extends HTMLElement | string>(parser: Parser<N>): Pa
91
113
  }
92
114
  function trimBlankStart<P extends Parser>(parser: P): P;
93
115
  function trimBlankStart<N>(parser: Parser<N>): Parser<N> {
94
- return input => {
95
- const context = input;
96
- const { source, position } = context;
116
+ return (input, output) => {
117
+ const { source, position } = input;
97
118
  if (position === source.length) return;
98
119
  const reg = blank.start;
99
120
  reg.lastIndex = position;
100
121
  reg.test(source);
101
- context.position = reg.lastIndex || position;
102
- return context.position === source.length
103
- ? new List()
104
- : parser(input);
122
+ input.position = reg.lastIndex || position;
123
+ return input.position === source.length
124
+ ? output.context
125
+ : parser(input, output);
105
126
  };
106
127
  }
107
128
  export function trimBlankEnd<P extends Parser<HTMLElement | string>>(parser: P): P;
@@ -1,6 +1,6 @@
1
1
  import { figure } from './figure';
2
2
  import { ParserOptions } from '../..';
3
- import { parse as parse_ } from '../api';
3
+ import { run, parse as parse_ } from '../api';
4
4
  import { html } from 'typed-dom/dom';
5
5
  import { normalize } from '../debug.test';
6
6
 
@@ -9,7 +9,7 @@ const parse = (s: string, o?: ParserOptions) => parse_(s, { test: true, ...o });
9
9
  describe('Unit: processor/figure', () => {
10
10
  describe('figure', () => {
11
11
  it('empty', () => {
12
- const target = parse('');
12
+ const target = run(parse(''));
13
13
  for (let i = 0; i < 3; ++i) {
14
14
  [...figure(target)];
15
15
  assert.deepStrictEqual(
@@ -19,12 +19,12 @@ describe('Unit: processor/figure', () => {
19
19
  });
20
20
 
21
21
  it('one', () => {
22
- const target = parse([
22
+ const target = run(parse([
23
23
  '$test-a\n> ',
24
24
  '$test-a',
25
25
  '$test-b',
26
26
  '$test-a',
27
- ].join('\n\n'));
27
+ ].join('\n\n')));
28
28
  for (let i = 0; i < 3; ++i) {
29
29
  [...figure(target)];
30
30
  assert.deepStrictEqual(
@@ -39,14 +39,14 @@ describe('Unit: processor/figure', () => {
39
39
  });
40
40
 
41
41
  it('some', () => {
42
- const target = parse([
42
+ const target = run(parse([
43
43
  '$test-a\n> ',
44
44
  '## 0',
45
45
  '$test-b\n> ',
46
46
  '$quote-a\n> ',
47
47
  '$test-b\n> ',
48
48
  '$test-c\n> ',
49
- ].join('\n\n'));
49
+ ].join('\n\n')));
50
50
  for (let i = 0; i < 3; ++i) {
51
51
  [...figure(target)];
52
52
  assert.deepStrictEqual(
@@ -63,10 +63,10 @@ describe('Unit: processor/figure', () => {
63
63
  });
64
64
 
65
65
  it('number', () => {
66
- const target = parse([
66
+ const target = run(parse([
67
67
  '$-a\n$$\n$$',
68
68
  '$-a',
69
- ].join('\n\n'));
69
+ ].join('\n\n')));
70
70
  for (let i = 0; i < 3; ++i) {
71
71
  [...figure(target)];
72
72
  assert.deepStrictEqual(
@@ -79,7 +79,7 @@ describe('Unit: processor/figure', () => {
79
79
  });
80
80
 
81
81
  it('fixed', () => {
82
- const target = parse([
82
+ const target = run(parse([
83
83
  '$test-2\n> ',
84
84
  '$test-3.1\n> ',
85
85
  '$-4.1.1\n$$\n$$',
@@ -88,7 +88,7 @@ describe('Unit: processor/figure', () => {
88
88
  '$test-2',
89
89
  '$-4.1.1',
90
90
  '$test-1',
91
- ].join('\n\n'));
91
+ ].join('\n\n')));
92
92
  for (let i = 0; i < 3; ++i) {
93
93
  [...figure(target)];
94
94
  assert.deepStrictEqual(
@@ -107,12 +107,12 @@ describe('Unit: processor/figure', () => {
107
107
  });
108
108
 
109
109
  it('separation', () => {
110
- const target = html('blockquote', parse([
110
+ const target = html('blockquote', run(parse([
111
111
  '!>> ~~~figure $test-a\n>> > \n>>\n~~~\n> ~~~figure $test-a\n> > \n>\n~~~',
112
112
  '~~~~example/markdown\n~~~figure $test-a\n> \n\n~~~\n\n$test-a\n~~~~',
113
113
  '~~~figure $test-b\n> \n\n~~~',
114
114
  '~~~figure $test-a\n> \n\n~~~',
115
- ].join('\n\n')).children);
115
+ ].join('\n\n'))).children);
116
116
  for (let i = 0; i < 3; ++i) {
117
117
  [...figure(target)];
118
118
  assert.deepStrictEqual(
@@ -127,7 +127,7 @@ describe('Unit: processor/figure', () => {
127
127
  });
128
128
 
129
129
  it('base', () => {
130
- const target = parse([
130
+ const target = run(parse([
131
131
  '# 0',
132
132
  '$-0.0',
133
133
  '## 0',
@@ -163,7 +163,7 @@ describe('Unit: processor/figure', () => {
163
163
  '$test-i\n> ',
164
164
  '# 0',
165
165
  '$test-j\n> ',
166
- ].join('\n\n'));
166
+ ].join('\n\n')));
167
167
  for (let i = 0; i < 3; ++i) {
168
168
  [...figure(target)];
169
169
  assert.deepStrictEqual(
@@ -209,7 +209,7 @@ describe('Unit: processor/figure', () => {
209
209
  });
210
210
 
211
211
  it('concat', () => {
212
- const target = parse([
212
+ const target = run(parse([
213
213
  '$-0.0',
214
214
  '## 0',
215
215
  '$-0.0',
@@ -229,7 +229,7 @@ describe('Unit: processor/figure', () => {
229
229
  '## 0',
230
230
  '$-9.0',
231
231
  '$test-e\n> ',
232
- ].join('\n\n'));
232
+ ].join('\n\n')));
233
233
  for (let i = 0; i < 3; ++i) {
234
234
  [...figure(target)];
235
235
  assert.deepStrictEqual(
@@ -259,11 +259,11 @@ describe('Unit: processor/figure', () => {
259
259
  });
260
260
 
261
261
  it('verbose', () => {
262
- const target = parse([
262
+ const target = run(parse([
263
263
  '~~~figure [$test-a]\n> \n\n~~~',
264
264
  '[$test-a]',
265
265
  '[$test-a]',
266
- ].join('\n\n'));
266
+ ].join('\n\n')));
267
267
  for (let i = 0; i < 3; ++i) {
268
268
  [...figure(target)];
269
269
  assert.deepStrictEqual(
@@ -277,11 +277,11 @@ describe('Unit: processor/figure', () => {
277
277
  });
278
278
 
279
279
  it('id', () => {
280
- const target = parse([
280
+ const target = run(parse([
281
281
  '$test-a\n> ',
282
282
  '==$test-a==',
283
283
  '- $test-a',
284
- ].join('\n\n'), { id: '0' });
284
+ ].join('\n\n'), { id: '0' }));
285
285
  for (let i = 0; i < 3; ++i) {
286
286
  [...figure(target, undefined, { id: '0' })];
287
287
  assert.deepStrictEqual(
@@ -3,7 +3,6 @@ import { markInvalid, unmarkInvalid } from '../parser/util';
3
3
  import { MultiQueue } from 'spica/queue';
4
4
  import { push } from 'spica/array';
5
5
  import { define } from 'typed-dom/dom';
6
- import { querySelectorAll } from 'typed-dom/query';
7
6
 
8
7
  export function* figure(
9
8
  target: ParentNode & Node,
@@ -14,19 +13,26 @@ export function* figure(
14
13
  } = {},
15
14
  ): Generator<HTMLAnchorElement | undefined, undefined, undefined> {
16
15
  const selector = ':is(figure[data-label], h1, h2)';
17
- const refs = new MultiQueue<string, HTMLAnchorElement>(push(
18
- querySelectorAll(target, 'a.label:not(.local)[data-label]'),
19
- notes && querySelectorAll(notes.references, 'a.label:not(.local)') || [])
20
- .map(el => [el.getAttribute('data-label')!, el]));
16
+ const refs = new MultiQueue<string, HTMLAnchorElement>(
17
+ !notes || notes.references.parentNode === target
18
+ ? Array.from(
19
+ target.querySelectorAll('a.label:not(.local)[data-label]'),
20
+ el => [el.getAttribute('data-label')!, el])
21
+ : push(
22
+ Array.from(
23
+ target.querySelectorAll('a.label:not(.local)[data-label]'),
24
+ el => [el.getAttribute('data-label')!, el] as const),
25
+ Array.from(
26
+ notes.references.querySelectorAll('a.label:not(.local)'),
27
+ el => [el.getAttribute('data-label')!, el] as const)));
21
28
  const labels = new Set<string>();
22
29
  const numbers = new Map<string, string>();
23
30
  let base = '0';
24
31
  let bases: readonly string[] = base.split('.');
25
- let index: readonly string[] = bases;
26
32
  for (
27
33
  let defs = target instanceof Element
28
34
  ? target.querySelectorAll(`:scope > ${selector}`)
29
- : target.querySelectorAll(`${selector}:not(* > *)`),
35
+ : target.querySelectorAll(`:not(* > *)${selector}`),
30
36
  len = defs.length, i = 0; i < len; ++i) {
31
37
  yield;
32
38
  const def = defs[i];
@@ -36,7 +42,7 @@ export function* figure(
36
42
  assert(base === '0' || bases.length > 1);
37
43
  const label = tagName === 'FIGURE'
38
44
  ? def.getAttribute('data-label')!
39
- : `$-${increment(index, def as HTMLHeadingElement)}`;
45
+ : `$-${increment(bases, def as HTMLHeadingElement)}`;
40
46
  if (label.endsWith('-')) continue;
41
47
  if (label.endsWith('-0')) {
42
48
  markInvalid(def, 'figure', 'argument', 'Invalid base index');
@@ -76,7 +82,7 @@ export function* figure(
76
82
  if (group !== '$' || tagName === 'FIGURE' && def.firstChild) continue;
77
83
  if (number.startsWith('0.')) {
78
84
  assert(number.endsWith('.0'));
79
- number = index.slice(0)
85
+ number = bases.slice(0)
80
86
  .reduce((ns, _, i, xs) => {
81
87
  i === ns.length
82
88
  ? xs.length = i
@@ -90,7 +96,7 @@ export function* figure(
90
96
  .join('.');
91
97
  }
92
98
  base = number;
93
- bases = index = base.split('.');
99
+ bases = base.split('.');
94
100
  tagName !== 'FIGURE' && numbers.clear();
95
101
  assert(def.tagName !== 'FIGURE' || !+def.setAttribute('data-number', number));
96
102
  continue;
@@ -135,6 +141,8 @@ export function* figure(
135
141
  }
136
142
  yield ref;
137
143
  }
144
+ assert(opts.id !== '' || !target.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
145
+ assert(opts.id !== '' || !notes?.references.querySelector('[id], .index[href], .label[href]'));
138
146
  }
139
147
 
140
148
  const messages = {
@@ -1,5 +1,5 @@
1
1
  import { note } from './note';
2
- import { parse as parse_ } from '../api';
2
+ import { run, parse as parse_ } from '../api';
3
3
  import { html } from 'typed-dom/dom';
4
4
  import { normalize } from '../debug.test';
5
5
 
@@ -8,7 +8,7 @@ const parse = (s: string) => parse_(s, { test: true });
8
8
  describe('Unit: processor/note', () => {
9
9
  describe('annotation', () => {
10
10
  it('empty', () => {
11
- const target = parse('');
11
+ const target = run(parse(''));
12
12
  [...note(target)];
13
13
  assert.deepStrictEqual(
14
14
  [...target.children].map(el => normalize(el.outerHTML)),
@@ -16,7 +16,7 @@ describe('Unit: processor/note', () => {
16
16
  });
17
17
 
18
18
  it('1', () => {
19
- const target = parse('((a b))');
19
+ const target = run(parse('((a b))'));
20
20
  for (let i = 0; i < 3; ++i) {
21
21
  assert.deepStrictEqual([...note(target)].length, i === 0 ? 2 : 3);
22
22
  assert.deepStrictEqual(
@@ -38,7 +38,7 @@ describe('Unit: processor/note', () => {
38
38
  });
39
39
 
40
40
  it('2', () => {
41
- const target = parse('((1))((12345678901234567890))');
41
+ const target = run(parse('((1))((12345678901234567890))'));
42
42
  for (let i = 0; i < 3; ++i) {
43
43
  assert.deepStrictEqual([...note(target)].length, i === 0 ? 4 : 6);
44
44
  assert.deepStrictEqual(
@@ -67,7 +67,7 @@ describe('Unit: processor/note', () => {
67
67
  });
68
68
 
69
69
  it('unify', () => {
70
- const target = parse('((1))((2))((3))((2))((4))');
70
+ const target = run(parse('((1))((2))((3))((2))((4))'));
71
71
  for (let i = 0; i < 3; ++i) {
72
72
  [...note(target)];
73
73
  assert.deepStrictEqual(
@@ -116,11 +116,11 @@ describe('Unit: processor/note', () => {
116
116
  });
117
117
 
118
118
  it('separation', () => {
119
- const target = parse([
119
+ const target = run(parse([
120
120
  '!>> ((1))\n> ((2))\n~~~',
121
121
  '~~~~example/markdown\n((3))\n~~~~',
122
122
  '((4))',
123
- ].join('\n\n'));
123
+ ].join('\n\n')));
124
124
  for (let i = 0; i < 3; ++i) {
125
125
  [...note(target)];
126
126
  assert.deepStrictEqual(
@@ -135,7 +135,7 @@ describe('Unit: processor/note', () => {
135
135
  });
136
136
 
137
137
  it('split', () => {
138
- const target = parse('((1))\n\n## a\n\n((2))((1))((3))((2))\n\n## b\n\n((2))');
138
+ const target = run(parse('((1))\n\n## a\n\n((2))((1))((3))((2))\n\n## b\n\n((2))'));
139
139
  for (let i = 0; i < 3; ++i) {
140
140
  [...note(target)];
141
141
  assert.deepStrictEqual(
@@ -201,7 +201,7 @@ describe('Unit: processor/note', () => {
201
201
  });
202
202
 
203
203
  it('id', () => {
204
- const target = parse('((a b))');
204
+ const target = run(parse('((a b))'));
205
205
  for (let i = 0; i < 3; ++i) {
206
206
  assert.deepStrictEqual([...note(target, undefined, { id: '0' })].length, i === 0 ? 2 : 3);
207
207
  assert.deepStrictEqual(
@@ -223,7 +223,7 @@ describe('Unit: processor/note', () => {
223
223
  });
224
224
 
225
225
  it('nest', () => {
226
- const target = parse('((a((b))))((a))((b))');
226
+ const target = run(parse('((a((b))))((a))((b))'));
227
227
  for (let i = 0; i < 3; ++i) {
228
228
  [...note(target)];
229
229
  assert.deepStrictEqual(
@@ -278,7 +278,7 @@ describe('Unit: processor/note', () => {
278
278
 
279
279
  describe('reference', () => {
280
280
  it('1', () => {
281
- const target = parse('[[a b]]');
281
+ const target = run(parse('[[a b]]'));
282
282
  const notes = { references: html('ol') };
283
283
  for (let i = 0; i < 3; ++i) {
284
284
  [...note(target, notes)];
@@ -305,7 +305,7 @@ describe('Unit: processor/note', () => {
305
305
  });
306
306
 
307
307
  it('abbr', () => {
308
- const target = parse('[[^A 1]][[^A 1|b]][[^A 1]]');
308
+ const target = run(parse('[[^A 1]][[^A 1|b]][[^A 1]]'));
309
309
  const notes = { references: html('ol') };
310
310
  for (let i = 0; i < 3; ++i) {
311
311
  [...note(target, notes)];
@@ -342,7 +342,7 @@ describe('Unit: processor/note', () => {
342
342
  });
343
343
 
344
344
  it('nest', () => {
345
- const target = parse('((a[[^B]]))[[^B|c]]');
345
+ const target = run(parse('((a[[^B]]))[[^B|c]]'));
346
346
  const notes = { references: html('ol') };
347
347
  for (let i = 0; i < 3; ++i) {
348
348
  [...note(target, notes)];
@@ -52,7 +52,7 @@ const annotation = build(
52
52
  'annotations',
53
53
  '.annotation:not(:is(.annotations, .references) &, .local)',
54
54
  n => `*${n}`,
55
- 'h1, h2, h3, h4, h5, h6, aside.aside, hr');
55
+ 'h1, h2, h3, h4, h5, h6, aside.aside, hr, .references');
56
56
  const reference = build(
57
57
  'reference',
58
58
  'references',
@@ -112,7 +112,7 @@ function build(
112
112
  const splitters = splitter
113
113
  ? target instanceof Element
114
114
  ? target.querySelectorAll(`:scope > :is(${splitter}, .${list})`)
115
- : target.querySelectorAll(`:is(${splitter}, .${list}):not(* > *)`)
115
+ : target.querySelectorAll(`:not(* > *):is(${splitter}, .${list})`)
116
116
  : [];
117
117
  let iSplitters = 0;
118
118
  let total = 0;
@@ -226,6 +226,8 @@ function build(
226
226
  splitter.remove();
227
227
  }
228
228
  }
229
+ assert(opts.id !== '' || !target.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
230
+ assert(opts.id !== '' || !note?.querySelector('[id], .index[href], .label[href]'));
229
231
  };
230
232
  }
231
233
 
@@ -1,4 +1,4 @@
1
- import { parse } from '../../../api';
1
+ import { run, parse } from '../../../api';
2
2
  import { html, define } from 'typed-dom/dom';
3
3
 
4
4
  const extensions = [
@@ -13,7 +13,7 @@ export function pdf(source: HTMLImageElement, url: URL): HTMLElement | undefined
13
13
  data: source.getAttribute('data-src'),
14
14
  }),
15
15
  html('div', [
16
- define(parse(`{ ${source.getAttribute('data-src')} }`).querySelector('a')!, {
16
+ define(run(parse(`{ ${source.getAttribute('data-src')} }`)).querySelector('a')!, {
17
17
  class: null,
18
18
  target: '_blank',
19
19
  }),
@@ -1,4 +1,4 @@
1
- import { parse } from '../../../api';
1
+ import { run, parse } from '../../../api';
2
2
  import { html as h, define } from 'typed-dom/dom';
3
3
  import DOMPurify from 'dompurify';
4
4
 
@@ -37,7 +37,7 @@ export function twitter(source: HTMLImageElement, url: URL): HTMLElement | undef
37
37
  error({ status, statusText }) {
38
38
  assert(Number.isSafeInteger(status));
39
39
  define(el, [
40
- define(parse(`{ ${source.getAttribute('data-src')} }`).querySelector('a')!, {
40
+ define(run(parse(`{ ${source.getAttribute('data-src')} }`)).querySelector('a')!, {
41
41
  class: null,
42
42
  target: '_blank',
43
43
  }),
@@ -1,46 +1,46 @@
1
1
  import { media } from './media';
2
- import { parse, caches } from '../../api';
2
+ import { run, parse, caches } from '../../api';
3
3
  import { html } from 'typed-dom/dom';
4
4
 
5
5
  describe('Unit: renderer/render/media', () => {
6
6
 
7
7
  describe('media', () => {
8
8
  it('twitter', done => {
9
- media(location.href, parse('!http://twitter.com/hourenso_u/status/856828123882676225').querySelector('img')!, {
9
+ media(location.href, run(parse('!http://twitter.com/hourenso_u/status/856828123882676225')).querySelector('img')!, {
10
10
  twitter: () => void done(false) || html('div')
11
11
  });
12
- media(location.href, parse('!https://twitter.com/hourenso_u/status/856828123882676225').querySelector('img')!, {
12
+ media(location.href, run(parse('!https://twitter.com/hourenso_u/status/856828123882676225')).querySelector('img')!, {
13
13
  twitter: () => void done() || html('div')
14
14
  });
15
15
  });
16
16
 
17
17
  it('youtube', done => {
18
- media(location.href, parse('!http://youtu.be/xRF7WIZV4lA').querySelector('img')!, {
18
+ media(location.href, run(parse('!http://youtu.be/xRF7WIZV4lA')).querySelector('img')!, {
19
19
  youtube: () => void done(false) || html('div')
20
20
  });
21
- media(location.href, parse('!https://youtu.be/xRF7WIZV4lA').querySelector('img')!, {
21
+ media(location.href, run(parse('!https://youtu.be/xRF7WIZV4lA')).querySelector('img')!, {
22
22
  youtube: () => void done() || html('div')
23
23
  });
24
- media(location.href, parse('!http://www.youtube.com/watch?v=xRF7WIZV4lA').querySelector('img')!, {
24
+ media(location.href, run(parse('!http://www.youtube.com/watch?v=xRF7WIZV4lA')).querySelector('img')!, {
25
25
  youtube: () => void done(false) || html('div')
26
26
  });
27
- media(location.href, parse('!https://www.youtube.com/watch?v=xRF7WIZV4lA').querySelector('img')!, {
27
+ media(location.href, run(parse('!https://www.youtube.com/watch?v=xRF7WIZV4lA')).querySelector('img')!, {
28
28
  youtube: () => void done() || html('div')
29
29
  });
30
30
  });
31
31
 
32
32
  it('pdf', done => {
33
- media(location.href, parse('!http://example.pdf').querySelector('img')!, {
33
+ media(location.href, run(parse('!http://example.pdf')).querySelector('img')!, {
34
34
  pdf: () => void done(false) || html('div')
35
35
  });
36
- assert(media(location.href, parse('!http://example/example.pdf').querySelector('img')!, {})!.querySelector('object')!.getAttribute('type') === 'application/pdf');
36
+ assert(media(location.href, run(parse('!http://example/example.pdf')).querySelector('img')!, {})!.querySelector('object')!.getAttribute('type') === 'application/pdf');
37
37
  done();
38
38
  });
39
39
 
40
40
  it('image', () => {
41
- assert(media(location.href, parse('!{/ 4x3}').querySelector('img')!, {}, caches.media)!.matches(`[src="/"][alt="/"][width="4"][height="3"]:not([aspect-ratio])`));
42
- assert(media(location.href, parse('!{/ 4:3}').querySelector('img')!, {}, caches.media)!.matches(`[src="/"][alt="/"][aspect-ratio="4/3"]:not([width]):not([height])`));
43
- assert(media(location.href, parse('!{/ 4x3}').querySelector('img')!, {}, caches.media)!.matches(`[src="/"][alt="/"][width="4"][height="3"]:not([aspect-ratio])`));
41
+ assert(media(location.href, run(parse('!{/ 4x3}')).querySelector('img')!, {}, caches.media)!.matches(`[src="/"][alt="/"][width="4"][height="3"]:not([aspect-ratio])`));
42
+ assert(media(location.href, run(parse('!{/ 4:3}')).querySelector('img')!, {}, caches.media)!.matches(`[src="/"][alt="/"][aspect-ratio="4/3"]:not([width]):not([height])`));
43
+ assert(media(location.href, run(parse('!{/ 4x3}')).querySelector('img')!, {}, caches.media)!.matches(`[src="/"][alt="/"][width="4"][height="3"]:not([aspect-ratio])`));
44
44
  });
45
45
 
46
46
  });
@@ -1,6 +1,6 @@
1
1
  import { render as render_ } from './render';
2
2
  import { RenderingOptions } from '../../';
3
- import { parse } from '../api/parse';
3
+ import { run, parse } from '../api';
4
4
 
5
5
  function render(target: HTMLElement, opts: RenderingOptions = {}): HTMLElement {
6
6
  render_(target, opts);
@@ -10,31 +10,31 @@ function render(target: HTMLElement, opts: RenderingOptions = {}): HTMLElement {
10
10
  describe('Unit: renderer/render', () => {
11
11
  describe('render', () => {
12
12
  it('code', () => {
13
- assert(render(parse('`${E = mc^2}$`').querySelector('p')!).querySelector('code'));
14
- assert(render(parse('```\n${E = mc^2}$\n```').querySelector('pre')!).matches('pre'));
13
+ assert(render(run(parse('`${E = mc^2}$`')).querySelector('p')!).querySelector('code'));
14
+ assert(render(run(parse('```\n${E = mc^2}$\n```')).querySelector('pre')!).matches('pre'));
15
15
  });
16
16
 
17
17
  it('math', async () => {
18
18
  // @ts-ignore
19
19
  MathJax.typesetPromise || await MathJax.startup.promise;
20
- //assert(render(parse('${E = mc^2}$').querySelector('p')!).querySelector('span.math')!.firstElementChild);
21
- assert(render(parse('$$\nE = mc^2\n$$').querySelector('div')!).firstElementChild);
20
+ //assert(render(run(parse('${E = mc^2}$')).querySelector('p')!).querySelector('span.math')!.firstElementChild);
21
+ assert(render(run(parse('$$\nE = mc^2\n$$')).querySelector('div')!).firstElementChild);
22
22
  });
23
23
 
24
24
  it('media', () => {
25
25
  // image
26
- assert(render(parse('!https://pbs.twimg.com/media/C-RAIleV0AAO81x.jpg').querySelector('div')!).querySelector('img')!.matches('div > a > img'));
27
- assert(render(parse('[!{https://pbs.twimg.com/media/C-RAIleV0AAO81x.jpg}]{#}').querySelector('div')!).querySelector('img')!.matches('div > a > img'));
26
+ assert(render(run(parse('!https://pbs.twimg.com/media/C-RAIleV0AAO81x.jpg')).querySelector('div')!).querySelector('img')!.matches('div > a > img'));
27
+ assert(render(run(parse('[!{https://pbs.twimg.com/media/C-RAIleV0AAO81x.jpg}]{#}')).querySelector('div')!).querySelector('img')!.matches('div > a > img'));
28
28
  // other
29
- assert(render(parse('!http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf').querySelector('div')!).querySelector('.media')!.matches('div > .media'));
30
- assert(render(parse('[!{http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf}]{#}').querySelector('div')!).querySelector('.media')!.matches('div > .media'));
29
+ assert(render(run(parse('!http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf')).querySelector('div')!).querySelector('.media')!.matches('div > .media'));
30
+ assert(render(run(parse('[!{http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf}]{#}')).querySelector('div')!).querySelector('.media')!.matches('div > .media'));
31
31
  // all
32
- assert(render(parse([
32
+ assert(render(run(parse([
33
33
  '!https://youtu.be/xRF7WIZV4lA',
34
34
  '!http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf',
35
35
  '!https://twitter.com/hourenso_u/status/856828123882676225?hide_thread=true',
36
36
  '!https://pbs.twimg.com/media/C-RAIleV0AAO81x.jpg',
37
- ].join('\n')).querySelector('div')!).querySelectorAll('.media').length === 4);
37
+ ].join('\n'))).querySelector('div')!).querySelectorAll('.media').length === 4);
38
38
  });
39
39
 
40
40
  });
@@ -1,11 +1,11 @@
1
1
  import { info } from './info';
2
- import { parse } from '../api';
2
+ import { run, parse } from '../api';
3
3
 
4
4
  describe('Unit: util/info', () => {
5
5
  describe('info', () => {
6
6
  it('empty', () => {
7
7
  assert.deepStrictEqual(
8
- info(parse('')),
8
+ info(run(parse(''))),
9
9
  {
10
10
  url: [],
11
11
  tel: [],