securemark 0.237.2 → 0.240.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.
- package/CHANGELOG.md +12 -0
- package/dist/securemark.js +153 -92
- package/markdown.d.ts +6 -4
- package/package-lock.json +53 -53
- 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/debug.test.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 +22 -22
- package/src/parser/block/extension/fig.ts +1 -1
- package/src/parser/block/extension/figure.test.ts +39 -33
- package/src/parser/block/extension/figure.ts +51 -25
- package/src/parser/block/olist.test.ts +2 -0
- package/src/parser/block/ulist.test.ts +2 -0
- package/src/parser/block.ts +2 -2
- package/src/parser/header.test.ts +4 -4
- package/src/parser/header.ts +7 -5
- package/src/parser/inline/extension/index.test.ts +19 -13
- package/src/parser/inline/extension/index.ts +4 -3
- 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/htmlentity.ts +2 -2
- package/src/parser/inline/media.ts +2 -2
- package/src/parser/inline/reference.test.ts +7 -7
- package/src/parser/inline/reference.ts +1 -1
- package/src/parser/inline/ruby.ts +2 -2
- package/src/parser/processor/figure.test.ts +79 -77
- package/src/parser/processor/figure.ts +32 -19
- package/src/parser/segment.test.ts +2 -2
- package/src/parser/segment.ts +2 -2
- package/src/parser/source/str.ts +23 -4
- package/src/parser/source/text.ts +3 -0
- package/src/parser/source.ts +1 -1
- package/src/parser/util.ts +2 -2
|
@@ -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
|
|
|
@@ -83,8 +83,8 @@ function attributes(texts: string[], rubies: string[]): Record<string, string> {
|
|
|
83
83
|
let attrs: Record<string, string> | undefined;
|
|
84
84
|
for (const ss of [texts, rubies]) {
|
|
85
85
|
for (let i = 0; i < ss.length; ++i) {
|
|
86
|
-
if (ss[i].indexOf('\
|
|
87
|
-
ss[i] = ss[i].replace(/\
|
|
86
|
+
if (ss[i].indexOf('\x1B') === -1) continue;
|
|
87
|
+
ss[i] = ss[i].replace(/\x1B/g, '');
|
|
88
88
|
attrs ??= {
|
|
89
89
|
class: 'invalid',
|
|
90
90
|
'data-invalid-syntax': 'ruby',
|
|
@@ -19,42 +19,44 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
19
19
|
|
|
20
20
|
it('one', () => {
|
|
21
21
|
const target = parse([
|
|
22
|
-
'$
|
|
23
|
-
'$
|
|
24
|
-
'$
|
|
22
|
+
'$test-a\n> ',
|
|
23
|
+
'$test-a',
|
|
24
|
+
'$test-b',
|
|
25
|
+
'$test-a',
|
|
25
26
|
].join('\n\n'));
|
|
26
27
|
for (let i = 0; i < 3; ++i) {
|
|
27
28
|
[...figure(target)];
|
|
28
29
|
assert.deepStrictEqual(
|
|
29
30
|
[...target.children].map(el => el.outerHTML),
|
|
30
31
|
[
|
|
31
|
-
'<figure data-type="quote" data-label="
|
|
32
|
-
'<p><a class="label" data-label="
|
|
33
|
-
'<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>',
|
|
34
36
|
]);
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
it('some', () => {
|
|
39
41
|
const target = parse([
|
|
40
|
-
'$
|
|
42
|
+
'$test-a\n> ',
|
|
41
43
|
'## 0',
|
|
42
|
-
'$
|
|
43
|
-
'$
|
|
44
|
-
'$
|
|
45
|
-
'$
|
|
44
|
+
'$test-b\n> ',
|
|
45
|
+
'$quote-a\n> ',
|
|
46
|
+
'$test-b\n> ',
|
|
47
|
+
'$test-c\n> ',
|
|
46
48
|
].join('\n\n'));
|
|
47
49
|
for (let i = 0; i < 3; ++i) {
|
|
48
50
|
[...figure(target)];
|
|
49
51
|
assert.deepStrictEqual(
|
|
50
52
|
[...target.children].map(el => el.outerHTML),
|
|
51
53
|
[
|
|
52
|
-
'<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>',
|
|
53
55
|
'<h2 id="index:0">0</h2>',
|
|
54
|
-
'<figure data-type="quote" data-label="
|
|
55
|
-
'<figure data-type="quote" data-label="
|
|
56
|
-
'<figure data-type="quote" data-label="
|
|
57
|
-
'<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>',
|
|
58
60
|
]);
|
|
59
61
|
}
|
|
60
62
|
});
|
|
@@ -69,7 +71,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
69
71
|
assert.deepStrictEqual(
|
|
70
72
|
[...target.children].map(el => el.outerHTML),
|
|
71
73
|
[
|
|
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
|
|
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>',
|
|
73
75
|
'<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
|
|
74
76
|
]);
|
|
75
77
|
}
|
|
@@ -77,48 +79,48 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
77
79
|
|
|
78
80
|
it('fixed', () => {
|
|
79
81
|
const target = parse([
|
|
80
|
-
'$
|
|
81
|
-
'$
|
|
82
|
+
'$test-2\n> ',
|
|
83
|
+
'$test-3.1\n> ',
|
|
82
84
|
'$-4.1.1\n$$\n$$',
|
|
83
85
|
'$-a\n$$\n$$',
|
|
84
|
-
'$
|
|
85
|
-
'$
|
|
86
|
+
'$test-a\n> ',
|
|
87
|
+
'$test-2',
|
|
86
88
|
'$-4.1.1',
|
|
87
|
-
'$
|
|
89
|
+
'$test-1',
|
|
88
90
|
].join('\n\n'));
|
|
89
91
|
for (let i = 0; i < 3; ++i) {
|
|
90
92
|
[...figure(target)];
|
|
91
93
|
assert.deepStrictEqual(
|
|
92
94
|
[...target.children].map(el => el.outerHTML),
|
|
93
95
|
[
|
|
94
|
-
'<figure data-type="quote" data-label="
|
|
95
|
-
'<figure data-type="quote" data-label="
|
|
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
|
|
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
|
|
98
|
-
'<figure data-type="quote" data-label="
|
|
99
|
-
'<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>',
|
|
100
102
|
'<p><a class="label" data-label="$-4.1.1" href="#label:$-4.1.1">(4.1.1)</a></p>',
|
|
101
|
-
'<p><a class="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>',
|
|
102
104
|
]);
|
|
103
105
|
}
|
|
104
106
|
});
|
|
105
107
|
|
|
106
108
|
it('separation', () => {
|
|
107
109
|
const target = html('blockquote', parse([
|
|
108
|
-
'!>> ~~~figure $
|
|
109
|
-
'~~~~example/markdown\n~~~figure $
|
|
110
|
-
'~~~figure $
|
|
111
|
-
'~~~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~~~',
|
|
112
114
|
].join('\n\n')).children);
|
|
113
115
|
for (let i = 0; i < 3; ++i) {
|
|
114
116
|
[...figure(target)];
|
|
115
117
|
assert.deepStrictEqual(
|
|
116
118
|
[...target.children].map(el => el.outerHTML),
|
|
117
119
|
[
|
|
118
|
-
'<blockquote><blockquote><section><figure data-type="quote" data-label="
|
|
119
|
-
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $
|
|
120
|
-
'<figure data-type="quote" data-label="
|
|
121
|
-
'<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>',
|
|
122
124
|
]);
|
|
123
125
|
}
|
|
124
126
|
});
|
|
@@ -128,18 +130,18 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
128
130
|
'# 0',
|
|
129
131
|
'$-0.0',
|
|
130
132
|
'## 0',
|
|
131
|
-
'$
|
|
133
|
+
'$test-1\n> ',
|
|
132
134
|
'## 0',
|
|
133
135
|
'!> ## 0',
|
|
134
|
-
'$
|
|
136
|
+
'$test-b\n> ',
|
|
135
137
|
'## 0',
|
|
136
138
|
'$-0.0.0',
|
|
137
139
|
'### 0',
|
|
138
140
|
'$-0.0',
|
|
139
|
-
'$
|
|
141
|
+
'$test-c\n> ',
|
|
140
142
|
'## 0',
|
|
141
143
|
'$-0.1.0',
|
|
142
|
-
'$
|
|
144
|
+
'$test-d\n> ',
|
|
143
145
|
'$-0.0',
|
|
144
146
|
'$-0.1.0',
|
|
145
147
|
'$-0.4.0',
|
|
@@ -147,19 +149,19 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
147
149
|
'## 0',
|
|
148
150
|
'## 0',
|
|
149
151
|
'$-0.0',
|
|
150
|
-
'$
|
|
152
|
+
'$test-e\n> ',
|
|
151
153
|
'## 0',
|
|
152
154
|
'$-5.0',
|
|
153
|
-
'$
|
|
155
|
+
'$test-f\n> ',
|
|
154
156
|
'$-0',
|
|
155
|
-
'$
|
|
157
|
+
'$test-g\n> ',
|
|
156
158
|
'### 0',
|
|
157
159
|
'$-0.0.0',
|
|
158
|
-
'$
|
|
160
|
+
'$test-h\n> ',
|
|
159
161
|
'### 0',
|
|
160
|
-
'$
|
|
162
|
+
'$test-i\n> ',
|
|
161
163
|
'# 0',
|
|
162
|
-
'$
|
|
164
|
+
'$test-j\n> ',
|
|
163
165
|
].join('\n\n'));
|
|
164
166
|
for (let i = 0; i < 3; ++i) {
|
|
165
167
|
[...figure(target)];
|
|
@@ -169,18 +171,18 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
169
171
|
'<h1 id="index:0">0</h1>',
|
|
170
172
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
|
|
171
173
|
'<h2 id="index:0">0</h2>',
|
|
172
|
-
'<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>',
|
|
173
175
|
'<h2 id="index:0">0</h2>',
|
|
174
176
|
'<blockquote><section><h2>0</h2><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
|
|
175
|
-
'<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>',
|
|
176
178
|
'<h2 id="index:0">0</h2>',
|
|
177
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>',
|
|
178
180
|
'<h3 id="index:0">0</h3>',
|
|
179
181
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="3.0"></figure>',
|
|
180
|
-
'<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>',
|
|
181
183
|
'<h2 id="index:0">0</h2>',
|
|
182
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>',
|
|
183
|
-
'<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>',
|
|
184
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>',
|
|
185
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>',
|
|
186
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>',
|
|
@@ -188,19 +190,19 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
188
190
|
'<h2 id="index:0">0</h2>',
|
|
189
191
|
'<h2 id="index:0">0</h2>',
|
|
190
192
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="6.0"></figure>',
|
|
191
|
-
'<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>',
|
|
192
194
|
'<h2 id="index:0">0</h2>',
|
|
193
195
|
'<figure data-label="$-5.0" data-group="$" hidden="" data-number="5.0"></figure>',
|
|
194
|
-
'<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>',
|
|
195
197
|
'<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="
|
|
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>',
|
|
197
199
|
'<h3 id="index:0">0</h3>',
|
|
198
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>',
|
|
199
|
-
'<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>',
|
|
200
202
|
'<h3 id="index:0">0</h3>',
|
|
201
|
-
'<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>',
|
|
202
204
|
'<h1 id="index:0">0</h1>',
|
|
203
|
-
'<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>',
|
|
204
206
|
]);
|
|
205
207
|
}
|
|
206
208
|
});
|
|
@@ -210,22 +212,22 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
210
212
|
'$-0.0',
|
|
211
213
|
'## 0',
|
|
212
214
|
'$-0.0',
|
|
213
|
-
'$
|
|
215
|
+
'$test-a\n> ',
|
|
214
216
|
'$-0.0',
|
|
215
217
|
'## 0',
|
|
216
|
-
'$
|
|
218
|
+
'$test-b\n> ',
|
|
217
219
|
'$-0.0',
|
|
218
220
|
'### 0',
|
|
219
|
-
'$
|
|
221
|
+
'$test-c\n> ',
|
|
220
222
|
'$-1.0',
|
|
221
223
|
'## 0',
|
|
222
224
|
'$-0.0',
|
|
223
|
-
'$
|
|
225
|
+
'$test-d\n> ',
|
|
224
226
|
'### 0',
|
|
225
227
|
'$-0.0',
|
|
226
228
|
'## 0',
|
|
227
229
|
'$-9.0',
|
|
228
|
-
'$
|
|
230
|
+
'$test-e\n> ',
|
|
229
231
|
].join('\n\n'));
|
|
230
232
|
for (let i = 0; i < 3; ++i) {
|
|
231
233
|
[...figure(target)];
|
|
@@ -235,56 +237,56 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
235
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>',
|
|
236
238
|
'<h2 id="index:0">0</h2>',
|
|
237
239
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
|
|
238
|
-
'<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>',
|
|
239
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>',
|
|
240
242
|
'<h2 id="index:0">0</h2>',
|
|
241
|
-
'<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>',
|
|
242
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>',
|
|
243
245
|
'<h3 id="index:0">0</h3>',
|
|
244
|
-
'<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>',
|
|
245
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>',
|
|
246
248
|
'<h2 id="index:0">0</h2>',
|
|
247
249
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
|
|
248
|
-
'<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>',
|
|
249
251
|
'<h3 id="index:0">0</h3>',
|
|
250
252
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
|
|
251
253
|
'<h2 id="index:0">0</h2>',
|
|
252
254
|
'<figure data-label="$-9.0" data-group="$" hidden="" data-number="9.0"></figure>',
|
|
253
|
-
'<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>',
|
|
254
256
|
]);
|
|
255
257
|
}
|
|
256
258
|
});
|
|
257
259
|
|
|
258
260
|
it('verbose', () => {
|
|
259
261
|
const target = parse([
|
|
260
|
-
'~~~figure [$
|
|
261
|
-
'[$
|
|
262
|
-
'[$
|
|
262
|
+
'~~~figure [$test-a]\n> \n\n~~~',
|
|
263
|
+
'[$test-a]',
|
|
264
|
+
'[$test-a]',
|
|
263
265
|
].join('\n\n'));
|
|
264
266
|
for (let i = 0; i < 3; ++i) {
|
|
265
267
|
[...figure(target)];
|
|
266
268
|
assert.deepStrictEqual(
|
|
267
269
|
[...target.children].map(el => el.outerHTML),
|
|
268
270
|
[
|
|
269
|
-
'<figure data-type="quote" data-label="
|
|
270
|
-
'<p><a class="label" data-label="
|
|
271
|
-
'<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>',
|
|
272
274
|
]);
|
|
273
275
|
}
|
|
274
276
|
});
|
|
275
277
|
|
|
276
278
|
it('id', () => {
|
|
277
279
|
const target = parse([
|
|
278
|
-
'$
|
|
279
|
-
'$
|
|
280
|
+
'$test-a\n> ',
|
|
281
|
+
'$test-a',
|
|
280
282
|
].join('\n\n'));
|
|
281
283
|
for (let i = 0; i < 3; ++i) {
|
|
282
284
|
[...figure(target, undefined, { id: '0' })];
|
|
283
285
|
assert.deepStrictEqual(
|
|
284
286
|
[...target.children].map(el => el.outerHTML),
|
|
285
287
|
[
|
|
286
|
-
'<figure data-type="quote" data-label="
|
|
287
|
-
'<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>',
|
|
288
290
|
]);
|
|
289
291
|
}
|
|
290
292
|
});
|
|
@@ -29,7 +29,7 @@ export function* figure(
|
|
|
29
29
|
yield;
|
|
30
30
|
const def = defs[i];
|
|
31
31
|
if (def.parentNode !== target) continue;
|
|
32
|
-
const { tagName
|
|
32
|
+
const { tagName } = def;
|
|
33
33
|
if (bases.length === 1 && tagName[0] === 'H') continue;
|
|
34
34
|
assert(base === '0' || bases.length > 1);
|
|
35
35
|
const label = tagName === 'FIGURE'
|
|
@@ -38,7 +38,7 @@ export function* figure(
|
|
|
38
38
|
if (label.endsWith('-')) continue;
|
|
39
39
|
if (label.endsWith('-0')) {
|
|
40
40
|
define(def, {
|
|
41
|
-
class: void classList.add('invalid'),
|
|
41
|
+
class: void def.classList.add('invalid'),
|
|
42
42
|
'data-invalid-syntax': 'figure',
|
|
43
43
|
'data-invalid-type': 'argument',
|
|
44
44
|
'data-invalid-message': 'Invalid base index',
|
|
@@ -50,7 +50,7 @@ export function* figure(
|
|
|
50
50
|
// $-x.x.0 is disabled.
|
|
51
51
|
if (label.lastIndexOf('.', label.length - 3) !== -1) {
|
|
52
52
|
define(def, {
|
|
53
|
-
class: void classList.add('invalid'),
|
|
53
|
+
class: void def.classList.add('invalid'),
|
|
54
54
|
'data-invalid-syntax': 'figure',
|
|
55
55
|
'data-invalid-type': 'argument',
|
|
56
56
|
'data-invalid-message': 'Base index must be $-x.0 format',
|
|
@@ -61,17 +61,17 @@ export function* figure(
|
|
|
61
61
|
// $-x.0 after h1-h6.
|
|
62
62
|
if (!/^H[1-6]$/.test(def.previousElementSibling?.tagName ?? '')) {
|
|
63
63
|
define(def, {
|
|
64
|
-
class: void classList.add('invalid'),
|
|
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 {
|
|
73
|
-
|
|
74
|
-
class: void classList.remove('invalid'),
|
|
72
|
+
else if (def.getAttribute('data-invalid-message') === messages.declaration) {
|
|
73
|
+
define(def, {
|
|
74
|
+
class: void def.classList.remove('invalid'),
|
|
75
75
|
'data-invalid-syntax': null,
|
|
76
76
|
'data-invalid-type': null,
|
|
77
77
|
'data-invalid-message': null,
|
|
@@ -118,7 +118,6 @@ export function* figure(
|
|
|
118
118
|
assert(number.split('.').pop() !== '0');
|
|
119
119
|
!isFixed(label) && numbers.set(group, number);
|
|
120
120
|
assert(!+def.setAttribute('data-number', number));
|
|
121
|
-
opts.id !== '' && def.setAttribute('id', `label:${opts.id ? `${opts.id}:` : ''}${label}`);
|
|
122
121
|
const figindex = group === '$'
|
|
123
122
|
? `(${number})`
|
|
124
123
|
: `${capitalize(group)}${group === 'fig' ? '.' : ''} ${number}`;
|
|
@@ -126,27 +125,35 @@ export function* figure(
|
|
|
126
125
|
def.querySelector(':scope > figcaption > .figindex')!,
|
|
127
126
|
group === '$' ? figindex : `${figindex}. `);
|
|
128
127
|
if (labels.has(label)) {
|
|
129
|
-
if (classList.contains('invalid')
|
|
130
|
-
def.getAttribute('data-invalid-message') !== 'Duplicate label') continue;
|
|
128
|
+
if (def.classList.contains('invalid')) continue;
|
|
131
129
|
define(def, {
|
|
132
130
|
id: null,
|
|
133
|
-
class: void classList.add('invalid'),
|
|
131
|
+
class: void def.classList.add('invalid'),
|
|
134
132
|
'data-invalid-syntax': 'figure',
|
|
135
133
|
'data-invalid-type': 'argument',
|
|
136
|
-
'data-invalid-message':
|
|
134
|
+
'data-invalid-message': messages.duplicate,
|
|
137
135
|
});
|
|
138
136
|
continue;
|
|
139
137
|
}
|
|
140
|
-
else {
|
|
141
|
-
labels.add(label);
|
|
138
|
+
else if (def.getAttribute('data-invalid-message') === messages.duplicate) {
|
|
142
139
|
define(def, {
|
|
143
|
-
class: void classList.remove('invalid'),
|
|
140
|
+
class: void def.classList.remove('invalid'),
|
|
144
141
|
'data-invalid-syntax': null,
|
|
145
142
|
'data-invalid-type': null,
|
|
146
143
|
'data-invalid-message': null,
|
|
147
144
|
});
|
|
148
145
|
}
|
|
146
|
+
labels.add(label);
|
|
147
|
+
opts.id !== '' && def.setAttribute('id', `label:${opts.id ? `${opts.id}:` : ''}${label}`);
|
|
149
148
|
for (const ref of refs.take(label, Infinity)) {
|
|
149
|
+
if (ref.getAttribute('data-invalid-message') === messages.reference) {
|
|
150
|
+
define(ref, {
|
|
151
|
+
class: void ref.classList.remove('invalid'),
|
|
152
|
+
'data-invalid-syntax': null,
|
|
153
|
+
'data-invalid-type': null,
|
|
154
|
+
'data-invalid-message': null,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
150
157
|
if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
|
|
151
158
|
yield define(ref,
|
|
152
159
|
opts.id !== '' ? { href: `#${def.id}` } : { class: `${ref.className} disabled` },
|
|
@@ -154,12 +161,12 @@ export function* figure(
|
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
for (const [, ref] of refs) {
|
|
157
|
-
if (opts.id !== '') {
|
|
164
|
+
if (opts.id !== '' && !ref.classList.contains('invalid')) {
|
|
158
165
|
define(ref, {
|
|
159
|
-
class:
|
|
166
|
+
class: void ref.classList.add('invalid'),
|
|
160
167
|
'data-invalid-syntax': 'label',
|
|
161
168
|
'data-invalid-type': 'reference',
|
|
162
|
-
'data-invalid-message':
|
|
169
|
+
'data-invalid-message': messages.reference,
|
|
163
170
|
});
|
|
164
171
|
}
|
|
165
172
|
yield ref;
|
|
@@ -167,6 +174,12 @@ export function* figure(
|
|
|
167
174
|
return;
|
|
168
175
|
}
|
|
169
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
|
+
|
|
170
183
|
function increment(bases: readonly string[], el: HTMLHeadingElement): string {
|
|
171
184
|
const index = (+el.tagName[1] - 1 || 1) - 1;
|
|
172
185
|
assert(index >= 0);
|
|
@@ -4,12 +4,12 @@ describe('Unit: parser/segment', () => {
|
|
|
4
4
|
describe('segment', () => {
|
|
5
5
|
it('huge input', () => {
|
|
6
6
|
const result = segment(`${'\n'.repeat(10 * 1000 ** 2)}`).next().value?.split('\n', 1)[0];
|
|
7
|
-
assert(result?.startsWith('\
|
|
7
|
+
assert(result?.startsWith('\x07Too large input'));
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it('huge segment', () => {
|
|
11
11
|
const result = segment(`${'\n'.repeat(1000 ** 2 - 1)}`).next().value?.split('\n', 1)[0];
|
|
12
|
-
assert(result?.startsWith('\
|
|
12
|
+
assert(result?.startsWith('\x07Too large segment'));
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it('basic', () => {
|
package/src/parser/segment.ts
CHANGED
|
@@ -23,7 +23,7 @@ const parser: SegmentParser = union([
|
|
|
23
23
|
]);
|
|
24
24
|
|
|
25
25
|
export function* segment(source: string): Generator<string, undefined, undefined> {
|
|
26
|
-
if (!validate(source, MAX_INPUT_SIZE)) return yield `\
|
|
26
|
+
if (!validate(source, MAX_INPUT_SIZE)) return yield `\x07Too large input over ${MAX_INPUT_SIZE.toLocaleString('en')} bytes.\n${source.slice(0, 1001)}`;
|
|
27
27
|
assert(source.length < Number.MAX_SAFE_INTEGER);
|
|
28
28
|
while (source !== '') {
|
|
29
29
|
const result = parser(source, {})!;
|
|
@@ -36,7 +36,7 @@ export function* segment(source: string): Generator<string, undefined, undefined
|
|
|
36
36
|
const seg = segs[i];
|
|
37
37
|
validate(seg, MAX_SEGMENT_SIZE)
|
|
38
38
|
? yield seg
|
|
39
|
-
: yield `\
|
|
39
|
+
: yield `\x07Too large segment over ${MAX_SEGMENT_SIZE.toLocaleString('en')} bytes.\n${seg}`
|
|
40
40
|
}
|
|
41
41
|
source = rest;
|
|
42
42
|
}
|
package/src/parser/source/str.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { StrParser } from '../source';
|
|
|
3
3
|
import { Parser, Context } from '../../combinator/data/parser';
|
|
4
4
|
import { creator } from '../../combinator';
|
|
5
5
|
|
|
6
|
-
export function str(pattern: string | RegExp
|
|
7
|
-
export function str(pattern: string | RegExp
|
|
6
|
+
export function str(pattern: string | RegExp): StrParser;
|
|
7
|
+
export function str(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
|
|
8
8
|
assert(pattern);
|
|
9
9
|
return typeof pattern === 'string'
|
|
10
10
|
? creator(source => {
|
|
@@ -16,8 +16,27 @@ export function str(pattern: string | RegExp, mustConsume = true): Parser<string
|
|
|
16
16
|
: creator(source => {
|
|
17
17
|
if (source === '') return;
|
|
18
18
|
const m = source.match(pattern);
|
|
19
|
-
return m &&
|
|
19
|
+
return m && m[0].length > 0
|
|
20
20
|
? [[m[0]], source.slice(m[0].length)]
|
|
21
21
|
: undefined;
|
|
22
22
|
});
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function stropt(pattern: string | RegExp): StrParser;
|
|
26
|
+
export function stropt(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
|
|
27
|
+
assert(pattern);
|
|
28
|
+
return typeof pattern === 'string'
|
|
29
|
+
? creator(source => {
|
|
30
|
+
if (source === '') return;
|
|
31
|
+
return source.slice(0, pattern.length) === pattern
|
|
32
|
+
? [[pattern], source.slice(pattern.length)]
|
|
33
|
+
: [[], source];
|
|
34
|
+
})
|
|
35
|
+
: creator(source => {
|
|
36
|
+
if (source === '') return;
|
|
37
|
+
const m = source.match(pattern);
|
|
38
|
+
return m
|
|
39
|
+
? [[m[0]], source.slice(m[0].length)]
|
|
40
|
+
: [[], source];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -24,6 +24,7 @@ export const text: TextParser = creator((source, context) => {
|
|
|
24
24
|
case '。':
|
|
25
25
|
case '!':
|
|
26
26
|
case '?':
|
|
27
|
+
assert(source[0] !== '\x1B');
|
|
27
28
|
return text(source.slice(1), context);
|
|
28
29
|
}
|
|
29
30
|
break;
|
|
@@ -39,8 +40,10 @@ export const text: TextParser = creator((source, context) => {
|
|
|
39
40
|
case '\\':
|
|
40
41
|
switch (source[1]) {
|
|
41
42
|
case undefined:
|
|
43
|
+
assert(source[0] !== '\x1B');
|
|
42
44
|
return [[], ''];
|
|
43
45
|
case '\n':
|
|
46
|
+
assert(source[0] !== '\x1B');
|
|
44
47
|
return [[html('span', { class: 'linebreak' }, ' ')], source.slice(2)];
|
|
45
48
|
default:
|
|
46
49
|
return [[source.slice(1, 2)], source.slice(2)];
|