securemark 0.274.1 → 0.274.3
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/.eslintrc.json +0 -2
- package/CHANGELOG.md +8 -0
- package/dist/index.js +101 -129
- package/markdown.d.ts +5 -6
- package/package.json +1 -1
- package/src/parser/api/bind.test.ts +6 -6
- package/src/parser/api/parse.test.ts +69 -4
- package/src/parser/inline/mark.ts +9 -3
- package/src/parser/inline/media.ts +7 -19
- package/src/parser/inline/reference.test.ts +54 -27
- package/src/parser/inline/reference.ts +20 -15
- package/src/parser/processor/figure.ts +14 -53
- package/src/parser/processor/note.test.ts +36 -23
- package/src/parser/processor/note.ts +56 -56
- package/src/parser/util.ts +26 -0
|
@@ -5,6 +5,7 @@ import { attributes } from './html';
|
|
|
5
5
|
import { unsafehtmlentity } from './htmlentity';
|
|
6
6
|
import { txt, linebreak, str } from '../source';
|
|
7
7
|
import { Syntax, State } from '../context';
|
|
8
|
+
import { markInvalid } from '../util';
|
|
8
9
|
import { ReadonlyURL } from 'spica/url';
|
|
9
10
|
import { unshift, push } from 'spica/array';
|
|
10
11
|
import { html, define } from 'typed-dom/dom';
|
|
@@ -87,32 +88,19 @@ function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
|
|
|
87
88
|
case 'https:':
|
|
88
89
|
assert(uri.host);
|
|
89
90
|
if (/\/\.\.?(?:\/|$)/.test('/' + uri.source.slice(0, uri.source.search(/[?#]|$/)))) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
'data-invalid-syntax': 'media',
|
|
93
|
-
'data-invalid-type': 'argument',
|
|
94
|
-
'data-invalid-message': 'Dot-segments cannot be used in media paths; use subresource paths instead',
|
|
95
|
-
});
|
|
91
|
+
markInvalid(target, 'media', 'argument',
|
|
92
|
+
'Dot-segments cannot be used in media paths; use subresource paths instead');
|
|
96
93
|
return false;
|
|
97
94
|
}
|
|
98
95
|
break;
|
|
99
96
|
default:
|
|
100
|
-
|
|
101
|
-
class: void target.classList.add('invalid'),
|
|
102
|
-
'data-invalid-syntax': 'media',
|
|
103
|
-
'data-invalid-type': 'argument',
|
|
104
|
-
'data-invalid-message': 'Invalid protocol',
|
|
105
|
-
});
|
|
97
|
+
markInvalid(target, 'media', 'argument', 'Invalid protocol');
|
|
106
98
|
return false;
|
|
107
99
|
}
|
|
108
100
|
if (alt.includes('\x1B')) {
|
|
109
|
-
define(target, {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
'data-invalid-type': 'content',
|
|
113
|
-
'data-invalid-message': `Cannot use invalid HTML entitiy "${alt.match(/&[0-9A-Za-z]+;/)![0]}"`,
|
|
114
|
-
alt: target.getAttribute('alt')?.replace(/\x1B/g, ''),
|
|
115
|
-
});
|
|
101
|
+
define(target, { alt: target.getAttribute('alt')?.replace(/\x1B/g, '') });
|
|
102
|
+
markInvalid(target, 'media', 'content',
|
|
103
|
+
`Cannot use invalid HTML entitiy "${alt.match(/&[0-9A-Za-z]+;/)![0]}"`);
|
|
116
104
|
return false;
|
|
117
105
|
}
|
|
118
106
|
return true;
|
|
@@ -54,41 +54,68 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
54
54
|
|
|
55
55
|
it('abbr', () => {
|
|
56
56
|
assert.deepStrictEqual(inspect(parser('[[^]]')), [['<sup class="invalid"><span>^</span></sup>'], '']);
|
|
57
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
58
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
59
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
60
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
61
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
62
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
63
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
64
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
65
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
66
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
67
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
68
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
69
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
70
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
71
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
72
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
73
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
74
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
75
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
76
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
57
|
+
assert.deepStrictEqual(inspect(parser('[[^A]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
58
|
+
assert.deepStrictEqual(inspect(parser('[[^A,]]')), [['<sup class="reference" data-abbr="A,"><span></span></sup>'], '']);
|
|
59
|
+
assert.deepStrictEqual(inspect(parser('[[^A, ]]')), [['<sup class="reference" data-abbr="A,"><span></span></sup>'], '']);
|
|
60
|
+
assert.deepStrictEqual(inspect(parser('[[^A.]]')), [['<sup class="reference" data-abbr="A."><span></span></sup>'], '']);
|
|
61
|
+
assert.deepStrictEqual(inspect(parser('[[^A.,]]')), [['<sup class="reference" data-abbr="A.,"><span></span></sup>'], '']);
|
|
62
|
+
assert.deepStrictEqual(inspect(parser('[[^A?]]')), [['<sup class="reference" data-abbr="A?"><span></span></sup>'], '']);
|
|
63
|
+
assert.deepStrictEqual(inspect(parser('[[^A?,]]')), [['<sup class="reference" data-abbr="A?,"><span></span></sup>'], '']);
|
|
64
|
+
assert.deepStrictEqual(inspect(parser('[[^A ]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
65
|
+
assert.deepStrictEqual(inspect(parser('[[^A ]]')), [['<sup class="invalid"><span>^A</span></sup>'], '']);
|
|
66
|
+
assert.deepStrictEqual(inspect(parser('[[^A B]]')), [['<sup class="reference" data-abbr="A B"><span></span></sup>'], '']);
|
|
67
|
+
assert.deepStrictEqual(inspect(parser('[[^A B]]')), [['<sup class="invalid"><span>^A B</span></sup>'], '']);
|
|
68
|
+
assert.deepStrictEqual(inspect(parser('[[^A|]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
69
|
+
assert.deepStrictEqual(inspect(parser('[[^A,|]]')), [['<sup class="reference" data-abbr="A,"><span></span></sup>'], '']);
|
|
70
|
+
assert.deepStrictEqual(inspect(parser('[[^A |]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
71
|
+
assert.deepStrictEqual(inspect(parser('[[^A|b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
|
|
72
|
+
assert.deepStrictEqual(inspect(parser('[[^A|b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
|
|
73
|
+
assert.deepStrictEqual(inspect(parser('[[^A|b ]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
|
|
74
|
+
assert.deepStrictEqual(inspect(parser('[[^A|b ]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
|
|
75
|
+
assert.deepStrictEqual(inspect(parser('[[^A|<wbr>]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
76
|
+
assert.deepStrictEqual(inspect(parser('[[^A|<wbr>b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
|
|
77
|
+
assert.deepStrictEqual(inspect(parser('[[^A| ]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
78
|
+
assert.deepStrictEqual(inspect(parser('[[^A| b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
|
|
79
|
+
assert.deepStrictEqual(inspect(parser('[[^A| ]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
|
|
80
|
+
assert.deepStrictEqual(inspect(parser('[[^A|^]]')), [['<sup class="reference" data-abbr="A"><span>^</span></sup>'], '']);
|
|
81
|
+
assert.deepStrictEqual(inspect(parser('[[^A|^B]]')), [['<sup class="reference" data-abbr="A"><span>^B</span></sup>'], '']);
|
|
77
82
|
assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="invalid"><span>^1</span></sup>'], '']);
|
|
78
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
83
|
+
assert.deepStrictEqual(inspect(parser('[[^1A]]')), [['<sup class="invalid"><span>^1A</span></sup>'], '']);
|
|
79
84
|
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid"><span>^1</span></sup>'], '']);
|
|
80
|
-
assert.deepStrictEqual(inspect(parser('[[^1
|
|
85
|
+
assert.deepStrictEqual(inspect(parser('[[^1 A]]')), [['<sup class="invalid"><span>^1 A</span></sup>'], '']);
|
|
81
86
|
assert.deepStrictEqual(inspect(parser('[[^1|]]')), [['<sup class="invalid"><span>^1|</span></sup>'], '']);
|
|
82
87
|
assert.deepStrictEqual(inspect(parser('[[^1 |]]')), [['<sup class="invalid"><span>^1 |</span></sup>'], '']);
|
|
83
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
84
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
85
|
-
assert.deepStrictEqual(inspect(parser('[[^Xyz, 2020, p1-2]]')), [['<sup class="reference" data-abbr="Xyz, 2020, p1-2"><span></span></sup>'], '']);
|
|
86
|
-
assert.deepStrictEqual(inspect(parser('[[^X. Y., Z et al., 2020, p1-2]]')), [['<sup class="reference" data-abbr="X. Y., Z et al., 2020, p1-2"><span></span></sup>'], '']);
|
|
88
|
+
assert.deepStrictEqual(inspect(parser('[[^Abc]]')), [['<sup class="reference" data-abbr="Abc"><span></span></sup>'], '']);
|
|
89
|
+
assert.deepStrictEqual(inspect(parser('[[^A, B]]')), [['<sup class="reference" data-abbr="A, B"><span></span></sup>'], '']);
|
|
87
90
|
assert.deepStrictEqual(inspect(parser(`[[^A's, Aces']]`)), [[`<sup class="reference" data-abbr="A's, Aces'"><span></span></sup>`], '']);
|
|
91
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020]]')), [['<sup class="reference" data-abbr="Xyz 2020"><span></span></sup>'], '']);
|
|
92
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1"><span></span></sup>'], '']);
|
|
93
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, 2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, 2"><span></span></sup>'], '']);
|
|
94
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1"><span></span></sup>'], '']);
|
|
95
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1.1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1"><span></span></sup>'], '']);
|
|
96
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1.1-2.1b]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b"><span></span></sup>'], '']);
|
|
97
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1.1a-b]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b"><span></span></sup>'], '']);
|
|
98
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1-2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1-2"><span></span></sup>'], '']);
|
|
99
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1:1-2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1:1-2"><span></span></sup>'], '']);
|
|
100
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1n]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1n"><span></span></sup>'], '']);
|
|
101
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1n1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1n1"><span></span></sup>'], '']);
|
|
102
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1nn1-2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1nn1-2"><span></span></sup>'], '']);
|
|
103
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, i]]')), [['<sup class="reference" data-abbr="Xyz 2020, i"><span></span></sup>'], '']);
|
|
104
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, capter 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, capter 1"><span></span></sup>'], '']);
|
|
105
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, cap. 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, cap. 1"><span></span></sup>'], '']);
|
|
106
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020a]]')), [['<sup class="reference" data-abbr="Xyz 2020a"><span></span></sup>'], '']);
|
|
107
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020a, 1]]')), [['<sup class="reference" data-abbr="Xyz 2020a, 1"><span></span></sup>'], '']);
|
|
108
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020-2021a]]')), [['<sup class="reference" data-abbr="Xyz 2020-2021a"><span></span></sup>'], '']);
|
|
109
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020-2021a, 1]]')), [['<sup class="reference" data-abbr="Xyz 2020-2021a, 1"><span></span></sup>'], '']);
|
|
110
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz, April 1, 2020]]')), [['<sup class="reference" data-abbr="Xyz, April 1, 2020"><span></span></sup>'], '']);
|
|
111
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz, April 1, 2020, 1]]')), [['<sup class="reference" data-abbr="Xyz, April 1, 2020, 1"><span></span></sup>'], '']);
|
|
112
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz n.d.]]')), [['<sup class="reference" data-abbr="Xyz n.d."><span></span></sup>'], '']);
|
|
113
|
+
assert.deepStrictEqual(inspect(parser('[[^Xyz n.d., 1]]')), [['<sup class="reference" data-abbr="Xyz n.d., 1"><span></span></sup>'], '']);
|
|
114
|
+
assert.deepStrictEqual(inspect(parser('[[^X. Y., and Z et al. 2020, 1-2]]')), [['<sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2"><span></span></sup>'], '']);
|
|
88
115
|
assert.deepStrictEqual(inspect(parser('[[^^]]')), [['<sup class="invalid"><span>^^</span></sup>'], '']);
|
|
89
116
|
assert.deepStrictEqual(inspect(parser('[[\\^]]')), [['<sup class="reference"><span>^</span></sup>'], '']);
|
|
90
117
|
assert.deepStrictEqual(inspect(parser('[[^ ]]')), [['<sup class="invalid"><span>^</span></sup>'], '']);
|
|
91
|
-
assert.deepStrictEqual(inspect(parser('[[^
|
|
118
|
+
assert.deepStrictEqual(inspect(parser('[[^ A]]')), [['<sup class="invalid"><span>^ A</span></sup>'], '']);
|
|
92
119
|
assert.deepStrictEqual(inspect(parser('[[^ |]]')), [['<sup class="invalid"><span>^ |</span></sup>'], '']);
|
|
93
120
|
assert.deepStrictEqual(inspect(parser('[[^ |b]]')), [['<sup class="invalid"><span>^ |b</span></sup>'], '']);
|
|
94
121
|
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid"><span>^ |</span></sup>'], '']);
|
|
@@ -4,7 +4,6 @@ import { inline } from '../inline';
|
|
|
4
4
|
import { str } from '../source';
|
|
5
5
|
import { Syntax, State } from '../context';
|
|
6
6
|
import { regBlankStart, startLoose, trimNode } from '../visibility';
|
|
7
|
-
import { stringify } from '../util';
|
|
8
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
8
|
|
|
10
9
|
export const reference: ReferenceParser = lazy(() => surround(
|
|
@@ -21,24 +20,30 @@ export const reference: ReferenceParser = lazy(() => surround(
|
|
|
21
20
|
false,
|
|
22
21
|
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest]));
|
|
23
22
|
|
|
23
|
+
// Chicago-Style
|
|
24
24
|
const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
|
|
25
25
|
'^',
|
|
26
|
-
union([str(/^(
|
|
26
|
+
union([str(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]),
|
|
27
27
|
/^\|?(?=]])|^\|[^\S\n]*/),
|
|
28
|
-
([source], rest) => [[
|
|
28
|
+
([source], rest) => [['\n', source.trimEnd()], rest.replace(regBlankStart, '')]));
|
|
29
29
|
|
|
30
30
|
function attributes(ns: (string | HTMLElement)[]): Record<string, string | undefined> {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
switch (ns[0]) {
|
|
32
|
+
case '':
|
|
33
|
+
return {
|
|
34
|
+
class: 'invalid',
|
|
35
|
+
'data-invalid-syntax': 'reference',
|
|
36
|
+
'data-invalid-type': 'syntax',
|
|
37
|
+
'data-invalid-message': 'Invalid abbreviation',
|
|
38
|
+
};
|
|
39
|
+
case '\n':
|
|
40
|
+
const abbr = ns[1] as string;
|
|
41
|
+
ns[0] = ns[1] = '';
|
|
42
|
+
return {
|
|
33
43
|
class: 'reference',
|
|
34
|
-
'data-abbr':
|
|
35
|
-
}
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'data-invalid-syntax': 'reference',
|
|
40
|
-
'data-invalid-type': 'syntax',
|
|
41
|
-
'data-invalid-message': 'Invalid abbr',
|
|
42
|
-
}
|
|
43
|
-
: { class: 'reference' };
|
|
44
|
+
'data-abbr': abbr,
|
|
45
|
+
};
|
|
46
|
+
default:
|
|
47
|
+
return { class: 'reference' };
|
|
48
|
+
}
|
|
44
49
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { number as calculate, isFixed } from '../inline/extension/label';
|
|
2
|
+
import { markInvalid, unmarkInvalid } from '../util';
|
|
2
3
|
import { MultiQueue } from 'spica/queue';
|
|
3
4
|
import { push } from 'spica/array';
|
|
4
5
|
import { define } from 'typed-dom/dom';
|
|
@@ -32,46 +33,26 @@ export function* figure(
|
|
|
32
33
|
: `$-${increment(index, def as HTMLHeadingElement)}`;
|
|
33
34
|
if (label.endsWith('-')) continue;
|
|
34
35
|
if (label.endsWith('-0')) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'data-invalid-syntax': 'figure',
|
|
38
|
-
'data-invalid-type': 'argument',
|
|
39
|
-
'data-invalid-message': 'Invalid base index',
|
|
40
|
-
hidden: null,
|
|
41
|
-
});
|
|
36
|
+
markInvalid(def, 'figure', 'argument', 'Invalid base index');
|
|
37
|
+
define(def, { hidden: null });
|
|
42
38
|
continue;
|
|
43
39
|
}
|
|
44
40
|
if (tagName === 'FIGURE' && label.endsWith('.0')) {
|
|
45
41
|
// $-x.x.0 is disabled.
|
|
46
42
|
if (label.lastIndexOf('.', label.length - 3) !== -1) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'data-invalid-syntax': 'figure',
|
|
50
|
-
'data-invalid-type': 'argument',
|
|
51
|
-
'data-invalid-message': 'Base index must be $-x.0 format',
|
|
52
|
-
hidden: null,
|
|
53
|
-
});
|
|
43
|
+
markInvalid(def, 'figure', 'argument', 'Base index must be $-x.0 format');
|
|
44
|
+
define(def, { hidden: null });
|
|
54
45
|
continue;
|
|
55
46
|
}
|
|
56
47
|
// $-x.0 after h1-h6.
|
|
57
48
|
if (!/^H[1-6]$/.test(def.previousElementSibling?.tagName ?? '')) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'data-invalid-syntax': 'figure',
|
|
61
|
-
'data-invalid-type': 'position',
|
|
62
|
-
'data-invalid-message': messages.declaration,
|
|
63
|
-
hidden: null,
|
|
64
|
-
});
|
|
49
|
+
markInvalid(def, 'figure', 'position', messages.declaration);
|
|
50
|
+
define(def, { hidden: null });
|
|
65
51
|
continue;
|
|
66
52
|
}
|
|
67
53
|
else if (def.getAttribute('data-invalid-message') === messages.declaration) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'data-invalid-syntax': null,
|
|
71
|
-
'data-invalid-type': null,
|
|
72
|
-
'data-invalid-message': null,
|
|
73
|
-
hidden: '',
|
|
74
|
-
});
|
|
54
|
+
unmarkInvalid(def);
|
|
55
|
+
define(def, { hidden: null });
|
|
75
56
|
}
|
|
76
57
|
}
|
|
77
58
|
const group = label.split('-', 1)[0];
|
|
@@ -120,33 +101,18 @@ export function* figure(
|
|
|
120
101
|
group === '$' ? figindex : `${figindex}. `);
|
|
121
102
|
if (labels.has(label)) {
|
|
122
103
|
if (def.classList.contains('invalid')) continue;
|
|
123
|
-
define(def, {
|
|
124
|
-
|
|
125
|
-
class: void def.classList.add('invalid'),
|
|
126
|
-
'data-invalid-syntax': 'figure',
|
|
127
|
-
'data-invalid-type': 'argument',
|
|
128
|
-
'data-invalid-message': messages.duplicate,
|
|
129
|
-
});
|
|
104
|
+
define(def, { id: null });
|
|
105
|
+
markInvalid(def, 'figure', 'argument', messages.duplicate);
|
|
130
106
|
continue;
|
|
131
107
|
}
|
|
132
108
|
else if (def.getAttribute('data-invalid-message') === messages.duplicate) {
|
|
133
|
-
|
|
134
|
-
class: void def.classList.remove('invalid'),
|
|
135
|
-
'data-invalid-syntax': null,
|
|
136
|
-
'data-invalid-type': null,
|
|
137
|
-
'data-invalid-message': null,
|
|
138
|
-
});
|
|
109
|
+
unmarkInvalid(def);
|
|
139
110
|
}
|
|
140
111
|
labels.add(label);
|
|
141
112
|
opts.id !== '' && def.setAttribute('id', `label:${opts.id ? `${opts.id}:` : ''}${label}`);
|
|
142
113
|
for (const ref of refs.take(label, Infinity)) {
|
|
143
114
|
if (ref.getAttribute('data-invalid-message') === messages.reference) {
|
|
144
|
-
|
|
145
|
-
class: void ref.classList.remove('invalid'),
|
|
146
|
-
'data-invalid-syntax': null,
|
|
147
|
-
'data-invalid-type': null,
|
|
148
|
-
'data-invalid-message': null,
|
|
149
|
-
});
|
|
115
|
+
unmarkInvalid(ref);
|
|
150
116
|
}
|
|
151
117
|
if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
|
|
152
118
|
yield define(ref,
|
|
@@ -156,12 +122,7 @@ export function* figure(
|
|
|
156
122
|
}
|
|
157
123
|
for (const [, ref] of refs) {
|
|
158
124
|
if (opts.id !== '' && !ref.classList.contains('invalid')) {
|
|
159
|
-
|
|
160
|
-
class: void ref.classList.add('invalid'),
|
|
161
|
-
'data-invalid-syntax': 'label',
|
|
162
|
-
'data-invalid-type': 'reference',
|
|
163
|
-
'data-invalid-message': messages.reference,
|
|
164
|
-
});
|
|
125
|
+
markInvalid(ref, 'label', 'reference', messages.reference);
|
|
165
126
|
}
|
|
166
127
|
yield ref;
|
|
167
128
|
}
|
|
@@ -162,7 +162,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
it('split', () => {
|
|
165
|
-
const target = parse('((1))\n\n## a\n\n((2))((1))((3))((2))');
|
|
165
|
+
const target = parse('((1))\n\n## a\n\n((2))((1))((3))((2))\n\n## b\n\n((2))');
|
|
166
166
|
for (let i = 0; i < 3; ++i) {
|
|
167
167
|
[...note(target)];
|
|
168
168
|
assert.deepStrictEqual(
|
|
@@ -216,6 +216,19 @@ describe('Unit: parser/processor/note', () => {
|
|
|
216
216
|
html('sup', [html('a', { href: '#annotation::ref:3:1' }, '^4')]),
|
|
217
217
|
]),
|
|
218
218
|
]).outerHTML,
|
|
219
|
+
html('h2', { id: 'index::b' }, 'b').outerHTML,
|
|
220
|
+
html('p', [
|
|
221
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2:3', title: '2' }, [
|
|
222
|
+
html('span', { hidden: '' }, '2'),
|
|
223
|
+
html('a', { href: '#annotation::def:2:2' }, '*5')
|
|
224
|
+
]),
|
|
225
|
+
]).outerHTML,
|
|
226
|
+
html('ol', { class: 'annotations' }, [
|
|
227
|
+
html('li', { id: 'annotation::def:2:2', 'data-marker': '*5' }, [
|
|
228
|
+
html('span', '2'),
|
|
229
|
+
html('sup', [html('a', { href: '#annotation::ref:2:3' }, '^6')]),
|
|
230
|
+
]),
|
|
231
|
+
]).outerHTML,
|
|
219
232
|
]);
|
|
220
233
|
}
|
|
221
234
|
});
|
|
@@ -260,14 +273,14 @@ describe('Unit: parser/processor/note', () => {
|
|
|
260
273
|
html('p', [
|
|
261
274
|
html('sup', { class: 'reference', id: 'reference::ref:a_b:1', title: 'a b' }, [
|
|
262
275
|
html('span', { hidden: '' }, 'a b'),
|
|
263
|
-
html('a', { href: '#reference::def:a_b
|
|
276
|
+
html('a', { href: '#reference::def:a_b' }, '[1]')
|
|
264
277
|
]),
|
|
265
278
|
]).outerHTML,
|
|
266
279
|
]);
|
|
267
280
|
assert.deepStrictEqual(
|
|
268
281
|
note.outerHTML,
|
|
269
282
|
html('ol', [
|
|
270
|
-
html('li', { id: 'reference::def:a_b
|
|
283
|
+
html('li', { id: 'reference::def:a_b' }, [
|
|
271
284
|
html('span', 'a b'),
|
|
272
285
|
html('sup', [html('a', { href: '#reference::ref:a_b:1' }, '^1')]),
|
|
273
286
|
]),
|
|
@@ -276,7 +289,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
276
289
|
});
|
|
277
290
|
|
|
278
291
|
it('abbr', () => {
|
|
279
|
-
const target = parse('[[^
|
|
292
|
+
const target = parse('[[^A 1|b]][[^A 1]][[^A 1]]');
|
|
280
293
|
const note = html('ol');
|
|
281
294
|
for (let i = 0; i < 3; ++i) {
|
|
282
295
|
[...reference(target, note)];
|
|
@@ -284,29 +297,29 @@ describe('Unit: parser/processor/note', () => {
|
|
|
284
297
|
[...target.children].map(el => el.outerHTML),
|
|
285
298
|
[
|
|
286
299
|
html('p', [
|
|
287
|
-
html('sup', { class: 'reference', 'data-abbr': '
|
|
300
|
+
html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:1', title: 'b' }, [
|
|
288
301
|
html('span', { hidden: '' }, 'b'),
|
|
289
|
-
html('a', { href: '#reference::def:
|
|
302
|
+
html('a', { href: '#reference::def:A_1' }, '[A 1]')
|
|
290
303
|
]),
|
|
291
|
-
html('sup', { class: 'reference', 'data-abbr': '
|
|
304
|
+
html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:2', title: 'b' }, [
|
|
292
305
|
html('span', { hidden: '' }),
|
|
293
|
-
html('a', { href: '#reference::def:
|
|
306
|
+
html('a', { href: '#reference::def:A_1' }, '[A 1]')
|
|
294
307
|
]),
|
|
295
|
-
html('sup', { class: 'reference', 'data-abbr': '
|
|
308
|
+
html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:3', title: 'b' }, [
|
|
296
309
|
html('span', { hidden: '' }),
|
|
297
|
-
html('a', { href: '#reference::def:
|
|
310
|
+
html('a', { href: '#reference::def:A_1' }, '[A 1]')
|
|
298
311
|
]),
|
|
299
312
|
]).outerHTML,
|
|
300
313
|
]);
|
|
301
314
|
assert.deepStrictEqual(
|
|
302
315
|
note.outerHTML,
|
|
303
316
|
html('ol', [
|
|
304
|
-
html('li', { id: 'reference::def:
|
|
317
|
+
html('li', { id: 'reference::def:A_1' }, [
|
|
305
318
|
html('span', 'b'),
|
|
306
319
|
html('sup', [
|
|
307
|
-
html('a', { href: '#reference::ref:
|
|
308
|
-
html('a', { href: '#reference::ref:
|
|
309
|
-
html('a', { href: '#reference::ref:
|
|
320
|
+
html('a', { href: '#reference::ref:A_1:1', title: 'b' }, '^1'),
|
|
321
|
+
html('a', { href: '#reference::ref:A_1:2' }, '^2'),
|
|
322
|
+
html('a', { href: '#reference::ref:A_1:3' }, '^3'),
|
|
310
323
|
])
|
|
311
324
|
]),
|
|
312
325
|
]).outerHTML);
|
|
@@ -314,7 +327,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
314
327
|
});
|
|
315
328
|
|
|
316
329
|
it('nest', () => {
|
|
317
|
-
const target = parse('((a[[^
|
|
330
|
+
const target = parse('((a[[^B]]))[[^B|c]]');
|
|
318
331
|
const note = html('ol');
|
|
319
332
|
for (let i = 0; i < 3; ++i) {
|
|
320
333
|
[...annotation(target)];
|
|
@@ -326,24 +339,24 @@ describe('Unit: parser/processor/note', () => {
|
|
|
326
339
|
html('sup', { class: 'annotation', id: 'annotation::ref:a:1', title: 'a' }, [
|
|
327
340
|
html('span', { hidden: '' }, [
|
|
328
341
|
'a',
|
|
329
|
-
html('sup', { class: 'reference', 'data-abbr': '
|
|
342
|
+
html('sup', { class: 'reference', 'data-abbr': 'B' }, [
|
|
330
343
|
html('span'),
|
|
331
344
|
]),
|
|
332
345
|
]),
|
|
333
346
|
html('a', { href: '#annotation::def:a:1' }, '*1')
|
|
334
347
|
]),
|
|
335
|
-
html('sup', { class: 'reference', 'data-abbr': '
|
|
348
|
+
html('sup', { class: 'reference', 'data-abbr': 'B', id: 'reference::ref:B:1', title: 'c' }, [
|
|
336
349
|
html('span', { hidden: '' }, 'c'),
|
|
337
|
-
html('a', { href: '#reference::def:
|
|
350
|
+
html('a', { href: '#reference::def:B' }, '[B]')
|
|
338
351
|
]),
|
|
339
352
|
]).outerHTML,
|
|
340
353
|
html('ol', { class: 'annotations' }, [
|
|
341
354
|
html('li', { id: 'annotation::def:a:1', 'data-marker': '*1' }, [
|
|
342
355
|
html('span', [
|
|
343
356
|
'a',
|
|
344
|
-
html('sup', { class: 'reference', 'data-abbr': '
|
|
357
|
+
html('sup', { class: 'reference', 'data-abbr': 'B', id: 'reference::ref:B:2', title: 'c' }, [
|
|
345
358
|
html('span', { hidden: '' }),
|
|
346
|
-
html('a', { href: '#reference::def:
|
|
359
|
+
html('a', { href: '#reference::def:B' }, '[B]')
|
|
347
360
|
]),
|
|
348
361
|
]),
|
|
349
362
|
html('sup', [html('a', { href: '#annotation::ref:a:1' }, '^1')])
|
|
@@ -353,11 +366,11 @@ describe('Unit: parser/processor/note', () => {
|
|
|
353
366
|
assert.deepStrictEqual(
|
|
354
367
|
note.outerHTML,
|
|
355
368
|
html('ol', [
|
|
356
|
-
html('li', { id: 'reference::def:
|
|
369
|
+
html('li', { id: 'reference::def:B' }, [
|
|
357
370
|
html('span', 'c'),
|
|
358
371
|
html('sup', [
|
|
359
|
-
html('a', { href: '#reference::ref:
|
|
360
|
-
html('a', { href: '#reference::ref:
|
|
372
|
+
html('a', { href: '#reference::ref:B:1', title: 'c' }, '^1'),
|
|
373
|
+
html('a', { href: '#reference::ref:B:2' }, '^2'),
|
|
361
374
|
]),
|
|
362
375
|
]),
|
|
363
376
|
]).outerHTML);
|