securemark 0.235.1 → 0.236.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 +179 -141
- package/markdown.d.ts +7 -2
- package/package-lock.json +43 -64
- package/package.json +3 -3
- package/src/debug.test.ts +3 -1
- package/src/parser/api/parse.test.ts +3 -3
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/codeblock.ts +1 -1
- package/src/parser/block/extension/aside.test.ts +1 -1
- package/src/parser/block/extension/aside.ts +2 -2
- package/src/parser/block/extension/example.test.ts +2 -2
- package/src/parser/block/extension/example.ts +2 -2
- package/src/parser/block/extension/fig.test.ts +20 -20
- package/src/parser/block/extension/figure.test.ts +33 -31
- package/src/parser/block/extension/figure.ts +8 -4
- package/src/parser/block/extension/message.ts +2 -2
- package/src/parser/block/extension/placeholder.ts +1 -1
- package/src/parser/block/extension/table.ts +5 -5
- package/src/parser/block/ilist.ts +1 -1
- package/src/parser/block/mathblock.ts +1 -1
- package/src/parser/block/olist.ts +1 -1
- package/src/parser/block/paragraph.test.ts +1 -1
- package/src/parser/block/reply/quote.ts +1 -1
- package/src/parser/block/table.ts +1 -1
- package/src/parser/block/ulist.ts +1 -1
- package/src/parser/header.ts +1 -1
- package/src/parser/inline/annotation.ts +3 -3
- package/src/parser/inline/bracket.test.ts +10 -10
- package/src/parser/inline/bracket.ts +2 -5
- package/src/parser/inline/deletion.test.ts +4 -1
- package/src/parser/inline/deletion.ts +7 -4
- package/src/parser/inline/emphasis.ts +2 -2
- package/src/parser/inline/emstrong.ts +4 -4
- package/src/parser/inline/extension/placeholder.ts +1 -1
- package/src/parser/inline/html.test.ts +25 -17
- package/src/parser/inline/html.ts +43 -19
- package/src/parser/inline/htmlentity.test.ts +1 -1
- package/src/parser/inline/htmlentity.ts +18 -11
- package/src/parser/inline/insertion.test.ts +4 -1
- package/src/parser/inline/insertion.ts +7 -4
- package/src/parser/inline/link.test.ts +3 -0
- package/src/parser/inline/link.ts +10 -11
- package/src/parser/inline/mark.ts +2 -2
- package/src/parser/inline/math.ts +1 -1
- package/src/parser/inline/media.test.ts +3 -0
- package/src/parser/inline/media.ts +4 -4
- package/src/parser/inline/reference.ts +7 -7
- package/src/parser/inline/ruby.ts +2 -2
- package/src/parser/inline/strong.ts +2 -2
- package/src/parser/inline.test.ts +2 -2
- package/src/parser/processor/figure.test.ts +33 -29
- package/src/parser/processor/figure.ts +25 -3
- package/src/parser/processor/footnote.ts +3 -3
- package/src/parser/util.ts +38 -32
|
@@ -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
|
|
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>',
|
|
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
|
|
52
|
+
'<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>',
|
|
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
|
|
53
|
-
'<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div
|
|
54
|
+
'<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>',
|
|
55
|
+
'<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>',
|
|
56
|
+
'<figure 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-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
|
|
72
|
+
'<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>',
|
|
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
|
|
91
|
-
'<figure data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div
|
|
92
|
-
'<figure data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><div
|
|
93
|
-
'<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div
|
|
94
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div
|
|
94
|
+
'<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>',
|
|
95
|
+
'<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>',
|
|
96
|
+
'<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>',
|
|
97
|
+
'<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>',
|
|
98
|
+
'<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>',
|
|
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-
|
|
101
|
+
'<p><a class="label disabled invalid" data-label="fig-1" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-message="Missing the reference">$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
|
|
115
|
-
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n> \n\n~~~\n\n$fig-a</pre><hr><section><figure data-label="fig-a" data-group="fig" data-number="1"><div
|
|
116
|
-
'<figure data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div
|
|
117
|
-
'<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div
|
|
118
|
+
'<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>',
|
|
119
|
+
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n> \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>',
|
|
120
|
+
'<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>',
|
|
121
|
+
'<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
122
|
]);
|
|
119
123
|
}
|
|
120
124
|
});
|
|
@@ -163,16 +167,16 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
163
167
|
'<h1 id="index:0">0</h1>',
|
|
164
168
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
|
|
165
169
|
'<h2 id="index:0">0</h2>',
|
|
166
|
-
'<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div
|
|
170
|
+
'<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>',
|
|
167
171
|
'<h2 id="index:0">0</h2>',
|
|
168
172
|
'<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
|
|
173
|
+
'<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>',
|
|
170
174
|
'<h2 id="index:0">0</h2>',
|
|
171
175
|
'<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
|
|
176
|
+
'<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>',
|
|
173
177
|
'<h2 id="index:0">0</h2>',
|
|
174
178
|
'<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
|
|
179
|
+
'<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
180
|
'<figure data-label="$-0.0" data-group="$" hidden=""></figure>',
|
|
177
181
|
'<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
|
|
178
182
|
'<figure data-label="$-0.4.0" data-group="$" hidden=""></figure>',
|
|
@@ -180,19 +184,19 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
180
184
|
'<h2 id="index:0">0</h2>',
|
|
181
185
|
'<h2 id="index:0">0</h2>',
|
|
182
186
|
'<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
|
|
187
|
+
'<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>',
|
|
184
188
|
'<h2 id="index:0">0</h2>',
|
|
185
189
|
'<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
|
|
190
|
+
'<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
191
|
'<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
|
|
192
|
+
'<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>',
|
|
189
193
|
'<h3 id="index:0">0</h3>',
|
|
190
194
|
'<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
|
|
195
|
+
'<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>',
|
|
192
196
|
'<h3 id="index:0">0</h3>',
|
|
193
|
-
'<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div
|
|
197
|
+
'<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>',
|
|
194
198
|
'<h1 id="index:0">0</h1>',
|
|
195
|
-
'<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div
|
|
199
|
+
'<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>',
|
|
196
200
|
]);
|
|
197
201
|
}
|
|
198
202
|
});
|
|
@@ -219,10 +223,10 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
219
223
|
'<h2 id="index:0">0</h2>',
|
|
220
224
|
'<h2 id="index:0">0</h2>',
|
|
221
225
|
'<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
|
|
226
|
+
'<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>',
|
|
223
227
|
'<h2 id="index:0">0</h2>',
|
|
224
228
|
'<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
|
|
229
|
+
'<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>',
|
|
226
230
|
]);
|
|
227
231
|
}
|
|
228
232
|
});
|
|
@@ -238,7 +242,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
238
242
|
assert.deepStrictEqual(
|
|
239
243
|
[...target.children].map(el => el.outerHTML),
|
|
240
244
|
[
|
|
241
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div
|
|
245
|
+
'<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>',
|
|
242
246
|
'<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
|
|
243
247
|
'<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
|
|
244
248
|
]);
|
|
@@ -255,7 +259,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
255
259
|
assert.deepStrictEqual(
|
|
256
260
|
[...target.children].map(el => el.outerHTML),
|
|
257
261
|
[
|
|
258
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div
|
|
262
|
+
'<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>',
|
|
259
263
|
'<p><a class="label" data-label="fig-a" href="#label:0:fig-a">Fig. 1</a></p>',
|
|
260
264
|
]);
|
|
261
265
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Infinity, Map } from 'spica/global';
|
|
1
|
+
import { Infinity, Set, Map } from 'spica/global';
|
|
2
2
|
import { number as calculate, isFixed } from '../inline/extension/label';
|
|
3
3
|
import { define } from 'typed-dom';
|
|
4
4
|
import { MultiMap } from 'spica/multimap';
|
|
@@ -16,6 +16,7 @@ export function* figure(
|
|
|
16
16
|
footnotes?.annotations.querySelectorAll<HTMLAnchorElement>('a.label:not(.disabled)') ?? []),
|
|
17
17
|
footnotes?.references.querySelectorAll<HTMLAnchorElement>('a.label:not(.disabled)') ?? [])
|
|
18
18
|
.map(el => [el.getAttribute('data-label')!, el]));
|
|
19
|
+
const labels = new Set<string>();
|
|
19
20
|
const numbers = new Map<string, string>();
|
|
20
21
|
let base = '0';
|
|
21
22
|
let bases: readonly string[] = base.split('.');
|
|
@@ -76,7 +77,7 @@ export function* figure(
|
|
|
76
77
|
assert(def.tagName !== 'FIGURE' || !+def.setAttribute('data-number', number));
|
|
77
78
|
continue;
|
|
78
79
|
}
|
|
79
|
-
assert(def.matches('figure:not([
|
|
80
|
+
assert(def.matches('figure:not([hidden])'));
|
|
80
81
|
assert(number.split('.').pop() !== '0');
|
|
81
82
|
!isFixed(label) && numbers.set(group, number);
|
|
82
83
|
assert(!+def.setAttribute('data-number', number));
|
|
@@ -87,6 +88,27 @@ export function* figure(
|
|
|
87
88
|
define(
|
|
88
89
|
def.querySelector(':scope > figcaption > .figindex')!,
|
|
89
90
|
group === '$' ? figindex : `${figindex}. `);
|
|
91
|
+
if (labels.has(label)) {
|
|
92
|
+
if (def.classList.contains('invalid') &&
|
|
93
|
+
def.getAttribute('data-invalid-message') !== 'Duplicate label') continue;
|
|
94
|
+
define(def, {
|
|
95
|
+
id: null,
|
|
96
|
+
class: void def.classList.add('invalid'),
|
|
97
|
+
'data-invalid-syntax': 'figure',
|
|
98
|
+
'data-invalid-type': 'argument',
|
|
99
|
+
'data-invalid-message': 'Duplicate label',
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
labels.add(label);
|
|
105
|
+
define(def, {
|
|
106
|
+
class: void def.classList.remove('invalid'),
|
|
107
|
+
'data-invalid-syntax': null,
|
|
108
|
+
'data-invalid-type': null,
|
|
109
|
+
'data-invalid-message': null,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
90
112
|
for (const ref of refs.take(label, Infinity)) {
|
|
91
113
|
if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
|
|
92
114
|
yield define(ref,
|
|
@@ -100,7 +122,7 @@ export function* figure(
|
|
|
100
122
|
class: `${ref.className} disabled invalid`,
|
|
101
123
|
'data-invalid-syntax': 'label',
|
|
102
124
|
'data-invalid-type': 'reference',
|
|
103
|
-
'data-invalid-
|
|
125
|
+
'data-invalid-message': 'Missing the reference',
|
|
104
126
|
});
|
|
105
127
|
}
|
|
106
128
|
yield ref;
|
|
@@ -56,7 +56,7 @@ function build(
|
|
|
56
56
|
class: `${ref.className} invalid`,
|
|
57
57
|
'data-invalid-syntax': syntax,
|
|
58
58
|
'data-invalid-type': 'style',
|
|
59
|
-
'data-invalid-
|
|
59
|
+
'data-invalid-message': `${syntax[0].toUpperCase() + syntax.slice(1)} style must be consistent`,
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
if (ref.firstElementChild?.getAttribute('hidden') !== '') {
|
|
@@ -96,7 +96,7 @@ function build(
|
|
|
96
96
|
class: void ref.classList.remove('invalid'),
|
|
97
97
|
'data-invalid-syntax': null,
|
|
98
98
|
'data-invalid-type': null,
|
|
99
|
-
'data-invalid-
|
|
99
|
+
'data-invalid-message': null,
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -110,7 +110,7 @@ function build(
|
|
|
110
110
|
: { class: void ref.classList.add('invalid'),
|
|
111
111
|
'data-invalid-syntax': syntax,
|
|
112
112
|
'data-invalid-type': 'content',
|
|
113
|
-
'data-invalid-
|
|
113
|
+
'data-invalid-message': 'Missing the content',
|
|
114
114
|
},
|
|
115
115
|
});
|
|
116
116
|
yield ref.appendChild(html('a', { href: refId && defId && `#${defId}` }, marker(defIndex, abbr)));
|
package/src/parser/util.ts
CHANGED
|
@@ -5,15 +5,23 @@ import { union, some, verify, convert } from '../combinator';
|
|
|
5
5
|
import { unsafehtmlentity } from './inline/htmlentity';
|
|
6
6
|
import { linebreak, unescsource } from './source';
|
|
7
7
|
import { invisibleHTMLEntityNames } from './api/normalize';
|
|
8
|
-
import {
|
|
8
|
+
import { reduce } from 'spica/memoize';
|
|
9
|
+
import { push } from 'spica/array';
|
|
9
10
|
|
|
10
|
-
export function
|
|
11
|
-
return new RegExp(String.raw
|
|
11
|
+
export function blank(prefix: '' | RegExp, suffix: string | RegExp): RegExp {
|
|
12
|
+
return new RegExp(String.raw
|
|
13
|
+
`^${
|
|
14
|
+
prefix && prefix.source
|
|
15
|
+
}(?:\\\s|[^\S\n]+|\n|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)?${
|
|
16
|
+
typeof suffix === 'string' ? suffix.replace(/[*+()\[\]]/g, '\\$&') : suffix.source
|
|
17
|
+
}`);
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
15
21
|
export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
16
|
-
const blankline = new RegExp(String.raw
|
|
22
|
+
const blankline = new RegExp(String.raw
|
|
23
|
+
`^(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`,
|
|
24
|
+
'gm');
|
|
17
25
|
return union([
|
|
18
26
|
convert(
|
|
19
27
|
source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
|
|
@@ -45,9 +53,9 @@ export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, ex
|
|
|
45
53
|
? parser(source, context)
|
|
46
54
|
: undefined;
|
|
47
55
|
}
|
|
48
|
-
export
|
|
56
|
+
export const isStartLoose = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
|
|
49
57
|
return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
|
|
50
|
-
}
|
|
58
|
+
}, (source, _, except = '') => `${source}\0${except}`);
|
|
51
59
|
export function startTight<P extends Parser<unknown>>(parser: P, except?: string): P;
|
|
52
60
|
export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
|
|
53
61
|
return (source, context) =>
|
|
@@ -55,7 +63,7 @@ export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
|
|
|
55
63
|
? parser(source, context)
|
|
56
64
|
: undefined;
|
|
57
65
|
}
|
|
58
|
-
|
|
66
|
+
const isStartTight = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
|
|
59
67
|
if (source === '') return true;
|
|
60
68
|
if (except && source.slice(0, except.length) === except) return false;
|
|
61
69
|
switch (source[0]) {
|
|
@@ -85,7 +93,7 @@ function isStartTight(source: string, context: MarkdownParser.Context, except?:
|
|
|
85
93
|
default:
|
|
86
94
|
return source[0].trimStart() !== '';
|
|
87
95
|
}
|
|
88
|
-
}
|
|
96
|
+
}, (source, _, except = '') => `${source}\0${except}`);
|
|
89
97
|
export function isStartTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
|
|
90
98
|
if (nodes.length === 0) return true;
|
|
91
99
|
return isVisible(nodes[0], 0);
|
|
@@ -122,23 +130,29 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
|
|
125
|
-
export function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
131
|
-
if (typeof node === 'string') {
|
|
132
|
-
const pos = node.length - node.trimStart().length;
|
|
133
|
-
if (pos > 0) {
|
|
134
|
-
nodes[0] = node.slice(pos);
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
nodes.shift();
|
|
139
|
-
}
|
|
140
|
-
return nodes;
|
|
133
|
+
export function trimSpaceStart<P extends Parser<unknown>>(parser: P): P;
|
|
134
|
+
export function trimSpaceStart<T>(parser: Parser<T>): Parser<T> {
|
|
135
|
+
return convert(
|
|
136
|
+
reduce(source => source.replace(/^[^\S\n]+/, '')),
|
|
137
|
+
parser);
|
|
141
138
|
}
|
|
139
|
+
//export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
140
|
+
// return trimNodeStart(trimNodeEnd(nodes));
|
|
141
|
+
//}
|
|
142
|
+
//function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
143
|
+
// for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
144
|
+
// if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
145
|
+
// if (typeof node === 'string') {
|
|
146
|
+
// const pos = node.length - node.trimStart().length;
|
|
147
|
+
// if (pos > 0) {
|
|
148
|
+
// nodes[0] = node.slice(pos);
|
|
149
|
+
// break;
|
|
150
|
+
// }
|
|
151
|
+
// }
|
|
152
|
+
// nodes.shift();
|
|
153
|
+
// }
|
|
154
|
+
// return nodes;
|
|
155
|
+
//}
|
|
142
156
|
export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
143
157
|
const skip = nodes.length > 0 &&
|
|
144
158
|
typeof nodes[nodes.length - 1] === 'object' &&
|
|
@@ -157,14 +171,6 @@ export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | str
|
|
|
157
171
|
}
|
|
158
172
|
return push(nodes, skip);
|
|
159
173
|
}
|
|
160
|
-
export function trimNodeEndBR<T extends HTMLElement | string>(nodes: T[]): T[];
|
|
161
|
-
export function trimNodeEndBR(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
162
|
-
if (nodes.length === 0) return nodes;
|
|
163
|
-
const node = nodes[nodes.length - 1];
|
|
164
|
-
return typeof node === 'object' && node.tagName === 'BR'
|
|
165
|
-
? pop(nodes)[0]
|
|
166
|
-
: nodes;
|
|
167
|
-
}
|
|
168
174
|
|
|
169
175
|
export function stringify(nodes: readonly (HTMLElement | string)[]): string {
|
|
170
176
|
let acc = '';
|