securemark 0.232.0 → 0.233.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/design.md +4 -0
- package/dist/securemark.js +91 -117
- package/markdown.d.ts +13 -22
- package/package-lock.json +259 -245
- package/package.json +5 -5
- package/src/combinator/control/manipulation/indent.test.ts +12 -12
- package/src/combinator/control/manipulation/surround.ts +4 -3
- package/src/parser/api/parse.test.ts +6 -6
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/extension/aside.test.ts +1 -1
- package/src/parser/block/extension/aside.ts +3 -3
- package/src/parser/block/extension/example.test.ts +2 -2
- package/src/parser/block/extension/table.ts +3 -3
- package/src/parser/block/paragraph.test.ts +7 -6
- package/src/parser/block/reply/cite.ts +3 -3
- package/src/parser/block/reply/quote.ts +5 -3
- package/src/parser/block/reply.ts +4 -4
- package/src/parser/inline/annotation.test.ts +0 -2
- package/src/parser/inline/autolink/anchor.ts +3 -1
- package/src/parser/inline/comment.test.ts +39 -38
- package/src/parser/inline/comment.ts +21 -28
- package/src/parser/inline/deletion.test.ts +0 -1
- package/src/parser/inline/emphasis.test.ts +0 -3
- package/src/parser/inline/extension/index.test.ts +4 -3
- package/src/parser/inline/extension/index.ts +2 -2
- package/src/parser/inline/extension/indexee.ts +21 -19
- package/src/parser/inline/extension/placeholder.test.ts +7 -7
- package/src/parser/inline/insertion.test.ts +0 -1
- package/src/parser/inline/link.test.ts +0 -1
- package/src/parser/inline/mark.test.ts +0 -3
- package/src/parser/inline/media.ts +9 -9
- package/src/parser/inline/reference.test.ts +17 -19
- package/src/parser/inline/reference.ts +1 -1
- package/src/parser/inline/strong.test.ts +0 -3
- package/src/parser/inline.ts +3 -3
- package/src/parser/processor/figure.test.ts +25 -25
- package/src/parser/processor/figure.ts +1 -1
- package/src/parser/util.ts +2 -17
- package/src/parser/util.test.ts +0 -14
|
@@ -2,7 +2,7 @@ import { undefined } from 'spica/global';
|
|
|
2
2
|
import { ExtensionParser } from '../../inline';
|
|
3
3
|
import { union, some, validate, guard, context, creator, surround, open, lazy, fmap } from '../../../combinator';
|
|
4
4
|
import { inline } from '../../inline';
|
|
5
|
-
import { indexee,
|
|
5
|
+
import { indexee, identity } from './indexee';
|
|
6
6
|
import { txt, str } from '../../source';
|
|
7
7
|
import { startTight, trimNodeEnd } from '../../util';
|
|
8
8
|
import { html, define, defrag } from 'typed-dom';
|
|
@@ -44,7 +44,7 @@ const signature: IndexParser.SignatureParser = lazy(() => creator(fmap(open(
|
|
|
44
44
|
'|#',
|
|
45
45
|
startTight(some(union([bracket, txt]), ']', /^\\?\n/))),
|
|
46
46
|
ns => [
|
|
47
|
-
html('span', { class: 'indexer', 'data-index':
|
|
47
|
+
html('span', { class: 'indexer', 'data-index': identity(join(ns)).slice(6) }),
|
|
48
48
|
])));
|
|
49
49
|
|
|
50
50
|
const bracket: IndexParser.SignatureParser.BracketParser = lazy(() => creator(union([
|
|
@@ -6,12 +6,16 @@ import { define } from 'typed-dom';
|
|
|
6
6
|
|
|
7
7
|
export function indexee<P extends Parser<unknown, MarkdownParser.Context>>(parser: P): P;
|
|
8
8
|
export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>): Parser<HTMLElement> {
|
|
9
|
-
return fmap(parser, ([el], _, { id }) => [define(el, { id: id !== '' && identity(el) || undefined })]);
|
|
9
|
+
return fmap(parser, ([el], _, { id }) => [define(el, { id: id !== '' && identity(text(el)) || undefined })]);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function identity(
|
|
13
|
-
|
|
12
|
+
export function identity(index: string): string {
|
|
13
|
+
assert(!index.includes('\n'));
|
|
14
|
+
return `index:${index.trim().replace(/\s+/g, '_').slice(0, 101).replace(/^(.{97}).{4}$/, '$1...')}`;
|
|
14
15
|
}
|
|
16
|
+
assert(identity('0'.repeat(100)).slice(6) === '0'.repeat(100));
|
|
17
|
+
assert(identity('0'.repeat(101)).slice(6) === '0'.repeat(97) + '...');
|
|
18
|
+
assert(identity('0'.repeat(200)).slice(6) === '0'.repeat(97) + '...');
|
|
15
19
|
|
|
16
20
|
export function text(source: HTMLElement | DocumentFragment): string {
|
|
17
21
|
assert(source instanceof DocumentFragment || !source.matches('.indexer'));
|
|
@@ -22,34 +26,32 @@ export function text(source: HTMLElement | DocumentFragment): string {
|
|
|
22
26
|
if (indexer) return indexer.getAttribute('data-index')!;
|
|
23
27
|
const target = source.cloneNode(true) as typeof source;
|
|
24
28
|
for (
|
|
25
|
-
let es = target.querySelectorAll('code[data-src], .math[data-src], rt, rp, .reference'),
|
|
29
|
+
let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference'),
|
|
26
30
|
i = 0, len = es.length; i < len; ++i) {
|
|
27
31
|
const el = es[i];
|
|
28
32
|
switch (el.tagName) {
|
|
33
|
+
case 'CODE':
|
|
34
|
+
define(el, el.getAttribute('data-src')!);
|
|
35
|
+
continue;
|
|
29
36
|
case 'RT':
|
|
30
37
|
case 'RP':
|
|
31
38
|
el.remove();
|
|
32
39
|
continue;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
default:
|
|
40
|
+
}
|
|
41
|
+
switch (el.className) {
|
|
42
|
+
case 'math':
|
|
37
43
|
define(el, el.getAttribute('data-src')!);
|
|
38
44
|
continue;
|
|
45
|
+
case 'comment':
|
|
46
|
+
el.remove();
|
|
47
|
+
continue;
|
|
48
|
+
case 'reference':
|
|
49
|
+
assert(el.firstElementChild?.hasAttribute('hidden'));
|
|
50
|
+
el.firstChild!.remove();
|
|
51
|
+
continue;
|
|
39
52
|
}
|
|
40
53
|
}
|
|
41
54
|
// Better:
|
|
42
55
|
//return target.innerText;
|
|
43
56
|
return target.textContent!;
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
export function identify(index: string): string {
|
|
47
|
-
assert(!index.includes('\n'));
|
|
48
|
-
assert(index === index.trim());
|
|
49
|
-
return index
|
|
50
|
-
? `index:${index.replace(/\s+/g, '_').slice(0, 101).replace(/^(.{97}).{4}$/, '$1...')}`
|
|
51
|
-
: '';
|
|
52
|
-
}
|
|
53
|
-
assert(identify('0'.repeat(100)).slice(6) === '0'.repeat(100));
|
|
54
|
-
assert(identify('0'.repeat(101)).slice(6) === '0'.repeat(97) + '...');
|
|
55
|
-
assert(identify('0'.repeat(200)).slice(6) === '0'.repeat(97) + '...');
|
|
@@ -20,8 +20,6 @@ describe('Unit: parser/inline/extension/placeholder', () => {
|
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('[^\n]')), undefined);
|
|
21
21
|
assert.deepStrictEqual(inspect(parser('[^\na]')), undefined);
|
|
22
22
|
assert.deepStrictEqual(inspect(parser('[^\\\na]')), undefined);
|
|
23
|
-
assert.deepStrictEqual(inspect(parser('[^[# a #]]')), undefined);
|
|
24
|
-
assert.deepStrictEqual(inspect(parser('[^[# a #]b]')), undefined);
|
|
25
23
|
assert.deepStrictEqual(inspect(parser('[^ !http://host]')), undefined);
|
|
26
24
|
assert.deepStrictEqual(inspect(parser('[^a')), undefined);
|
|
27
25
|
assert.deepStrictEqual(inspect(parser('[^a\n]')), undefined);
|
|
@@ -41,17 +39,19 @@ describe('Unit: parser/inline/extension/placeholder', () => {
|
|
|
41
39
|
it('valid', () => {
|
|
42
40
|
assert.deepStrictEqual(inspect(parser('[^a]')), [['<span class="invalid">a</span>'], '']);
|
|
43
41
|
assert.deepStrictEqual(inspect(parser('[^a b]')), [['<span class="invalid">a b</span>'], '']);
|
|
44
|
-
assert.deepStrictEqual(inspect(parser('[^\\]]')), [['<span class="invalid">]</span>'], '']);
|
|
45
|
-
assert.deepStrictEqual(inspect(parser('[^(])]')), [['<span class="invalid"><span class="paren">(])</span></span>'], '']);
|
|
46
|
-
assert.deepStrictEqual(inspect(parser('[^!http://host]')), [['<span class="invalid"><a href="http://host" target="_blank"><img class="media" data-src="http://host" alt=""></a></span>'], '']);
|
|
47
42
|
assert.deepStrictEqual(inspect(parser('[^a ]')), [['<span class="invalid">a </span>'], '']);
|
|
48
43
|
assert.deepStrictEqual(inspect(parser('[^a ]')), [['<span class="invalid">a </span>'], '']);
|
|
49
44
|
assert.deepStrictEqual(inspect(parser('[^a\\ ]')), [['<span class="invalid">a </span>'], '']);
|
|
50
45
|
assert.deepStrictEqual(inspect(parser('[^a\\ \\ ]')), [['<span class="invalid">a </span>'], '']);
|
|
51
46
|
assert.deepStrictEqual(inspect(parser('[^a<wbr>]')), [['<span class="invalid">a<wbr></span>'], '']);
|
|
52
47
|
assert.deepStrictEqual(inspect(parser('[^a<wbr><wbr>]')), [['<span class="invalid">a<wbr><wbr></span>'], '']);
|
|
53
|
-
assert.deepStrictEqual(inspect(parser('[^a[# b #]]')), [['<span class="invalid">a<
|
|
54
|
-
assert.deepStrictEqual(inspect(parser('[^a[# b #][# c #]]')), [['<span class="invalid">a<
|
|
48
|
+
assert.deepStrictEqual(inspect(parser('[^a[# b #]]')), [['<span class="invalid">a<span class="comment">[# b #]</span></span>'], '']);
|
|
49
|
+
assert.deepStrictEqual(inspect(parser('[^a[# b #][# c #]]')), [['<span class="invalid">a<span class="comment">[# b #]</span><span class="comment">[# c #]</span></span>'], '']);
|
|
50
|
+
assert.deepStrictEqual(inspect(parser('[^\\]]')), [['<span class="invalid">]</span>'], '']);
|
|
51
|
+
assert.deepStrictEqual(inspect(parser('[^(])]')), [['<span class="invalid"><span class="paren">(])</span></span>'], '']);
|
|
52
|
+
assert.deepStrictEqual(inspect(parser('[^!http://host]')), [['<span class="invalid"><a href="http://host" target="_blank"><img class="media" data-src="http://host" alt=""></a></span>'], '']);
|
|
53
|
+
assert.deepStrictEqual(inspect(parser('[^[# a #]]')), [['<span class="invalid"><span class="comment">[# a #]</span></span>'], '']);
|
|
54
|
+
assert.deepStrictEqual(inspect(parser('[^[# a #]b]')), [['<span class="invalid"><span class="comment">[# a #]</span>b</span>'], '']);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
});
|
|
@@ -26,7 +26,6 @@ describe('Unit: parser/inline/insertion', () => {
|
|
|
26
26
|
assert.deepStrictEqual(inspect(parser('++\na++')), [['<ins><br>a</ins>'], '']);
|
|
27
27
|
assert.deepStrictEqual(inspect(parser('++\\\na++')), [['<ins><span class="linebreak"> </span>a</ins>'], '']);
|
|
28
28
|
assert.deepStrictEqual(inspect(parser('++<wbr>a++')), [['<ins><wbr>a</ins>'], '']);
|
|
29
|
-
assert.deepStrictEqual(inspect(parser('++[# a #]b++')), [['<ins><sup class="comment" title="a"></sup>b</ins>'], '']);
|
|
30
29
|
assert.deepStrictEqual(inspect(parser('++a\n++')), [['<ins>a</ins>'], '']);
|
|
31
30
|
assert.deepStrictEqual(inspect(parser('++a\nb++')), [['<ins>a<br>b</ins>'], '']);
|
|
32
31
|
assert.deepStrictEqual(inspect(parser('++a\\\nb++')), [['<ins>a<span class="linebreak"> </span>b</ins>'], '']);
|
|
@@ -72,7 +72,6 @@ describe('Unit: parser/inline/link', () => {
|
|
|
72
72
|
assert.deepStrictEqual(inspect(parser('[a\nb]{b}')), undefined);
|
|
73
73
|
assert.deepStrictEqual(inspect(parser('[a\\\nb]{b}')), undefined);
|
|
74
74
|
assert.deepStrictEqual(inspect(parser('[<wbr>]{b}')), undefined);
|
|
75
|
-
assert.deepStrictEqual(inspect(parser('[[# a #]]{b}')), undefined);
|
|
76
75
|
assert.deepStrictEqual(inspect(parser('[*a\nb*]{/}')), undefined);
|
|
77
76
|
assert.deepStrictEqual(inspect(parser('[http://host]{http://host}')), undefined);
|
|
78
77
|
assert.deepStrictEqual(inspect(parser('[]{ttp://host}')), [['<a class="invalid">ttp://host</a>'], '']);
|
|
@@ -16,14 +16,12 @@ describe('Unit: parser/inline/mark', () => {
|
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('==a\n==')), [['==', 'a', '<br>'], '==']);
|
|
17
17
|
assert.deepStrictEqual(inspect(parser('==a\\ ==')), [['==', 'a', ' '], '==']);
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('==a\\\n==')), [['==', 'a', '<span class="linebreak"> </span>'], '==']);
|
|
19
|
-
assert.deepStrictEqual(inspect(parser('==a [# b #]==')), [['==', 'a', ' ', '<sup class="comment" title="b"></sup>'], '==']);
|
|
20
19
|
assert.deepStrictEqual(inspect(parser('== ==')), undefined);
|
|
21
20
|
assert.deepStrictEqual(inspect(parser('== a==')), undefined);
|
|
22
21
|
assert.deepStrictEqual(inspect(parser('== a ==')), undefined);
|
|
23
22
|
assert.deepStrictEqual(inspect(parser('==\na==')), undefined);
|
|
24
23
|
assert.deepStrictEqual(inspect(parser('==\\\na==')), undefined);
|
|
25
24
|
assert.deepStrictEqual(inspect(parser('==<wbr>a==')), undefined);
|
|
26
|
-
assert.deepStrictEqual(inspect(parser('==[# a #]b==')), undefined);
|
|
27
25
|
assert.deepStrictEqual(inspect(parser(' ==a==')), undefined);
|
|
28
26
|
});
|
|
29
27
|
|
|
@@ -37,7 +35,6 @@ describe('Unit: parser/inline/mark', () => {
|
|
|
37
35
|
});
|
|
38
36
|
|
|
39
37
|
it('nest', () => {
|
|
40
|
-
assert.deepStrictEqual(inspect(parser('==a[# b #]==')), [['<mark>a<sup class="comment" title="b"></sup></mark>'], '']);
|
|
41
38
|
assert.deepStrictEqual(inspect(parser('==*==a==*==')), [['<mark><em><mark>a</mark></em></mark>'], '']);
|
|
42
39
|
});
|
|
43
40
|
|
|
@@ -73,6 +73,15 @@ function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
|
|
|
73
73
|
case 'http:':
|
|
74
74
|
case 'https:':
|
|
75
75
|
assert(uri.host);
|
|
76
|
+
if (/\/\.\.?(?:\/|$)/.test('/' + uri.source.slice(0, uri.source.search(/[?#]|$/)))) {
|
|
77
|
+
define(target, {
|
|
78
|
+
class: void target.classList.add('invalid'),
|
|
79
|
+
'data-invalid-syntax': 'media',
|
|
80
|
+
'data-invalid-type': 'argument',
|
|
81
|
+
'data-invalid-description': 'Dot-segments cannot be used in media paths; use subresource paths instead.',
|
|
82
|
+
});
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
76
85
|
break;
|
|
77
86
|
default:
|
|
78
87
|
define(target, {
|
|
@@ -83,15 +92,6 @@ function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
|
|
|
83
92
|
});
|
|
84
93
|
return false;
|
|
85
94
|
}
|
|
86
|
-
if (/\/\.\.?(?:\/|$)/.test('/' + uri.source.slice(0, uri.source.search(/[?#]|$/)))) {
|
|
87
|
-
define(target, {
|
|
88
|
-
class: void target.classList.add('invalid'),
|
|
89
|
-
'data-invalid-syntax': 'media',
|
|
90
|
-
'data-invalid-type': 'argument',
|
|
91
|
-
'data-invalid-description': 'Dot-segments cannot be used in media paths; use subresource paths instead.',
|
|
92
|
-
});
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
95
|
if (alt.includes('\0')) {
|
|
96
96
|
define(target, {
|
|
97
97
|
class: void target.classList.add('invalid'),
|
|
@@ -23,7 +23,6 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
23
23
|
assert.deepStrictEqual(inspect(parser('[[a\nb]]')), undefined);
|
|
24
24
|
assert.deepStrictEqual(inspect(parser('[[a\\\nb]]')), undefined);
|
|
25
25
|
assert.deepStrictEqual(inspect(parser('[[<wbr>a]]')), undefined);
|
|
26
|
-
assert.deepStrictEqual(inspect(parser('[[[# a #]b]]')), undefined);
|
|
27
26
|
assert.deepStrictEqual(inspect(parser('[[a]b]]')), undefined);
|
|
28
27
|
assert.deepStrictEqual(inspect(parser('[[*a\nb*]]')), undefined);
|
|
29
28
|
assert.deepStrictEqual(inspect(parser('[[\\]]')), undefined);
|
|
@@ -39,7 +38,6 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
39
38
|
assert.deepStrictEqual(inspect(parser('[[a ]]')), [['<sup class="reference">a</sup>'], '']);
|
|
40
39
|
assert.deepStrictEqual(inspect(parser('[[a ]]')), [['<sup class="reference">a</sup>'], '']);
|
|
41
40
|
assert.deepStrictEqual(inspect(parser('[[a <wbr>]]')), [['<sup class="reference">a</sup>'], '']);
|
|
42
|
-
assert.deepStrictEqual(inspect(parser('[[a [# b #]]]')), [['<sup class="reference">a <sup class="comment" title="b"></sup></sup>'], '']);
|
|
43
41
|
assert.deepStrictEqual(inspect(parser('[[ab]]')), [['<sup class="reference">ab</sup>'], '']);
|
|
44
42
|
});
|
|
45
43
|
|
|
@@ -55,46 +53,46 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
55
53
|
});
|
|
56
54
|
|
|
57
55
|
it('abbr', () => {
|
|
58
|
-
assert.deepStrictEqual(inspect(parser('[[^]]')), [['<sup class="
|
|
56
|
+
assert.deepStrictEqual(inspect(parser('[[^]]')), [['<sup class="invalid">^</sup>'], '']);
|
|
59
57
|
assert.deepStrictEqual(inspect(parser('[[^a]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
60
58
|
assert.deepStrictEqual(inspect(parser('[[^a,]]')), [['<sup class="reference" data-abbr="a,"></sup>'], '']);
|
|
61
59
|
assert.deepStrictEqual(inspect(parser('[[^a, ]]')), [['<sup class="reference" data-abbr="a,"></sup>'], '']);
|
|
62
60
|
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
63
|
-
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="
|
|
61
|
+
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="invalid">^a</sup>'], '']);
|
|
64
62
|
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="reference" data-abbr="a b"></sup>'], '']);
|
|
65
|
-
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="
|
|
63
|
+
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="invalid">^a b</sup>'], '']);
|
|
66
64
|
assert.deepStrictEqual(inspect(parser('[[^a|]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
67
65
|
assert.deepStrictEqual(inspect(parser('[[^a,|]]')), [['<sup class="reference" data-abbr="a,"></sup>'], '']);
|
|
68
66
|
assert.deepStrictEqual(inspect(parser('[[^a |]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
69
|
-
assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="
|
|
67
|
+
assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="invalid">^a|b</sup>'], '']);
|
|
70
68
|
assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
71
69
|
assert.deepStrictEqual(inspect(parser('[[^a| b]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
72
70
|
assert.deepStrictEqual(inspect(parser('[[^a| b ]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
73
71
|
assert.deepStrictEqual(inspect(parser('[[^a| b ]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
74
72
|
assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"></sup>'], '']);
|
|
75
73
|
assert.deepStrictEqual(inspect(parser('[[^a| b]]')), [['<sup class="reference" data-abbr="a">b</sup>'], '']);
|
|
76
|
-
assert.deepStrictEqual(inspect(parser('[[^a| <wbr>]]')), [['<sup class="
|
|
77
|
-
assert.deepStrictEqual(inspect(parser('[[^a| <wbr>b]]')), [['<sup class="
|
|
74
|
+
assert.deepStrictEqual(inspect(parser('[[^a| <wbr>]]')), [['<sup class="invalid">^a|</sup>'], '']);
|
|
75
|
+
assert.deepStrictEqual(inspect(parser('[[^a| <wbr>b]]')), [['<sup class="invalid">^a| <wbr>b</sup>'], '']);
|
|
78
76
|
assert.deepStrictEqual(inspect(parser('[[^a| ^b]]')), [['<sup class="reference" data-abbr="a">^b</sup>'], '']);
|
|
79
|
-
assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="
|
|
77
|
+
assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="invalid">^1</sup>'], '']);
|
|
80
78
|
assert.deepStrictEqual(inspect(parser('[[^1a]]')), [['<sup class="reference" data-abbr="1a"></sup>'], '']);
|
|
81
|
-
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="
|
|
79
|
+
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid">^1</sup>'], '']);
|
|
82
80
|
assert.deepStrictEqual(inspect(parser('[[^1 a]]')), [['<sup class="reference" data-abbr="1 a"></sup>'], '']);
|
|
83
|
-
assert.deepStrictEqual(inspect(parser('[[^1|]]')), [['<sup class="
|
|
84
|
-
assert.deepStrictEqual(inspect(parser('[[^1 |]]')), [['<sup class="
|
|
81
|
+
assert.deepStrictEqual(inspect(parser('[[^1|]]')), [['<sup class="invalid">^1|</sup>'], '']);
|
|
82
|
+
assert.deepStrictEqual(inspect(parser('[[^1 |]]')), [['<sup class="invalid">^1 |</sup>'], '']);
|
|
85
83
|
assert.deepStrictEqual(inspect(parser('[[^Xyz2020]]')), [['<sup class="reference" data-abbr="Xyz2020"></sup>'], '']);
|
|
86
84
|
assert.deepStrictEqual(inspect(parser('[[^Xyz 2020]]')), [['<sup class="reference" data-abbr="Xyz 2020"></sup>'], '']);
|
|
87
85
|
assert.deepStrictEqual(inspect(parser('[[^Xyz, 2020, p1-2]]')), [['<sup class="reference" data-abbr="Xyz, 2020, p1-2"></sup>'], '']);
|
|
88
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"></sup>'], '']);
|
|
89
87
|
assert.deepStrictEqual(inspect(parser(`[[^A's, Aces']]`)), [[`<sup class="reference" data-abbr="A's, Aces'"></sup>`], '']);
|
|
90
|
-
assert.deepStrictEqual(inspect(parser('[[^^]]')), [['<sup class="
|
|
88
|
+
assert.deepStrictEqual(inspect(parser('[[^^]]')), [['<sup class="invalid">^^</sup>'], '']);
|
|
91
89
|
assert.deepStrictEqual(inspect(parser('[[\\^]]')), [['<sup class="reference">^</sup>'], '']);
|
|
92
|
-
assert.deepStrictEqual(inspect(parser('[[^ ]]')), [['<sup class="
|
|
93
|
-
assert.deepStrictEqual(inspect(parser('[[^ a]]')), [['<sup class="
|
|
94
|
-
assert.deepStrictEqual(inspect(parser('[[^ |]]')), [['<sup class="
|
|
95
|
-
assert.deepStrictEqual(inspect(parser('[[^ |b]]')), [['<sup class="
|
|
96
|
-
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="
|
|
97
|
-
assert.deepStrictEqual(inspect(parser('[[^ | b]]')), [['<sup class="
|
|
90
|
+
assert.deepStrictEqual(inspect(parser('[[^ ]]')), [['<sup class="invalid">^</sup>'], '']);
|
|
91
|
+
assert.deepStrictEqual(inspect(parser('[[^ a]]')), [['<sup class="invalid">^ a</sup>'], '']);
|
|
92
|
+
assert.deepStrictEqual(inspect(parser('[[^ |]]')), [['<sup class="invalid">^ |</sup>'], '']);
|
|
93
|
+
assert.deepStrictEqual(inspect(parser('[[^ |b]]')), [['<sup class="invalid">^ |b</sup>'], '']);
|
|
94
|
+
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid">^ |</sup>'], '']);
|
|
95
|
+
assert.deepStrictEqual(inspect(parser('[[^ | b]]')), [['<sup class="invalid">^ | b</sup>'], '']);
|
|
98
96
|
});
|
|
99
97
|
|
|
100
98
|
});
|
|
@@ -43,7 +43,7 @@ function attributes(ns: (string | HTMLElement)[]): Record<string, string | undef
|
|
|
43
43
|
}
|
|
44
44
|
: ns[0] === ''
|
|
45
45
|
? {
|
|
46
|
-
class: '
|
|
46
|
+
class: 'invalid',
|
|
47
47
|
'data-invalid-syntax': 'reference',
|
|
48
48
|
'data-invalid-type': 'syntax',
|
|
49
49
|
'data-invalid-description': 'Invalid abbr.',
|
|
@@ -15,7 +15,6 @@ describe('Unit: parser/inline/strong', () => {
|
|
|
15
15
|
assert.deepStrictEqual(inspect(parser('**a\\ **')), [['**', 'a', ' '], '**']);
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('**a\\\n**')), [['**', 'a', '<span class="linebreak"> </span>'], '**']);
|
|
17
17
|
assert.deepStrictEqual(inspect(parser('**a*b**')), [['**', 'a', '<em>b</em>', '*'], '']);
|
|
18
|
-
assert.deepStrictEqual(inspect(parser('**a [# b #]**')), [['**', 'a', ' ', '<sup class="comment" title="b"></sup>'], '**']);
|
|
19
18
|
assert.deepStrictEqual(inspect(parser('** **')), undefined);
|
|
20
19
|
assert.deepStrictEqual(inspect(parser('** a**')), undefined);
|
|
21
20
|
assert.deepStrictEqual(inspect(parser('** a **')), undefined);
|
|
@@ -24,7 +23,6 @@ describe('Unit: parser/inline/strong', () => {
|
|
|
24
23
|
assert.deepStrictEqual(inspect(parser('**\\ a**')), undefined);
|
|
25
24
|
assert.deepStrictEqual(inspect(parser('**\\\na**')), undefined);
|
|
26
25
|
assert.deepStrictEqual(inspect(parser('**<wbr>a**')), undefined);
|
|
27
|
-
assert.deepStrictEqual(inspect(parser('**[# a #]b**')), undefined);
|
|
28
26
|
assert.deepStrictEqual(inspect(parser('***a***')), undefined);
|
|
29
27
|
assert.deepStrictEqual(inspect(parser(' **a**')), undefined);
|
|
30
28
|
});
|
|
@@ -40,7 +38,6 @@ describe('Unit: parser/inline/strong', () => {
|
|
|
40
38
|
assert.deepStrictEqual(inspect(parser('**a*b*c**')), [['<strong>a<em>b</em>c</strong>'], '']);
|
|
41
39
|
assert.deepStrictEqual(inspect(parser('**a*b*c**d')), [['<strong>a<em>b</em>c</strong>'], 'd']);
|
|
42
40
|
assert.deepStrictEqual(inspect(parser('**a *b***')), [['<strong>a <em>b</em></strong>'], '']);
|
|
43
|
-
assert.deepStrictEqual(inspect(parser('**a[# b #]**')), [['<strong>a<sup class="comment" title="b"></sup></strong>'], '']);
|
|
44
41
|
assert.deepStrictEqual(inspect(parser('**`a`**')), [['<strong><code data-src="`a`">a</code></strong>'], '']);
|
|
45
42
|
assert.deepStrictEqual(inspect(parser('**<small>**')), [['<strong><small></strong>'], '']);
|
|
46
43
|
assert.deepStrictEqual(inspect(parser('**(*a*)**')), [['<strong><span class="paren">(<em>a</em>)</span></strong>'], '']);
|
package/src/parser/inline.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { escape } from './inline/escape';
|
|
|
4
4
|
import { annotation } from './inline/annotation';
|
|
5
5
|
import { reference } from './inline/reference';
|
|
6
6
|
import { template } from './inline/template';
|
|
7
|
+
import { comment } from './inline/comment';
|
|
7
8
|
import { extension } from './inline/extension';
|
|
8
9
|
import { ruby } from './inline/ruby';
|
|
9
10
|
import { link } from './inline/link';
|
|
10
11
|
import { html } from './inline/html';
|
|
11
|
-
import { comment } from './inline/comment';
|
|
12
12
|
import { insertion } from './inline/insertion';
|
|
13
13
|
import { deletion } from './inline/deletion';
|
|
14
14
|
import { mark } from './inline/mark';
|
|
@@ -29,11 +29,11 @@ export import EscapeParser = InlineParser.EscapeParser;
|
|
|
29
29
|
export import AnnotationParser = InlineParser.AnnotationParser;
|
|
30
30
|
export import ReferenceParser = InlineParser.ReferenceParser;
|
|
31
31
|
export import TemplateParser = InlineParser.TemplateParser;
|
|
32
|
+
export import CommentParser = InlineParser.CommentParser;
|
|
32
33
|
export import ExtensionParser = InlineParser.ExtensionParser;
|
|
33
34
|
export import RubyParser = InlineParser.RubyParser;
|
|
34
35
|
export import LinkParser = InlineParser.LinkParser;
|
|
35
36
|
export import HTMLParser = InlineParser.HTMLParser;
|
|
36
|
-
export import CommentParser = InlineParser.CommentParser;
|
|
37
37
|
export import InsertionParser = InlineParser.InsertionParser;
|
|
38
38
|
export import DeletionParser = InlineParser.DeletionParser;
|
|
39
39
|
export import MarkParser = InlineParser.MarkParser;
|
|
@@ -54,12 +54,12 @@ export const inline: InlineParser = union([
|
|
|
54
54
|
annotation,
|
|
55
55
|
reference,
|
|
56
56
|
template,
|
|
57
|
+
comment,
|
|
57
58
|
extension,
|
|
58
59
|
ruby,
|
|
59
60
|
link,
|
|
60
61
|
media,
|
|
61
62
|
html,
|
|
62
|
-
comment,
|
|
63
63
|
insertion,
|
|
64
64
|
deletion,
|
|
65
65
|
mark,
|
|
@@ -28,7 +28,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
28
28
|
assert.deepStrictEqual(
|
|
29
29
|
[...target.children].map(el => el.outerHTML),
|
|
30
30
|
[
|
|
31
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
31
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
32
32
|
'<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
|
|
33
33
|
'<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
|
|
34
34
|
]);
|
|
@@ -47,10 +47,10 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
47
47
|
assert.deepStrictEqual(
|
|
48
48
|
[...target.children].map(el => el.outerHTML),
|
|
49
49
|
[
|
|
50
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
50
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
51
51
|
'<h2 id="index:0">0</h2>',
|
|
52
|
-
'<figure data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2
|
|
53
|
-
'<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Table 1
|
|
52
|
+
'<figure data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2. </span><figcaption></figcaption></figure>',
|
|
53
|
+
'<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Table 1. </span><figcaption></figcaption></figure>',
|
|
54
54
|
]);
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -87,11 +87,11 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
87
87
|
assert.deepStrictEqual(
|
|
88
88
|
[...target.children].map(el => el.outerHTML),
|
|
89
89
|
[
|
|
90
|
-
'<figure data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2
|
|
91
|
-
'<figure data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 3.1
|
|
90
|
+
'<figure data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2. </span><figcaption></figcaption></figure>',
|
|
91
|
+
'<figure data-label="fig-3.1" data-group="fig" data-number="3.1" id="label:fig-3.1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 3.1. </span><figcaption></figcaption></figure>',
|
|
92
92
|
'<figure data-label="$-4.1.1" data-group="$" data-number="4.1.1" id="label:$-4.1.1"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><span class="figindex">(4.1.1)</span><figcaption></figcaption></figure>',
|
|
93
93
|
'<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><span class="figindex">(1)</span><figcaption></figcaption></figure>',
|
|
94
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
94
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
95
95
|
'<p><a class="label" data-label="fig-2" href="#label:fig-2">Fig. 2</a></p>',
|
|
96
96
|
'<p><a class="label" data-label="$-4.1.1" href="#label:$-4.1.1">(4.1.1)</a></p>',
|
|
97
97
|
'<p><a class="label disabled invalid" data-label="fig-1" data-invalid-syntax="label" data-invalid-type="reference" data-invalid-description="Missing the reference.">$fig-1</a></p>',
|
|
@@ -111,10 +111,10 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
111
111
|
assert.deepStrictEqual(
|
|
112
112
|
[...target.children].map(el => el.outerHTML),
|
|
113
113
|
[
|
|
114
|
-
'<blockquote><blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
115
|
-
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n> \n\n~~~\n\n$fig-a</pre><hr><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
116
|
-
'<figure data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
117
|
-
'<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2
|
|
114
|
+
'<blockquote><blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
|
|
115
|
+
'<aside class="example" data-type="markdown"><pre translate="no">~~~figure $fig-a\n> \n\n~~~\n\n$fig-a</pre><hr><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure><p><a class="label disabled" data-label="fig-a">Fig. 1</a></p><ol class="annotations"></ol><ol class="references"></ol></section></aside>',
|
|
116
|
+
'<figure data-label="fig-b" data-group="fig" data-number="1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
117
|
+
'<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2. </span><figcaption></figcaption></figure>',
|
|
118
118
|
]);
|
|
119
119
|
}
|
|
120
120
|
});
|
|
@@ -163,16 +163,16 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
163
163
|
'<h1 id="index:0">0</h1>',
|
|
164
164
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="0.0"></figure>',
|
|
165
165
|
'<h2 id="index:0">0</h2>',
|
|
166
|
-
'<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
166
|
+
'<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
167
167
|
'<h2 id="index:0">0</h2>',
|
|
168
168
|
'<blockquote><section><h2>0</h2><ol class="annotations"></ol><ol class="references"></ol></section></blockquote>',
|
|
169
|
-
'<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2.1
|
|
169
|
+
'<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2.1. </span><figcaption></figcaption></figure>',
|
|
170
170
|
'<h2 id="index:0">0</h2>',
|
|
171
171
|
'<figure data-label="$-0.0.0" data-group="$" hidden=""></figure>',
|
|
172
|
-
'<figure data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 3.1
|
|
172
|
+
'<figure data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 3.1. </span><figcaption></figcaption></figure>',
|
|
173
173
|
'<h2 id="index:0">0</h2>',
|
|
174
174
|
'<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
|
|
175
|
-
'<figure data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 4.1
|
|
175
|
+
'<figure data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 4.1. </span><figcaption></figcaption></figure>',
|
|
176
176
|
'<figure data-label="$-0.0" data-group="$" hidden=""></figure>',
|
|
177
177
|
'<figure data-label="$-0.1.0" data-group="$" hidden=""></figure>',
|
|
178
178
|
'<figure data-label="$-0.4.0" data-group="$" hidden=""></figure>',
|
|
@@ -180,19 +180,19 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
180
180
|
'<h2 id="index:0">0</h2>',
|
|
181
181
|
'<h2 id="index:0">0</h2>',
|
|
182
182
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="6.0"></figure>',
|
|
183
|
-
'<figure data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 6.1
|
|
183
|
+
'<figure data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 6.1. </span><figcaption></figcaption></figure>',
|
|
184
184
|
'<h2 id="index:0">0</h2>',
|
|
185
185
|
'<figure data-label="$-5.0" data-group="$" hidden="" data-number="5.0"></figure>',
|
|
186
|
-
'<figure data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.1
|
|
186
|
+
'<figure data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.1. </span><figcaption></figcaption></figure>',
|
|
187
187
|
'<figure data-label="$-0" data-group="$" hidden=""></figure>',
|
|
188
|
-
'<figure data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.2
|
|
188
|
+
'<figure data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.2. </span><figcaption></figcaption></figure>',
|
|
189
189
|
'<h3 id="index:0">0</h3>',
|
|
190
190
|
'<figure data-label="$-0.0.0" data-group="$" hidden=""></figure>',
|
|
191
|
-
'<figure data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.3
|
|
191
|
+
'<figure data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.3. </span><figcaption></figcaption></figure>',
|
|
192
192
|
'<h3 id="index:0">0</h3>',
|
|
193
|
-
'<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.4
|
|
193
|
+
'<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 5.4. </span><figcaption></figcaption></figure>',
|
|
194
194
|
'<h1 id="index:0">0</h1>',
|
|
195
|
-
'<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 6.1
|
|
195
|
+
'<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 6.1. </span><figcaption></figcaption></figure>',
|
|
196
196
|
]);
|
|
197
197
|
}
|
|
198
198
|
});
|
|
@@ -219,10 +219,10 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
219
219
|
'<h2 id="index:0">0</h2>',
|
|
220
220
|
'<h2 id="index:0">0</h2>',
|
|
221
221
|
'<figure data-label="$-1.0" data-group="$" hidden="" data-number="1.0"></figure>',
|
|
222
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1.1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1.1
|
|
222
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1.1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1.1. </span><figcaption></figcaption></figure>',
|
|
223
223
|
'<h2 id="index:0">0</h2>',
|
|
224
224
|
'<figure data-label="$-0.0" data-group="$" hidden="" data-number="2.0"></figure>',
|
|
225
|
-
'<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2.1
|
|
225
|
+
'<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 2.1. </span><figcaption></figcaption></figure>',
|
|
226
226
|
]);
|
|
227
227
|
}
|
|
228
228
|
});
|
|
@@ -238,7 +238,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
238
238
|
assert.deepStrictEqual(
|
|
239
239
|
[...target.children].map(el => el.outerHTML),
|
|
240
240
|
[
|
|
241
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
241
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
242
242
|
'<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
|
|
243
243
|
'<p><a class="label" data-label="fig-a" href="#label:fig-a">Fig. 1</a></p>',
|
|
244
244
|
]);
|
|
@@ -255,7 +255,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
255
255
|
assert.deepStrictEqual(
|
|
256
256
|
[...target.children].map(el => el.outerHTML),
|
|
257
257
|
[
|
|
258
|
-
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1
|
|
258
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div class="figcontent"><blockquote></blockquote></div><span class="figindex">Fig. 1. </span><figcaption></figcaption></figure>',
|
|
259
259
|
'<p><a class="label" data-label="fig-a" href="#label:0:fig-a">Fig. 1</a></p>',
|
|
260
260
|
]);
|
|
261
261
|
}
|
|
@@ -86,7 +86,7 @@ export function* figure(
|
|
|
86
86
|
: `${capitalize(group)}${group === 'fig' ? '.' : ''} ${number}`;
|
|
87
87
|
define(
|
|
88
88
|
def.querySelector(':scope > .figindex')!,
|
|
89
|
-
group === '$' ? figindex : `${figindex}
|
|
89
|
+
group === '$' ? figindex : `${figindex}. `);
|
|
90
90
|
for (const ref of refs.take(label, Infinity)) {
|
|
91
91
|
if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
|
|
92
92
|
yield define(ref,
|
package/src/parser/util.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { undefined } from 'spica/global';
|
|
|
2
2
|
import { MarkdownParser } from '../../markdown';
|
|
3
3
|
import { Parser, eval } from '../combinator/data/parser';
|
|
4
4
|
import { union, some, verify, convert } from '../combinator';
|
|
5
|
-
import { comment } from './inline/comment';
|
|
6
5
|
import { unsafehtmlentity } from './inline/htmlentity';
|
|
7
6
|
import { linebreak, unescsource } from './source';
|
|
8
7
|
import { push, pop } from 'spica/array';
|
|
@@ -42,13 +41,13 @@ const invisibleHTMLEntityNames = [
|
|
|
42
41
|
'InvisibleComma',
|
|
43
42
|
'ic',
|
|
44
43
|
];
|
|
45
|
-
const blankline = new RegExp(String.raw`^(?!$)(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr
|
|
44
|
+
const blankline = new RegExp(String.raw`^(?!$)(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`, 'gm');
|
|
46
45
|
|
|
47
46
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
48
47
|
export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
49
48
|
return union([
|
|
50
49
|
convert(
|
|
51
|
-
source => source.replace(blankline,
|
|
50
|
+
source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
|
|
52
51
|
verify(parser, (ns, rest, context) => !rest && hasVisible(ns, context))),
|
|
53
52
|
some(union([linebreak, unescsource])),
|
|
54
53
|
]);
|
|
@@ -117,15 +116,6 @@ function isStartTight(source: string, context: MarkdownParser.Context): boolean
|
|
|
117
116
|
return false;
|
|
118
117
|
}
|
|
119
118
|
return true;
|
|
120
|
-
case '[':
|
|
121
|
-
switch (true) {
|
|
122
|
-
case source.length >= 7
|
|
123
|
-
&& source[1] === '#'
|
|
124
|
-
&& eval(comment(source, context))?.[0].className === 'comment':
|
|
125
|
-
assert(!eval(comment(source, context))?.[0].matches('.invalid'));
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return true;
|
|
129
119
|
default:
|
|
130
120
|
return source[0].trimStart() !== '';
|
|
131
121
|
}
|
|
@@ -138,7 +128,6 @@ export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boole
|
|
|
138
128
|
if (nodes.length === 0) return true;
|
|
139
129
|
for (let i = nodes.length; i--;) {
|
|
140
130
|
const node = nodes[i];
|
|
141
|
-
if (typeof node === 'object' && node.className === 'comment') continue;
|
|
142
131
|
return isVisible(node, -1);
|
|
143
132
|
}
|
|
144
133
|
return false;
|
|
@@ -165,8 +154,6 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
|
165
154
|
return false;
|
|
166
155
|
case 'SPAN':
|
|
167
156
|
return node.className !== 'linebreak';
|
|
168
|
-
case 'SUP':
|
|
169
|
-
return node.className !== 'comment';
|
|
170
157
|
default:
|
|
171
158
|
return true;
|
|
172
159
|
}
|
|
@@ -179,7 +166,6 @@ export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string
|
|
|
179
166
|
function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
180
167
|
for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
181
168
|
if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
182
|
-
if (typeof node === 'object' && node.className === 'comment') break;
|
|
183
169
|
if (typeof node === 'string') {
|
|
184
170
|
const pos = node.length - node.trimStart().length;
|
|
185
171
|
if (pos > 0) {
|
|
@@ -198,7 +184,6 @@ export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | str
|
|
|
198
184
|
? [nodes.pop()!]
|
|
199
185
|
: [];
|
|
200
186
|
for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[nodes.length - 1], -1);) {
|
|
201
|
-
if (typeof node === 'object' && node.className === 'comment') break;
|
|
202
187
|
if (typeof node === 'string') {
|
|
203
188
|
const pos = node.trimEnd().length;
|
|
204
189
|
if (pos > 0) {
|