securemark 0.270.2 → 0.272.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 +128 -99
- package/package.json +16 -16
- package/src/parser/api/bind.test.ts +3 -3
- package/src/parser/api/parse.test.ts +5 -5
- package/src/parser/block/extension/aside.ts +3 -3
- package/src/parser/block/extension/table.test.ts +58 -35
- package/src/parser/block/extension/table.ts +67 -31
- 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/footnote.test.ts +38 -38
- package/src/parser/processor/footnote.ts +25 -30
- package/tsconfig.json +2 -1
- package/webpack.config.js +4 -4
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { MarkdownParser } from '../../../../markdown';
|
|
2
2
|
import { Parser } from '../../../combinator/data/parser';
|
|
3
3
|
import { fmap } from '../../../combinator';
|
|
4
|
+
import { reduce } from 'spica/memoize';
|
|
4
5
|
import { define } from 'typed-dom/dom';
|
|
5
6
|
|
|
6
7
|
export function indexee<P extends Parser<unknown, MarkdownParser.Context>>(parser: P, optional?: boolean): P;
|
|
7
8
|
export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>, optional?: boolean): Parser<HTMLElement> {
|
|
8
|
-
return fmap(parser, ([el], _, { id }) => [define(el, { id: identity(id,
|
|
9
|
+
return fmap(parser, ([el], _, { id }) => [define(el, { id: identity(id, index(el, optional)) })]);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export function identity(id: string | undefined, text: string, name: 'index' | 'mark'
|
|
12
|
+
export function identity(id: string | undefined, text: string, name: 'index' | 'mark' = 'index'): string | undefined {
|
|
12
13
|
assert(!id?.match(/[^0-9a-z/-]/i));
|
|
13
14
|
assert(!text.includes('\n'));
|
|
14
15
|
if (id === '') return undefined;
|
|
@@ -20,7 +21,6 @@ export function identity(id: string | undefined, text: string, name: 'index' | '
|
|
|
20
21
|
case 'index':
|
|
21
22
|
return `${name}:${id ?? ''}:${cs.slice(0, 97).join('')}...`;
|
|
22
23
|
case 'mark':
|
|
23
|
-
case 'note':
|
|
24
24
|
return `${name}:${id ?? ''}:${cs.slice(0, 50).join('')}...${cs.slice(-47).join('')}`;
|
|
25
25
|
}
|
|
26
26
|
assert(false);
|
|
@@ -32,7 +32,7 @@ assert(identity(undefined, '0'.repeat(100 - 1) + 1, 'mark')!.slice(6) === '0'.re
|
|
|
32
32
|
assert(identity(undefined, '0'.repeat(100) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
|
|
33
33
|
assert(identity(undefined, '0'.repeat(200) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
|
|
34
34
|
|
|
35
|
-
export function
|
|
35
|
+
export function index(source: Element | DocumentFragment, optional = false): string {
|
|
36
36
|
assert(source instanceof DocumentFragment || !source.matches('.indexer'));
|
|
37
37
|
assert(source.querySelectorAll(':scope > .indexer').length <= 1);
|
|
38
38
|
if (!source.firstChild) return '';
|
|
@@ -40,6 +40,10 @@ export function text(source: Element | DocumentFragment, optional = false): stri
|
|
|
40
40
|
const index = indexer?.getAttribute('data-index');
|
|
41
41
|
if (index) return index;
|
|
42
42
|
if (index === '' && optional) return '';
|
|
43
|
+
return text(source);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const text = reduce((source: Element | DocumentFragment): string => {
|
|
43
47
|
assert(!navigator.userAgent.includes('Chrome') || !source.querySelector('br:not(:has(+ :is(ul, ol)))'));
|
|
44
48
|
const target = source.cloneNode(true) as typeof source;
|
|
45
49
|
for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'),
|
|
@@ -72,4 +76,4 @@ export function text(source: Element | DocumentFragment, optional = false): stri
|
|
|
72
76
|
// Better:
|
|
73
77
|
//return target.innerText;
|
|
74
78
|
return target.textContent!;
|
|
75
|
-
}
|
|
79
|
+
});
|
|
@@ -73,11 +73,11 @@ const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union(
|
|
|
73
73
|
surround(str('"'), precedence(8, some(union([unsafehtmlentity, txt]), '"')), str('"'), true),
|
|
74
74
|
])));
|
|
75
75
|
|
|
76
|
-
const option: MediaParser.ParameterParser.OptionParser = union([
|
|
76
|
+
const option: MediaParser.ParameterParser.OptionParser = lazy(() => union([
|
|
77
77
|
fmap(str(/^[^\S\n]+[1-9][0-9]*x[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` width="${opt.slice(1).split('x')[0]}"`, ` height="${opt.slice(1).split('x')[1]}"`]),
|
|
78
78
|
fmap(str(/^[^\S\n]+[1-9][0-9]*:[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` aspect-ratio="${opt.slice(1).split(':').join('/')}"`]),
|
|
79
79
|
linkoption,
|
|
80
|
-
]);
|
|
80
|
+
]));
|
|
81
81
|
|
|
82
82
|
function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
|
|
83
83
|
assert(target.tagName === 'IMG');
|
package/src/parser/inline.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MarkdownParser } from '../../markdown';
|
|
2
|
-
import { union } from '../combinator';
|
|
2
|
+
import { union, lazy } from '../combinator';
|
|
3
3
|
import { annotation } from './inline/annotation';
|
|
4
4
|
import { reference } from './inline/reference';
|
|
5
5
|
import { template } from './inline/template';
|
|
@@ -45,7 +45,7 @@ export import ShortMediaParser = InlineParser.ShortMediaParser;
|
|
|
45
45
|
export import AutolinkParser = InlineParser.AutolinkParser;
|
|
46
46
|
export import BracketParser = InlineParser.BracketParser;
|
|
47
47
|
|
|
48
|
-
export const inline: InlineParser = union([
|
|
48
|
+
export const inline: InlineParser = lazy(() => union([
|
|
49
49
|
annotation,
|
|
50
50
|
reference,
|
|
51
51
|
template,
|
|
@@ -68,7 +68,7 @@ export const inline: InlineParser = union([
|
|
|
68
68
|
autolink,
|
|
69
69
|
bracket,
|
|
70
70
|
text
|
|
71
|
-
]);
|
|
71
|
+
]));
|
|
72
72
|
|
|
73
73
|
export { indexee } from './inline/extension/indexee';
|
|
74
74
|
export { indexer } from './inline/extension/indexer';
|
|
@@ -29,15 +29,15 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
29
29
|
html('p', [
|
|
30
30
|
html('sup', { class: "annotation", id: "annotation::ref:1", title: "a b" }, [
|
|
31
31
|
html('span', { hidden: '' }, 'a b'),
|
|
32
|
-
html('a', { href: "#annotation::def:
|
|
32
|
+
html('a', { href: "#annotation::def:a_b" }, '*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::def:
|
|
40
|
-
html('span',
|
|
39
|
+
html('li', { id: 'annotation::def:a_b' }, [
|
|
40
|
+
html('span', 'a b'),
|
|
41
41
|
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
42
42
|
]),
|
|
43
43
|
]).outerHTML);
|
|
@@ -59,7 +59,7 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
59
59
|
]),
|
|
60
60
|
html('sup', { class: "annotation", id: "annotation::ref:2", title: "12345678901234567890" }, [
|
|
61
61
|
html('span', { hidden: '' }, '12345678901234567890'),
|
|
62
|
-
html('a', { href: "#annotation::def:
|
|
62
|
+
html('a', { href: "#annotation::def:12345678901234567890" }, '*2')
|
|
63
63
|
]),
|
|
64
64
|
]).outerHTML,
|
|
65
65
|
]);
|
|
@@ -67,11 +67,11 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
67
67
|
footnote.outerHTML,
|
|
68
68
|
html('ol', [
|
|
69
69
|
html('li', { id: 'annotation::def:1' }, [
|
|
70
|
-
html('span',
|
|
70
|
+
html('span', '1'),
|
|
71
71
|
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
72
72
|
]),
|
|
73
|
-
html('li', { id: 'annotation::def:
|
|
74
|
-
html('span',
|
|
73
|
+
html('li', { id: 'annotation::def:12345678901234567890' }, [
|
|
74
|
+
html('span', '12345678901234567890'),
|
|
75
75
|
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
|
|
76
76
|
]),
|
|
77
77
|
]).outerHTML);
|
|
@@ -113,22 +113,22 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
113
113
|
footnote.outerHTML,
|
|
114
114
|
html('ol', [
|
|
115
115
|
html('li', { id: 'annotation::def:1' }, [
|
|
116
|
-
html('span',
|
|
116
|
+
html('span', '1'),
|
|
117
117
|
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
118
118
|
]),
|
|
119
119
|
html('li', { id: 'annotation::def:2' }, [
|
|
120
|
-
html('span',
|
|
120
|
+
html('span', '2'),
|
|
121
121
|
html('sup', [
|
|
122
122
|
html('a', { href: '#annotation::ref:2' }, '^2'),
|
|
123
123
|
html('a', { href: '#annotation::ref:4' }, '^4'),
|
|
124
124
|
]),
|
|
125
125
|
]),
|
|
126
126
|
html('li', { id: 'annotation::def:3' }, [
|
|
127
|
-
html('span',
|
|
127
|
+
html('span', '3'),
|
|
128
128
|
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
|
|
129
129
|
]),
|
|
130
130
|
html('li', { id: 'annotation::def:4' }, [
|
|
131
|
-
html('span',
|
|
131
|
+
html('span', '4'),
|
|
132
132
|
html('sup', [html('a', { href: '#annotation::ref:5' }, '^5')])
|
|
133
133
|
]),
|
|
134
134
|
]).outerHTML);
|
|
@@ -141,9 +141,9 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
141
141
|
|
|
142
142
|
it('separation', () => {
|
|
143
143
|
const target = html('blockquote', parse([
|
|
144
|
-
'!>> ((
|
|
145
|
-
'~~~~example/markdown\n((
|
|
146
|
-
'((
|
|
144
|
+
'!>> ((1))\n> ((2))\n~~~',
|
|
145
|
+
'~~~~example/markdown\n((3))\n~~~~',
|
|
146
|
+
'((4))',
|
|
147
147
|
].join('\n\n')).children);
|
|
148
148
|
const footnote = html('ol');
|
|
149
149
|
for (let i = 0; i < 3; ++i) {
|
|
@@ -151,13 +151,13 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
151
151
|
assert.deepStrictEqual(
|
|
152
152
|
[...target.children].map(el => el.outerHTML),
|
|
153
153
|
[
|
|
154
|
-
'<blockquote><blockquote><section><p><sup class="annotation disabled" title="
|
|
155
|
-
'<aside class="example" data-type="markdown"><pre translate="no">((
|
|
156
|
-
'<p><sup class="annotation" id="annotation::ref:1" title="
|
|
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
157
|
]);
|
|
158
158
|
assert.deepStrictEqual(
|
|
159
159
|
footnote.outerHTML,
|
|
160
|
-
'<ol><li id="annotation::def:
|
|
160
|
+
'<ol><li id="annotation::def:4"><span>4</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>');
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
|
|
@@ -172,15 +172,15 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
172
172
|
html('p', [
|
|
173
173
|
html('sup', { class: "annotation", id: "annotation:0:ref:1", title: "a b" }, [
|
|
174
174
|
html('span', { hidden: '' }, 'a b'),
|
|
175
|
-
html('a', { href: "#annotation:0:def:
|
|
175
|
+
html('a', { href: "#annotation:0:def:a_b" }, '*1')
|
|
176
176
|
]),
|
|
177
177
|
]).outerHTML,
|
|
178
178
|
]);
|
|
179
179
|
assert.deepStrictEqual(
|
|
180
180
|
footnote.outerHTML,
|
|
181
181
|
html('ol', [
|
|
182
|
-
html('li', { id: 'annotation:0:def:
|
|
183
|
-
html('span',
|
|
182
|
+
html('li', { id: 'annotation:0:def:a_b' }, [
|
|
183
|
+
html('span', 'a b'),
|
|
184
184
|
html('sup', [html('a', { href: '#annotation:0:ref:1' }, '^1')])
|
|
185
185
|
]),
|
|
186
186
|
]).outerHTML);
|
|
@@ -202,7 +202,7 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
202
202
|
]).outerHTML,
|
|
203
203
|
html('ol', { class: 'annotations' }, [
|
|
204
204
|
html('li', { id: 'annotation::def:1', 'data-marker': '*1' }, [
|
|
205
|
-
html('span',
|
|
205
|
+
html('span', '1'),
|
|
206
206
|
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
207
207
|
]),
|
|
208
208
|
]).outerHTML,
|
|
@@ -220,11 +220,11 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
220
220
|
]).outerHTML,
|
|
221
221
|
html('ol', { class: 'annotations' }, [
|
|
222
222
|
html('li', { id: 'annotation::def:2', 'data-marker': '*2' }, [
|
|
223
|
-
html('span',
|
|
223
|
+
html('span', '2'),
|
|
224
224
|
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
|
|
225
225
|
]),
|
|
226
226
|
html('li', { id: 'annotation::def:3', 'data-marker': '*3' }, [
|
|
227
|
-
html('span',
|
|
227
|
+
html('span', '3'),
|
|
228
228
|
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
|
|
229
229
|
]),
|
|
230
230
|
]).outerHTML,
|
|
@@ -237,7 +237,7 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
237
237
|
]).outerHTML,
|
|
238
238
|
html('ol', { class: 'annotations' }, [
|
|
239
239
|
html('li', { id: 'annotation::def:4', 'data-marker': '*4' }, [
|
|
240
|
-
html('span',
|
|
240
|
+
html('span', '4'),
|
|
241
241
|
html('sup', [html('a', { href: '#annotation::ref:4' }, '^4')])
|
|
242
242
|
]),
|
|
243
243
|
]).outerHTML,
|
|
@@ -259,15 +259,15 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
259
259
|
html('p', [
|
|
260
260
|
html('sup', { class: "reference", id: "reference::ref:1", title: "a b" }, [
|
|
261
261
|
html('span', { hidden: '' }, 'a b'),
|
|
262
|
-
html('a', { href: "#reference::def:
|
|
262
|
+
html('a', { href: "#reference::def:a_b" }, '[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::def:
|
|
270
|
-
html('span',
|
|
269
|
+
html('li', { id: 'reference::def:a_b' }, [
|
|
270
|
+
html('span', 'a b'),
|
|
271
271
|
html('sup', [html('a', { href: '#reference::ref:1' }, '^1')])
|
|
272
272
|
]),
|
|
273
273
|
]).outerHTML);
|
|
@@ -275,7 +275,7 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
275
275
|
});
|
|
276
276
|
|
|
277
277
|
it('abbr', () => {
|
|
278
|
-
const target = parse('[[^a]][[^a
|
|
278
|
+
const target = parse('[[^a| b]][[^a]][[^a]]');
|
|
279
279
|
const footnote = html('ol');
|
|
280
280
|
for (let i = 0; i < 3; ++i) {
|
|
281
281
|
[...reference(target, footnote)];
|
|
@@ -284,27 +284,27 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
284
284
|
[
|
|
285
285
|
html('p', [
|
|
286
286
|
html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:1", title: "b" }, [
|
|
287
|
-
html('span', { hidden: '' }),
|
|
288
|
-
html('a', { href: "#reference::def:
|
|
287
|
+
html('span', { hidden: '' }, 'b'),
|
|
288
|
+
html('a', { href: "#reference::def:a" }, '[a]')
|
|
289
289
|
]),
|
|
290
290
|
html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:2", title: "b" }, [
|
|
291
|
-
html('span', { hidden: '' }
|
|
292
|
-
html('a', { href: "#reference::def:
|
|
291
|
+
html('span', { hidden: '' }),
|
|
292
|
+
html('a', { href: "#reference::def:a" }, '[a]')
|
|
293
293
|
]),
|
|
294
294
|
html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:3", title: "b" }, [
|
|
295
295
|
html('span', { hidden: '' }),
|
|
296
|
-
html('a', { href: "#reference::def:
|
|
296
|
+
html('a', { href: "#reference::def:a" }, '[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::def:
|
|
304
|
-
html('span',
|
|
303
|
+
html('li', { id: 'reference::def:a' }, [
|
|
304
|
+
html('span', 'b'),
|
|
305
305
|
html('sup', [
|
|
306
|
-
html('a', { href: '#reference::ref:1' }, '^1'),
|
|
307
|
-
html('a', { href: '#reference::ref:2'
|
|
306
|
+
html('a', { href: '#reference::ref:1', title: 'b' }, '^1'),
|
|
307
|
+
html('a', { href: '#reference::ref:2' }, '^2'),
|
|
308
308
|
html('a', { href: '#reference::ref:3' }, '^3'),
|
|
309
309
|
])
|
|
310
310
|
]),
|
|
@@ -12,8 +12,8 @@ export function* footnote(
|
|
|
12
12
|
const el = es[i];
|
|
13
13
|
el.parentNode === target && el.remove();
|
|
14
14
|
}
|
|
15
|
-
yield* reference(target, footnotes?.references, opts, bottom);
|
|
16
15
|
yield* annotation(target, footnotes?.annotations, opts, bottom);
|
|
16
|
+
yield* reference(target, footnotes?.references, opts, bottom);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -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:${
|
|
106
|
+
id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${identifier}` : undefined,
|
|
114
107
|
'data-marker': !footnote ? 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'));
|
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
|
{
|