securemark 0.238.0 → 0.240.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.
- package/CHANGELOG.md +12 -0
- package/dist/securemark.js +73 -47
- package/markdown.d.ts +5 -3
- package/package-lock.json +123 -124
- package/package.json +1 -1
- package/src/combinator/data/parser/subsequence.ts +5 -9
- package/src/combinator/data/parser/tails.ts +1 -1
- package/src/combinator/data/parser/union.ts +1 -1
- package/src/parser/api/header.test.ts +1 -1
- package/src/parser/api/header.ts +3 -3
- package/src/parser/api/parse.test.ts +7 -7
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/extension/aside.test.ts +1 -1
- package/src/parser/block/extension/example.test.ts +2 -2
- package/src/parser/block/extension/fig.test.ts +21 -21
- package/src/parser/block/extension/figure.test.ts +37 -33
- package/src/parser/block/extension/figure.ts +35 -5
- package/src/parser/block/olist.test.ts +2 -0
- package/src/parser/block/ulist.test.ts +2 -0
- package/src/parser/header.test.ts +4 -4
- package/src/parser/header.ts +7 -5
- package/src/parser/inline/bracket.test.ts +5 -1
- package/src/parser/inline/bracket.ts +2 -2
- package/src/parser/inline/extension/indexee.ts +7 -3
- package/src/parser/inline/extension/indexer.test.ts +2 -1
- package/src/parser/inline/extension/indexer.ts +6 -3
- package/src/parser/inline/reference.test.ts +7 -7
- package/src/parser/inline/reference.ts +1 -1
- package/src/parser/processor/figure.test.ts +79 -79
- package/src/parser/processor/figure.ts +12 -6
|
@@ -22,12 +22,13 @@ export function text(source: HTMLElement | DocumentFragment, optional = false):
|
|
|
22
22
|
assert(source instanceof DocumentFragment || !source.matches('.indexer'));
|
|
23
23
|
assert(source.querySelectorAll(':scope > .indexer').length <= 1);
|
|
24
24
|
const indexer = source.querySelector(':scope > .indexer');
|
|
25
|
-
if (indexer) return
|
|
26
|
-
|
|
25
|
+
if (!indexer && optional) return '';
|
|
26
|
+
const index = indexer?.getAttribute('data-index');
|
|
27
|
+
if (index) return index;
|
|
27
28
|
assert(!source.querySelector('.annotation, br'));
|
|
28
29
|
const target = source.cloneNode(true) as typeof source;
|
|
29
30
|
for (
|
|
30
|
-
let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference'),
|
|
31
|
+
let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference, .checkbox, ul, ol'),
|
|
31
32
|
i = 0, len = es.length; i < len; ++i) {
|
|
32
33
|
const el = es[i];
|
|
33
34
|
switch (el.tagName) {
|
|
@@ -36,6 +37,8 @@ export function text(source: HTMLElement | DocumentFragment, optional = false):
|
|
|
36
37
|
continue;
|
|
37
38
|
case 'RT':
|
|
38
39
|
case 'RP':
|
|
40
|
+
case 'UL':
|
|
41
|
+
case 'OL':
|
|
39
42
|
el.remove();
|
|
40
43
|
continue;
|
|
41
44
|
}
|
|
@@ -44,6 +47,7 @@ export function text(source: HTMLElement | DocumentFragment, optional = false):
|
|
|
44
47
|
define(el, el.getAttribute('data-src')!);
|
|
45
48
|
continue;
|
|
46
49
|
case 'comment':
|
|
50
|
+
case 'checkbox':
|
|
47
51
|
el.remove();
|
|
48
52
|
continue;
|
|
49
53
|
case 'reference':
|
|
@@ -12,13 +12,14 @@ describe('Unit: parser/inline/extension/indexer', () => {
|
|
|
12
12
|
assert.deepStrictEqual(inspect(parser(' ')), undefined);
|
|
13
13
|
assert.deepStrictEqual(inspect(parser(' #')), undefined);
|
|
14
14
|
assert.deepStrictEqual(inspect(parser(' #a')), undefined);
|
|
15
|
-
assert.deepStrictEqual(inspect(parser(' [#]')), undefined);
|
|
15
|
+
assert.deepStrictEqual(inspect(parser(' [# ]')), undefined);
|
|
16
16
|
assert.deepStrictEqual(inspect(parser(' [#]]')), undefined);
|
|
17
17
|
assert.deepStrictEqual(inspect(parser(' [#a]]')), undefined);
|
|
18
18
|
assert.deepStrictEqual(inspect(parser(' [#&a;]')), undefined);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('valid', () => {
|
|
22
|
+
assert.deepStrictEqual(inspect(parser(' [#]')), [['<span class="indexer" data-index=""></span>'], '']);
|
|
22
23
|
assert.deepStrictEqual(inspect(parser(' [#a]')), [['<span class="indexer" data-index="a"></span>'], '']);
|
|
23
24
|
assert.deepStrictEqual(inspect(parser(' [#a] ')), [['<span class="indexer" data-index="a"></span>'], '']);
|
|
24
25
|
assert.deepStrictEqual(inspect(parser(' [#a ]')), [['<span class="indexer" data-index="a"></span>'], '']);
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../inline';
|
|
2
|
-
import { union, verify, creator, context, surround, fmap } from '../../../combinator';
|
|
2
|
+
import { union, verify, focus, creator, context, surround, fmap } from '../../../combinator';
|
|
3
3
|
import { index } from './index';
|
|
4
4
|
import { html } from 'typed-dom';
|
|
5
5
|
|
|
6
6
|
export const indexer: ExtensionParser.IndexerParser = creator(fmap(verify(surround(
|
|
7
|
-
/^\s+(?=\[
|
|
7
|
+
/^\s+(?=\[#\S)/,
|
|
8
8
|
context({ syntax: { inline: {
|
|
9
9
|
index: true,
|
|
10
10
|
}}},
|
|
11
|
-
union([
|
|
11
|
+
union([
|
|
12
|
+
focus('[#]', () => [[html('a', { href: '#' })], '']),
|
|
13
|
+
index,
|
|
14
|
+
])),
|
|
12
15
|
/^\s*$/),
|
|
13
16
|
// Indexer is invisible but invalids must be visible.
|
|
14
17
|
([el]) => el.getElementsByClassName('invalid').length === 0),
|
|
@@ -64,16 +64,16 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
64
64
|
assert.deepStrictEqual(inspect(parser('[[^a|]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
65
65
|
assert.deepStrictEqual(inspect(parser('[[^a,|]]')), [['<sup class="reference" data-abbr="a,"></sup>'], '']);
|
|
66
66
|
assert.deepStrictEqual(inspect(parser('[[^a |]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
67
|
-
assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="
|
|
67
|
+
assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
68
|
+
assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
69
|
+
assert.deepStrictEqual(inspect(parser('[[^a|b ]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
70
|
+
assert.deepStrictEqual(inspect(parser('[[^a|b ]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
71
|
+
assert.deepStrictEqual(inspect(parser('[[^a|<wbr>]]')), [['<sup class="invalid">^a|</sup>'], '']);
|
|
72
|
+
assert.deepStrictEqual(inspect(parser('[[^a|<wbr>b]]')), [['<sup class="invalid">^a|<wbr>b</sup>'], '']);
|
|
73
|
+
assert.deepStrictEqual(inspect(parser('[[^a|^b]]')), [['<sup class="reference" data-abbr="a">^b</sup>'], '']);
|
|
68
74
|
assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
69
75
|
assert.deepStrictEqual(inspect(parser('[[^a| b]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
70
|
-
assert.deepStrictEqual(inspect(parser('[[^a| b ]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
71
|
-
assert.deepStrictEqual(inspect(parser('[[^a| b ]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
72
76
|
assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
73
|
-
assert.deepStrictEqual(inspect(parser('[[^a| b]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
74
|
-
assert.deepStrictEqual(inspect(parser('[[^a| <wbr>]]')), [['<sup class="invalid">^a|</sup>'], '']);
|
|
75
|
-
assert.deepStrictEqual(inspect(parser('[[^a| <wbr>b]]')), [['<sup class="invalid">^a| <wbr>b</sup>'], '']);
|
|
76
|
-
assert.deepStrictEqual(inspect(parser('[[^a| ^b]]')), [['<sup class="reference" data-abbr="a">^b</sup>'], '']);
|
|
77
77
|
assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="invalid">^1</sup>'], '']);
|
|
78
78
|
assert.deepStrictEqual(inspect(parser('[[^1a]]')), [['<sup class="reference" data-abbr="1a"></sup>'], '']);
|
|
79
79
|
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid">^1</sup>'], '']);
|
|
@@ -31,7 +31,7 @@ export const reference: ReferenceParser = lazy(() => creator(validate('[[', ']]'
|
|
|
31
31
|
const abbr: ReferenceParser.AbbrParser = creator(fmap(verify(surround(
|
|
32
32
|
'^',
|
|
33
33
|
union([str(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]),
|
|
34
|
-
/^\|?(?=]])|^\|[^\S\n]
|
|
34
|
+
/^\|?(?=]])|^\|[^\S\n]*/),
|
|
35
35
|
(_, rest, context) => isStartLoose(rest, context)),
|
|
36
36
|
([source]) => [html('abbr', source)]));
|
|
37
37
|
|
|
@@ -19,44 +19,44 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
19
19
|
|
|
20
20
|
it('one', () => {
|
|
21
21
|
const target = parse([
|
|
22
|
-
'$
|
|
23
|
-
'$
|
|
24
|
-
'$
|
|
25
|
-
'$
|
|
22
|
+
'$test-a\n> ',
|
|
23
|
+
'$test-a',
|
|
24
|
+
'$test-b',
|
|
25
|
+
'$test-a',
|
|
26
26
|
].join('\n\n'));
|
|
27
27
|
for (let i = 0; i < 3; ++i) {
|
|
28
28
|
[...figure(target)];
|
|
29
29
|
assert.deepStrictEqual(
|
|
30
30
|
[...target.children].map(el => el.outerHTML),
|
|
31
31
|
[
|
|
32
|
-
'<figure data-type="quote" data-label="
|
|
33
|
-
'<p><a class="label" data-label="
|
|
34
|
-
'<p><a class="label invalid" data-label="
|
|
35
|
-
'<p><a class="label" data-label="
|
|
32
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:test-a"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
33
|
+
'<p><a class="label" data-label="test-a" href="#label:test-a">Test 1</a></p>',
|
|
34
|
+
'<p><a class="label invalid" data-label="test-b" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-message="Missing the target figure">$test-b</a></p>',
|
|
35
|
+
'<p><a class="label" data-label="test-a" href="#label:test-a">Test 1</a></p>',
|
|
36
36
|
]);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
it('some', () => {
|
|
41
41
|
const target = parse([
|
|
42
|
-
'$
|
|
42
|
+
'$test-a\n> ',
|
|
43
43
|
'## 0',
|
|
44
|
-
'$
|
|
45
|
-
'$
|
|
46
|
-
'$
|
|
47
|
-
'$
|
|
44
|
+
'$test-b\n> ',
|
|
45
|
+
'$quote-a\n> ',
|
|
46
|
+
'$test-b\n> ',
|
|
47
|
+
'$test-c\n> ',
|
|
48
48
|
].join('\n\n'));
|
|
49
49
|
for (let i = 0; i < 3; ++i) {
|
|
50
50
|
[...figure(target)];
|
|
51
51
|
assert.deepStrictEqual(
|
|
52
52
|
[...target.children].map(el => el.outerHTML),
|
|
53
53
|
[
|
|
54
|
-
'<figure data-type="quote" data-label="
|
|
54
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:test-a"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
55
55
|
'<h2 id="index:0">0</h2>',
|
|
56
|
-
'<figure data-type="quote" data-label="
|
|
57
|
-
'<figure data-type="quote" data-label="
|
|
58
|
-
'<figure data-type="quote" data-label="
|
|
59
|
-
'<figure data-type="quote" data-label="
|
|
56
|
+
'<figure data-type="quote" data-label="test-b" data-group="test" data-number="2" id="label:test-b"><figcaption><span class="figindex">Test 2. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
57
|
+
'<figure data-type="quote" data-label="quote-a" data-group="quote" data-number="1" id="label:quote-a"><figcaption><span class="figindex">Quote 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
58
|
+
'<figure data-type="quote" data-label="test-b" data-group="test" data-number="3" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Duplicate label"><figcaption><span class="figindex">Test 3. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
59
|
+
'<figure data-type="quote" data-label="test-c" data-group="test" data-number="4" id="label:test-c"><figcaption><span class="figindex">Test 4. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
60
60
|
]);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
@@ -71,7 +71,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
71
71
|
assert.deepStrictEqual(
|
|
72
72
|
[...target.children].map(el => el.outerHTML),
|
|
73
73
|
[
|
|
74
|
-
'<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div
|
|
74
|
+
'<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
|
|
75
75
|
'<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
|
|
76
76
|
]);
|
|
77
77
|
}
|
|
@@ -79,48 +79,48 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
79
79
|
|
|
80
80
|
it('fixed', () => {
|
|
81
81
|
const target = parse([
|
|
82
|
-
'$
|
|
83
|
-
'$
|
|
82
|
+
'$test-2\n> ',
|
|
83
|
+
'$test-3.1\n> ',
|
|
84
84
|
'$-4.1.1\n$$\n$$',
|
|
85
85
|
'$-a\n$$\n$$',
|
|
86
|
-
'$
|
|
87
|
-
'$
|
|
86
|
+
'$test-a\n> ',
|
|
87
|
+
'$test-2',
|
|
88
88
|
'$-4.1.1',
|
|
89
|
-
'$
|
|
89
|
+
'$test-1',
|
|
90
90
|
].join('\n\n'));
|
|
91
91
|
for (let i = 0; i < 3; ++i) {
|
|
92
92
|
[...figure(target)];
|
|
93
93
|
assert.deepStrictEqual(
|
|
94
94
|
[...target.children].map(el => el.outerHTML),
|
|
95
95
|
[
|
|
96
|
-
'<figure data-type="quote" data-label="
|
|
97
|
-
'<figure data-type="quote" data-label="
|
|
98
|
-
'<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
|
|
99
|
-
'<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div><div class="math" translate="no">$$\n$$</div></div
|
|
100
|
-
'<figure data-type="quote" data-label="
|
|
101
|
-
'<p><a class="label" data-label="
|
|
96
|
+
'<figure data-type="quote" data-label="test-2" data-group="test" data-number="2" id="label:test-2"><figcaption><span class="figindex">Test 2. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
97
|
+
'<figure data-type="quote" data-label="test-3.1" data-group="test" data-number="3.1" id="label:test-3.1"><figcaption><span class="figindex">Test 3.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
98
|
+
'<figure data-type="math" data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><figcaption><span class="figindex">(4.1.1)</span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
|
|
99
|
+
'<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
|
|
100
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:test-a"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
101
|
+
'<p><a class="label" data-label="test-2" href="#label:test-2">Test 2</a></p>',
|
|
102
102
|
'<p><a class="label" data-label="$-4.1.1" href="#label:$-4.1.1">(4.1.1)</a></p>',
|
|
103
|
-
'<p><a class="label invalid" data-label="
|
|
103
|
+
'<p><a class="label invalid" data-label="test-1" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-message="Missing the target figure">$test-1</a></p>',
|
|
104
104
|
]);
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
it('separation', () => {
|
|
109
109
|
const target = html('blockquote', parse([
|
|
110
|
-
'!>> ~~~figure $
|
|
111
|
-
'~~~~example/markdown\n~~~figure $
|
|
112
|
-
'~~~figure $
|
|
113
|
-
'~~~figure $
|
|
110
|
+
'!>> ~~~figure $test-a\n>> > \n>>\n~~~\n> ~~~figure $test-a\n> > \n>\n~~~',
|
|
111
|
+
'~~~~example/markdown\n~~~figure $test-a\n> \n\n~~~\n\n$test-a\n~~~~',
|
|
112
|
+
'~~~figure $test-b\n> \n\n~~~',
|
|
113
|
+
'~~~figure $test-a\n> \n\n~~~',
|
|
114
114
|
].join('\n\n')).children);
|
|
115
115
|
for (let i = 0; i < 3; ++i) {
|
|
116
116
|
[...figure(target)];
|
|
117
117
|
assert.deepStrictEqual(
|
|
118
118
|
[...target.children].map(el => el.outerHTML),
|
|
119
119
|
[
|
|
120
|
-
'<blockquote><blockquote><section><figure data-type="quote" data-label="
|
|
121
|
-
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $
|
|
122
|
-
'<figure data-type="quote" data-label="
|
|
123
|
-
'<figure data-type="quote" data-label="
|
|
120
|
+
'<blockquote><blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
|
|
121
|
+
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $test-a\n> \n\n~~~\n\n$test-a</pre><hr><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure><p><a class="label disabled" data-label="test-a">Test 1</a></p><ol class="annotations"></ol><ol class="references"></ol></section></aside>',
|
|
122
|
+
'<figure data-type="quote" data-label="test-b" data-group="test" data-number="1" id="label:test-b"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
123
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="2" id="label:test-a"><figcaption><span class="figindex">Test 2. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
124
124
|
]);
|
|
125
125
|
}
|
|
126
126
|
});
|
|
@@ -130,18 +130,18 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
130
130
|
'# 0',
|
|
131
131
|
'$-0.0',
|
|
132
132
|
'## 0',
|
|
133
|
-
'$
|
|
133
|
+
'$test-1\n> ',
|
|
134
134
|
'## 0',
|
|
135
135
|
'!> ## 0',
|
|
136
|
-
'$
|
|
136
|
+
'$test-b\n> ',
|
|
137
137
|
'## 0',
|
|
138
138
|
'$-0.0.0',
|
|
139
139
|
'### 0',
|
|
140
140
|
'$-0.0',
|
|
141
|
-
'$
|
|
141
|
+
'$test-c\n> ',
|
|
142
142
|
'## 0',
|
|
143
143
|
'$-0.1.0',
|
|
144
|
-
'$
|
|
144
|
+
'$test-d\n> ',
|
|
145
145
|
'$-0.0',
|
|
146
146
|
'$-0.1.0',
|
|
147
147
|
'$-0.4.0',
|
|
@@ -149,19 +149,19 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
149
149
|
'## 0',
|
|
150
150
|
'## 0',
|
|
151
151
|
'$-0.0',
|
|
152
|
-
'$
|
|
152
|
+
'$test-e\n> ',
|
|
153
153
|
'## 0',
|
|
154
154
|
'$-5.0',
|
|
155
|
-
'$
|
|
155
|
+
'$test-f\n> ',
|
|
156
156
|
'$-0',
|
|
157
|
-
'$
|
|
157
|
+
'$test-g\n> ',
|
|
158
158
|
'### 0',
|
|
159
159
|
'$-0.0.0',
|
|
160
|
-
'$
|
|
160
|
+
'$test-h\n> ',
|
|
161
161
|
'### 0',
|
|
162
|
-
'$
|
|
162
|
+
'$test-i\n> ',
|
|
163
163
|
'# 0',
|
|
164
|
-
'$
|
|
164
|
+
'$test-j\n> ',
|
|
165
165
|
].join('\n\n'));
|
|
166
166
|
for (let i = 0; i < 3; ++i) {
|
|
167
167
|
[...figure(target)];
|
|
@@ -171,18 +171,18 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
171
171
|
'<h1 id="index:0">0</h1>',
|
|
172
172
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
|
|
173
173
|
'<h2 id="index:0">0</h2>',
|
|
174
|
-
'<figure data-type="quote" data-label="
|
|
174
|
+
'<figure data-type="quote" data-label="test-1" data-group="test" data-number="1" id="label:test-1"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
175
175
|
'<h2 id="index:0">0</h2>',
|
|
176
176
|
'<blockquote><section><h2>0</h2><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
|
|
177
|
-
'<figure data-type="quote" data-label="
|
|
177
|
+
'<figure data-type="quote" data-label="test-b" data-group="test" data-number="2.1" id="label:test-b"><figcaption><span class="figindex">Test 2.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
178
178
|
'<h2 id="index:0">0</h2>',
|
|
179
179
|
'<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>',
|
|
180
180
|
'<h3 id="index:0">0</h3>',
|
|
181
181
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="3.0"></figure>',
|
|
182
|
-
'<figure data-type="quote" data-label="
|
|
182
|
+
'<figure data-type="quote" data-label="test-c" data-group="test" data-number="3.1" id="label:test-c"><figcaption><span class="figindex">Test 3.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
183
183
|
'<h2 id="index:0">0</h2>',
|
|
184
184
|
'<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>',
|
|
185
|
-
'<figure data-type="quote" data-label="
|
|
185
|
+
'<figure data-type="quote" data-label="test-d" data-group="test" data-number="4.1" id="label:test-d"><figcaption><span class="figindex">Test 4.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
186
186
|
'<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 to 6 headings"></figure>',
|
|
187
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>',
|
|
188
188
|
'<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>',
|
|
@@ -190,19 +190,19 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
190
190
|
'<h2 id="index:0">0</h2>',
|
|
191
191
|
'<h2 id="index:0">0</h2>',
|
|
192
192
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="6.0"></figure>',
|
|
193
|
-
'<figure data-type="quote" data-label="
|
|
193
|
+
'<figure data-type="quote" data-label="test-e" data-group="test" data-number="6.1" id="label:test-e"><figcaption><span class="figindex">Test 6.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
194
194
|
'<h2 id="index:0">0</h2>',
|
|
195
195
|
'<figure data-label="$-5.0" data-group="$" hidden="" data-number="5.0"></figure>',
|
|
196
|
-
'<figure data-type="quote" data-label="
|
|
196
|
+
'<figure data-type="quote" data-label="test-f" data-group="test" data-number="5.1" id="label:test-f"><figcaption><span class="figindex">Test 5.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
197
197
|
'<figure data-label="$-0" data-group="$" class="invalid" data-invalid-syntax="figure" data-invalid-type="argument" data-invalid-message="Invalid base index"></figure>',
|
|
198
|
-
'<figure data-type="quote" data-label="
|
|
198
|
+
'<figure data-type="quote" data-label="test-g" data-group="test" data-number="5.2" id="label:test-g"><figcaption><span class="figindex">Test 5.2. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
199
199
|
'<h3 id="index:0">0</h3>',
|
|
200
200
|
'<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>',
|
|
201
|
-
'<figure data-type="quote" data-label="
|
|
201
|
+
'<figure data-type="quote" data-label="test-h" data-group="test" data-number="5.3" id="label:test-h"><figcaption><span class="figindex">Test 5.3. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
202
202
|
'<h3 id="index:0">0</h3>',
|
|
203
|
-
'<figure data-type="quote" data-label="
|
|
203
|
+
'<figure data-type="quote" data-label="test-i" data-group="test" data-number="5.4" id="label:test-i"><figcaption><span class="figindex">Test 5.4. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
204
204
|
'<h1 id="index:0">0</h1>',
|
|
205
|
-
'<figure data-type="quote" data-label="
|
|
205
|
+
'<figure data-type="quote" data-label="test-j" data-group="test" data-number="6.1" id="label:test-j"><figcaption><span class="figindex">Test 6.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
206
206
|
]);
|
|
207
207
|
}
|
|
208
208
|
});
|
|
@@ -212,22 +212,22 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
212
212
|
'$-0.0',
|
|
213
213
|
'## 0',
|
|
214
214
|
'$-0.0',
|
|
215
|
-
'$
|
|
215
|
+
'$test-a\n> ',
|
|
216
216
|
'$-0.0',
|
|
217
217
|
'## 0',
|
|
218
|
-
'$
|
|
218
|
+
'$test-b\n> ',
|
|
219
219
|
'$-0.0',
|
|
220
220
|
'### 0',
|
|
221
|
-
'$
|
|
221
|
+
'$test-c\n> ',
|
|
222
222
|
'$-1.0',
|
|
223
223
|
'## 0',
|
|
224
224
|
'$-0.0',
|
|
225
|
-
'$
|
|
225
|
+
'$test-d\n> ',
|
|
226
226
|
'### 0',
|
|
227
227
|
'$-0.0',
|
|
228
228
|
'## 0',
|
|
229
229
|
'$-9.0',
|
|
230
|
-
'$
|
|
230
|
+
'$test-e\n> ',
|
|
231
231
|
].join('\n\n'));
|
|
232
232
|
for (let i = 0; i < 3; ++i) {
|
|
233
233
|
[...figure(target)];
|
|
@@ -237,56 +237,56 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
237
237
|
'<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 to 6 headings"></figure>',
|
|
238
238
|
'<h2 id="index:0">0</h2>',
|
|
239
239
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
|
|
240
|
-
'<figure data-type="quote" data-label="
|
|
240
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="0.1" id="label:test-a"><figcaption><span class="figindex">Test 0.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
241
241
|
'<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 to 6 headings"></figure>',
|
|
242
242
|
'<h2 id="index:0">0</h2>',
|
|
243
|
-
'<figure data-type="quote" data-label="
|
|
243
|
+
'<figure data-type="quote" data-label="test-b" data-group="test" data-number="1.1" id="label:test-b"><figcaption><span class="figindex">Test 1.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
244
244
|
'<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 to 6 headings"></figure>',
|
|
245
245
|
'<h3 id="index:0">0</h3>',
|
|
246
|
-
'<figure data-type="quote" data-label="
|
|
246
|
+
'<figure data-type="quote" data-label="test-c" data-group="test" data-number="1.2" id="label:test-c"><figcaption><span class="figindex">Test 1.2. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
247
247
|
'<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 to 6 headings"></figure>',
|
|
248
248
|
'<h2 id="index:0">0</h2>',
|
|
249
249
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
|
|
250
|
-
'<figure data-type="quote" data-label="
|
|
250
|
+
'<figure data-type="quote" data-label="test-d" data-group="test" data-number="2.1" id="label:test-d"><figcaption><span class="figindex">Test 2.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
251
251
|
'<h3 id="index:0">0</h3>',
|
|
252
252
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
|
|
253
253
|
'<h2 id="index:0">0</h2>',
|
|
254
254
|
'<figure data-label="$-9.0" data-group="$" hidden="" data-number="9.0"></figure>',
|
|
255
|
-
'<figure data-type="quote" data-label="
|
|
255
|
+
'<figure data-type="quote" data-label="test-e" data-group="test" data-number="9.1" id="label:test-e"><figcaption><span class="figindex">Test 9.1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
256
256
|
]);
|
|
257
257
|
}
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
it('verbose', () => {
|
|
261
261
|
const target = parse([
|
|
262
|
-
'~~~figure [$
|
|
263
|
-
'[$
|
|
264
|
-
'[$
|
|
262
|
+
'~~~figure [$test-a]\n> \n\n~~~',
|
|
263
|
+
'[$test-a]',
|
|
264
|
+
'[$test-a]',
|
|
265
265
|
].join('\n\n'));
|
|
266
266
|
for (let i = 0; i < 3; ++i) {
|
|
267
267
|
[...figure(target)];
|
|
268
268
|
assert.deepStrictEqual(
|
|
269
269
|
[...target.children].map(el => el.outerHTML),
|
|
270
270
|
[
|
|
271
|
-
'<figure data-type="quote" data-label="
|
|
272
|
-
'<p><a class="label" data-label="
|
|
273
|
-
'<p><a class="label" data-label="
|
|
271
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:test-a"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
272
|
+
'<p><a class="label" data-label="test-a" href="#label:test-a">Test 1</a></p>',
|
|
273
|
+
'<p><a class="label" data-label="test-a" href="#label:test-a">Test 1</a></p>',
|
|
274
274
|
]);
|
|
275
275
|
}
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
it('id', () => {
|
|
279
279
|
const target = parse([
|
|
280
|
-
'$
|
|
281
|
-
'$
|
|
280
|
+
'$test-a\n> ',
|
|
281
|
+
'$test-a',
|
|
282
282
|
].join('\n\n'));
|
|
283
283
|
for (let i = 0; i < 3; ++i) {
|
|
284
284
|
[...figure(target, undefined, { id: '0' })];
|
|
285
285
|
assert.deepStrictEqual(
|
|
286
286
|
[...target.children].map(el => el.outerHTML),
|
|
287
287
|
[
|
|
288
|
-
'<figure data-type="quote" data-label="
|
|
289
|
-
'<p><a class="label" data-label="
|
|
288
|
+
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:0:test-a"><figcaption><span class="figindex">Test 1. </span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
289
|
+
'<p><a class="label" data-label="test-a" href="#label:0:test-a">Test 1</a></p>',
|
|
290
290
|
]);
|
|
291
291
|
}
|
|
292
292
|
});
|
|
@@ -64,12 +64,12 @@ export function* figure(
|
|
|
64
64
|
class: void def.classList.add('invalid'),
|
|
65
65
|
'data-invalid-syntax': 'figure',
|
|
66
66
|
'data-invalid-type': 'position',
|
|
67
|
-
'data-invalid-message':
|
|
67
|
+
'data-invalid-message': messages.declaration,
|
|
68
68
|
hidden: null,
|
|
69
69
|
});
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
72
|
-
else if (def.getAttribute('data-invalid-message') ===
|
|
72
|
+
else if (def.getAttribute('data-invalid-message') === messages.declaration) {
|
|
73
73
|
define(def, {
|
|
74
74
|
class: void def.classList.remove('invalid'),
|
|
75
75
|
'data-invalid-syntax': null,
|
|
@@ -131,11 +131,11 @@ export function* figure(
|
|
|
131
131
|
class: void def.classList.add('invalid'),
|
|
132
132
|
'data-invalid-syntax': 'figure',
|
|
133
133
|
'data-invalid-type': 'argument',
|
|
134
|
-
'data-invalid-message':
|
|
134
|
+
'data-invalid-message': messages.duplicate,
|
|
135
135
|
});
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
-
else if (def.getAttribute('data-invalid-message') ===
|
|
138
|
+
else if (def.getAttribute('data-invalid-message') === messages.duplicate) {
|
|
139
139
|
define(def, {
|
|
140
140
|
class: void def.classList.remove('invalid'),
|
|
141
141
|
'data-invalid-syntax': null,
|
|
@@ -146,7 +146,7 @@ export function* figure(
|
|
|
146
146
|
labels.add(label);
|
|
147
147
|
opts.id !== '' && def.setAttribute('id', `label:${opts.id ? `${opts.id}:` : ''}${label}`);
|
|
148
148
|
for (const ref of refs.take(label, Infinity)) {
|
|
149
|
-
if (ref.getAttribute('data-invalid-message') ===
|
|
149
|
+
if (ref.getAttribute('data-invalid-message') === messages.reference) {
|
|
150
150
|
define(ref, {
|
|
151
151
|
class: void ref.classList.remove('invalid'),
|
|
152
152
|
'data-invalid-syntax': null,
|
|
@@ -166,7 +166,7 @@ export function* figure(
|
|
|
166
166
|
class: void ref.classList.add('invalid'),
|
|
167
167
|
'data-invalid-syntax': 'label',
|
|
168
168
|
'data-invalid-type': 'reference',
|
|
169
|
-
'data-invalid-message':
|
|
169
|
+
'data-invalid-message': messages.reference,
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
yield ref;
|
|
@@ -174,6 +174,12 @@ export function* figure(
|
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
const messages = {
|
|
178
|
+
declaration: 'Base index declarations must be after level 1 to 6 headings',
|
|
179
|
+
duplicate: 'Duplicate label',
|
|
180
|
+
reference: 'Missing the target figure',
|
|
181
|
+
} as const;
|
|
182
|
+
|
|
177
183
|
function increment(bases: readonly string[], el: HTMLHeadingElement): string {
|
|
178
184
|
const index = (+el.tagName[1] - 1 || 1) - 1;
|
|
179
185
|
assert(index >= 0);
|