securemark 0.234.2 → 0.235.1
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/dist/securemark.js +173 -158
- package/package-lock.json +40 -37
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.ts +0 -2
- package/src/combinator/control/constraint/contract.ts +1 -1
- package/src/combinator/control/manipulation/context.test.ts +4 -4
- package/src/combinator/control/manipulation/context.ts +7 -0
- package/src/combinator/control/manipulation/match.ts +1 -1
- package/src/combinator/control/manipulation/resource.ts +6 -3
- package/src/combinator/control/manipulation/scope.ts +1 -1
- package/src/combinator/control/manipulation/surround.ts +3 -4
- package/src/combinator/data/parser/inits.ts +1 -1
- package/src/combinator/data/parser/sequence.ts +1 -1
- package/src/combinator/data/parser/some.ts +41 -21
- package/src/combinator/data/parser.ts +33 -7
- package/src/parser/api/bind.test.ts +3 -3
- package/src/parser/api/normalize.ts +7 -6
- package/src/parser/api/parse.test.ts +12 -5
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/extension/aside.test.ts +1 -1
- package/src/parser/block/extension/example.test.ts +2 -2
- package/src/parser/block/extension/fig.test.ts +20 -20
- package/src/parser/block/extension/figure.test.ts +31 -28
- package/src/parser/block/extension/figure.ts +4 -2
- package/src/parser/block/extension/table.ts +6 -6
- package/src/parser/block/heading.test.ts +1 -1
- package/src/parser/block.ts +1 -2
- package/src/parser/inline/bracket.ts +3 -3
- package/src/parser/inline/emphasis.ts +7 -10
- package/src/parser/inline/emstrong.ts +7 -8
- package/src/parser/inline/extension/index.test.ts +19 -18
- package/src/parser/inline/extension/index.ts +3 -4
- package/src/parser/inline/extension/indexer.test.ts +1 -0
- package/src/parser/inline/extension/indexer.ts +1 -0
- package/src/parser/inline/html.ts +7 -11
- package/src/parser/inline/htmlentity.ts +8 -11
- package/src/parser/inline/link.ts +3 -4
- package/src/parser/inline/mark.ts +3 -6
- package/src/parser/inline/media.ts +8 -5
- package/src/parser/inline/ruby.ts +3 -4
- package/src/parser/inline/strong.test.ts +1 -1
- package/src/parser/inline/strong.ts +7 -10
- package/src/parser/inline.test.ts +0 -1
- package/src/parser/processor/figure.test.ts +28 -28
- package/src/parser/processor/figure.ts +1 -1
- package/src/parser/util.ts +14 -51
|
@@ -26,11 +26,9 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
26
26
|
memoize(
|
|
27
27
|
([, tag]) =>
|
|
28
28
|
surround(
|
|
29
|
-
|
|
30
|
-
([,
|
|
31
|
-
[h(tag as 'span', attributes('html', [], attrspec[tag],
|
|
32
|
-
rest
|
|
33
|
-
]),
|
|
29
|
+
`<${tag}`, some(union([attribute])), '>', true,
|
|
30
|
+
([, bs = []], rest) =>
|
|
31
|
+
[[h(tag as 'span', attributes('html', [], attrspec[tag], bs))], rest]),
|
|
34
32
|
([, tag]) => tag)),
|
|
35
33
|
match(
|
|
36
34
|
/^(?=<(sup|sub|small|bdo|bdi)(?=[^\S\n]|>))/,
|
|
@@ -80,9 +78,7 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
80
78
|
([as, bs, cs], rest) =>
|
|
81
79
|
[[elem(tag, as, trimNodeEndBR(defrag(bs)), cs, {})], rest],
|
|
82
80
|
([as, bs], rest) =>
|
|
83
|
-
as.length === 1
|
|
84
|
-
? [unshift(as, bs), rest]
|
|
85
|
-
: undefined)),
|
|
81
|
+
as.length === 1 ? [unshift(as, bs), rest] : undefined)),
|
|
86
82
|
([, tag]) => tag,
|
|
87
83
|
new Cache(1000))),
|
|
88
84
|
])))));
|
|
@@ -91,8 +87,10 @@ export const attribute: HTMLParser.TagParser.AttributeParser = union([
|
|
|
91
87
|
str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/),
|
|
92
88
|
]);
|
|
93
89
|
|
|
94
|
-
function elem(tag: string, as:
|
|
90
|
+
function elem(tag: string, as: string[], bs: (HTMLElement | string)[], cs: string[], context: MarkdownParser.Context): HTMLElement {
|
|
91
|
+
assert(as.length > 0);
|
|
95
92
|
assert(bs.length === defrag(bs).length);
|
|
93
|
+
assert(cs.length === 1);
|
|
96
94
|
if (!tags.includes(tag)) return invalid('tag', `Invalid HTML tag <${tag}>.`, as, bs, cs);
|
|
97
95
|
switch (tag) {
|
|
98
96
|
case 'sup':
|
|
@@ -115,8 +113,6 @@ function elem(tag: string, as: (HTMLElement | string)[], bs: (HTMLElement | stri
|
|
|
115
113
|
case as[as.length - 1] !== '>'
|
|
116
114
|
|| 'data-invalid-syntax' in (attrs = attributes('html', [], attrspec[tag], as.slice(1, -1) as string[])):
|
|
117
115
|
return invalid('attribute', 'Invalid HTML attribute.', as, bs, cs);
|
|
118
|
-
case cs.length === 0:
|
|
119
|
-
return invalid('closer', `Missing the closing HTML tag <${tag}>.`, as, bs, cs);
|
|
120
116
|
default:
|
|
121
117
|
assert(attrs);
|
|
122
118
|
return h(tag as 'span', attrs, bs);
|
|
@@ -2,18 +2,15 @@ import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
|
|
|
2
2
|
import { union, validate, focus, creator, fmap } from '../../combinator';
|
|
3
3
|
import { html } from 'typed-dom';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
export const unsafehtmlentity: UnsafeHTMLEntityParser = creator(validate('&', fmap(focus(
|
|
5
|
+
export const unsafehtmlentity: UnsafeHTMLEntityParser = creator(validate('&', focus(
|
|
8
6
|
/^&(?!NewLine;)[0-9A-Za-z]+;/,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
])));
|
|
7
|
+
(parser => entity => (
|
|
8
|
+
parser.innerHTML = entity,
|
|
9
|
+
entity = parser.textContent!,
|
|
10
|
+
[[`${entity[0] !== '&' || entity.length === 1 ? '' : '\0'}${entity}`], '']
|
|
11
|
+
))(html('b')))));
|
|
15
12
|
|
|
16
|
-
export const htmlentity: HTMLEntityParser =
|
|
13
|
+
export const htmlentity: HTMLEntityParser = fmap(
|
|
17
14
|
union([unsafehtmlentity]),
|
|
18
15
|
([str]) => [
|
|
19
16
|
str[0] === '\0'
|
|
@@ -24,4 +21,4 @@ export const htmlentity: HTMLEntityParser = creator(validate('&', fmap(
|
|
|
24
21
|
'data-invalid-description': 'Invalid HTML entity.',
|
|
25
22
|
}, str.slice(1))
|
|
26
23
|
: str,
|
|
27
|
-
])
|
|
24
|
+
]);
|
|
@@ -16,8 +16,7 @@ const optspec = {
|
|
|
16
16
|
} as const;
|
|
17
17
|
ObjectSetPrototypeOf(optspec, null);
|
|
18
18
|
|
|
19
|
-
export const link: LinkParser = lazy(() => creator(10, bind(
|
|
20
|
-
validate(['[', '{'], '}', '\n',
|
|
19
|
+
export const link: LinkParser = lazy(() => creator(10, validate(['[', '{'], '}', '\n', bind(
|
|
21
20
|
guard(context => context.syntax?.inline?.link ?? true,
|
|
22
21
|
reverse(tails([
|
|
23
22
|
context({ syntax: { inline: {
|
|
@@ -44,7 +43,7 @@ export const link: LinkParser = lazy(() => creator(10, bind(
|
|
|
44
43
|
true),
|
|
45
44
|
]))),
|
|
46
45
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]?}/)),
|
|
47
|
-
])))
|
|
46
|
+
]))),
|
|
48
47
|
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
|
|
49
48
|
assert(params.every(p => typeof p === 'string'));
|
|
50
49
|
if (eval(some(autolink)(stringify(content), context))?.some(node => typeof node === 'object')) return;
|
|
@@ -62,7 +61,7 @@ export const link: LinkParser = lazy(() => creator(10, bind(
|
|
|
62
61
|
if (el.classList.contains('invalid')) return [[el], rest];
|
|
63
62
|
assert(el.classList.length === 0);
|
|
64
63
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
65
|
-
})));
|
|
64
|
+
}))));
|
|
66
65
|
|
|
67
66
|
export const uri: LinkParser.ParameterParser.UriParser = union([
|
|
68
67
|
open(/^[^\S\n]/, str(/^\S+/)),
|
|
@@ -2,19 +2,16 @@ import { MarkParser } from '../inline';
|
|
|
2
2
|
import { union, some, creator, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import { startTight,
|
|
5
|
+
import { startTight, delimiter } from '../util';
|
|
6
6
|
import { html, defrag } from 'typed-dom';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
|
|
9
9
|
export const mark: MarkParser = lazy(() => creator(surround(
|
|
10
10
|
str('=='),
|
|
11
11
|
startTight(some(union([
|
|
12
|
-
some(inline, delimiter(
|
|
12
|
+
some(inline, delimiter(/==/)),
|
|
13
13
|
open(some(inline, '='), inline),
|
|
14
14
|
]))),
|
|
15
15
|
str('=='), false,
|
|
16
|
-
([
|
|
17
|
-
isEndTightNodes(bs)
|
|
18
|
-
? [[html('mark', defrag(bs))], rest]
|
|
19
|
-
: [unshift(as, bs), cs[0] + rest],
|
|
16
|
+
([, bs], rest) => [[html('mark', defrag(bs))], rest],
|
|
20
17
|
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -18,14 +18,17 @@ const optspec = {
|
|
|
18
18
|
} as const;
|
|
19
19
|
ObjectSetPrototypeOf(optspec, null);
|
|
20
20
|
|
|
21
|
-
export const media: MediaParser = lazy(() => creator(10, bind(verify(fmap(open(
|
|
21
|
+
export const media: MediaParser = lazy(() => creator(10, validate(['![', '!{'], '}', '\n', bind(verify(fmap(open(
|
|
22
22
|
'!',
|
|
23
|
-
validate(['[', '{'], '}', '\n',
|
|
24
23
|
guard(context => context.syntax?.inline?.media ?? true,
|
|
25
24
|
tails([
|
|
26
|
-
dup(surround(
|
|
25
|
+
dup(surround(
|
|
26
|
+
/^\[(?!\s*\\\s)/,
|
|
27
|
+
some(union([unsafehtmlentity, bracket, txt]), ']', /^\\?\n/),
|
|
28
|
+
']',
|
|
29
|
+
true)),
|
|
27
30
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]?}/)),
|
|
28
|
-
])))
|
|
31
|
+
]))),
|
|
29
32
|
([as, bs]) => bs ? [[join(as).trim() || join(as)], bs] : [[''], as]),
|
|
30
33
|
([[text]]) => text === '' || text.trim() !== ''),
|
|
31
34
|
([[text], params], rest, context) => {
|
|
@@ -51,7 +54,7 @@ export const media: MediaParser = lazy(() => creator(10, bind(verify(fmap(open(
|
|
|
51
54
|
link as MediaParser,
|
|
52
55
|
([link]) => [define(link, { target: '_blank' }, [el])])
|
|
53
56
|
(`{ ${INSECURE_URI}${join(params)} }${rest}`, context);
|
|
54
|
-
})));
|
|
57
|
+
}))));
|
|
55
58
|
|
|
56
59
|
const bracket: MediaParser.TextParser.BracketParser = lazy(() => union([
|
|
57
60
|
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
@@ -8,12 +8,11 @@ import { isStartTightNodes } from '../util';
|
|
|
8
8
|
import { html, defrag } from 'typed-dom';
|
|
9
9
|
import { unshift, push, join } from 'spica/array';
|
|
10
10
|
|
|
11
|
-
export const ruby: RubyParser = lazy(() => creator(bind(verify(
|
|
12
|
-
validate('[', ')', '\n',
|
|
11
|
+
export const ruby: RubyParser = lazy(() => creator(validate('[', ')', '\n', bind(verify(
|
|
13
12
|
sequence([
|
|
14
13
|
surround('[', focus(/^(?:\\[^\n]|[^\\\[\]\n])+(?=]\()/, text), ']'),
|
|
15
14
|
surround('(', focus(/^(?:\\[^\n]|[^\\\(\)\n])+(?=\))/, text), ')'),
|
|
16
|
-
])
|
|
15
|
+
]),
|
|
17
16
|
([texts]) => isStartTightNodes(texts)),
|
|
18
17
|
([texts, rubies], rest) => {
|
|
19
18
|
const tail = typeof texts[texts.length - 1] === 'object'
|
|
@@ -44,7 +43,7 @@ export const ruby: RubyParser = lazy(() => creator(bind(verify(
|
|
|
44
43
|
[html('rp', '('), html('rt', join(rubies, ' ').trim()), html('rp', ')')]), tail)))
|
|
45
44
|
], rest];
|
|
46
45
|
}
|
|
47
|
-
})));
|
|
46
|
+
}))));
|
|
48
47
|
|
|
49
48
|
const text: RubyParser.TextParser = creator((source, context) => {
|
|
50
49
|
const acc = [''];
|
|
@@ -9,11 +9,11 @@ describe('Unit: parser/inline/strong', () => {
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('**')), undefined);
|
|
11
11
|
assert.deepStrictEqual(inspect(parser('**a')), [['**', 'a'], '']);
|
|
12
|
-
assert.deepStrictEqual(inspect(parser('**a*')), [['**', 'a', '*'], '']);
|
|
13
12
|
assert.deepStrictEqual(inspect(parser('**a **')), [['**', 'a', ' ', '**'], '']);
|
|
14
13
|
assert.deepStrictEqual(inspect(parser('**a\n**')), [['**', 'a', '<br>', '**'], '']);
|
|
15
14
|
assert.deepStrictEqual(inspect(parser('**a\\ **')), [['**', 'a', ' ', '**'], '']);
|
|
16
15
|
assert.deepStrictEqual(inspect(parser('**a\\\n**')), [['**', 'a', '<span class="linebreak"> </span>', '**'], '']);
|
|
16
|
+
assert.deepStrictEqual(inspect(parser('**a*')), [['**', 'a', '*'], '']);
|
|
17
17
|
assert.deepStrictEqual(inspect(parser('**a*b**')), [['**', 'a', '<em>b</em>', '*'], '']);
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('** **')), undefined);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('** a**')), undefined);
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { StrongParser } from '../inline';
|
|
2
|
-
import { union, some, creator, surround, open,
|
|
2
|
+
import { union, some, creator, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import { startTight,
|
|
5
|
+
import { startTight, delimiter } from '../util';
|
|
6
6
|
import { html, defrag } from 'typed-dom';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
|
|
9
|
-
export const strong: StrongParser = lazy(() => creator(surround(
|
|
10
|
-
str('**'),
|
|
9
|
+
export const strong: StrongParser = lazy(() => creator(surround(
|
|
10
|
+
str('**'),
|
|
11
11
|
startTight(some(union([
|
|
12
|
-
some(inline, delimiter(
|
|
12
|
+
some(inline, delimiter(/\*\*/)),
|
|
13
13
|
open(some(inline, '*'), inline),
|
|
14
|
-
]))),
|
|
14
|
+
])), '*'),
|
|
15
15
|
str('**'), false,
|
|
16
|
-
([
|
|
17
|
-
isEndTightNodes(bs)
|
|
18
|
-
? [[html('strong', defrag(bs))], rest]
|
|
19
|
-
: [unshift(as, bs), cs[0] + rest],
|
|
16
|
+
([, bs], rest) => [[html('strong', defrag(bs))], rest],
|
|
20
17
|
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -92,7 +92,6 @@ describe('Unit: parser/inline', () => {
|
|
|
92
92
|
assert.deepStrictEqual(inspect(parser('***a***')), [['<em><strong>a</strong></em>'], '']);
|
|
93
93
|
assert.deepStrictEqual(inspect(parser('***a***b')), [['<em><strong>a</strong></em>', 'b'], '']);
|
|
94
94
|
assert.deepStrictEqual(inspect(parser('***a****')), [['<em><strong>a</strong></em>', '*'], '']);
|
|
95
|
-
assert.deepStrictEqual(inspect(parser('***a *b****')), [['<em><strong>a <em>b</em></strong></em>'], '']);
|
|
96
95
|
assert.deepStrictEqual(inspect(parser('****a***')), [['****', 'a', '***'], '']);
|
|
97
96
|
assert.deepStrictEqual(inspect(parser('****a****')), [['****', 'a', '****'], '']);
|
|
98
97
|
assert.deepStrictEqual(inspect(parser('*(*a*)*')), [['<em><span class="paren">(<em>a</em>)</span></em>'], '']);
|
|
@@ -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. </span
|
|
31
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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. </span
|
|
50
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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. </span
|
|
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
|
|
52
|
+
'<figure data-label="fig-b" data-group="fig" data-number="2" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></figcaption></figure>',
|
|
53
|
+
'<figure data-label="table-a" data-group="table" data-number="1" id="label:table-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Table 1. </span></figcaption></figure>',
|
|
54
54
|
]);
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -65,7 +65,7 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
65
65
|
assert.deepStrictEqual(
|
|
66
66
|
[...target.children].map(el => el.outerHTML),
|
|
67
67
|
[
|
|
68
|
-
'<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
|
|
68
|
+
'<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
|
|
69
69
|
'<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
|
|
70
70
|
]);
|
|
71
71
|
}
|
|
@@ -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. </span
|
|
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
|
|
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
|
|
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
|
|
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
|
|
90
|
+
'<figure data-label="fig-2" data-group="fig" data-number="2" id="label:fig-2"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></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><figcaption><span class="figindex">Fig. 3.1. </span></figcaption></figure>',
|
|
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><figcaption><span class="figindex">(4.1.1)</span></figcaption></figure>',
|
|
93
|
+
'<figure data-label="$-a" data-group="$" data-number="1" id="label:$-a"><div class="figcontent"><div class="math" translate="no">$$\n$$</div></div><figcaption><span class="figindex">(1)</span></figcaption></figure>',
|
|
94
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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. </span
|
|
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
|
|
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
|
|
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
|
|
114
|
+
'<blockquote><blockquote><section><figure data-label="fig-a" data-group="fig" data-number="1"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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><figcaption><span class="figindex">Fig. 1. </span></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><figcaption><span class="figindex">Fig. 1. </span></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><figcaption><span class="figindex">Fig. 1. </span></figcaption></figure>',
|
|
117
|
+
'<figure data-label="fig-a" data-group="fig" data-number="2" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2. </span></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. </span
|
|
166
|
+
'<figure data-label="fig-1" data-group="fig" data-number="1" id="label:fig-1"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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. </span
|
|
169
|
+
'<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></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. </span
|
|
172
|
+
'<figure data-label="fig-c" data-group="fig" data-number="3.1" id="label:fig-c"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 3.1. </span></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. </span
|
|
175
|
+
'<figure data-label="fig-d" data-group="fig" data-number="4.1" id="label:fig-d"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 4.1. </span></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. </span
|
|
183
|
+
'<figure data-label="fig-e" data-group="fig" data-number="6.1" id="label:fig-e"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></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. </span
|
|
186
|
+
'<figure data-label="fig-f" data-group="fig" data-number="5.1" id="label:fig-f"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.1. </span></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. </span
|
|
188
|
+
'<figure data-label="fig-g" data-group="fig" data-number="5.2" id="label:fig-g"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.2. </span></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. </span
|
|
191
|
+
'<figure data-label="fig-h" data-group="fig" data-number="5.3" id="label:fig-h"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.3. </span></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. </span
|
|
193
|
+
'<figure data-label="fig-i" data-group="fig" data-number="5.4" id="label:fig-i"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 5.4. </span></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. </span
|
|
195
|
+
'<figure data-label="fig-j" data-group="fig" data-number="6.1" id="label:fig-j"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 6.1. </span></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. </span
|
|
222
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1.1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1.1. </span></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. </span
|
|
225
|
+
'<figure data-label="fig-b" data-group="fig" data-number="2.1" id="label:fig-b"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 2.1. </span></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. </span
|
|
241
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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. </span
|
|
258
|
+
'<figure data-label="fig-a" data-group="fig" data-number="1" id="label:0:fig-a"><div class="figcontent"><blockquote></blockquote></div><figcaption><span class="figindex">Fig. 1. </span></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
|
}
|
|
@@ -85,7 +85,7 @@ export function* figure(
|
|
|
85
85
|
? `(${number})`
|
|
86
86
|
: `${capitalize(group)}${group === 'fig' ? '.' : ''} ${number}`;
|
|
87
87
|
define(
|
|
88
|
-
def.querySelector(':scope > .figindex')!,
|
|
88
|
+
def.querySelector(':scope > figcaption > .figindex')!,
|
|
89
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;
|
package/src/parser/util.ts
CHANGED
|
@@ -4,51 +4,16 @@ import { Parser, eval } from '../combinator/data/parser';
|
|
|
4
4
|
import { union, some, verify, convert } from '../combinator';
|
|
5
5
|
import { unsafehtmlentity } from './inline/htmlentity';
|
|
6
6
|
import { linebreak, unescsource } from './source';
|
|
7
|
+
import { invisibleHTMLEntityNames } from './api/normalize';
|
|
7
8
|
import { push, pop } from 'spica/array';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'Tab',
|
|
12
|
-
'NewLine',
|
|
13
|
-
'NonBreakingSpace',
|
|
14
|
-
'nbsp',
|
|
15
|
-
'shy',
|
|
16
|
-
'ensp',
|
|
17
|
-
'emsp',
|
|
18
|
-
'emsp13',
|
|
19
|
-
'emsp14',
|
|
20
|
-
'numsp',
|
|
21
|
-
'puncsp',
|
|
22
|
-
'ThinSpace',
|
|
23
|
-
'thinsp',
|
|
24
|
-
'VeryThinSpace',
|
|
25
|
-
'hairsp',
|
|
26
|
-
'ZeroWidthSpace',
|
|
27
|
-
'NegativeVeryThinSpace',
|
|
28
|
-
'NegativeThinSpace',
|
|
29
|
-
'NegativeMediumSpace',
|
|
30
|
-
'NegativeThickSpace',
|
|
31
|
-
'zwj',
|
|
32
|
-
'zwnj',
|
|
33
|
-
'lrm',
|
|
34
|
-
'rlm',
|
|
35
|
-
'MediumSpace',
|
|
36
|
-
'NoBreak',
|
|
37
|
-
'ApplyFunction',
|
|
38
|
-
'af',
|
|
39
|
-
'InvisibleTimes',
|
|
40
|
-
'it',
|
|
41
|
-
'InvisibleComma',
|
|
42
|
-
'ic',
|
|
43
|
-
] as const;
|
|
44
|
-
const blankline = new RegExp(String.raw`^(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`, 'gm');
|
|
45
|
-
|
|
46
|
-
export function delimiter(opener: string): RegExp {
|
|
47
|
-
return new RegExp(String.raw`^(?:\s+|\\\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)?${opener}`);
|
|
10
|
+
export function delimiter(opener: RegExp): RegExp {
|
|
11
|
+
return new RegExp(String.raw`^(?:\s+|\\\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)?${opener.source}`);
|
|
48
12
|
}
|
|
49
13
|
|
|
50
14
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
51
15
|
export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
16
|
+
const blankline = new RegExp(String.raw`^(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`, 'gm');
|
|
52
17
|
return union([
|
|
53
18
|
convert(
|
|
54
19
|
source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
|
|
@@ -81,20 +46,18 @@ export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, ex
|
|
|
81
46
|
: undefined;
|
|
82
47
|
}
|
|
83
48
|
export function isStartLoose(source: string, context: MarkdownParser.Context, except?: string): boolean {
|
|
84
|
-
|
|
85
|
-
if (source === '') return true;
|
|
86
|
-
return source.slice(0, except?.length ?? 0) !== except
|
|
87
|
-
&& isStartTight(source, context);
|
|
49
|
+
return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
|
|
88
50
|
}
|
|
89
|
-
export function startTight<P extends Parser<unknown>>(parser: P): P;
|
|
90
|
-
export function startTight<T>(parser: Parser<T
|
|
51
|
+
export function startTight<P extends Parser<unknown>>(parser: P, except?: string): P;
|
|
52
|
+
export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
|
|
91
53
|
return (source, context) =>
|
|
92
|
-
isStartTight(source, context)
|
|
54
|
+
isStartTight(source, context, except)
|
|
93
55
|
? parser(source, context)
|
|
94
56
|
: undefined;
|
|
95
57
|
}
|
|
96
|
-
function isStartTight(source: string, context: MarkdownParser.Context): boolean {
|
|
58
|
+
function isStartTight(source: string, context: MarkdownParser.Context, except?: string): boolean {
|
|
97
59
|
if (source === '') return true;
|
|
60
|
+
if (except && source.slice(0, except.length) === except) return false;
|
|
98
61
|
switch (source[0]) {
|
|
99
62
|
case ' ':
|
|
100
63
|
case ' ':
|
|
@@ -127,10 +90,10 @@ export function isStartTightNodes(nodes: readonly (HTMLElement | string)[]): boo
|
|
|
127
90
|
if (nodes.length === 0) return true;
|
|
128
91
|
return isVisible(nodes[0], 0);
|
|
129
92
|
}
|
|
130
|
-
export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
|
|
131
|
-
if (nodes.length === 0) return true;
|
|
132
|
-
return isVisible(nodes[nodes.length - 1], -1);
|
|
133
|
-
}
|
|
93
|
+
//export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
|
|
94
|
+
// if (nodes.length === 0) return true;
|
|
95
|
+
// return isVisible(nodes[nodes.length - 1], -1);
|
|
96
|
+
//}
|
|
134
97
|
function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
135
98
|
switch (typeof node) {
|
|
136
99
|
case 'string':
|