securemark 0.271.0 → 0.273.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 +8 -0
- package/dist/index.js +99 -100
- package/index.d.ts +2 -2
- package/package.json +16 -16
- package/src/parser/api/bind.test.ts +5 -5
- package/src/parser/api/bind.ts +4 -4
- package/src/parser/api/parse.test.ts +9 -9
- package/src/parser/api/parse.ts +4 -4
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/extension/aside.ts +4 -4
- package/src/parser/block/extension/example.ts +1 -1
- package/src/parser/inline/autolink/url.ts +2 -2
- package/src/parser/inline/autolink.ts +3 -3
- package/src/parser/inline/extension/indexee.ts +9 -5
- package/src/parser/inline/media.ts +2 -2
- package/src/parser/inline.ts +3 -3
- package/src/parser/processor/figure.ts +2 -2
- package/src/parser/processor/note.test.ts +369 -0
- package/src/parser/processor/{footnote.ts → note.ts} +38 -43
- package/tsconfig.json +2 -1
- package/webpack.config.js +4 -4
- package/src/parser/processor/footnote.test.ts +0 -317
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { note, annotation, reference } from './note';
|
|
2
|
+
import { parse as parse_ } from '../../parser';
|
|
3
|
+
import { html } from 'typed-dom/dom';
|
|
4
|
+
|
|
5
|
+
const parse = (s: string) => parse_(s, { test: true });
|
|
6
|
+
|
|
7
|
+
describe('Unit: parser/processor/note', () => {
|
|
8
|
+
describe('annotation', () => {
|
|
9
|
+
it('empty', () => {
|
|
10
|
+
const target = parse('');
|
|
11
|
+
const note = html('ol');
|
|
12
|
+
[...annotation(target, note)];
|
|
13
|
+
assert.deepStrictEqual(
|
|
14
|
+
[...target.children].map(el => el.outerHTML),
|
|
15
|
+
[]);
|
|
16
|
+
assert.deepStrictEqual(
|
|
17
|
+
note.outerHTML,
|
|
18
|
+
html('ol').outerHTML);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('1', () => {
|
|
22
|
+
const target = parse('((a b))');
|
|
23
|
+
const note = html('ol');
|
|
24
|
+
for (let i = 0; i < 3; ++i) {
|
|
25
|
+
assert.deepStrictEqual([...annotation(target, note)].length, i === 0 ? 2 : 1);
|
|
26
|
+
assert.deepStrictEqual(
|
|
27
|
+
[...target.children].map(el => el.outerHTML),
|
|
28
|
+
[
|
|
29
|
+
html('p', [
|
|
30
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: 'a b' }, [
|
|
31
|
+
html('span', { hidden: '' }, 'a b'),
|
|
32
|
+
html('a', { href: '#annotation::def:a_b' }, '*1')
|
|
33
|
+
]),
|
|
34
|
+
]).outerHTML,
|
|
35
|
+
]);
|
|
36
|
+
assert.deepStrictEqual(
|
|
37
|
+
note.outerHTML,
|
|
38
|
+
html('ol', [
|
|
39
|
+
html('li', { id: 'annotation::def:a_b' }, [
|
|
40
|
+
html('span', 'a b'),
|
|
41
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
42
|
+
]),
|
|
43
|
+
]).outerHTML);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('2', () => {
|
|
48
|
+
const target = parse('((1))((12345678901234567890))');
|
|
49
|
+
const note = html('ol');
|
|
50
|
+
for (let i = 0; i < 3; ++i) {
|
|
51
|
+
assert.deepStrictEqual([...annotation(target, note)].length, i === 0 ? 4 : 2);
|
|
52
|
+
assert.deepStrictEqual(
|
|
53
|
+
[...target.children].map(el => el.outerHTML),
|
|
54
|
+
[
|
|
55
|
+
html('p', [
|
|
56
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: '1' }, [
|
|
57
|
+
html('span', { hidden: '' }, '1'),
|
|
58
|
+
html('a', { href: '#annotation::def:1' }, '*1')
|
|
59
|
+
]),
|
|
60
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2', title: '12345678901234567890' }, [
|
|
61
|
+
html('span', { hidden: '' }, '12345678901234567890'),
|
|
62
|
+
html('a', { href: '#annotation::def:12345678901234567890' }, '*2')
|
|
63
|
+
]),
|
|
64
|
+
]).outerHTML,
|
|
65
|
+
]);
|
|
66
|
+
assert.deepStrictEqual(
|
|
67
|
+
note.outerHTML,
|
|
68
|
+
html('ol', [
|
|
69
|
+
html('li', { id: 'annotation::def:1' }, [
|
|
70
|
+
html('span', '1'),
|
|
71
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
72
|
+
]),
|
|
73
|
+
html('li', { id: 'annotation::def:12345678901234567890' }, [
|
|
74
|
+
html('span', '12345678901234567890'),
|
|
75
|
+
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')]),
|
|
76
|
+
]),
|
|
77
|
+
]).outerHTML);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('unify', () => {
|
|
82
|
+
const target = parse('((1))((2))((3))((2))((4))');
|
|
83
|
+
const note = html('ol');
|
|
84
|
+
for (let i = 0; i < 3; ++i) {
|
|
85
|
+
[...annotation(target, note)];
|
|
86
|
+
assert.deepStrictEqual(
|
|
87
|
+
[...target.children].map(el => el.outerHTML),
|
|
88
|
+
[
|
|
89
|
+
html('p', [
|
|
90
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: '1' }, [
|
|
91
|
+
html('span', { hidden: '' }, '1'),
|
|
92
|
+
html('a', { href: '#annotation::def:1' }, '*1')
|
|
93
|
+
]),
|
|
94
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2', title: '2' }, [
|
|
95
|
+
html('span', { hidden: '' }, '2'),
|
|
96
|
+
html('a', { href: '#annotation::def:2' }, '*2')
|
|
97
|
+
]),
|
|
98
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:3', title: '3' }, [
|
|
99
|
+
html('span', { hidden: '' }, '3'),
|
|
100
|
+
html('a', { href: '#annotation::def:3' }, '*3')
|
|
101
|
+
]),
|
|
102
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:4', title: '2' }, [
|
|
103
|
+
html('span', { hidden: '' }, '2'),
|
|
104
|
+
html('a', { href: '#annotation::def:2' }, '*2')
|
|
105
|
+
]),
|
|
106
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:5', title: '4' }, [
|
|
107
|
+
html('span', { hidden: '' }, '4'),
|
|
108
|
+
html('a', { href: '#annotation::def:4' }, '*4')
|
|
109
|
+
]),
|
|
110
|
+
]).outerHTML,
|
|
111
|
+
]);
|
|
112
|
+
assert.deepStrictEqual(
|
|
113
|
+
note.outerHTML,
|
|
114
|
+
html('ol', [
|
|
115
|
+
html('li', { id: 'annotation::def:1' }, [
|
|
116
|
+
html('span', '1'),
|
|
117
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
118
|
+
]),
|
|
119
|
+
html('li', { id: 'annotation::def:2' }, [
|
|
120
|
+
html('span', '2'),
|
|
121
|
+
html('sup', [
|
|
122
|
+
html('a', { href: '#annotation::ref:2' }, '^2'),
|
|
123
|
+
html('a', { href: '#annotation::ref:4' }, '^4'),
|
|
124
|
+
]),
|
|
125
|
+
]),
|
|
126
|
+
html('li', { id: 'annotation::def:3' }, [
|
|
127
|
+
html('span', '3'),
|
|
128
|
+
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')]),
|
|
129
|
+
]),
|
|
130
|
+
html('li', { id: 'annotation::def:4' }, [
|
|
131
|
+
html('span', '4'),
|
|
132
|
+
html('sup', [html('a', { href: '#annotation::ref:5' }, '^5')]),
|
|
133
|
+
]),
|
|
134
|
+
]).outerHTML);
|
|
135
|
+
}
|
|
136
|
+
[...annotation(parse(''), note)];
|
|
137
|
+
assert.deepStrictEqual(
|
|
138
|
+
note.outerHTML,
|
|
139
|
+
html('ol').outerHTML);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('separation', () => {
|
|
143
|
+
const target = html('blockquote', parse([
|
|
144
|
+
'!>> ((1))\n> ((2))\n~~~',
|
|
145
|
+
'~~~~example/markdown\n((3))\n~~~~',
|
|
146
|
+
'((4))',
|
|
147
|
+
].join('\n\n')).children);
|
|
148
|
+
const note = html('ol');
|
|
149
|
+
for (let i = 0; i < 3; ++i) {
|
|
150
|
+
[...annotation(target, note)];
|
|
151
|
+
assert.deepStrictEqual(
|
|
152
|
+
[...target.children].map(el => el.outerHTML),
|
|
153
|
+
[
|
|
154
|
+
'<blockquote><blockquote><section><p><sup class="annotation disabled" title="1"><span hidden="">1</span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>1</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="2"><span hidden="">2</span><a>*1</a></sup><br>~~~</p><ol class="annotations"><li data-marker="*1"><span>2</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>',
|
|
155
|
+
'<aside class="example" data-type="markdown"><pre translate="no">((3))</pre><hr><section><p><sup class="annotation disabled" title="3"><span hidden="">3</span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>3</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></aside>',
|
|
156
|
+
'<p><sup class="annotation" id="annotation::ref:1" title="4"><span hidden="">4</span><a href="#annotation::def:4">*1</a></sup></p>',
|
|
157
|
+
]);
|
|
158
|
+
assert.deepStrictEqual(
|
|
159
|
+
note.outerHTML,
|
|
160
|
+
'<ol><li id="annotation::def:4"><span>4</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>');
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('split', () => {
|
|
165
|
+
const target = parse('((1))\n\n## a\n\n## b\n\n((2))((3))\n\n## c\n\n((4))');
|
|
166
|
+
for (let i = 0; i < 3; ++i) {
|
|
167
|
+
[...note(target)];
|
|
168
|
+
assert.deepStrictEqual(
|
|
169
|
+
[...target.children].map(el => el.outerHTML),
|
|
170
|
+
[
|
|
171
|
+
html('p', [
|
|
172
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: '1' }, [
|
|
173
|
+
html('span', { hidden: '' }, '1'),
|
|
174
|
+
html('a', { href: '#annotation::def:1' }, '*1')
|
|
175
|
+
]),
|
|
176
|
+
]).outerHTML,
|
|
177
|
+
html('ol', { class: 'annotations' }, [
|
|
178
|
+
html('li', { id: 'annotation::def:1', 'data-marker': '*1' }, [
|
|
179
|
+
html('span', '1'),
|
|
180
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
181
|
+
]),
|
|
182
|
+
]).outerHTML,
|
|
183
|
+
html('h2', { id: 'index::a' }, 'a').outerHTML,
|
|
184
|
+
html('h2', { id: 'index::b' }, 'b').outerHTML,
|
|
185
|
+
html('p', [
|
|
186
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2', title: '2' }, [
|
|
187
|
+
html('span', { hidden: '' }, '2'),
|
|
188
|
+
html('a', { href: '#annotation::def:2' }, '*2')
|
|
189
|
+
]),
|
|
190
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:3', title: '3' }, [
|
|
191
|
+
html('span', { hidden: '' }, '3'),
|
|
192
|
+
html('a', { href: '#annotation::def:3' }, '*3')
|
|
193
|
+
]),
|
|
194
|
+
]).outerHTML,
|
|
195
|
+
html('ol', { class: 'annotations' }, [
|
|
196
|
+
html('li', { id: 'annotation::def:2', 'data-marker': '*2' }, [
|
|
197
|
+
html('span', '2'),
|
|
198
|
+
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')]),
|
|
199
|
+
]),
|
|
200
|
+
html('li', { id: 'annotation::def:3', 'data-marker': '*3' }, [
|
|
201
|
+
html('span', '3'),
|
|
202
|
+
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')]),
|
|
203
|
+
]),
|
|
204
|
+
]).outerHTML,
|
|
205
|
+
html('h2', { id: 'index::c' }, 'c').outerHTML,
|
|
206
|
+
html('p', [
|
|
207
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:4', title: '4' }, [
|
|
208
|
+
html('span', { hidden: '' }, '4'),
|
|
209
|
+
html('a', { href: '#annotation::def:4' }, '*4')
|
|
210
|
+
]),
|
|
211
|
+
]).outerHTML,
|
|
212
|
+
html('ol', { class: 'annotations' }, [
|
|
213
|
+
html('li', { id: 'annotation::def:4', 'data-marker': '*4' }, [
|
|
214
|
+
html('span', '4'),
|
|
215
|
+
html('sup', [html('a', { href: '#annotation::ref:4' }, '^4')]),
|
|
216
|
+
]),
|
|
217
|
+
]).outerHTML,
|
|
218
|
+
]);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('id', () => {
|
|
223
|
+
const target = parse('((a b))');
|
|
224
|
+
const note = html('ol');
|
|
225
|
+
for (let i = 0; i < 3; ++i) {
|
|
226
|
+
assert.deepStrictEqual([...annotation(target, note, { id: '0' })].length, i === 0 ? 2 : 1);
|
|
227
|
+
assert.deepStrictEqual(
|
|
228
|
+
[...target.children].map(el => el.outerHTML),
|
|
229
|
+
[
|
|
230
|
+
html('p', [
|
|
231
|
+
html('sup', { class: 'annotation', id: 'annotation:0:ref:1', title: 'a b' }, [
|
|
232
|
+
html('span', { hidden: '' }, 'a b'),
|
|
233
|
+
html('a', { href: '#annotation:0:def:a_b' }, '*1')
|
|
234
|
+
]),
|
|
235
|
+
]).outerHTML,
|
|
236
|
+
]);
|
|
237
|
+
assert.deepStrictEqual(
|
|
238
|
+
note.outerHTML,
|
|
239
|
+
html('ol', [
|
|
240
|
+
html('li', { id: 'annotation:0:def:a_b' }, [
|
|
241
|
+
html('span', 'a b'),
|
|
242
|
+
html('sup', [html('a', { href: '#annotation:0:ref:1' }, '^1')]),
|
|
243
|
+
]),
|
|
244
|
+
]).outerHTML);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('reference', () => {
|
|
251
|
+
it('1', () => {
|
|
252
|
+
const target = parse('[[a b]]');
|
|
253
|
+
const note = html('ol');
|
|
254
|
+
for (let i = 0; i < 3; ++i) {
|
|
255
|
+
[...reference(target, note)];
|
|
256
|
+
assert.deepStrictEqual(
|
|
257
|
+
[...target.children].map(el => el.outerHTML),
|
|
258
|
+
[
|
|
259
|
+
html('p', [
|
|
260
|
+
html('sup', { class: 'reference', id: 'reference::ref:1', title: 'a b' }, [
|
|
261
|
+
html('span', { hidden: '' }, 'a b'),
|
|
262
|
+
html('a', { href: '#reference::def:a_b' }, '[1]')
|
|
263
|
+
]),
|
|
264
|
+
]).outerHTML,
|
|
265
|
+
]);
|
|
266
|
+
assert.deepStrictEqual(
|
|
267
|
+
note.outerHTML,
|
|
268
|
+
html('ol', [
|
|
269
|
+
html('li', { id: 'reference::def:a_b' }, [
|
|
270
|
+
html('span', 'a b'),
|
|
271
|
+
html('sup', [html('a', { href: '#reference::ref:1' }, '^1')]),
|
|
272
|
+
]),
|
|
273
|
+
]).outerHTML);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('abbr', () => {
|
|
278
|
+
const target = parse('[[^a|b]][[^a]][[^a]]');
|
|
279
|
+
const note = html('ol');
|
|
280
|
+
for (let i = 0; i < 3; ++i) {
|
|
281
|
+
[...reference(target, note)];
|
|
282
|
+
assert.deepStrictEqual(
|
|
283
|
+
[...target.children].map(el => el.outerHTML),
|
|
284
|
+
[
|
|
285
|
+
html('p', [
|
|
286
|
+
html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:1', title: 'b' }, [
|
|
287
|
+
html('span', { hidden: '' }, 'b'),
|
|
288
|
+
html('a', { href: '#reference::def:a' }, '[a]')
|
|
289
|
+
]),
|
|
290
|
+
html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:2', title: 'b' }, [
|
|
291
|
+
html('span', { hidden: '' }),
|
|
292
|
+
html('a', { href: '#reference::def:a' }, '[a]')
|
|
293
|
+
]),
|
|
294
|
+
html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:3', title: 'b' }, [
|
|
295
|
+
html('span', { hidden: '' }),
|
|
296
|
+
html('a', { href: '#reference::def:a' }, '[a]')
|
|
297
|
+
]),
|
|
298
|
+
]).outerHTML,
|
|
299
|
+
]);
|
|
300
|
+
assert.deepStrictEqual(
|
|
301
|
+
note.outerHTML,
|
|
302
|
+
html('ol', [
|
|
303
|
+
html('li', { id: 'reference::def:a' }, [
|
|
304
|
+
html('span', 'b'),
|
|
305
|
+
html('sup', [
|
|
306
|
+
html('a', { href: '#reference::ref:1', title: 'b' }, '^1'),
|
|
307
|
+
html('a', { href: '#reference::ref:2' }, '^2'),
|
|
308
|
+
html('a', { href: '#reference::ref:3' }, '^3'),
|
|
309
|
+
])
|
|
310
|
+
]),
|
|
311
|
+
]).outerHTML);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('nest', () => {
|
|
316
|
+
const target = parse('((a[[^b]]))[[^b|c]]');
|
|
317
|
+
const note = html('ol');
|
|
318
|
+
for (let i = 0; i < 3; ++i) {
|
|
319
|
+
[...annotation(target)];
|
|
320
|
+
[...reference(target, note)];
|
|
321
|
+
assert.deepStrictEqual(
|
|
322
|
+
[...target.children].map(el => el.outerHTML),
|
|
323
|
+
[
|
|
324
|
+
html('p', [
|
|
325
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: 'a' }, [
|
|
326
|
+
html('span', { hidden: '' }, [
|
|
327
|
+
'a',
|
|
328
|
+
html('sup', { class: 'reference', 'data-abbr': 'b' }, [
|
|
329
|
+
html('span'),
|
|
330
|
+
]),
|
|
331
|
+
]),
|
|
332
|
+
html('a', { href: '#annotation::def:a' }, '*1')
|
|
333
|
+
]),
|
|
334
|
+
html('sup', { class: 'reference', 'data-abbr': 'b', id: 'reference::ref:1', title: 'c' }, [
|
|
335
|
+
html('span', { hidden: '' }, 'c'),
|
|
336
|
+
html('a', { href: '#reference::def:b' }, '[b]')
|
|
337
|
+
]),
|
|
338
|
+
]).outerHTML,
|
|
339
|
+
html('ol', { class: 'annotations' }, [
|
|
340
|
+
html('li', { id: 'annotation::def:a', 'data-marker': '*1' }, [
|
|
341
|
+
html('span', [
|
|
342
|
+
'a',
|
|
343
|
+
html('sup', { class: 'reference', 'data-abbr': 'b', id: 'reference::ref:2', title: 'c' }, [
|
|
344
|
+
html('span', { hidden: '' }),
|
|
345
|
+
html('a', { href: '#reference::def:b' }, '[b]')
|
|
346
|
+
]),
|
|
347
|
+
]),
|
|
348
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
349
|
+
]),
|
|
350
|
+
]).outerHTML,
|
|
351
|
+
]);
|
|
352
|
+
assert.deepStrictEqual(
|
|
353
|
+
note.outerHTML,
|
|
354
|
+
html('ol', [
|
|
355
|
+
html('li', { id: 'reference::def:b' }, [
|
|
356
|
+
html('span', 'c'),
|
|
357
|
+
html('sup', [
|
|
358
|
+
html('a', { href: '#reference::ref:1', title: 'c' }, '^1'),
|
|
359
|
+
html('a', { href: '#reference::ref:2' }, '^2'),
|
|
360
|
+
]),
|
|
361
|
+
]),
|
|
362
|
+
]).outerHTML);
|
|
363
|
+
target.lastChild?.remove();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { identity, text } from '../inline/extension/indexee';
|
|
2
2
|
import { frag, html, define } from 'typed-dom/dom';
|
|
3
3
|
|
|
4
|
-
export function*
|
|
4
|
+
export function* note(
|
|
5
5
|
target: ParentNode & Node,
|
|
6
|
-
|
|
6
|
+
notes?: { readonly annotations?: HTMLOListElement; readonly references: HTMLOListElement; },
|
|
7
7
|
opts: { readonly id?: string; } = {},
|
|
8
8
|
bottom: Node | null = null,
|
|
9
9
|
): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
|
|
@@ -12,8 +12,8 @@ export function* footnote(
|
|
|
12
12
|
const el = es[i];
|
|
13
13
|
el.parentNode === target && el.remove();
|
|
14
14
|
}
|
|
15
|
-
yield*
|
|
16
|
-
yield*
|
|
15
|
+
yield* annotation(target, notes?.annotations, opts, bottom);
|
|
16
|
+
yield* reference(target, notes?.references, opts, bottom);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -30,7 +30,7 @@ function build(
|
|
|
30
30
|
// 構文ごとに各1回の処理では不可能
|
|
31
31
|
return function* (
|
|
32
32
|
target: ParentNode & Node,
|
|
33
|
-
|
|
33
|
+
note?: HTMLOListElement,
|
|
34
34
|
opts: { readonly id?: string } = {},
|
|
35
35
|
bottom: Node | null = null,
|
|
36
36
|
): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
|
|
@@ -44,25 +44,16 @@ function build(
|
|
|
44
44
|
}
|
|
45
45
|
const refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`);
|
|
46
46
|
const titles = new Map<string, string>();
|
|
47
|
-
const
|
|
48
|
-
for (let len = refs.length, i = 0; i < len; ++i) {
|
|
49
|
-
if (i % 10 === 9) yield;
|
|
50
|
-
const ref = refs[i];
|
|
51
|
-
const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild!.innerHTML}`;
|
|
52
|
-
if (titles.has(identifier)) continue;
|
|
53
|
-
const content = html('span',
|
|
54
|
-
{ id: identity(opts.id, text(ref.firstElementChild!), 'note') },
|
|
55
|
-
ref.firstElementChild!.cloneNode(true).childNodes);
|
|
56
|
-
const title = text(content).trim();
|
|
57
|
-
if (!title) continue;
|
|
58
|
-
titles.set(identifier, title);
|
|
59
|
-
contents.set(identifier, content);
|
|
60
|
-
}
|
|
47
|
+
const indexes = new Map<HTMLLIElement, number>();
|
|
61
48
|
let count = 0;
|
|
62
49
|
let total = 0;
|
|
63
50
|
let style: 'count' | 'abbr';
|
|
64
51
|
for (let len = refs.length, i = 0; i < len; ++i) {
|
|
65
52
|
const ref = refs[i];
|
|
53
|
+
if (ref.closest('[hidden]')) {
|
|
54
|
+
yield;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
66
57
|
while (splitters.length > 0
|
|
67
58
|
&& splitters[0].compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
68
59
|
if (defs.size > 0) {
|
|
@@ -74,8 +65,13 @@ function build(
|
|
|
74
65
|
}
|
|
75
66
|
splitters.shift();
|
|
76
67
|
}
|
|
77
|
-
const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild!.innerHTML}`;
|
|
78
68
|
const abbr = ref.getAttribute('data-abbr') || undefined;
|
|
69
|
+
const identifier = abbr || identity(undefined, text(ref.firstElementChild!), 'mark')?.slice(6) || '';
|
|
70
|
+
const title = undefined
|
|
71
|
+
|| titles.get(identifier)
|
|
72
|
+
|| titles.set(identifier, text(ref.firstElementChild!)).get(identifier)!
|
|
73
|
+
|| null;
|
|
74
|
+
assert(syntax !== 'annotation' || title);
|
|
79
75
|
style ??= abbr ? 'abbr' : 'count';
|
|
80
76
|
if (style === 'count' ? abbr : !abbr) {
|
|
81
77
|
define(ref, {
|
|
@@ -99,9 +95,6 @@ function build(
|
|
|
99
95
|
else {
|
|
100
96
|
ref.lastChild?.remove();
|
|
101
97
|
}
|
|
102
|
-
const title = titles.get(identifier);
|
|
103
|
-
assert(title !== '');
|
|
104
|
-
assert(syntax !== 'annotation' || title);
|
|
105
98
|
const refIndex = ++count;
|
|
106
99
|
const refId = opts.id !== ''
|
|
107
100
|
? `${syntax}:${opts.id ?? ''}:ref:${refIndex}`
|
|
@@ -110,24 +103,26 @@ function build(
|
|
|
110
103
|
|| defs.get(identifier)
|
|
111
104
|
|| defs.set(identifier, html('li',
|
|
112
105
|
{
|
|
113
|
-
id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${
|
|
114
|
-
'data-marker': !
|
|
106
|
+
id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${identifier}` : undefined,
|
|
107
|
+
'data-marker': !note ? marker(total + defs.size + 1, abbr) : undefined,
|
|
115
108
|
},
|
|
116
|
-
[
|
|
109
|
+
[define(ref.firstElementChild!.cloneNode(true), { hidden: null }), html('sup')]))
|
|
117
110
|
.get(identifier)!;
|
|
118
111
|
assert(def.lastChild);
|
|
119
|
-
const defIndex =
|
|
112
|
+
const defIndex = undefined
|
|
113
|
+
|| indexes.get(def)
|
|
114
|
+
|| indexes.set(def, total + defs.size).get(def)!;
|
|
120
115
|
const defId = def.id || undefined;
|
|
121
116
|
define(ref, {
|
|
122
117
|
id: refId,
|
|
123
|
-
class: opts.id !== '' ? undefined :
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
118
|
+
class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
|
|
119
|
+
title,
|
|
120
|
+
...!title && {
|
|
121
|
+
class: void ref.classList.add('invalid'),
|
|
122
|
+
'data-invalid-syntax': syntax,
|
|
123
|
+
'data-invalid-type': 'content',
|
|
124
|
+
'data-invalid-message': 'Missing the content',
|
|
125
|
+
},
|
|
131
126
|
});
|
|
132
127
|
yield ref.appendChild(html('a', { href: refId && defId && `#${defId}` }, marker(defIndex, abbr)));
|
|
133
128
|
assert(ref.title || ref.matches('.invalid'));
|
|
@@ -139,14 +134,14 @@ function build(
|
|
|
139
134
|
},
|
|
140
135
|
`^${refIndex}`));
|
|
141
136
|
}
|
|
142
|
-
if (defs.size > 0 ||
|
|
143
|
-
yield* proc(defs,
|
|
137
|
+
if (defs.size > 0 || note) {
|
|
138
|
+
yield* proc(defs, note ?? target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0] ?? bottom));
|
|
144
139
|
}
|
|
145
140
|
return;
|
|
146
141
|
}
|
|
147
142
|
|
|
148
|
-
function* proc(defs: Map<string, HTMLLIElement>,
|
|
149
|
-
const { children } =
|
|
143
|
+
function* proc(defs: Map<string, HTMLLIElement>, note: HTMLOListElement): Generator<HTMLLIElement | undefined, undefined, undefined> {
|
|
144
|
+
const { children } = note;
|
|
150
145
|
const size = defs.size;
|
|
151
146
|
let count = 0;
|
|
152
147
|
let length = children.length;
|
|
@@ -157,7 +152,7 @@ function build(
|
|
|
157
152
|
while (length > size) {
|
|
158
153
|
const node = children[count - 1] as HTMLLIElement;
|
|
159
154
|
if (equal(node, def)) continue I;
|
|
160
|
-
yield
|
|
155
|
+
yield note.removeChild(node);
|
|
161
156
|
--length;
|
|
162
157
|
assert(children.length === length);
|
|
163
158
|
}
|
|
@@ -165,13 +160,13 @@ function build(
|
|
|
165
160
|
? children[count - 1]
|
|
166
161
|
: null;
|
|
167
162
|
if (node && equal(node, def)) continue;
|
|
168
|
-
assert(def.parentNode !==
|
|
169
|
-
yield
|
|
163
|
+
assert(def.parentNode !== note);
|
|
164
|
+
yield note.insertBefore(def, node);
|
|
170
165
|
++length;
|
|
171
166
|
assert(children.length === length);
|
|
172
167
|
}
|
|
173
168
|
while (length > size) {
|
|
174
|
-
yield
|
|
169
|
+
yield note.removeChild(children[size] as HTMLLIElement);
|
|
175
170
|
--length;
|
|
176
171
|
assert(children.length === length);
|
|
177
172
|
}
|
package/tsconfig.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2021",
|
|
4
4
|
"lib": [
|
|
5
|
-
"
|
|
5
|
+
"ES2022",
|
|
6
6
|
"DOM",
|
|
7
7
|
"DOM.Iterable"
|
|
8
8
|
],
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"noImplicitOverride": true,
|
|
19
19
|
"noPropertyAccessFromIndexSignature": true,
|
|
20
20
|
"suppressImplicitAnyIndexErrors": true,
|
|
21
|
+
"ignoreDeprecations": "5.0",
|
|
21
22
|
"noFallthroughCasesInSwitch": true,
|
|
22
23
|
"noErrorTruncation": true,
|
|
23
24
|
"forceConsistentCasingInFileNames": true
|
package/webpack.config.js
CHANGED
|
@@ -33,7 +33,7 @@ module.exports = env => {
|
|
|
33
33
|
resolve: {
|
|
34
34
|
extensions: ['.ts', '.js'],
|
|
35
35
|
},
|
|
36
|
-
entry: glob.sync('./{src,test}/**/*.ts'),
|
|
36
|
+
entry: glob.sync('./{src,test}/**/*.ts', { absolute: true }).sort(),
|
|
37
37
|
output: {
|
|
38
38
|
filename: 'index.js',
|
|
39
39
|
path: path.resolve(__dirname, 'dist'),
|
|
@@ -81,7 +81,7 @@ module.exports = env => {
|
|
|
81
81
|
return merge(config);
|
|
82
82
|
case 'lint':
|
|
83
83
|
return merge(config, {
|
|
84
|
-
entry: glob.sync('./!(node_modules)/**/*.ts'),
|
|
84
|
+
entry: glob.sync('./!(node_modules)/**/*.ts', { absolute: true }),
|
|
85
85
|
plugins: [
|
|
86
86
|
new ESLintPlugin({
|
|
87
87
|
extensions: ['ts'],
|
|
@@ -90,7 +90,7 @@ module.exports = env => {
|
|
|
90
90
|
});
|
|
91
91
|
case 'bench':
|
|
92
92
|
return merge(config, {
|
|
93
|
-
entry: glob.sync('./benchmark/**/*.ts'),
|
|
93
|
+
entry: glob.sync('./benchmark/**/*.ts', { absolute: true }).sort(),
|
|
94
94
|
module: {
|
|
95
95
|
rules: [
|
|
96
96
|
{
|
|
@@ -109,7 +109,7 @@ module.exports = env => {
|
|
|
109
109
|
});
|
|
110
110
|
case 'dist':
|
|
111
111
|
return merge(config, {
|
|
112
|
-
entry: glob.sync('./index.ts'),
|
|
112
|
+
entry: glob.sync('./index.ts', { absolute: true }),
|
|
113
113
|
module: {
|
|
114
114
|
rules: [
|
|
115
115
|
{
|