securemark 0.264.0 → 0.266.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 +10 -0
- package/dist/index.js +44 -58
- package/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/combinator/data/parser/some.ts +2 -1
- package/src/parser/api/bind.test.ts +17 -17
- package/src/parser/api/bind.ts +1 -0
- package/src/parser/api/normalize.ts +1 -1
- package/src/parser/api/parse.test.ts +6 -6
- package/src/parser/api/parse.ts +2 -1
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/dlist.test.ts +34 -34
- package/src/parser/block/extension/aside.test.ts +3 -3
- package/src/parser/block/extension/aside.ts +2 -4
- package/src/parser/block/extension/figure.test.ts +2 -2
- package/src/parser/block/heading.test.ts +47 -47
- package/src/parser/block/olist.test.ts +30 -28
- package/src/parser/block/reply/cite.test.ts +1 -1
- package/src/parser/block/sidefence.ts +1 -1
- package/src/parser/block/ulist.test.ts +26 -26
- package/src/parser/inline/extension/index.test.ts +48 -48
- package/src/parser/inline/extension/index.ts +1 -1
- package/src/parser/inline/extension/indexee.ts +19 -18
- package/src/parser/inline/extension/indexer.ts +1 -1
- package/src/parser/inline/link.test.ts +26 -22
- package/src/parser/inline/link.ts +9 -14
- package/src/parser/inline/mark.test.ts +9 -9
- package/src/parser/inline/mark.ts +1 -1
- package/src/parser/inline.test.ts +7 -6
- package/src/parser/processor/figure.test.ts +19 -19
- package/src/parser/processor/figure.ts +0 -2
- package/src/parser/processor/footnote.test.ts +66 -66
- package/src/parser/processor/footnote.ts +11 -15
- package/src/util/toc.test.ts +28 -28
- package/src/util/toc.ts +0 -2
|
@@ -18,8 +18,6 @@ export function* figure(
|
|
|
18
18
|
let base = '0';
|
|
19
19
|
let bases: readonly string[] = base.split('.');
|
|
20
20
|
let index: readonly string[] = bases;
|
|
21
|
-
// Bug: Firefox
|
|
22
|
-
//for (let defs = target.querySelectorAll(':scope > figure[data-label], :scope > h1, :scope > h2'), len = defs.length, i = 0; i < len; ++i) {
|
|
23
21
|
for (
|
|
24
22
|
let defs = target.querySelectorAll('figure[data-label], h1, h2'),
|
|
25
23
|
len = defs.length, i = 0; i < len; ++i) {
|
|
@@ -27,18 +27,18 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
27
27
|
[...target.children].map(el => el.outerHTML),
|
|
28
28
|
[
|
|
29
29
|
html('p', [
|
|
30
|
-
html('sup', { class: "annotation", id: "annotation
|
|
30
|
+
html('sup', { class: "annotation", id: "annotation::ref:1", title: "a b" }, [
|
|
31
31
|
html('span', { hidden: '' }, 'a b'),
|
|
32
|
-
html('a', { href: "#annotation
|
|
32
|
+
html('a', { href: "#annotation::def:1" }, '*1')
|
|
33
33
|
]),
|
|
34
34
|
]).outerHTML,
|
|
35
35
|
]);
|
|
36
36
|
assert.deepStrictEqual(
|
|
37
37
|
footnote.outerHTML,
|
|
38
38
|
html('ol', [
|
|
39
|
-
html('li', { id: 'annotation
|
|
39
|
+
html('li', { id: 'annotation::def:1' }, [
|
|
40
40
|
'a b',
|
|
41
|
-
html('sup', [html('a', { href: '#annotation
|
|
41
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
42
42
|
]),
|
|
43
43
|
]).outerHTML);
|
|
44
44
|
}
|
|
@@ -53,26 +53,26 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
53
53
|
[...target.children].map(el => el.outerHTML),
|
|
54
54
|
[
|
|
55
55
|
html('p', [
|
|
56
|
-
html('sup', { class: "annotation", id: "annotation
|
|
56
|
+
html('sup', { class: "annotation", id: "annotation::ref:1", title: "1" }, [
|
|
57
57
|
html('span', { hidden: '' }, '1'),
|
|
58
|
-
html('a', { href: "#annotation
|
|
58
|
+
html('a', { href: "#annotation::def:1" }, '*1')
|
|
59
59
|
]),
|
|
60
|
-
html('sup', { class: "annotation", id: "annotation
|
|
60
|
+
html('sup', { class: "annotation", id: "annotation::ref:2", title: "12345678901234567890" }, [
|
|
61
61
|
html('span', { hidden: '' }, '12345678901234567890'),
|
|
62
|
-
html('a', { href: "#annotation
|
|
62
|
+
html('a', { href: "#annotation::def:2" }, '*2')
|
|
63
63
|
]),
|
|
64
64
|
]).outerHTML,
|
|
65
65
|
]);
|
|
66
66
|
assert.deepStrictEqual(
|
|
67
67
|
footnote.outerHTML,
|
|
68
68
|
html('ol', [
|
|
69
|
-
html('li', { id: 'annotation
|
|
69
|
+
html('li', { id: 'annotation::def:1' }, [
|
|
70
70
|
'1',
|
|
71
|
-
html('sup', [html('a', { href: '#annotation
|
|
71
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
72
72
|
]),
|
|
73
|
-
html('li', { id: 'annotation
|
|
73
|
+
html('li', { id: 'annotation::def:2' }, [
|
|
74
74
|
'12345678901234567890',
|
|
75
|
-
html('sup', [html('a', { href: '#annotation
|
|
75
|
+
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
|
|
76
76
|
]),
|
|
77
77
|
]).outerHTML);
|
|
78
78
|
}
|
|
@@ -87,49 +87,49 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
87
87
|
[...target.children].map(el => el.outerHTML),
|
|
88
88
|
[
|
|
89
89
|
html('p', [
|
|
90
|
-
html('sup', { class: "annotation", id: "annotation
|
|
90
|
+
html('sup', { class: "annotation", id: "annotation::ref:1", title: "1" }, [
|
|
91
91
|
html('span', { hidden: '' }, '1'),
|
|
92
|
-
html('a', { href: "#annotation
|
|
92
|
+
html('a', { href: "#annotation::def:1" }, '*1')
|
|
93
93
|
]),
|
|
94
|
-
html('sup', { class: "annotation", id: "annotation
|
|
94
|
+
html('sup', { class: "annotation", id: "annotation::ref:2", title: "2" }, [
|
|
95
95
|
html('span', { hidden: '' }, '2'),
|
|
96
|
-
html('a', { href: "#annotation
|
|
96
|
+
html('a', { href: "#annotation::def:2" }, '*2')
|
|
97
97
|
]),
|
|
98
|
-
html('sup', { class: "annotation", id: "annotation
|
|
98
|
+
html('sup', { class: "annotation", id: "annotation::ref:3", title: "3" }, [
|
|
99
99
|
html('span', { hidden: '' }, '3'),
|
|
100
|
-
html('a', { href: "#annotation
|
|
100
|
+
html('a', { href: "#annotation::def:3" }, '*3')
|
|
101
101
|
]),
|
|
102
|
-
html('sup', { class: "annotation", id: "annotation
|
|
102
|
+
html('sup', { class: "annotation", id: "annotation::ref:4", title: "2" }, [
|
|
103
103
|
html('span', { hidden: '' }, '2'),
|
|
104
|
-
html('a', { href: "#annotation
|
|
104
|
+
html('a', { href: "#annotation::def:2" }, '*2')
|
|
105
105
|
]),
|
|
106
|
-
html('sup', { class: "annotation", id: "annotation
|
|
106
|
+
html('sup', { class: "annotation", id: "annotation::ref:5", title: "4" }, [
|
|
107
107
|
html('span', { hidden: '' }, '4'),
|
|
108
|
-
html('a', { href: "#annotation
|
|
108
|
+
html('a', { href: "#annotation::def:4" }, '*4')
|
|
109
109
|
]),
|
|
110
110
|
]).outerHTML,
|
|
111
111
|
]);
|
|
112
112
|
assert.deepStrictEqual(
|
|
113
113
|
footnote.outerHTML,
|
|
114
114
|
html('ol', [
|
|
115
|
-
html('li', { id: 'annotation
|
|
115
|
+
html('li', { id: 'annotation::def:1' }, [
|
|
116
116
|
'1',
|
|
117
|
-
html('sup', [html('a', { href: '#annotation
|
|
117
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
118
118
|
]),
|
|
119
|
-
html('li', { id: 'annotation
|
|
119
|
+
html('li', { id: 'annotation::def:2' }, [
|
|
120
120
|
'2',
|
|
121
121
|
html('sup', [
|
|
122
|
-
html('a', { href: '#annotation
|
|
123
|
-
html('a', { href: '#annotation
|
|
122
|
+
html('a', { href: '#annotation::ref:2' }, '^2'),
|
|
123
|
+
html('a', { href: '#annotation::ref:4' }, '^4'),
|
|
124
124
|
]),
|
|
125
125
|
]),
|
|
126
|
-
html('li', { id: 'annotation
|
|
126
|
+
html('li', { id: 'annotation::def:3' }, [
|
|
127
127
|
'3',
|
|
128
|
-
html('sup', [html('a', { href: '#annotation
|
|
128
|
+
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
|
|
129
129
|
]),
|
|
130
|
-
html('li', { id: 'annotation
|
|
130
|
+
html('li', { id: 'annotation::def:4' }, [
|
|
131
131
|
'4',
|
|
132
|
-
html('sup', [html('a', { href: '#annotation
|
|
132
|
+
html('sup', [html('a', { href: '#annotation::ref:5' }, '^5')])
|
|
133
133
|
]),
|
|
134
134
|
]).outerHTML);
|
|
135
135
|
}
|
|
@@ -153,11 +153,11 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
153
153
|
[
|
|
154
154
|
'<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><span hidden="">a</span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1">a<sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="a"><span hidden="">a</span><a>*1</a></sup><br>~~~</p><ol class="annotations"><li data-marker="*1">a<sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>',
|
|
155
155
|
'<aside class="example" data-type="markdown"><pre translate="no">((a))</pre><hr><section><p><sup class="annotation disabled" title="a"><span hidden="">a</span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1">a<sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></aside>',
|
|
156
|
-
'<p><sup class="annotation" id="annotation
|
|
156
|
+
'<p><sup class="annotation" id="annotation::ref:1" title="a"><span hidden="">a</span><a href="#annotation::def:1">*1</a></sup></p>',
|
|
157
157
|
]);
|
|
158
158
|
assert.deepStrictEqual(
|
|
159
159
|
footnote.outerHTML,
|
|
160
|
-
'<ol><li id="annotation
|
|
160
|
+
'<ol><li id="annotation::def:1">a<sup><a href="#annotation::ref:1">^1</a></sup></li></ol>');
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
|
|
@@ -195,50 +195,50 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
195
195
|
[...target.children].map(el => el.outerHTML),
|
|
196
196
|
[
|
|
197
197
|
html('p', [
|
|
198
|
-
html('sup', { class: "annotation", id: "annotation
|
|
198
|
+
html('sup', { class: "annotation", id: "annotation::ref:1", title: "1" }, [
|
|
199
199
|
html('span', { hidden: '' }, '1'),
|
|
200
|
-
html('a', { href: "#annotation
|
|
200
|
+
html('a', { href: "#annotation::def:1" }, '*1')
|
|
201
201
|
]),
|
|
202
202
|
]).outerHTML,
|
|
203
203
|
html('ol', { class: 'annotations' }, [
|
|
204
|
-
html('li', { id: 'annotation
|
|
204
|
+
html('li', { id: 'annotation::def:1', 'data-marker': '*1' }, [
|
|
205
205
|
'1',
|
|
206
|
-
html('sup', [html('a', { href: '#annotation
|
|
206
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
207
207
|
]),
|
|
208
208
|
]).outerHTML,
|
|
209
|
-
html('h2', { id: 'index
|
|
210
|
-
html('h2', { id: 'index
|
|
209
|
+
html('h2', { id: 'index::a' }, 'a').outerHTML,
|
|
210
|
+
html('h2', { id: 'index::b' }, 'b').outerHTML,
|
|
211
211
|
html('p', [
|
|
212
|
-
html('sup', { class: "annotation", id: "annotation
|
|
212
|
+
html('sup', { class: "annotation", id: "annotation::ref:2", title: "2" }, [
|
|
213
213
|
html('span', { hidden: '' }, '2'),
|
|
214
|
-
html('a', { href: "#annotation
|
|
214
|
+
html('a', { href: "#annotation::def:2" }, '*2')
|
|
215
215
|
]),
|
|
216
|
-
html('sup', { class: "annotation", id: "annotation
|
|
216
|
+
html('sup', { class: "annotation", id: "annotation::ref:3", title: "3" }, [
|
|
217
217
|
html('span', { hidden: '' }, '3'),
|
|
218
|
-
html('a', { href: "#annotation
|
|
218
|
+
html('a', { href: "#annotation::def:3" }, '*3')
|
|
219
219
|
]),
|
|
220
220
|
]).outerHTML,
|
|
221
221
|
html('ol', { class: 'annotations' }, [
|
|
222
|
-
html('li', { id: 'annotation
|
|
222
|
+
html('li', { id: 'annotation::def:2', 'data-marker': '*2' }, [
|
|
223
223
|
'2',
|
|
224
|
-
html('sup', [html('a', { href: '#annotation
|
|
224
|
+
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
|
|
225
225
|
]),
|
|
226
|
-
html('li', { id: 'annotation
|
|
226
|
+
html('li', { id: 'annotation::def:3', 'data-marker': '*3' }, [
|
|
227
227
|
'3',
|
|
228
|
-
html('sup', [html('a', { href: '#annotation
|
|
228
|
+
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
|
|
229
229
|
]),
|
|
230
230
|
]).outerHTML,
|
|
231
|
-
html('h2', { id: 'index
|
|
231
|
+
html('h2', { id: 'index::c' }, 'c').outerHTML,
|
|
232
232
|
html('p', [
|
|
233
|
-
html('sup', { class: "annotation", id: "annotation
|
|
233
|
+
html('sup', { class: "annotation", id: "annotation::ref:4", title: "4" }, [
|
|
234
234
|
html('span', { hidden: '' }, '4'),
|
|
235
|
-
html('a', { href: "#annotation
|
|
235
|
+
html('a', { href: "#annotation::def:4" }, '*4')
|
|
236
236
|
]),
|
|
237
237
|
]).outerHTML,
|
|
238
238
|
html('ol', { class: 'annotations' }, [
|
|
239
|
-
html('li', { id: 'annotation
|
|
239
|
+
html('li', { id: 'annotation::def:4', 'data-marker': '*4' }, [
|
|
240
240
|
'4',
|
|
241
|
-
html('sup', [html('a', { href: '#annotation
|
|
241
|
+
html('sup', [html('a', { href: '#annotation::ref:4' }, '^4')])
|
|
242
242
|
]),
|
|
243
243
|
]).outerHTML,
|
|
244
244
|
]);
|
|
@@ -257,18 +257,18 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
257
257
|
[...target.children].map(el => el.outerHTML),
|
|
258
258
|
[
|
|
259
259
|
html('p', [
|
|
260
|
-
html('sup', { class: "reference", id: "reference
|
|
260
|
+
html('sup', { class: "reference", id: "reference::ref:1", title: "a b" }, [
|
|
261
261
|
html('span', { hidden: '' }, 'a b'),
|
|
262
|
-
html('a', { href: "#reference
|
|
262
|
+
html('a', { href: "#reference::def:1" }, '[1]')
|
|
263
263
|
]),
|
|
264
264
|
]).outerHTML,
|
|
265
265
|
]);
|
|
266
266
|
assert.deepStrictEqual(
|
|
267
267
|
footnote.outerHTML,
|
|
268
268
|
html('ol', [
|
|
269
|
-
html('li', { id: 'reference
|
|
269
|
+
html('li', { id: 'reference::def:1' }, [
|
|
270
270
|
'a b',
|
|
271
|
-
html('sup', [html('a', { href: '#reference
|
|
271
|
+
html('sup', [html('a', { href: '#reference::ref:1' }, '^1')])
|
|
272
272
|
]),
|
|
273
273
|
]).outerHTML);
|
|
274
274
|
}
|
|
@@ -283,29 +283,29 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
283
283
|
[...target.children].map(el => el.outerHTML),
|
|
284
284
|
[
|
|
285
285
|
html('p', [
|
|
286
|
-
html('sup', { class: "reference", 'data-abbr': "a", id: "reference
|
|
286
|
+
html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:1", title: "b" }, [
|
|
287
287
|
html('span', { hidden: '' }),
|
|
288
|
-
html('a', { href: "#reference
|
|
288
|
+
html('a', { href: "#reference::def:1" }, '[a]')
|
|
289
289
|
]),
|
|
290
|
-
html('sup', { class: "reference", 'data-abbr': "a", id: "reference
|
|
290
|
+
html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:2", title: "b" }, [
|
|
291
291
|
html('span', { hidden: '' }, 'b'),
|
|
292
|
-
html('a', { href: "#reference
|
|
292
|
+
html('a', { href: "#reference::def:1" }, '[a]')
|
|
293
293
|
]),
|
|
294
|
-
html('sup', { class: "reference", 'data-abbr': "a", id: "reference
|
|
294
|
+
html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:3", title: "b" }, [
|
|
295
295
|
html('span', { hidden: '' }),
|
|
296
|
-
html('a', { href: "#reference
|
|
296
|
+
html('a', { href: "#reference::def:1" }, '[a]')
|
|
297
297
|
]),
|
|
298
298
|
]).outerHTML,
|
|
299
299
|
]);
|
|
300
300
|
assert.deepStrictEqual(
|
|
301
301
|
footnote.outerHTML,
|
|
302
302
|
html('ol', [
|
|
303
|
-
html('li', { id: 'reference
|
|
303
|
+
html('li', { id: 'reference::def:1' }, [
|
|
304
304
|
'b',
|
|
305
305
|
html('sup', [
|
|
306
|
-
html('a', { href: '#reference
|
|
307
|
-
html('a', { href: '#reference
|
|
308
|
-
html('a', { href: '#reference
|
|
306
|
+
html('a', { href: '#reference::ref:1' }, '^1'),
|
|
307
|
+
html('a', { href: '#reference::ref:2', title: 'b' }, '^2'),
|
|
308
|
+
html('a', { href: '#reference::ref:3' }, '^3'),
|
|
309
309
|
])
|
|
310
310
|
]),
|
|
311
311
|
]).outerHTML);
|
|
@@ -8,8 +8,6 @@ export function* footnote(
|
|
|
8
8
|
opts: { readonly id?: string; } = {},
|
|
9
9
|
bottom: Node | null = null,
|
|
10
10
|
): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
|
|
11
|
-
// Bug: Firefox
|
|
12
|
-
//target.querySelectorAll(`:scope > .annotations`).forEach(el => el.remove());
|
|
13
11
|
for (let es = target.querySelectorAll(`.annotations`),
|
|
14
12
|
len = es.length, i = 0; i < len; ++i) {
|
|
15
13
|
const el = es[i];
|
|
@@ -40,8 +38,6 @@ function build(
|
|
|
40
38
|
const defs = new Map<string, HTMLLIElement>();
|
|
41
39
|
const buffer = new MultiQueue<string, HTMLElement>();
|
|
42
40
|
const titles = new Map<string, string>();
|
|
43
|
-
// Bug: Firefox
|
|
44
|
-
//const splitters = push([], target.querySelectorAll(`:scope > :is(${splitter ?? '_'})`));
|
|
45
41
|
const splitters: Element[] = [];
|
|
46
42
|
for (let es = target.querySelectorAll(splitter ?? '_'),
|
|
47
43
|
len = es.length, i = 0; i < len; ++i) {
|
|
@@ -56,14 +52,18 @@ function build(
|
|
|
56
52
|
len = refs.length, i = 0; i < len; ++i) {
|
|
57
53
|
yield;
|
|
58
54
|
const ref = refs[i];
|
|
59
|
-
while (
|
|
55
|
+
while (splitters.length > 0
|
|
56
|
+
&& splitters[0].compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
60
57
|
if (defs.size > 0) {
|
|
61
58
|
total += defs.size;
|
|
62
|
-
yield* proc(defs, target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0]
|
|
59
|
+
yield* proc(defs, target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0]));
|
|
60
|
+
}
|
|
61
|
+
else if (splitters.length % 100 === 0) {
|
|
62
|
+
yield;
|
|
63
63
|
}
|
|
64
64
|
splitters.shift();
|
|
65
65
|
}
|
|
66
|
-
const identifier =
|
|
66
|
+
const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild!.innerHTML}`;
|
|
67
67
|
const abbr = ref.getAttribute('data-abbr') || undefined;
|
|
68
68
|
const content = frag(ref.firstElementChild!.cloneNode(true).childNodes);
|
|
69
69
|
style ??= abbr ? 'abbr' : 'count';
|
|
@@ -89,12 +89,8 @@ function build(
|
|
|
89
89
|
else {
|
|
90
90
|
ref.lastChild?.remove();
|
|
91
91
|
}
|
|
92
|
-
const title = undefined
|
|
93
|
-
|
|
94
|
-
|| +identifier[0] && ref.title
|
|
95
|
-
|| text(content).trim()
|
|
96
|
-
|| content.textContent!.trim()
|
|
97
|
-
|| undefined;
|
|
92
|
+
const title = titles.get(identifier) || text(content).trim() || undefined;
|
|
93
|
+
assert(title !== '');
|
|
98
94
|
assert(syntax !== 'annotation' || title);
|
|
99
95
|
title
|
|
100
96
|
? !titles.has(identifier) && titles.set(identifier, title)
|
|
@@ -103,13 +99,13 @@ function build(
|
|
|
103
99
|
const blank = !!abbr && !content.firstChild;
|
|
104
100
|
const refIndex = ++count;
|
|
105
101
|
const refId = opts.id !== ''
|
|
106
|
-
?
|
|
102
|
+
? `${syntax}:${opts.id ?? ''}:ref:${refIndex}`
|
|
107
103
|
: undefined;
|
|
108
104
|
const def = undefined
|
|
109
105
|
|| defs.get(identifier)
|
|
110
106
|
|| defs.set(identifier, html('li',
|
|
111
107
|
{
|
|
112
|
-
id: opts.id !== '' ? `${syntax}:${opts.id
|
|
108
|
+
id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${total + defs.size + 1}` : undefined,
|
|
113
109
|
'data-marker': !footnote ? marker(total + defs.size + 1, abbr) : undefined,
|
|
114
110
|
},
|
|
115
111
|
[content.cloneNode(true), html('sup')]))
|
package/src/util/toc.test.ts
CHANGED
|
@@ -14,7 +14,7 @@ describe('Unit: util/toc', () => {
|
|
|
14
14
|
assert.strictEqual(
|
|
15
15
|
toc(parse('# 1')).outerHTML,
|
|
16
16
|
html('ul', [
|
|
17
|
-
html('li', [html('a', { href: '#index
|
|
17
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1')]),
|
|
18
18
|
]).outerHTML);
|
|
19
19
|
});
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ describe('Unit: util/toc', () => {
|
|
|
22
22
|
assert.strictEqual(
|
|
23
23
|
toc(parse('# 1\n\na')).outerHTML,
|
|
24
24
|
html('ul', [
|
|
25
|
-
html('li', [html('a', { href: '#index
|
|
25
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1')]),
|
|
26
26
|
]).outerHTML);
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -30,8 +30,8 @@ describe('Unit: util/toc', () => {
|
|
|
30
30
|
assert.strictEqual(
|
|
31
31
|
toc(parse('# 1\n\n# 2')).outerHTML,
|
|
32
32
|
html('ul', [
|
|
33
|
-
html('li', [html('a', { href: '#index
|
|
34
|
-
html('li', [html('a', { href: '#index
|
|
33
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1')]),
|
|
34
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '2' }, '2')]),
|
|
35
35
|
]).outerHTML);
|
|
36
36
|
});
|
|
37
37
|
|
|
@@ -39,9 +39,9 @@ describe('Unit: util/toc', () => {
|
|
|
39
39
|
assert.strictEqual(
|
|
40
40
|
toc(parse('# 1\n\n## 2')).outerHTML,
|
|
41
41
|
html('ul', [
|
|
42
|
-
html('li', [html('a', { href: '#index
|
|
42
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1'),
|
|
43
43
|
html('ul', [
|
|
44
|
-
html('li', [html('a', { href: '#index
|
|
44
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '1.1' }, '2')]),
|
|
45
45
|
]),
|
|
46
46
|
]),
|
|
47
47
|
]).outerHTML);
|
|
@@ -51,12 +51,12 @@ describe('Unit: util/toc', () => {
|
|
|
51
51
|
assert.strictEqual(
|
|
52
52
|
toc(parse('# 1\n\n## 2\n\n# 3')).outerHTML,
|
|
53
53
|
html('ul', [
|
|
54
|
-
html('li', [html('a', { href: '#index
|
|
54
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1'),
|
|
55
55
|
html('ul', [
|
|
56
|
-
html('li', [html('a', { href: '#index
|
|
56
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '1.1' }, '2')]),
|
|
57
57
|
]),
|
|
58
58
|
]),
|
|
59
|
-
html('li', [html('a', { href: '#index
|
|
59
|
+
html('li', [html('a', { href: '#index::3', 'data-index': '2' }, '3')]),
|
|
60
60
|
]).outerHTML);
|
|
61
61
|
});
|
|
62
62
|
|
|
@@ -64,14 +64,14 @@ describe('Unit: util/toc', () => {
|
|
|
64
64
|
assert.strictEqual(
|
|
65
65
|
toc(parse('# 1\n\n## 2\n\n### 3\n\n## 4')).outerHTML,
|
|
66
66
|
html('ul', [
|
|
67
|
-
html('li', [html('a', { href: '#index
|
|
67
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1'),
|
|
68
68
|
html('ul', [
|
|
69
|
-
html('li', [html('a', { href: '#index
|
|
69
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '1.1' }, '2'),
|
|
70
70
|
html('ul', [
|
|
71
|
-
html('li', [html('a', { href: '#index
|
|
71
|
+
html('li', [html('a', { href: '#index::3', 'data-index': '1.1.1' }, '3')]),
|
|
72
72
|
]),
|
|
73
73
|
]),
|
|
74
|
-
html('li', [html('a', { href: '#index
|
|
74
|
+
html('li', [html('a', { href: '#index::4', 'data-index': '1.2' }, '4')]),
|
|
75
75
|
]),
|
|
76
76
|
]),
|
|
77
77
|
]).outerHTML);
|
|
@@ -81,16 +81,16 @@ describe('Unit: util/toc', () => {
|
|
|
81
81
|
assert.strictEqual(
|
|
82
82
|
toc(parse('# 1\n\n## 2\n\n### 3\n\n# 4')).outerHTML,
|
|
83
83
|
html('ul', [
|
|
84
|
-
html('li', [html('a', { href: '#index
|
|
84
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1'),
|
|
85
85
|
html('ul', [
|
|
86
|
-
html('li', [html('a', { href: '#index
|
|
86
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '1.1' }, '2'),
|
|
87
87
|
html('ul', [
|
|
88
|
-
html('li', [html('a', { href: '#index
|
|
88
|
+
html('li', [html('a', { href: '#index::3', 'data-index': '1.1.1' }, '3')]),
|
|
89
89
|
]),
|
|
90
90
|
]),
|
|
91
91
|
]),
|
|
92
92
|
]),
|
|
93
|
-
html('li', [html('a', { href: '#index
|
|
93
|
+
html('li', [html('a', { href: '#index::4', 'data-index': '2' }, '4')]),
|
|
94
94
|
]).outerHTML);
|
|
95
95
|
});
|
|
96
96
|
|
|
@@ -98,10 +98,10 @@ describe('Unit: util/toc', () => {
|
|
|
98
98
|
assert.strictEqual(
|
|
99
99
|
toc(parse('# 1\n\n### 2\n\n## 3')).outerHTML,
|
|
100
100
|
html('ul', [
|
|
101
|
-
html('li', [html('a', { href: '#index
|
|
101
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1'),
|
|
102
102
|
html('ul', [
|
|
103
|
-
html('li', [html('a', { href: '#index
|
|
104
|
-
html('li', [html('a', { href: '#index
|
|
103
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '1.1' }, '2')]),
|
|
104
|
+
html('li', [html('a', { href: '#index::3', 'data-index': '1.2' }, '3')]),
|
|
105
105
|
]),
|
|
106
106
|
]),
|
|
107
107
|
]).outerHTML);
|
|
@@ -111,10 +111,10 @@ describe('Unit: util/toc', () => {
|
|
|
111
111
|
assert.strictEqual(
|
|
112
112
|
toc(parse('## 1\n\n# 2\n\n## 3')).outerHTML,
|
|
113
113
|
html('ul', [
|
|
114
|
-
html('li', [html('a', { href: '#index
|
|
115
|
-
html('li', [html('a', { href: '#index
|
|
114
|
+
html('li', [html('a', { href: '#index::1', 'data-index': '1' }, '1')]),
|
|
115
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '2' }, '2'),
|
|
116
116
|
html('ul', [
|
|
117
|
-
html('li', [html('a', { href: '#index
|
|
117
|
+
html('li', [html('a', { href: '#index::3', 'data-index': '2.1' }, '3')]),
|
|
118
118
|
]),
|
|
119
119
|
]),
|
|
120
120
|
]).outerHTML);
|
|
@@ -124,12 +124,12 @@ describe('Unit: util/toc', () => {
|
|
|
124
124
|
assert.strictEqual(
|
|
125
125
|
toc(parse('~~~aside\n# 1\n~~~\n\n# 2\n\n## 3\n\n~~~aside\n## 4\n~~~\n\n## 5')).outerHTML,
|
|
126
126
|
html('ul', [
|
|
127
|
-
html('li', [html('a', { href: '#index
|
|
128
|
-
html('li', [html('a', { href: '#index
|
|
127
|
+
html('li', [html('a', { href: '#index::1' }, '1')]),
|
|
128
|
+
html('li', [html('a', { href: '#index::2', 'data-index': '1' }, '2'),
|
|
129
129
|
html('ul', [
|
|
130
|
-
html('li', [html('a', { href: '#index
|
|
131
|
-
html('li', [html('a', { href: '#index
|
|
132
|
-
html('li', [html('a', { href: '#index
|
|
130
|
+
html('li', [html('a', { href: '#index::3', 'data-index': '1.1' }, '3')]),
|
|
131
|
+
html('li', [html('a', { href: '#index::4' }, '4')]),
|
|
132
|
+
html('li', [html('a', { href: '#index::5', 'data-index': '1.2' }, '5')]),
|
|
133
133
|
]),
|
|
134
134
|
]),
|
|
135
135
|
]).outerHTML);
|
package/src/util/toc.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { push } from 'spica/array';
|
|
2
2
|
import { html } from 'typed-dom/dom';
|
|
3
3
|
|
|
4
|
-
// Bug: Firefox
|
|
5
|
-
//const selector = `:scope > :is(h1, h2, h3, h4, h5, h6, aside.aside)[id]`;
|
|
6
4
|
const selector = ':is(h1, h2, h3, h4, h5, h6, aside.aside)[id]';
|
|
7
5
|
|
|
8
6
|
export function toc(source: DocumentFragment | HTMLElement | ShadowRoot): HTMLUListElement {
|