securemark 0.257.2 → 0.258.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/index.js +1238 -618
- package/markdown.d.ts +1 -12
- package/package.json +9 -9
- package/src/combinator/control/manipulation/convert.ts +8 -4
- package/src/combinator/control/manipulation/scope.ts +10 -2
- package/src/combinator/data/parser/context/delimiter.ts +70 -0
- package/src/combinator/data/parser/context/memo.ts +34 -0
- package/src/combinator/{control/manipulation → data/parser}/context.test.ts +9 -9
- package/src/combinator/data/parser/context.ts +158 -0
- package/src/combinator/data/parser/inits.ts +4 -3
- package/src/combinator/data/parser/sequence.test.ts +1 -1
- package/src/combinator/data/parser/sequence.ts +4 -3
- package/src/combinator/data/parser/some.test.ts +1 -1
- package/src/combinator/data/parser/some.ts +14 -37
- package/src/combinator/data/parser/subsequence.test.ts +1 -1
- package/src/combinator/data/parser/subsequence.ts +3 -3
- package/src/combinator/data/parser/tails.ts +3 -3
- package/src/combinator/data/parser/union.test.ts +1 -1
- package/src/combinator/data/parser.ts +6 -47
- package/src/combinator.ts +1 -2
- package/src/parser/api/bind.ts +5 -5
- package/src/parser/api/parse.test.ts +11 -8
- package/src/parser/api/parse.ts +3 -1
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/dlist.ts +4 -10
- package/src/parser/block/extension/figure.ts +4 -3
- package/src/parser/block/extension/table.ts +2 -2
- package/src/parser/block/heading.ts +5 -13
- package/src/parser/block/ilist.ts +3 -2
- package/src/parser/block/olist.ts +10 -7
- package/src/parser/block/paragraph.ts +1 -1
- package/src/parser/block/reply/cite.ts +1 -1
- package/src/parser/block/reply/quote.ts +1 -1
- package/src/parser/block/reply.ts +1 -1
- package/src/parser/block/sidefence.ts +1 -1
- package/src/parser/block/table.test.ts +5 -0
- package/src/parser/block/table.ts +14 -13
- package/src/parser/block/ulist.ts +4 -3
- package/src/parser/block.ts +1 -1
- package/src/parser/context.ts +32 -0
- package/src/parser/header.ts +1 -1
- package/src/parser/inline/annotation.test.ts +5 -5
- package/src/parser/inline/annotation.ts +9 -17
- package/src/parser/inline/autolink/email.ts +1 -1
- package/src/parser/inline/autolink/url.ts +1 -1
- package/src/parser/inline/autolink.ts +5 -3
- package/src/parser/inline/bracket.ts +16 -15
- package/src/parser/inline/code.ts +1 -1
- package/src/parser/inline/comment.ts +4 -3
- package/src/parser/inline/deletion.ts +5 -4
- package/src/parser/inline/emphasis.ts +5 -4
- package/src/parser/inline/emstrong.ts +5 -4
- package/src/parser/inline/extension/index.ts +7 -14
- package/src/parser/inline/extension/indexee.ts +8 -10
- package/src/parser/inline/extension/indexer.ts +4 -3
- package/src/parser/inline/extension/label.ts +3 -2
- package/src/parser/inline/extension/placeholder.ts +5 -4
- package/src/parser/inline/html.ts +5 -4
- package/src/parser/inline/htmlentity.ts +1 -1
- package/src/parser/inline/insertion.ts +5 -4
- package/src/parser/inline/link.test.ts +2 -1
- package/src/parser/inline/link.ts +21 -27
- package/src/parser/inline/mark.ts +5 -4
- package/src/parser/inline/math.ts +1 -1
- package/src/parser/inline/media.test.ts +1 -0
- package/src/parser/inline/media.ts +8 -7
- package/src/parser/inline/reference.test.ts +5 -5
- package/src/parser/inline/reference.ts +10 -16
- package/src/parser/inline/ruby.test.ts +1 -0
- package/src/parser/inline/ruby.ts +4 -3
- package/src/parser/inline/shortmedia.ts +3 -2
- package/src/parser/inline/strong.ts +5 -4
- package/src/parser/inline/template.test.ts +1 -1
- package/src/parser/inline/template.ts +9 -6
- package/src/parser/inline.test.ts +2 -1
- package/src/parser/locale.ts +6 -7
- package/src/parser/processor/footnote.ts +5 -3
- package/src/parser/source/text.ts +1 -1
- package/src/parser/util.ts +0 -220
- package/src/parser/visibility.ts +205 -0
- package/src/util/info.ts +4 -2
- package/src/util/quote.ts +12 -15
- package/src/util/toc.ts +14 -17
- package/webpack.config.js +1 -0
- package/src/combinator/control/manipulation/context.ts +0 -70
- package/src/combinator/control/manipulation/resource.ts +0 -54
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, creator, precedence, validate, focus, rewrite, convert, surround, open, lazy } from '../../../combinator';
|
|
3
3
|
import { textlink } from '../link';
|
|
4
4
|
import { unescsource } from '../../source';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AutolinkParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, guard, validate, fmap } from '../../combinator';
|
|
3
3
|
import { url } from './autolink/url';
|
|
4
4
|
import { email } from './autolink/email';
|
|
5
5
|
import { channel } from './autolink/channel';
|
|
@@ -8,11 +8,13 @@ import { hashtag, emoji } from './autolink/hashtag';
|
|
|
8
8
|
import { hashnum } from './autolink/hashnum';
|
|
9
9
|
import { anchor } from './autolink/anchor';
|
|
10
10
|
import { str } from '../source';
|
|
11
|
+
import { Rule, State } from '../context';
|
|
11
12
|
import { stringify } from '../util';
|
|
12
13
|
|
|
13
14
|
export const autolink: AutolinkParser = fmap(
|
|
14
15
|
validate(/^(?:[@#>0-9A-Za-z]|\S#)/,
|
|
15
|
-
guard(context => context.
|
|
16
|
+
guard(context => ~context.state! & State.autolink,
|
|
17
|
+
syntax(Rule.autolink, 1,
|
|
16
18
|
some(union([
|
|
17
19
|
url,
|
|
18
20
|
email,
|
|
@@ -29,5 +31,5 @@ export const autolink: AutolinkParser = fmap(
|
|
|
29
31
|
// Escape unmatched hashtag-like strings.
|
|
30
32
|
str(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])*/u.source.replace('emoji', emoji), 'u')),
|
|
31
33
|
anchor,
|
|
32
|
-
])))),
|
|
34
|
+
]))))),
|
|
33
35
|
ns => ns.length === 1 ? ns : [stringify(ns)]);
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { BracketParser } from '../inline';
|
|
3
|
-
import { union, some,
|
|
3
|
+
import { union, some, syntax, surround, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { str } from '../source';
|
|
6
|
+
import { Rule } from '../context';
|
|
6
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
8
|
import { unshift, push } from 'spica/array';
|
|
8
9
|
|
|
9
10
|
const index = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*/;
|
|
10
11
|
|
|
11
|
-
export const bracket: BracketParser = lazy(() =>
|
|
12
|
-
surround(str('('),
|
|
13
|
-
surround(str('('),
|
|
12
|
+
export const bracket: BracketParser = lazy(() => union([
|
|
13
|
+
syntax(Rule.none, 2, surround(str('('), str(index), str(')'))),
|
|
14
|
+
syntax(Rule.bracket, 2, surround(str('('), some(inline, ')', [[')', 2]]), str(')'), true,
|
|
14
15
|
([as, bs = [], cs], rest) => [[html('span', { class: 'paren' }, defrag(push(unshift(as, bs), cs)))], rest],
|
|
15
|
-
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
|
|
16
|
-
surround(str('('),
|
|
17
|
-
surround(str('('),
|
|
16
|
+
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest])),
|
|
17
|
+
syntax(Rule.none, 2, surround(str('('), str(new RegExp(index.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => c.trimStart() && String.fromCharCode(c.charCodeAt(0) + 0xFEE0)))), str(')'))),
|
|
18
|
+
syntax(Rule.bracket, 2, surround(str('('), some(inline, ')', [[')', 2]]), str(')'), true,
|
|
18
19
|
([as, bs = [], cs], rest) => [[html('span', { class: 'paren' }, defrag(push(unshift(as, bs), cs)))], rest],
|
|
19
|
-
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
20
|
-
surround(str('['),
|
|
20
|
+
([as, bs = []], rest) => [unshift(as, bs), rest])),
|
|
21
|
+
syntax(Rule.bracket, 2, surround(str('['), some(inline, ']', [[']', 2]]), str(']'), true,
|
|
21
22
|
undefined,
|
|
22
|
-
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
|
|
23
|
-
surround(str('{'),
|
|
23
|
+
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest])),
|
|
24
|
+
syntax(Rule.bracket, 2, surround(str('{'), some(inline, '}', [['}', 2]]), str('}'), true,
|
|
24
25
|
undefined,
|
|
25
|
-
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
26
|
+
([as, bs = []], rest) => [unshift(as, bs), rest])),
|
|
26
27
|
// Control media blinking in editing rather than control confusion of pairs of quote marks.
|
|
27
|
-
surround(str('"'),
|
|
28
|
+
syntax(Rule.quote, 8, surround(str('"'), some(inline, '"', [['"', 8]]), str('"'), true,
|
|
28
29
|
undefined,
|
|
29
|
-
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
30
|
-
]))
|
|
30
|
+
([as, bs = []], rest) => [unshift(as, bs), rest])),
|
|
31
|
+
]));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CodeParser } from '../inline';
|
|
2
|
-
import {
|
|
2
|
+
import { creator, validate, match } from '../../combinator';
|
|
3
3
|
import { html } from 'typed-dom/dom';
|
|
4
4
|
|
|
5
5
|
export const code: CodeParser = creator(validate('`', match(
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CommentParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, validate, surround, open, close, match, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { text, str } from '../source';
|
|
5
|
+
import { Rule } from '../context';
|
|
5
6
|
import { html, defrag } from 'typed-dom/dom';
|
|
6
7
|
import { memoize } from 'spica/memoize';
|
|
7
8
|
import { unshift, push } from 'spica/array';
|
|
8
9
|
|
|
9
|
-
export const comment: CommentParser = lazy(() => validate('[%',
|
|
10
|
+
export const comment: CommentParser = lazy(() => validate('[%', syntax(Rule.none, 4, match(
|
|
10
11
|
/^\[(%+)\s/,
|
|
11
12
|
memoize(
|
|
12
13
|
([, fence]) =>
|
|
@@ -21,4 +22,4 @@ export const comment: CommentParser = lazy(() => validate('[%', creator(preceden
|
|
|
21
22
|
]),
|
|
22
23
|
], rest],
|
|
23
24
|
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
24
|
-
([, fence]) => fence.length, [])))))
|
|
25
|
+
([, fence]) => fence.length, [])))));
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { DeletionParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import {
|
|
5
|
+
import { Rule } from '../context';
|
|
6
|
+
import { blankWith } from '../visibility';
|
|
6
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
8
|
import { unshift } from 'spica/array';
|
|
8
9
|
|
|
9
|
-
export const deletion: DeletionParser = lazy(() =>
|
|
10
|
+
export const deletion: DeletionParser = lazy(() => syntax(Rule.none, 1, surround(
|
|
10
11
|
str('~~'),
|
|
11
12
|
some(union([
|
|
12
13
|
some(inline, blankWith('\n', '~~')),
|
|
@@ -14,4 +15,4 @@ export const deletion: DeletionParser = lazy(() => creator(precedence(1, surroun
|
|
|
14
15
|
])),
|
|
15
16
|
str('~~'), false,
|
|
16
17
|
([, bs], rest) => [[html('del', defrag(bs))], rest],
|
|
17
|
-
([as, bs], rest) => [unshift(as, bs), rest])))
|
|
18
|
+
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { EmphasisParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { emstrong } from './emstrong';
|
|
5
5
|
import { strong } from './strong';
|
|
6
6
|
import { str } from '../source';
|
|
7
|
-
import {
|
|
7
|
+
import { Rule } from '../context';
|
|
8
|
+
import { startTight, blankWith } from '../visibility';
|
|
8
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
10
|
import { unshift } from 'spica/array';
|
|
10
11
|
|
|
11
|
-
export const emphasis: EmphasisParser = lazy(() =>
|
|
12
|
+
export const emphasis: EmphasisParser = lazy(() => syntax(Rule.none, 1, surround(
|
|
12
13
|
str('*'),
|
|
13
14
|
startTight(some(union([
|
|
14
15
|
strong,
|
|
@@ -21,4 +22,4 @@ export const emphasis: EmphasisParser = lazy(() => creator(precedence(1, surroun
|
|
|
21
22
|
])), '*'),
|
|
22
23
|
str('*'), false,
|
|
23
24
|
([, bs], rest) => [[html('em', defrag(bs))], rest],
|
|
24
|
-
([as, bs], rest) => [unshift(as, bs), rest])))
|
|
25
|
+
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { EmStrongParser, EmphasisParser, StrongParser } from '../inline';
|
|
2
2
|
import { Result, IntermediateParser } from '../../combinator/data/parser';
|
|
3
|
-
import { union,
|
|
3
|
+
import { union, syntax, some, surround, open, lazy, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { strong } from './strong';
|
|
6
6
|
import { emphasis } from './emphasis';
|
|
7
7
|
import { str } from '../source';
|
|
8
|
-
import {
|
|
8
|
+
import { Rule } from '../context';
|
|
9
|
+
import { startTight, blankWith } from '../visibility';
|
|
9
10
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
11
|
import { unshift } from 'spica/array';
|
|
11
12
|
|
|
@@ -26,7 +27,7 @@ const subemphasis: IntermediateParser<EmphasisParser> = lazy(() => some(union([
|
|
|
26
27
|
])),
|
|
27
28
|
])));
|
|
28
29
|
|
|
29
|
-
export const emstrong: EmStrongParser = lazy(() =>
|
|
30
|
+
export const emstrong: EmStrongParser = lazy(() => syntax(Rule.none, 1, surround(
|
|
30
31
|
str('***'),
|
|
31
32
|
startTight(some(union([
|
|
32
33
|
some(inline, blankWith('*')),
|
|
@@ -57,4 +58,4 @@ export const emstrong: EmStrongParser = lazy(() => creator(precedence(1, surroun
|
|
|
57
58
|
}
|
|
58
59
|
assert(false);
|
|
59
60
|
},
|
|
60
|
-
([as, bs], rest) => [unshift(as, bs), rest])))
|
|
61
|
+
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ExtensionParser } from '../../inline';
|
|
3
|
-
import { union, some,
|
|
3
|
+
import { union, some, syntax, creator, precedence, guard, state, validate, surround, open, lazy, fmap } from '../../../combinator';
|
|
4
4
|
import { inline } from '../../inline';
|
|
5
5
|
import { indexee, identity } from './indexee';
|
|
6
6
|
import { txt, str, stropt } from '../../source';
|
|
7
|
-
import {
|
|
7
|
+
import { Rule, State } from '../../context';
|
|
8
|
+
import { startTight, trimBlankEnd } from '../../visibility';
|
|
8
9
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
9
10
|
|
|
10
11
|
import IndexParser = ExtensionParser.IndexParser;
|
|
11
12
|
|
|
12
|
-
export const index: IndexParser = lazy(() => validate('[#',
|
|
13
|
+
export const index: IndexParser = lazy(() => validate('[#', syntax(Rule.index, 2, fmap(indexee(surround(
|
|
13
14
|
'[#',
|
|
14
|
-
guard(context => context.
|
|
15
|
+
guard(context => ~context.state! & State.index,
|
|
16
|
+
state(State.annotation | State.reference | State.index | State.label | State.link | State.media | State.autolink,
|
|
15
17
|
startTight(
|
|
16
|
-
context({ syntax: { inline: {
|
|
17
|
-
annotation: false,
|
|
18
|
-
reference: false,
|
|
19
|
-
index: false,
|
|
20
|
-
label: false,
|
|
21
|
-
link: false,
|
|
22
|
-
media: false,
|
|
23
|
-
autolink: false,
|
|
24
|
-
}}},
|
|
25
18
|
open(stropt(/^\|?/), trimBlankEnd(some(union([
|
|
26
19
|
signature,
|
|
27
20
|
inline,
|
|
@@ -37,7 +30,7 @@ export const index: IndexParser = lazy(() => validate('[#', creator(precedence(2
|
|
|
37
30
|
href: el.id ? `#${el.id}` : undefined,
|
|
38
31
|
},
|
|
39
32
|
el.childNodes),
|
|
40
|
-
]))))
|
|
33
|
+
]))));
|
|
41
34
|
|
|
42
35
|
const signature: IndexParser.SignatureParser = lazy(() => creator(fmap(open(
|
|
43
36
|
'|#',
|
|
@@ -3,6 +3,7 @@ import { MarkdownParser } from '../../../../markdown';
|
|
|
3
3
|
import { Parser } from '../../../combinator/data/parser';
|
|
4
4
|
import { fmap } from '../../../combinator';
|
|
5
5
|
import { define } from 'typed-dom/dom';
|
|
6
|
+
import { duffEach } from 'spica/duff';
|
|
6
7
|
|
|
7
8
|
export function indexee<P extends Parser<unknown, MarkdownParser.Context>>(parser: P, optional?: boolean): P;
|
|
8
9
|
export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>, optional?: boolean): Parser<HTMLElement> {
|
|
@@ -27,35 +28,32 @@ export function text(source: HTMLElement | DocumentFragment, optional = false):
|
|
|
27
28
|
if (index) return index;
|
|
28
29
|
assert(!source.querySelector('.annotation, br'));
|
|
29
30
|
const target = source.cloneNode(true) as typeof source;
|
|
30
|
-
|
|
31
|
-
let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference, .checkbox, ul, ol'),
|
|
32
|
-
i = 0, len = es.length; i < len; ++i) {
|
|
33
|
-
const el = es[i];
|
|
31
|
+
duffEach(target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference, .checkbox, ul, ol'), el => {
|
|
34
32
|
switch (el.tagName) {
|
|
35
33
|
case 'CODE':
|
|
36
34
|
define(el, el.getAttribute('data-src')!);
|
|
37
|
-
|
|
35
|
+
return;
|
|
38
36
|
case 'RT':
|
|
39
37
|
case 'RP':
|
|
40
38
|
case 'UL':
|
|
41
39
|
case 'OL':
|
|
42
40
|
el.remove();
|
|
43
|
-
|
|
41
|
+
return;
|
|
44
42
|
}
|
|
45
43
|
switch (el.className) {
|
|
46
44
|
case 'math':
|
|
47
45
|
define(el, el.getAttribute('data-src')!);
|
|
48
|
-
|
|
46
|
+
return;
|
|
49
47
|
case 'comment':
|
|
50
48
|
case 'checkbox':
|
|
51
49
|
el.remove();
|
|
52
|
-
|
|
50
|
+
return;
|
|
53
51
|
case 'reference':
|
|
54
52
|
assert(el.firstElementChild?.hasAttribute('hidden'));
|
|
55
53
|
el.firstChild!.remove();
|
|
56
|
-
|
|
54
|
+
return;
|
|
57
55
|
}
|
|
58
|
-
}
|
|
56
|
+
});
|
|
59
57
|
// Better:
|
|
60
58
|
//return target.innerText;
|
|
61
59
|
return target.textContent!;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../inline';
|
|
2
|
-
import { union, verify, focus,
|
|
2
|
+
import { union, creator, state, verify, focus, surround, fmap } from '../../../combinator';
|
|
3
3
|
import { index } from './index';
|
|
4
|
-
import {
|
|
4
|
+
import { State } from '../../context';
|
|
5
5
|
import { html } from 'typed-dom/dom';
|
|
6
6
|
|
|
7
7
|
export const indexer: ExtensionParser.IndexerParser = creator(fmap(verify(surround(
|
|
8
8
|
/^\s+(?=\[#\S)/,
|
|
9
|
-
|
|
9
|
+
state(State.index, false,
|
|
10
|
+
union([
|
|
10
11
|
focus('[#]', () => [[html('a', { href: '#' })], '']),
|
|
11
12
|
index,
|
|
12
13
|
])),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Array } from 'spica/global';
|
|
2
2
|
import { ExtensionParser } from '../../inline';
|
|
3
|
-
import { union,
|
|
3
|
+
import { union, guard, creator, validate, surround, clear, fmap } from '../../../combinator';
|
|
4
4
|
import { str } from '../../source';
|
|
5
|
+
import { State } from '../../context';
|
|
5
6
|
import { html } from 'typed-dom/dom';
|
|
6
7
|
|
|
7
8
|
const body = str(/^\$[A-Za-z]*(?:(?:-[A-Za-z][0-9A-Za-z]*)+|-(?:(?:0|[1-9][0-9]*)\.)*(?:0|[1-9][0-9]*)(?![0-9A-Za-z]))/);
|
|
@@ -12,7 +13,7 @@ export const segment: ExtensionParser.LabelParser.SegmentParser = clear(validate
|
|
|
12
13
|
])));
|
|
13
14
|
|
|
14
15
|
export const label: ExtensionParser.LabelParser = validate(['[$', '$'], creator(fmap(
|
|
15
|
-
guard(context => context.
|
|
16
|
+
guard(context => ~context.state! & State.label,
|
|
16
17
|
union([
|
|
17
18
|
surround('[', body, ']'),
|
|
18
19
|
body,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, validate, surround, lazy } from '../../../combinator';
|
|
3
3
|
import { inline } from '../../inline';
|
|
4
4
|
import { str } from '../../source';
|
|
5
|
-
import {
|
|
5
|
+
import { Rule } from '../../context';
|
|
6
|
+
import { startTight } from '../../visibility';
|
|
6
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
8
|
import { unshift } from 'spica/array';
|
|
8
9
|
|
|
@@ -10,7 +11,7 @@ import { unshift } from 'spica/array';
|
|
|
10
11
|
|
|
11
12
|
// All syntax surrounded by square brackets shouldn't contain line breaks.
|
|
12
13
|
|
|
13
|
-
export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'],
|
|
14
|
+
export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], syntax(Rule.none, 2, surround(
|
|
14
15
|
str(/^\[[:^]/),
|
|
15
16
|
startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]])),
|
|
16
17
|
str(']'), false,
|
|
@@ -22,4 +23,4 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validat
|
|
|
22
23
|
'data-invalid-message': `Reserved start symbol "${as[0][1]}" cannot be used in "[]"`,
|
|
23
24
|
}, defrag(bs)),
|
|
24
25
|
], rest],
|
|
25
|
-
([as, bs], rest) => [unshift(as, bs), rest]))))
|
|
26
|
+
([as, bs], rest) => [unshift(as, bs), rest]))));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { undefined, Object } from 'spica/global';
|
|
2
2
|
import { HTMLParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, validate, focus,
|
|
3
|
+
import { union, subsequence, some, syntax, validate, focus, surround, open, match, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { str } from '../source';
|
|
6
|
-
import {
|
|
6
|
+
import { Rule } from '../context';
|
|
7
|
+
import { isStartLooseNodes, blankWith } from '../visibility';
|
|
7
8
|
import { html as h, defrag } from 'typed-dom/dom';
|
|
8
9
|
import { memoize } from 'spica/memoize';
|
|
9
10
|
import { Cache } from 'spica/cache';
|
|
@@ -18,7 +19,7 @@ const attrspecs = {
|
|
|
18
19
|
Object.setPrototypeOf(attrspecs, null);
|
|
19
20
|
Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
|
|
20
21
|
|
|
21
|
-
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/,
|
|
22
|
+
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(Rule.none, 5, union([
|
|
22
23
|
focus(
|
|
23
24
|
'<wbr>',
|
|
24
25
|
() => [[h('wbr')], '']),
|
|
@@ -59,7 +60,7 @@ export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^
|
|
|
59
60
|
[[elem(tag, as, bs, [])], rest]),
|
|
60
61
|
([, tag]) => tag,
|
|
61
62
|
new Cache(10000))),
|
|
62
|
-
])))))
|
|
63
|
+
])))));
|
|
63
64
|
|
|
64
65
|
export const attribute: HTMLParser.TagParser.AttributeParser = union([
|
|
65
66
|
str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
|
|
3
|
-
import { union, validate, focus,
|
|
3
|
+
import { union, creator, validate, focus, fmap } from '../../combinator';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
import { reduce } from 'spica/memoize';
|
|
6
6
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { InsertionParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import {
|
|
5
|
+
import { Rule } from '../context';
|
|
6
|
+
import { blankWith } from '../visibility';
|
|
6
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
8
|
import { unshift } from 'spica/array';
|
|
8
9
|
|
|
9
|
-
export const insertion: InsertionParser = lazy(() =>
|
|
10
|
+
export const insertion: InsertionParser = lazy(() => syntax(Rule.none, 1, surround(
|
|
10
11
|
str('++'),
|
|
11
12
|
some(union([
|
|
12
13
|
some(inline, blankWith('\n', '++')),
|
|
@@ -14,4 +15,4 @@ export const insertion: InsertionParser = lazy(() => creator(precedence(1, surro
|
|
|
14
15
|
])),
|
|
15
16
|
str('++'), false,
|
|
16
17
|
([, bs], rest) => [[html('ins', defrag(bs))], rest],
|
|
17
|
-
([as, bs], rest) => [unshift(as, bs), rest])))
|
|
18
|
+
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -45,6 +45,7 @@ describe('Unit: parser/inline/link', () => {
|
|
|
45
45
|
it('invalid', () => {
|
|
46
46
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
47
47
|
assert.deepStrictEqual(inspect(parser('{}')), undefined);
|
|
48
|
+
assert.deepStrictEqual(inspect(parser('[{b}')), [['', '[', '<a href="b">b</a>'], '']);
|
|
48
49
|
assert.deepStrictEqual(inspect(parser('[]')), undefined);
|
|
49
50
|
assert.deepStrictEqual(inspect(parser('[]{}')), undefined);
|
|
50
51
|
assert.deepStrictEqual(inspect(parser('[]{ }')), undefined);
|
|
@@ -64,7 +65,7 @@ describe('Unit: parser/inline/link', () => {
|
|
|
64
65
|
assert.deepStrictEqual(inspect(parser('[\\ ]{b}')), undefined);
|
|
65
66
|
assert.deepStrictEqual(inspect(parser('[\\\n]{b}')), undefined);
|
|
66
67
|
assert.deepStrictEqual(inspect(parser('[	]{b}')), undefined);
|
|
67
|
-
assert.deepStrictEqual(inspect(parser('[[]{b}')),
|
|
68
|
+
assert.deepStrictEqual(inspect(parser('[[]{b}')), [['', '[', '<a href="b">b</a>'], '']);
|
|
68
69
|
assert.deepStrictEqual(inspect(parser('[]]{b}')), undefined);
|
|
69
70
|
assert.deepStrictEqual(inspect(parser('[a]{}')), undefined);
|
|
70
71
|
assert.deepStrictEqual(inspect(parser('[a\nb]{b}')), undefined);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
2
|
import { LinkParser, TextLinkParser } from '../inline';
|
|
3
3
|
import { Result, eval } from '../../combinator/data/parser';
|
|
4
|
-
import { union, inits, tails, subsequence, some,
|
|
4
|
+
import { union, inits, tails, subsequence, some, guard, syntax, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
5
5
|
import { inline, media, shortmedia } from '../inline';
|
|
6
6
|
import { attributes } from './html';
|
|
7
7
|
import { autolink } from '../autolink';
|
|
8
8
|
import { unescsource, str } from '../source';
|
|
9
|
-
import {
|
|
9
|
+
import { Rule, State } from '../context';
|
|
10
|
+
import { trimNode } from '../visibility';
|
|
11
|
+
import { stringify } from '../util';
|
|
10
12
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
11
13
|
import { ReadonlyURL } from 'spica/url';
|
|
12
14
|
|
|
@@ -15,41 +17,29 @@ const optspec = {
|
|
|
15
17
|
} as const;
|
|
16
18
|
Object.setPrototypeOf(optspec, null);
|
|
17
19
|
|
|
18
|
-
export const link: LinkParser = lazy(() => validate(['[', '{'],
|
|
19
|
-
guard(context => context.
|
|
20
|
+
export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link, 2, 10, bind(
|
|
21
|
+
guard(context => ~context.state! & State.link,
|
|
20
22
|
fmap(subsequence([
|
|
21
|
-
|
|
22
|
-
link: false,
|
|
23
|
-
}}},
|
|
23
|
+
state(State.link,
|
|
24
24
|
dup(union([
|
|
25
25
|
surround('[', media, ']'),
|
|
26
26
|
surround('[', shortmedia, ']'),
|
|
27
27
|
surround(
|
|
28
28
|
'[',
|
|
29
|
-
|
|
30
|
-
annotation: false,
|
|
31
|
-
reference: false,
|
|
32
|
-
index: false,
|
|
33
|
-
label: false,
|
|
34
|
-
// Redundant
|
|
35
|
-
//link: false,
|
|
36
|
-
media: false,
|
|
37
|
-
autolink: false,
|
|
38
|
-
}}},
|
|
29
|
+
state(State.annotation | State.reference | State.index | State.label | State.media | State.autolink,
|
|
39
30
|
some(inline, ']', [[/^\\?\n/, 9], [']', 2]])),
|
|
40
31
|
']',
|
|
41
32
|
true,
|
|
42
33
|
undefined,
|
|
43
|
-
([, ns = [], rest], next) => next[0] === ']' ? undefined : optimize('[', ns, rest)),
|
|
34
|
+
([, ns = [], rest], next) => next[0] === ']' ? undefined : optimize('[', ns, rest, next)),
|
|
44
35
|
]))),
|
|
45
|
-
// 全体の失敗が確定した時も解析し予算を浪費している
|
|
46
36
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
47
|
-
]),
|
|
37
|
+
], nodes => nodes[0][0] !== ''),
|
|
48
38
|
([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []])),
|
|
49
39
|
([content, params]: [(HTMLElement | string)[], string[]], rest, context) => {
|
|
50
|
-
if (params.length === 0) return;
|
|
51
40
|
assert(content[0] !== '' || params.length === 0);
|
|
52
41
|
if (content[0] === '') return [content, rest];
|
|
42
|
+
if (params.length === 0) return;
|
|
53
43
|
assert(params.every(p => typeof p === 'string'));
|
|
54
44
|
if (content.length !== 0 && trimNode(content).length === 0) return;
|
|
55
45
|
if (eval(some(autolink)(stringify(content), context))?.some(node => typeof node === 'object')) return;
|
|
@@ -67,9 +57,9 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], creator(10, prec
|
|
|
67
57
|
if (el.classList.contains('invalid')) return [[el], rest];
|
|
68
58
|
assert(el.classList.length === 0);
|
|
69
59
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
70
|
-
}))))
|
|
60
|
+
}))));
|
|
71
61
|
|
|
72
|
-
export const textlink: TextLinkParser = lazy(() => validate(['[', '{'],
|
|
62
|
+
export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link, 2, 10, bind(
|
|
73
63
|
reverse(tails([
|
|
74
64
|
dup(surround('[', some(union([unescsource]), ']'), ']')),
|
|
75
65
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
@@ -92,7 +82,7 @@ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], creator(
|
|
|
92
82
|
assert(!el.classList.contains('invalid'));
|
|
93
83
|
assert(el.classList.length === 0);
|
|
94
84
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
95
|
-
}))))
|
|
85
|
+
}))));
|
|
96
86
|
|
|
97
87
|
export const uri: LinkParser.ParameterParser.UriParser = fmap(union([
|
|
98
88
|
open(/^[^\S\n]+/, str(/^\S+/)),
|
|
@@ -196,11 +186,15 @@ function decode(uri: string): string {
|
|
|
196
186
|
}
|
|
197
187
|
}
|
|
198
188
|
|
|
199
|
-
export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string): Result<string> {
|
|
189
|
+
export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string, next: string): Result<string> {
|
|
190
|
+
if (next[+(next[0] === '\\')] === '\n') return;
|
|
200
191
|
let count = 0;
|
|
201
192
|
for (let i = 0; i < ns.length - 1; i += 2) {
|
|
202
|
-
|
|
203
|
-
|
|
193
|
+
const fst = ns[i];
|
|
194
|
+
const snd = ns[i + 1] as string;
|
|
195
|
+
assert(typeof snd === 'string');
|
|
196
|
+
if (fst !== '' || snd[0] !== opener[0]) break;
|
|
197
|
+
count += snd.length;
|
|
204
198
|
}
|
|
205
199
|
return [['', opener[0].repeat(opener.length + count)], rest.slice(count)];
|
|
206
200
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { MarkParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import { startTight, blankWith } from '../
|
|
5
|
+
import { startTight, blankWith } from '../visibility';
|
|
6
|
+
import { Rule } from '../context';
|
|
6
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
8
|
import { unshift } from 'spica/array';
|
|
8
9
|
|
|
9
|
-
export const mark: MarkParser = lazy(() =>
|
|
10
|
+
export const mark: MarkParser = lazy(() => syntax(Rule.none, 1, surround(
|
|
10
11
|
str('=='),
|
|
11
12
|
startTight(some(union([
|
|
12
13
|
some(inline, blankWith('==')),
|
|
@@ -14,4 +15,4 @@ export const mark: MarkParser = lazy(() => creator(precedence(1, surround(
|
|
|
14
15
|
]))),
|
|
15
16
|
str('=='), false,
|
|
16
17
|
([, bs], rest) => [[html('mark', defrag(bs))], rest],
|
|
17
|
-
([as, bs], rest) => [unshift(as, bs), rest])))
|
|
18
|
+
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MathParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, creator, precedence, validate, focus, rewrite, surround, lazy } from '../../combinator';
|
|
3
3
|
import { escsource, unescsource } from '../source';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
|
|
@@ -22,6 +22,7 @@ describe('Unit: parser/inline/media', () => {
|
|
|
22
22
|
assert.deepStrictEqual(inspect(parser('{}')), undefined);
|
|
23
23
|
assert.deepStrictEqual(inspect(parser('[]')), undefined);
|
|
24
24
|
assert.deepStrictEqual(inspect(parser('!{}')), undefined);
|
|
25
|
+
assert.deepStrictEqual(inspect(parser('![{b}')), undefined);
|
|
25
26
|
assert.deepStrictEqual(inspect(parser('![]')), undefined);
|
|
26
27
|
assert.deepStrictEqual(inspect(parser('![]{}')), undefined);
|
|
27
28
|
assert.deepStrictEqual(inspect(parser('![]{ }')), undefined);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { undefined, location } from 'spica/global';
|
|
2
2
|
import { MediaParser } from '../inline';
|
|
3
|
-
import { union, inits, tails, some,
|
|
3
|
+
import { union, inits, tails, some, creator, precedence, guard, syntax, validate, verify, surround, open, dup, lazy, fmap, bind } from '../../combinator';
|
|
4
4
|
import { textlink, uri, option as linkoption, resolve } from './link';
|
|
5
5
|
import { attributes } from './html';
|
|
6
6
|
import { unsafehtmlentity } from './htmlentity';
|
|
7
7
|
import { txt, str } from '../source';
|
|
8
|
+
import { Rule, State } from '../context';
|
|
8
9
|
import { html, define } from 'typed-dom/dom';
|
|
9
10
|
import { ReadonlyURL } from 'spica/url';
|
|
10
11
|
import { unshift, shift, push } from 'spica/array';
|
|
@@ -17,9 +18,9 @@ const optspec = {
|
|
|
17
18
|
} as const;
|
|
18
19
|
Object.setPrototypeOf(optspec, null);
|
|
19
20
|
|
|
20
|
-
export const media: MediaParser = lazy(() => validate(['![', '!{'],
|
|
21
|
+
export const media: MediaParser = lazy(() => validate(['![', '!{'], syntax(Rule.media, 2, 10, bind(verify(fmap(open(
|
|
21
22
|
'!',
|
|
22
|
-
guard(context => context.
|
|
23
|
+
guard(context => ~context.state! & State.media,
|
|
23
24
|
tails([
|
|
24
25
|
dup(surround(
|
|
25
26
|
'[',
|
|
@@ -52,19 +53,19 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], creator(10,
|
|
|
52
53
|
if (el.hasAttribute('aspect-ratio')) {
|
|
53
54
|
el.style.aspectRatio = el.getAttribute('aspect-ratio')!;
|
|
54
55
|
}
|
|
55
|
-
if (context.
|
|
56
|
+
if (context.state! & State.link || cache && cache.tagName !== 'IMG') return [[el], rest];
|
|
56
57
|
return fmap(
|
|
57
58
|
textlink as MediaParser,
|
|
58
59
|
([link]) => [define(link, { target: '_blank' }, [el])])
|
|
59
60
|
(`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
|
|
60
|
-
}))))
|
|
61
|
+
}))));
|
|
61
62
|
|
|
62
|
-
const bracket: MediaParser.TextParser.BracketParser = lazy(() => union([
|
|
63
|
+
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creator(union([
|
|
63
64
|
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
64
65
|
surround(str('['), some(union([unsafehtmlentity, bracket, txt]), ']'), str(']'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
65
66
|
surround(str('{'), some(union([unsafehtmlentity, bracket, txt]), '}'), str('}'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
66
67
|
surround(str('"'), precedence(8, some(union([unsafehtmlentity, txt]), '"')), str('"'), true),
|
|
67
|
-
]));
|
|
68
|
+
])));
|
|
68
69
|
|
|
69
70
|
const option: MediaParser.ParameterParser.OptionParser = union([
|
|
70
71
|
fmap(str(/^[^\S\n]+[1-9][0-9]*x[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` width="${opt.slice(1).split('x')[0]}"`, ` height="${opt.slice(1).split('x')[1]}"`]),
|