securemark 0.235.3 → 0.237.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 (51) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/securemark.js +220 -114
  3. package/karma.conf.js +1 -1
  4. package/markdown.d.ts +11 -10
  5. package/package-lock.json +91 -54
  6. package/package.json +1 -1
  7. package/src/debug.test.ts +3 -1
  8. package/src/parser/api/bind.ts +7 -3
  9. package/src/parser/api/parse.test.ts +3 -3
  10. package/src/parser/api/parse.ts +8 -11
  11. package/src/parser/block/blockquote.test.ts +1 -1
  12. package/src/parser/block/codeblock.ts +2 -2
  13. package/src/parser/block/dlist.ts +1 -3
  14. package/src/parser/block/extension/aside.test.ts +1 -1
  15. package/src/parser/block/extension/aside.ts +3 -3
  16. package/src/parser/block/extension/example.test.ts +2 -2
  17. package/src/parser/block/extension/example.ts +3 -3
  18. package/src/parser/block/extension/fig.test.ts +22 -20
  19. package/src/parser/block/extension/figure.test.ts +33 -31
  20. package/src/parser/block/extension/figure.ts +33 -4
  21. package/src/parser/block/extension/message.ts +3 -3
  22. package/src/parser/block/extension/placeholder.ts +2 -2
  23. package/src/parser/block/extension/table.ts +6 -6
  24. package/src/parser/block/extension.ts +1 -1
  25. package/src/parser/block/heading.test.ts +1 -1
  26. package/src/parser/block/heading.ts +11 -7
  27. package/src/parser/block/ilist.ts +1 -1
  28. package/src/parser/block/mathblock.ts +2 -2
  29. package/src/parser/block/olist.test.ts +8 -0
  30. package/src/parser/block/olist.ts +7 -7
  31. package/src/parser/block/reply/cite.test.ts +4 -0
  32. package/src/parser/block/reply/cite.ts +1 -0
  33. package/src/parser/block/reply/quote.ts +1 -1
  34. package/src/parser/block/table.ts +1 -1
  35. package/src/parser/block/ulist.test.ts +8 -0
  36. package/src/parser/block/ulist.ts +7 -7
  37. package/src/parser/header.ts +1 -1
  38. package/src/parser/inline/extension/indexee.ts +8 -8
  39. package/src/parser/inline/extension/placeholder.ts +1 -1
  40. package/src/parser/inline/html.ts +7 -7
  41. package/src/parser/inline/htmlentity.ts +1 -1
  42. package/src/parser/inline/link.ts +4 -4
  43. package/src/parser/inline/math.ts +1 -1
  44. package/src/parser/inline/media.ts +3 -3
  45. package/src/parser/inline/reference.ts +1 -1
  46. package/src/parser/inline/ruby.ts +1 -1
  47. package/src/parser/inline.ts +2 -0
  48. package/src/parser/processor/figure.test.ts +72 -44
  49. package/src/parser/processor/figure.ts +79 -20
  50. package/src/parser/processor/footnote.ts +4 -4
  51. package/src/util/quote.ts +1 -0
@@ -2,7 +2,7 @@ import { UListParser } from '../block';
2
2
  import { union, inits, subsequence, some, block, line, validate, indent, focus, rewrite, context, creator, open, trim, trimStart, fallback, lazy, fmap } from '../../combinator';
3
3
  import { olist_ } from './olist';
4
4
  import { ilist_ } from './ilist';
5
- import { inline } from '../inline';
5
+ import { inline, indexer, indexee } from '../inline';
6
6
  import { html, defrag } from 'typed-dom';
7
7
  import { unshift } from 'spica/array';
8
8
  import { contentline } from '../source';
@@ -15,13 +15,13 @@ export const ulist: UListParser = lazy(() => block(validate(
15
15
  export const ulist_: UListParser = lazy(() => block(fmap(validate(
16
16
  /^-(?=$|\s)/,
17
17
  some(creator(union([
18
- fmap(fallback(
18
+ indexee(fmap(fallback(
19
19
  inits([
20
- line(open(/^-(?:$|\s)/, trim(subsequence([checkbox, trimStart(some(inline))])), true)),
20
+ line(open(/^-(?:$|\s)/, trim(subsequence([checkbox, trimStart(some(union([indexer, inline])))])), true)),
21
21
  indent(union([ulist_, olist_, ilist_])),
22
22
  ]),
23
- iitem),
24
- ns => [html('li', defrag(fillFirstLine(ns)))]),
23
+ invalid),
24
+ ns => [html('li', defrag(fillFirstLine(ns)))]), true),
25
25
  ])))),
26
26
  es => [format(html('ul', es))])));
27
27
 
@@ -31,12 +31,12 @@ export const checkbox = focus(
31
31
  html('span', { class: 'checkbox' }, source[1].trimStart() ? '☑' : '☐'),
32
32
  ], '']);
33
33
 
34
- const iitem = rewrite(contentline, source => [[
34
+ const invalid = rewrite(contentline, source => [[
35
35
  html('span', {
36
36
  class: 'invalid',
37
37
  'data-invalid-syntax': 'listitem',
38
38
  'data-invalid-type': 'syntax',
39
- 'data-invalid-description': 'Fix the indent or the head of the list item.',
39
+ 'data-invalid-message': 'Fix the indent or the head of the list item',
40
40
  }, source.replace('\n', ''))
41
41
  ], '']);
42
42
 
@@ -31,7 +31,7 @@ export const header: MarkdownParser.HeaderParser = lazy(() => validate(
31
31
  translate: 'no',
32
32
  'data-invalid-syntax': 'header',
33
33
  'data-invalid-type': 'syntax',
34
- 'data-invalid-description': 'Invalid syntax.',
34
+ 'data-invalid-message': 'Invalid syntax',
35
35
  }, normalize(source)),
36
36
  ], ''],
37
37
  ]))),
@@ -4,9 +4,9 @@ import { Parser } from '../../../combinator/data/parser';
4
4
  import { fmap } from '../../../combinator';
5
5
  import { define } from 'typed-dom';
6
6
 
7
- export function indexee<P extends Parser<unknown, MarkdownParser.Context>>(parser: P): P;
8
- export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>): Parser<HTMLElement> {
9
- return fmap(parser, ([el], _, { id }) => [define(el, { id: id !== '' && identity(text(el)) || undefined })]);
7
+ export function indexee<P extends Parser<unknown, MarkdownParser.Context>>(parser: P, optional?: boolean): P;
8
+ export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>, optional?: boolean): Parser<HTMLElement> {
9
+ return fmap(parser, ([el], _, { id }) => [define(el, { id: id !== '' && identity(text(el, optional)) || undefined })]);
10
10
  }
11
11
 
12
12
  export function identity(text: string): string {
@@ -18,13 +18,13 @@ assert(identity('0'.repeat(100)).slice(6) === '0'.repeat(100));
18
18
  assert(identity('0'.repeat(101)).slice(6) === '0'.repeat(97) + '...');
19
19
  assert(identity('0'.repeat(200)).slice(6) === '0'.repeat(97) + '...');
20
20
 
21
- export function text(source: HTMLElement | DocumentFragment): string {
21
+ export function text(source: HTMLElement | DocumentFragment, optional = false): string {
22
22
  assert(source instanceof DocumentFragment || !source.matches('.indexer'));
23
- assert(source.querySelectorAll('.indexer').length <= 1);
24
- assert(source.querySelector('.indexer') === source.querySelector(':scope > .indexer'));
25
- assert(!source.querySelector('.annotation, br'));
26
- const indexer = source.querySelector('.indexer');
23
+ assert(source.querySelectorAll(':scope > .indexer').length <= 1);
24
+ const indexer = source.querySelector(':scope > .indexer');
27
25
  if (indexer) return indexer.getAttribute('data-index')!;
26
+ if (optional) return '';
27
+ assert(!source.querySelector('.annotation, br'));
28
28
  const target = source.cloneNode(true) as typeof source;
29
29
  for (
30
30
  let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference'),
@@ -19,7 +19,7 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => creator
19
19
  class: 'invalid',
20
20
  'data-invalid-syntax': 'extension',
21
21
  'data-invalid-type': 'syntax',
22
- 'data-invalid-description': 'Invalid symbol.',
22
+ 'data-invalid-message': 'Invalid symbol',
23
23
  }, defrag(bs)),
24
24
  ], rest],
25
25
  ([as, bs], rest) => [unshift(as, bs), rest]))));
@@ -116,38 +116,38 @@ function elem(tag: string, as: string[], bs: (HTMLElement | string)[], cs: strin
116
116
  assert(as[0][0] === '<' && as[as.length - 1].slice(-1) === '>');
117
117
  assert(bs.length === defrag(bs).length);
118
118
  assert(cs.length === 1);
119
- if (!tags.includes(tag)) return invalid('tag', `Invalid HTML tag <${tag}>.`, as, bs, cs);
119
+ if (!tags.includes(tag)) return invalid('tag', `Invalid HTML tag <${tag}>`, as, bs, cs);
120
120
  switch (tag) {
121
121
  case 'sup':
122
122
  case 'sub':
123
123
  switch (true) {
124
124
  case context.state?.in?.supsub:
125
- return invalid('nest', `<${tag}> HTML tag cannot be used in <sup> or <sub> HTML tag.`, as, bs, cs);
125
+ return invalid('nest', `<${tag}> HTML tag cannot be used in <sup> or <sub> HTML tag`, as, bs, cs);
126
126
  }
127
127
  break;
128
128
  case 'small':
129
129
  switch (true) {
130
130
  case context.state?.in?.supsub:
131
131
  case context.state?.in?.small:
132
- return invalid('nest', `<${tag}> HTML tag cannot be used in <sup>, <sub>, or <small> HTML tag.`, as, bs, cs);
132
+ return invalid('nest', `<${tag}> HTML tag cannot be used in <sup>, <sub>, or <small> HTML tag`, as, bs, cs);
133
133
  }
134
134
  break;
135
135
  }
136
136
  let attrs: Record<string, string | undefined> | undefined;
137
137
  switch (true) {
138
138
  case 'data-invalid-syntax' in (attrs = attributes('html', [], attrspec[tag], as.slice(1, -1) as string[])):
139
- return invalid('attribute', 'Invalid HTML attribute.', as, bs, cs);
139
+ return invalid('attribute', 'Invalid HTML attribute', as, bs, cs);
140
140
  default:
141
141
  assert(attrs);
142
142
  return h(tag as 'span', attrs, bs);
143
143
  }
144
144
  }
145
- function invalid(type: string, description: string, as: (HTMLElement | string)[], bs: (HTMLElement | string)[], cs: (HTMLElement | string)[]): HTMLElement {
145
+ function invalid(type: string, message: string, as: (HTMLElement | string)[], bs: (HTMLElement | string)[], cs: (HTMLElement | string)[]): HTMLElement {
146
146
  return h('span', {
147
147
  class: 'invalid',
148
148
  'data-invalid-syntax': 'html',
149
149
  'data-invalid-type': type,
150
- 'data-invalid-description': description,
150
+ 'data-invalid-message': message,
151
151
  }, defrag(push(unshift(as, bs), cs)));
152
152
  }
153
153
 
@@ -187,7 +187,7 @@ export function attributes(
187
187
  attrs['class'] = join(classes, ' ');
188
188
  attrs['data-invalid-syntax'] = syntax;
189
189
  attrs['data-invalid-type'] = 'argument';
190
- attrs['data-invalid-description'] = 'Invalid argument.';
190
+ attrs['data-invalid-message'] = 'Invalid argument';
191
191
  }
192
192
  return attrs;
193
193
  }
@@ -16,7 +16,7 @@ export const htmlentity: HTMLEntityParser = fmap(
16
16
  class: 'invalid',
17
17
  'data-invalid-syntax': 'htmlentity',
18
18
  'data-invalid-type': 'syntax',
19
- 'data-invalid-description': 'Invalid HTML entity.',
19
+ 'data-invalid-message': 'Invalid HTML entity',
20
20
  }, test.slice(1))
21
21
  : test,
22
22
  ]);
@@ -103,7 +103,7 @@ function elem(
103
103
  origin: string,
104
104
  ): HTMLAnchorElement {
105
105
  let type: string;
106
- let description: string;
106
+ let message: string;
107
107
  switch (uri.protocol) {
108
108
  case 'http:':
109
109
  case 'https:':
@@ -111,7 +111,7 @@ function elem(
111
111
  if (INSECURE_URI.slice(0, 2) === '^/' &&
112
112
  /\/\.\.?(?:\/|$)/.test(INSECURE_URI.slice(0, INSECURE_URI.search(/[?#]|$/)))) {
113
113
  type = 'argument';
114
- description = 'Dot-segments cannot be used in subresource paths.';
114
+ message = 'Dot-segments cannot be used in subresource paths';
115
115
  break;
116
116
  }
117
117
  return html('a',
@@ -140,7 +140,7 @@ function elem(
140
140
  return html('a', { href: uri.source }, content);
141
141
  }
142
142
  type = 'content';
143
- description = 'Invalid phone number.';
143
+ message = 'Invalid phone number';
144
144
  break;
145
145
  }
146
146
  return html('a',
@@ -148,7 +148,7 @@ function elem(
148
148
  class: 'invalid',
149
149
  'data-invalid-syntax': 'link',
150
150
  'data-invalid-type': type ??= 'argument',
151
- 'data-invalid-description': description ??= 'Invalid protocol.',
151
+ 'data-invalid-message': message ??= 'Invalid protocol',
152
152
  },
153
153
  content.length === 0
154
154
  ? INSECURE_URI
@@ -29,7 +29,7 @@ export const math: MathParser = lazy(() => creator(validate('$', rewrite(
29
29
  translate: 'no',
30
30
  'data-invalid-syntax': 'math',
31
31
  'data-invalid-type': 'content',
32
- 'data-invalid-description': `"${source.match(disallowedCommand)![0]}" command is disallowed.`,
32
+ 'data-invalid-message': `"${source.match(disallowedCommand)![0]}" command is disallowed`,
33
33
  },
34
34
  source)
35
35
  ], '']))));
@@ -81,7 +81,7 @@ function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
81
81
  class: void target.classList.add('invalid'),
82
82
  'data-invalid-syntax': 'media',
83
83
  'data-invalid-type': 'argument',
84
- 'data-invalid-description': 'Dot-segments cannot be used in media paths; use subresource paths instead.',
84
+ 'data-invalid-message': 'Dot-segments cannot be used in media paths; use subresource paths instead',
85
85
  });
86
86
  return false;
87
87
  }
@@ -91,7 +91,7 @@ function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
91
91
  class: void target.classList.add('invalid'),
92
92
  'data-invalid-syntax': 'media',
93
93
  'data-invalid-type': 'argument',
94
- 'data-invalid-description': 'Invalid protocol.',
94
+ 'data-invalid-message': 'Invalid protocol',
95
95
  });
96
96
  return false;
97
97
  }
@@ -100,7 +100,7 @@ function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
100
100
  class: void target.classList.add('invalid'),
101
101
  'data-invalid-syntax': 'media',
102
102
  'data-invalid-type': 'content',
103
- 'data-invalid-description': `Cannot use invalid HTML entitiy "${alt.match(/&[0-9A-Za-z]+;/)![0]}".`,
103
+ 'data-invalid-message': `Cannot use invalid HTML entitiy "${alt.match(/&[0-9A-Za-z]+;/)![0]}"`,
104
104
  alt: target.getAttribute('alt')?.replace(/\0/g, ''),
105
105
  });
106
106
  return false;
@@ -46,7 +46,7 @@ function attributes(ns: (string | HTMLElement)[]): Record<string, string | undef
46
46
  class: 'invalid',
47
47
  'data-invalid-syntax': 'reference',
48
48
  'data-invalid-type': 'syntax',
49
- 'data-invalid-description': 'Invalid abbr.',
49
+ 'data-invalid-message': 'Invalid abbr',
50
50
  }
51
51
  : { class: 'reference' };
52
52
  }
@@ -89,7 +89,7 @@ function attributes(texts: string[], rubies: string[]): Record<string, string> {
89
89
  class: 'invalid',
90
90
  'data-invalid-syntax': 'ruby',
91
91
  'data-invalid-type': ss === texts ? 'content' : 'argument',
92
- 'data-invalid-description': 'Invalid HTML entity.',
92
+ 'data-invalid-message': 'Invalid HTML entity',
93
93
  };
94
94
  }
95
95
  }
@@ -75,5 +75,7 @@ export const inline: InlineParser = union([
75
75
  text
76
76
  ]);
77
77
 
78
+ export { indexee } from './inline/extension/indexee';
79
+ export { indexer } from './inline/extension/indexer';
78
80
  export { media } from './inline/media';
79
81
  export { shortmedia } from './inline/shortmedia';
@@ -28,7 +28,7 @@ describe('Unit: parser/processor/figure', () => {
28
28
  assert.deepStrictEqual(
29
29
  [...target.children].map(el => el.outerHTML),
30
30
  [
31
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
31
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
32
32
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
33
33
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
34
34
  ]);
@@ -41,16 +41,20 @@ describe('Unit: parser/processor/figure', () => {
41
41
  '## 0',
42
42
  '$fig-b\n> ',
43
43
  '$table-a\n> ',
44
+ '$fig-b\n> ',
45
+ '$fig-c\n> ',
44
46
  ].join('\n\n'));
45
47
  for (let i = 0; i < 3; ++i) {
46
48
  [...figure(target)];
47
49
  assert.deepStrictEqual(
48
50
  [...target.children].map(el => el.outerHTML),
49
51
  [
50
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
52
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
51
53
  '<h2 id="index:0">0</h2>',
52
- '<figure data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
53
- '<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Table 1. </span></figcaption></figure>',
54
+ '<figure data-type="quote" data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
55
+ '<figure data-type="quote" data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Table 1. </span></figcaption></figure>',
56
+ '<figure data-type="quote" data-label="fig-b" data-group="fig" data-number="3" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Duplicate label"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3. </span></figcaption></figure>',
57
+ '<figure data-type="quote" data-label="fig-c" data-group="fig" data-number="4" id="label:fig-c"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 4. </span></figcaption></figure>',
54
58
  ]);
55
59
  }
56
60
  });
@@ -65,7 +69,7 @@ describe('Unit: parser/processor/figure', () => {
65
69
  assert.deepStrictEqual(
66
70
  [...target.children].map(el => el.outerHTML),
67
71
  [
68
- '<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
72
+ '<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
69
73
  '<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
70
74
  ]);
71
75
  }
@@ -87,14 +91,14 @@ describe('Unit: parser/processor/figure', () => {
87
91
  assert.deepStrictEqual(
88
92
  [...target.children].map(el => el.outerHTML),
89
93
  [
90
- '<figure data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
91
- '<figure data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
92
- '<figure data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(4.1.1)</span></figcaption></figure>',
93
- '<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
94
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
94
+ '<figure data-type="quote" data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
95
+ '<figure data-type="quote" data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
96
+ '<figure data-type="math" data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(4.1.1)</span></figcaption></figure>',
97
+ '<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
98
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
95
99
  '<p><a class="label" data-label="fig-2" href="#label:fig-2">Fig. 2</a></p>',
96
100
  '<p><a class="label" data-label="$-4.1.1" href="#label:$-4.1.1">(4.1.1)</a></p>',
97
- '<p><a class="label disabled invalid" data-label="fig-1" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-description="Missing the reference.">$fig-1</a></p>',
101
+ '<p><a class="label disabled invalid" data-label="fig-1" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-message="Missing the target figure">$fig-1</a></p>',
98
102
  ]);
99
103
  }
100
104
  });
@@ -111,10 +115,10 @@ describe('Unit: parser/processor/figure', () => {
111
115
  assert.deepStrictEqual(
112
116
  [...target.children].map(el => el.outerHTML),
113
117
  [
114
- '<blockquote><blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
115
- '<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n&gt; \n\n~~~\n\n$fig-a</pre><hr><section><figure data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><p><a class="label disabled" data-label="fig-a">Fig. 1</a></p><ol class="annotations"></ol><ol class="references"></ol></section></aside>',
116
- '<figure data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
117
- '<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
118
+ '<blockquote><blockquote><section><figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote><section><figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
119
+ '<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n&gt; \n\n~~~\n\n$fig-a</pre><hr><section><figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure><p><a class="label disabled" data-label="fig-a">Fig. 1</a></p><ol class="annotations"></ol><ol class="references"></ol></section></aside>',
120
+ '<figure data-type="quote" data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
121
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
118
122
  ]);
119
123
  }
120
124
  });
@@ -130,6 +134,8 @@ describe('Unit: parser/processor/figure', () => {
130
134
  '$fig-b\n> ',
131
135
  '## 0',
132
136
  '$-0.0.0',
137
+ '### 0',
138
+ '$-0.0',
133
139
  '$fig-c\n> ',
134
140
  '## 0',
135
141
  '$-0.1.0',
@@ -163,66 +169,88 @@ describe('Unit: parser/processor/figure', () => {
163
169
  '<h1 id="index:0">0</h1>',
164
170
  '<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
165
171
  '<h2 id="index:0">0</h2>',
166
- '<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
172
+ '<figure data-type="quote" data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
167
173
  '<h2 id="index:0">0</h2>',
168
174
  '<blockquote><section><h2>0</h2><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
169
- '<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></figcaption></figure>',
175
+ '<figure data-type="quote" data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></figcaption></figure>',
170
176
  '<h2 id="index:0">0</h2>',
171
- '<figure data-label="$-0.0.0" data-group="$" hidden=""></figure>',
172
- '<figure data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
177
+ '<figure data-label="$-0.0.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Base index must be $-x.0 format"></figure>',
178
+ '<h3 id="index:0">0</h3>',
179
+ '<figure data-label="$-0.0" data-group="$" hidden="" data-number="3.0"></figure>',
180
+ '<figure data-type="quote" data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
173
181
  '<h2 id="index:0">0</h2>',
174
- '<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
175
- '<figure data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 4.1. </span></figcaption></figure>',
176
- '<figure data-label="$-0.0" data-group="$" hidden=""></figure>',
177
- '<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
178
- '<figure data-label="$-0.4.0" data-group="$" hidden=""></figure>',
179
- '<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
182
+ '<figure data-label="$-0.1.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Base index must be $-x.0 format"></figure>',
183
+ '<figure data-type="quote" data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 4.1. </span></figcaption></figure>',
184
+ '<figure data-label="$-0.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="position" data-invalid-message="Base index declarations must be after level 1 or 2 headings"></figure>',
185
+ '<figure data-label="$-0.1.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Base index must be $-x.0 format"></figure>',
186
+ '<figure data-label="$-0.4.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Base index must be $-x.0 format"></figure>',
187
+ '<figure data-label="$-0.1.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Base index must be $-x.0 format"></figure>',
180
188
  '<h2 id="index:0">0</h2>',
181
189
  '<h2 id="index:0">0</h2>',
182
190
  '<figure data-label="$-0.0" data-group="$" hidden="" data-number="6.0"></figure>',
183
- '<figure data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></figcaption></figure>',
191
+ '<figure data-type="quote" data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></figcaption></figure>',
184
192
  '<h2 id="index:0">0</h2>',
185
193
  '<figure data-label="$-5.0" data-group="$" hidden="" data-number="5.0"></figure>',
186
- '<figure data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.1. </span></figcaption></figure>',
187
- '<figure data-label="$-0" data-group="$" hidden=""></figure>',
188
- '<figure data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.2. </span></figcaption></figure>',
194
+ '<figure data-type="quote" data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.1. </span></figcaption></figure>',
195
+ '<figure data-label="$-0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Invalid base index"></figure>',
196
+ '<figure data-type="quote" data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.2. </span></figcaption></figure>',
189
197
  '<h3 id="index:0">0</h3>',
190
- '<figure data-label="$-0.0.0" data-group="$" hidden=""></figure>',
191
- '<figure data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.3. </span></figcaption></figure>',
198
+ '<figure data-label="$-0.0.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Base index must be $-x.0 format"></figure>',
199
+ '<figure data-type="quote" data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.3. </span></figcaption></figure>',
192
200
  '<h3 id="index:0">0</h3>',
193
- '<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.4. </span></figcaption></figure>',
201
+ '<figure data-type="quote" data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.4. </span></figcaption></figure>',
194
202
  '<h1 id="index:0">0</h1>',
195
- '<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></figcaption></figure>',
203
+ '<figure data-type="quote" data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></figcaption></figure>',
196
204
  ]);
197
205
  }
198
206
  });
199
207
 
200
- it('concatenation', () => {
208
+ it('concat', () => {
201
209
  const target = parse([
202
- '# 0',
203
210
  '$-0.0',
204
211
  '## 0',
212
+ '$-0.0',
213
+ '$fig-a\n> ',
214
+ '$-0.0',
205
215
  '## 0',
216
+ '$fig-b\n> ',
217
+ '$-0.0',
218
+ '### 0',
219
+ '$fig-c\n> ',
206
220
  '$-1.0',
207
- '$fig-a\n> ',
208
221
  '## 0',
209
222
  '$-0.0',
210
- '$fig-b\n> ',
223
+ '$fig-d\n> ',
224
+ '### 0',
225
+ '$-0.0',
226
+ '## 0',
227
+ '$-9.0',
228
+ '$fig-e\n> ',
211
229
  ].join('\n\n'));
212
230
  for (let i = 0; i < 3; ++i) {
213
231
  [...figure(target)];
214
232
  assert.deepStrictEqual(
215
233
  [...target.children].map(el => normalize(el.outerHTML)),
216
234
  [
217
- '<h1 id="index:0">0</h1>',
218
- '<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
235
+ '<figure data-label="$-0.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="position" data-invalid-message="Base index declarations must be after level 1 or 2 headings"></figure>',
219
236
  '<h2 id="index:0">0</h2>',
237
+ '<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
238
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="0.1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 0.1. </span></figcaption></figure>',
239
+ '<figure data-label="$-0.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="position" data-invalid-message="Base index declarations must be after level 1 or 2 headings"></figure>',
220
240
  '<h2 id="index:0">0</h2>',
221
- '<figure data-label="$-1.0" data-group="$" hidden="" data-number="1.0"></figure>',
222
- '<figure data-label="fig-a" data-group="fig" data-number="1.1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1.1. </span></figcaption></figure>',
241
+ '<figure data-type="quote" data-label="fig-b" data-group="fig" data-number="1.1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1.1. </span></figcaption></figure>',
242
+ '<figure data-label="$-0.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="position" data-invalid-message="Base index declarations must be after level 1 or 2 headings"></figure>',
243
+ '<h3 id="index:0">0</h3>',
244
+ '<figure data-type="quote" data-label="fig-c" data-group="fig" data-number="1.2" id="label:fig-c"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1.2. </span></figcaption></figure>',
245
+ '<figure data-label="$-1.0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="position" data-invalid-message="Base index declarations must be after level 1 or 2 headings"></figure>',
223
246
  '<h2 id="index:0">0</h2>',
224
247
  '<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
225
- '<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></figcaption></figure>',
248
+ '<figure data-type="quote" data-label="fig-d" data-group="fig" data-number="2.1" id="label:fig-d"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></figcaption></figure>',
249
+ '<h3 id="index:0">0</h3>',
250
+ '<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
251
+ '<h2 id="index:0">0</h2>',
252
+ '<figure data-label="$-9.0" data-group="$" hidden="" data-number="9.0"></figure>',
253
+ '<figure data-type="quote" data-label="fig-e" data-group="fig" data-number="9.1" id="label:fig-e"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 9.1. </span></figcaption></figure>',
226
254
  ]);
227
255
  }
228
256
  });
@@ -238,7 +266,7 @@ describe('Unit: parser/processor/figure', () => {
238
266
  assert.deepStrictEqual(
239
267
  [...target.children].map(el => el.outerHTML),
240
268
  [
241
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
269
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
242
270
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
243
271
  '<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
244
272
  ]);
@@ -255,7 +283,7 @@ describe('Unit: parser/processor/figure', () => {
255
283
  assert.deepStrictEqual(
256
284
  [...target.children].map(el => el.outerHTML),
257
285
  [
258
- '<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
286
+ '<figure data-type="quote" data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
259
287
  '<p><a class="label" data-label="fig-a" href="#label:0:fig-a">Fig. 1</a></p>',
260
288
  ]);
261
289
  }