securemark 0.282.0 → 0.283.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 +5 -0
- package/design.md +5 -9
- package/dist/index.js +7363 -7188
- package/package.json +2 -2
- package/src/combinator/control/manipulation/convert.ts +4 -8
- package/src/combinator/control/manipulation/indent.ts +3 -5
- package/src/combinator/control/manipulation/scope.ts +6 -3
- package/src/combinator/control/manipulation/surround.ts +17 -2
- package/src/combinator/data/parser/context.test.ts +6 -6
- package/src/combinator/data/parser/context.ts +25 -39
- package/src/combinator/data/parser.ts +2 -3
- package/src/parser/api/bind.ts +6 -6
- package/src/parser/api/parse.test.ts +17 -16
- package/src/parser/api/parse.ts +0 -3
- package/src/parser/block/blockquote.ts +4 -3
- package/src/parser/block/dlist.test.ts +1 -1
- package/src/parser/block/dlist.ts +6 -6
- package/src/parser/block/extension/aside.ts +4 -3
- package/src/parser/block/extension/example.ts +4 -3
- package/src/parser/block/extension/table.ts +7 -7
- package/src/parser/block/heading.ts +3 -2
- package/src/parser/block/ilist.ts +2 -1
- package/src/parser/block/olist.ts +4 -3
- package/src/parser/block/reply/cite.ts +3 -3
- package/src/parser/block/reply/quote.ts +3 -3
- package/src/parser/block/sidefence.ts +2 -1
- package/src/parser/block/table.ts +9 -9
- package/src/parser/block/ulist.ts +6 -5
- package/src/parser/block.ts +16 -5
- package/src/parser/context.ts +9 -21
- package/src/parser/inline/annotation.ts +5 -4
- package/src/parser/inline/autolink/email.ts +2 -1
- package/src/parser/inline/autolink/url.ts +6 -5
- package/src/parser/inline/autolink.ts +2 -2
- package/src/parser/inline/bracket.ts +17 -17
- package/src/parser/inline/code.test.ts +1 -1
- package/src/parser/inline/code.ts +2 -1
- package/src/parser/inline/deletion.ts +3 -3
- package/src/parser/inline/emphasis.ts +3 -3
- package/src/parser/inline/emstrong.ts +3 -3
- package/src/parser/inline/extension/index.ts +18 -6
- package/src/parser/inline/extension/indexee.ts +2 -2
- package/src/parser/inline/extension/indexer.ts +2 -1
- package/src/parser/inline/extension/label.ts +2 -2
- package/src/parser/inline/extension/placeholder.ts +4 -4
- package/src/parser/inline/html.ts +2 -2
- package/src/parser/inline/htmlentity.ts +2 -1
- package/src/parser/inline/insertion.ts +3 -3
- package/src/parser/inline/link.test.ts +2 -2
- package/src/parser/inline/link.ts +7 -7
- package/src/parser/inline/mark.ts +3 -3
- package/src/parser/inline/math.test.ts +3 -3
- package/src/parser/inline/math.ts +6 -5
- package/src/parser/inline/media.test.ts +1 -1
- package/src/parser/inline/media.ts +5 -5
- package/src/parser/inline/reference.ts +6 -5
- package/src/parser/inline/remark.ts +2 -2
- package/src/parser/inline/ruby.ts +3 -3
- package/src/parser/inline/strong.ts +3 -3
- package/src/parser/inline/template.ts +4 -4
- package/src/parser/inline.ts +1 -0
- package/src/parser/source/escapable.ts +2 -1
- package/src/parser/source/str.ts +3 -2
- package/src/parser/source/text.ts +2 -1
- package/src/parser/source/unescapable.ts +2 -1
- package/src/combinator/data/parser/context/memo.ts +0 -57
|
@@ -2,7 +2,7 @@ import { ExtensionParser } from '../../inline';
|
|
|
2
2
|
import { union, some, syntax, creation, validate, surround, lazy } from '../../../combinator';
|
|
3
3
|
import { inline } from '../../inline';
|
|
4
4
|
import { str } from '../../source';
|
|
5
|
-
import {
|
|
5
|
+
import { State, Recursion } from '../../context';
|
|
6
6
|
import { startTight } from '../../visibility';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
@@ -11,9 +11,9 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
11
11
|
|
|
12
12
|
// All syntax surrounded by square brackets shouldn't contain line breaks.
|
|
13
13
|
|
|
14
|
-
export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate('[', creation(surround(
|
|
14
|
+
export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate('[', creation(1, Recursion.inline, surround(
|
|
15
15
|
str(/^\[[:^|]/),
|
|
16
|
-
syntax(
|
|
16
|
+
syntax(2, State.none,
|
|
17
17
|
startTight(some(union([inline]), ']', [[']', 2]]))),
|
|
18
18
|
str(']'), false,
|
|
19
19
|
([, bs], rest) => [[
|
|
@@ -24,4 +24,4 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validat
|
|
|
24
24
|
'data-invalid-message': `Invalid start symbol or linebreak`,
|
|
25
25
|
}, defrag(bs)),
|
|
26
26
|
], rest],
|
|
27
|
-
([as, bs], rest) => [unshift(as, bs), rest]))));
|
|
27
|
+
([as, bs], rest) => [unshift(as, bs), rest], 3))));
|
|
@@ -2,7 +2,7 @@ import { HTMLParser } from '../inline';
|
|
|
2
2
|
import { union, subsequence, some, syntax, creation, validate, focus, surround, open, match, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import {
|
|
5
|
+
import { State, Recursion } from '../context';
|
|
6
6
|
import { isStartLooseNodes, blankWith } from '../visibility';
|
|
7
7
|
import { memoize } from 'spica/memoize';
|
|
8
8
|
import { Clock } from 'spica/clock';
|
|
@@ -18,7 +18,7 @@ const attrspecs = {
|
|
|
18
18
|
Object.setPrototypeOf(attrspecs, null);
|
|
19
19
|
Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
|
|
20
20
|
|
|
21
|
-
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/i, creation(
|
|
21
|
+
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/i, creation(1, Recursion.inline, syntax(4, State.none, union([
|
|
22
22
|
focus(
|
|
23
23
|
/^<wbr[^\S\n]*>/i,
|
|
24
24
|
() => [[h('wbr')], '']),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
|
|
2
2
|
import { union, creation, validate, focus, fmap } from '../../combinator';
|
|
3
|
+
import { Recursion } from '../context';
|
|
3
4
|
import { html } from 'typed-dom/dom';
|
|
4
5
|
import { reduce } from 'spica/memoize';
|
|
5
6
|
|
|
6
|
-
export const unsafehtmlentity: UnsafeHTMLEntityParser = creation(validate('&', focus(
|
|
7
|
+
export const unsafehtmlentity: UnsafeHTMLEntityParser = creation(1, Recursion.ignore, validate('&', focus(
|
|
7
8
|
/^&[0-9A-Za-z]+;/,
|
|
8
9
|
({ source }) => [[parse(source) ?? `\x1B${source}`], ''])));
|
|
9
10
|
|
|
@@ -2,14 +2,14 @@ import { InsertionParser } from '../inline';
|
|
|
2
2
|
import { union, some, syntax, creation, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import {
|
|
5
|
+
import { State, Recursion } from '../context';
|
|
6
6
|
import { blankWith } from '../visibility';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
9
|
|
|
10
|
-
export const insertion: InsertionParser = lazy(() => creation(surround(
|
|
10
|
+
export const insertion: InsertionParser = lazy(() => creation(1, Recursion.inline, surround(
|
|
11
11
|
str('++', '+'),
|
|
12
|
-
syntax(
|
|
12
|
+
syntax(1, State.none,
|
|
13
13
|
some(union([
|
|
14
14
|
some(inline, blankWith('\n', '++')),
|
|
15
15
|
open('\n', some(inline, '+'), true),
|
|
@@ -13,10 +13,10 @@ describe('Unit: parser/inline/link', () => {
|
|
|
13
13
|
assert.deepStrictEqual(inspect(parser('[]{data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K}')), [['<a class="invalid">data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K</a>'], '']);
|
|
14
14
|
assert.deepStrictEqual(inspect(parser('[]{any:alert}')), [['<a class="invalid">any:alert</a>'], '']);
|
|
15
15
|
assert.deepStrictEqual(inspect(parser('[]{"}')), [['<a class="url" href=""">"</a>'], '']);
|
|
16
|
-
assert.deepStrictEqual(inspect(parser('[]{<}')), [['<a class="url" href="
|
|
16
|
+
assert.deepStrictEqual(inspect(parser('[]{<}')), [['<a class="url" href="<"><</a>'], '']);
|
|
17
17
|
assert.deepStrictEqual(inspect(parser('[]{\\}')), [['<a class="url" href="\\">\\</a>'], '']);
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('[]{\\"}')), [['<a class="url" href="\\"">\\"</a>'], '']);
|
|
19
|
-
assert.deepStrictEqual(inspect(parser('[]{\\<}')), [['<a class="url" href="
|
|
19
|
+
assert.deepStrictEqual(inspect(parser('[]{\\<}')), [['<a class="url" href="\\<">\\<</a>'], '']);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it('fishing', () => {
|
|
@@ -4,7 +4,7 @@ import { union, inits, tails, sequence, some, constraint, syntax, creation, prec
|
|
|
4
4
|
import { inline, media, shortmedia } from '../inline';
|
|
5
5
|
import { attributes } from './html';
|
|
6
6
|
import { linebreak, unescsource, str } from '../source';
|
|
7
|
-
import {
|
|
7
|
+
import { State, Recursion } from '../context';
|
|
8
8
|
import { trimBlankStart, trimNodeEnd } from '../visibility';
|
|
9
9
|
import { stringify } from '../util';
|
|
10
10
|
import { ReadonlyURL } from 'spica/url';
|
|
@@ -20,15 +20,15 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], union([
|
|
|
20
20
|
textlink,
|
|
21
21
|
])));
|
|
22
22
|
|
|
23
|
-
export const textlink: LinkParser.TextLinkParser = lazy(() => creation(
|
|
23
|
+
export const textlink: LinkParser.TextLinkParser = lazy(() => creation(1, Recursion.ignore,
|
|
24
24
|
constraint(State.link, false,
|
|
25
|
-
syntax(
|
|
25
|
+
syntax(2, State.linkers | State.media,
|
|
26
26
|
bind(reverse(tails([
|
|
27
27
|
dup(surround(
|
|
28
28
|
'[',
|
|
29
29
|
trimBlankStart(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]])),
|
|
30
30
|
']',
|
|
31
|
-
true)),
|
|
31
|
+
true, undefined, undefined, 1)),
|
|
32
32
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
33
33
|
])),
|
|
34
34
|
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
|
|
@@ -38,9 +38,9 @@ export const textlink: LinkParser.TextLinkParser = lazy(() => creation(10,
|
|
|
38
38
|
return [[parse(content, params, context)], rest];
|
|
39
39
|
})))));
|
|
40
40
|
|
|
41
|
-
export const medialink: LinkParser.MediaLinkParser = lazy(() => creation(
|
|
41
|
+
export const medialink: LinkParser.MediaLinkParser = lazy(() => creation(1, Recursion.ignore,
|
|
42
42
|
constraint(State.link | State.media, false,
|
|
43
|
-
syntax(
|
|
43
|
+
syntax(2, State.linkers,
|
|
44
44
|
bind(reverse(sequence([
|
|
45
45
|
dup(surround(
|
|
46
46
|
'[',
|
|
@@ -57,7 +57,7 @@ export const linemedialink: LinkParser.LineMediaLinkParser = surround(
|
|
|
57
57
|
/^(?=[^\S\n]*(?:$|\n))/);
|
|
58
58
|
|
|
59
59
|
export const unsafelink: LinkParser.UnsafeLinkParser = lazy(() =>
|
|
60
|
-
creation(
|
|
60
|
+
creation(1, Recursion.ignore, precedence(2,
|
|
61
61
|
bind(reverse(tails([
|
|
62
62
|
dup(surround(
|
|
63
63
|
'[',
|
|
@@ -4,14 +4,14 @@ import { inline } from '../inline';
|
|
|
4
4
|
import { identity, signature } from './extension/indexee';
|
|
5
5
|
import { str } from '../source';
|
|
6
6
|
import { startTight, blankWith } from '../visibility';
|
|
7
|
-
import {
|
|
7
|
+
import { State, Recursion } from '../context';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
10
10
|
|
|
11
|
-
export const mark: MarkParser = lazy(() => creation(surround(
|
|
11
|
+
export const mark: MarkParser = lazy(() => creation(1, Recursion.inline, surround(
|
|
12
12
|
str('==', '='),
|
|
13
13
|
constraint(State.mark, false,
|
|
14
|
-
syntax(
|
|
14
|
+
syntax(1, State.none,
|
|
15
15
|
startTight(some(union([
|
|
16
16
|
some(inline, blankWith('=='), [[/^\\?\n/, 9]]),
|
|
17
17
|
open(some(inline, '=', [[/^\\?\n/, 9]]), mark),
|
|
@@ -115,8 +115,8 @@ describe('Unit: parser/inline/math', () => {
|
|
|
115
115
|
assert.deepStrictEqual(inspect(parser('$(0, 1]$)')), [['<span class="math" translate="no" data-src="$(0, 1]$">$(0, 1]$</span>'], ')']);
|
|
116
116
|
assert.deepStrictEqual(inspect(parser('$\\{0,1\\}$')), [['<span class="math" translate="no" data-src="$\\{0,1\\}$">$\\{0,1\\}$</span>'], '']);
|
|
117
117
|
assert.deepStrictEqual(inspect(parser('$n=1$')), [['<span class="math" translate="no" data-src="$n=1$">$n=1$</span>'], '']);
|
|
118
|
-
assert.deepStrictEqual(inspect(parser('$n<m$')), [['<span class="math" translate="no" data-src="$n
|
|
119
|
-
assert.deepStrictEqual(inspect(parser('$n>m$')), [['<span class="math" translate="no" data-src="$n
|
|
118
|
+
assert.deepStrictEqual(inspect(parser('$n<m$')), [['<span class="math" translate="no" data-src="$n<m$">$n<m$</span>'], '']);
|
|
119
|
+
assert.deepStrictEqual(inspect(parser('$n>m$')), [['<span class="math" translate="no" data-src="$n>m$">$n>m$</span>'], '']);
|
|
120
120
|
assert.deepStrictEqual(inspect(parser('$E = mc^2$')), [['<span class="math" translate="no" data-src="$E = mc^2$">$E = mc^2$</span>'], '']);
|
|
121
121
|
assert.deepStrictEqual(inspect(parser('$f(x)$')), [['<span class="math" translate="no" data-src="$f(x)$">$f(x)$</span>'], '']);
|
|
122
122
|
assert.deepStrictEqual(inspect(parser('$f: x \\to y$')), [['<span class="math" translate="no" data-src="$f: x \\to y$">$f: x \\to y$</span>'], '']);
|
|
@@ -143,7 +143,7 @@ describe('Unit: parser/inline/math', () => {
|
|
|
143
143
|
|
|
144
144
|
it('nest', () => {
|
|
145
145
|
assert.deepStrictEqual(inspect(parser('${*a*}$')), [['<span class="math" translate="no" data-src="${*a*}$">${*a*}$</span>'], '']);
|
|
146
|
-
assert.deepStrictEqual(inspect(parser('${<wbr>}$')), [['<span class="math" translate="no" data-src="${
|
|
146
|
+
assert.deepStrictEqual(inspect(parser('${<wbr>}$')), [['<span class="math" translate="no" data-src="${<wbr>}$">${<wbr>}$</span>'], '']);
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { MathParser } from '../inline';
|
|
2
2
|
import { union, some, creation, precedence, validate, focus, rewrite, surround, lazy } from '../../combinator';
|
|
3
|
-
import { escsource, unescsource } from '../source';
|
|
3
|
+
import { escsource, unescsource, str } from '../source';
|
|
4
|
+
import { Recursion } from '../context';
|
|
4
5
|
import { html } from 'typed-dom/dom';
|
|
5
6
|
|
|
6
7
|
const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
|
|
7
8
|
|
|
8
|
-
export const math: MathParser = lazy(() => validate('$', creation(rewrite(
|
|
9
|
+
export const math: MathParser = lazy(() => validate('$', creation(1, Recursion.ignore, rewrite(
|
|
9
10
|
union([
|
|
10
11
|
surround('$', precedence(6, bracket), '$'),
|
|
11
12
|
surround(
|
|
@@ -31,11 +32,11 @@ export const math: MathParser = lazy(() => validate('$', creation(rewrite(
|
|
|
31
32
|
source)
|
|
32
33
|
], '']))));
|
|
33
34
|
|
|
34
|
-
const bracket: MathParser.BracketParser = lazy(() => creation(surround(
|
|
35
|
-
'{',
|
|
35
|
+
const bracket: MathParser.BracketParser = lazy(() => creation(0, Recursion.terminal, surround(
|
|
36
|
+
str('{'),
|
|
36
37
|
some(union([
|
|
37
38
|
bracket,
|
|
38
39
|
some(escsource, /^(?:[{}$]|\\?\n)/),
|
|
39
40
|
])),
|
|
40
|
-
'}',
|
|
41
|
+
str('}'),
|
|
41
42
|
true)));
|
|
@@ -91,7 +91,7 @@ describe('Unit: parser/inline/media', () => {
|
|
|
91
91
|
assert.deepStrictEqual(inspect(parser('![\\[]{/}')), [['<a href="/" target="_blank"><img class="media" data-src="/" alt="["></a>'], '']);
|
|
92
92
|
assert.deepStrictEqual(inspect(parser('![\\"]{"?"#"}')), [['<a href=""?"#"" target="_blank"><img class="media" data-src=""?"#"" alt="""></a>'], '']);
|
|
93
93
|
assert.deepStrictEqual(inspect(parser('![*a*]{/}')), [['<a href="/" target="_blank"><img class="media" data-src="/" alt="*a*"></a>'], '']);
|
|
94
|
-
assert.deepStrictEqual(inspect(parser('![<wbr>]{/}')), [['<a href="/" target="_blank"><img class="media" data-src="/" alt="
|
|
94
|
+
assert.deepStrictEqual(inspect(parser('![<wbr>]{/}')), [['<a href="/" target="_blank"><img class="media" data-src="/" alt="<wbr>"></a>'], '']);
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
it('external', () => {
|
|
@@ -4,7 +4,7 @@ import { unsafelink, uri, option as linkoption, resolve } from './link';
|
|
|
4
4
|
import { attributes } from './html';
|
|
5
5
|
import { unsafehtmlentity } from './htmlentity';
|
|
6
6
|
import { txt, linebreak, str } from '../source';
|
|
7
|
-
import {
|
|
7
|
+
import { State, Recursion } from '../context';
|
|
8
8
|
import { markInvalid } from '../util';
|
|
9
9
|
import { ReadonlyURL } from 'spica/url';
|
|
10
10
|
import { unshift, push } from 'spica/array';
|
|
@@ -18,10 +18,10 @@ const optspec = {
|
|
|
18
18
|
} as const;
|
|
19
19
|
Object.setPrototypeOf(optspec, null);
|
|
20
20
|
|
|
21
|
-
export const media: MediaParser = lazy(() => validate(['![', '!{'], creation(
|
|
21
|
+
export const media: MediaParser = lazy(() => validate(['![', '!{'], creation(1, Recursion.ignore, open(
|
|
22
22
|
'!',
|
|
23
23
|
constraint(State.media, false,
|
|
24
|
-
syntax(
|
|
24
|
+
syntax(2, ~State.link,
|
|
25
25
|
bind(verify(fmap(tails([
|
|
26
26
|
dup(surround(
|
|
27
27
|
'[',
|
|
@@ -55,7 +55,7 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], creation(10,
|
|
|
55
55
|
el.style.aspectRatio = el.getAttribute('aspect-ratio')!;
|
|
56
56
|
}
|
|
57
57
|
if (context.state! & State.link) return [[el], rest];
|
|
58
|
-
if (cache && cache.tagName !== 'IMG') return
|
|
58
|
+
if (cache && cache.tagName !== 'IMG') return [[el], rest];
|
|
59
59
|
return fmap(
|
|
60
60
|
unsafelink as MediaParser,
|
|
61
61
|
([link]) => [define(link, { class: null, target: '_blank' }, [el])])
|
|
@@ -67,7 +67,7 @@ export const linemedia: MediaParser.LineMediaParser = surround(
|
|
|
67
67
|
union([media]),
|
|
68
68
|
/^(?=[^\S\n]*(?:$|\n))/);
|
|
69
69
|
|
|
70
|
-
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union([
|
|
70
|
+
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(0, Recursion.terminal, union([
|
|
71
71
|
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true,
|
|
72
72
|
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
73
73
|
surround(str('['), some(union([unsafehtmlentity, bracket, txt]), ']'), str(']'), true,
|
|
@@ -2,24 +2,25 @@ import { ReferenceParser } from '../inline';
|
|
|
2
2
|
import { union, subsequence, some, syntax, creation, constraint, surround, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
|
-
import {
|
|
5
|
+
import { State, Recursion } from '../context';
|
|
6
6
|
import { blank, trimBlankStart, trimNodeEnd } from '../visibility';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
|
|
9
|
-
export const reference: ReferenceParser = lazy(() => creation(surround(
|
|
9
|
+
export const reference: ReferenceParser = lazy(() => creation(1, Recursion.ignore, surround(
|
|
10
10
|
'[[',
|
|
11
11
|
constraint(State.reference, false,
|
|
12
|
-
syntax(
|
|
12
|
+
syntax(6, State.annotation | State.reference | State.media,
|
|
13
13
|
subsequence([
|
|
14
14
|
abbr,
|
|
15
15
|
trimBlankStart(some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])),
|
|
16
16
|
]))),
|
|
17
17
|
']]',
|
|
18
18
|
false,
|
|
19
|
-
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNodeEnd(defrag(ns)))])], rest]
|
|
19
|
+
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNodeEnd(defrag(ns)))])], rest],
|
|
20
|
+
undefined, 1)));
|
|
20
21
|
|
|
21
22
|
// Chicago-Style
|
|
22
|
-
const abbr: ReferenceParser.AbbrParser = creation(surround(
|
|
23
|
+
const abbr: ReferenceParser.AbbrParser = creation(1, Recursion.ignore, surround(
|
|
23
24
|
'^',
|
|
24
25
|
union([str(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]),
|
|
25
26
|
/^\|?(?=]])|^\|[^\S\n]*/,
|
|
@@ -2,12 +2,12 @@ import { RemarkParser } from '../inline';
|
|
|
2
2
|
import { union, some, syntax, creation, validate, surround, open, close, match, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { text, str } from '../source';
|
|
5
|
-
import {
|
|
5
|
+
import { State, Recursion } from '../context';
|
|
6
6
|
import { memoize } from 'spica/memoize';
|
|
7
7
|
import { unshift, push } from 'spica/array';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
9
|
|
|
10
|
-
export const remark: RemarkParser = lazy(() => validate('[%', creation(
|
|
10
|
+
export const remark: RemarkParser = lazy(() => validate('[%', creation(1, Recursion.inline, syntax(5, State.none, match(
|
|
11
11
|
/^\[(%+)\s/,
|
|
12
12
|
memoize(
|
|
13
13
|
([, fence]) =>
|
|
@@ -3,12 +3,12 @@ import { eval, exec } from '../../combinator/data/parser';
|
|
|
3
3
|
import { sequence, syntax, creation, validate, verify, surround, lazy, fmap } from '../../combinator';
|
|
4
4
|
import { unsafehtmlentity } from './htmlentity';
|
|
5
5
|
import { text as txt, str } from '../source';
|
|
6
|
-
import {
|
|
6
|
+
import { State, Recursion } from '../context';
|
|
7
7
|
import { isStartTightNodes } from '../visibility';
|
|
8
8
|
import { unshift, push } from 'spica/array';
|
|
9
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
10
|
|
|
11
|
-
export const ruby: RubyParser = lazy(() => validate('[', creation(
|
|
11
|
+
export const ruby: RubyParser = lazy(() => validate('[', creation(1, Recursion.ignore, syntax(2, State.all, fmap(verify(fmap(
|
|
12
12
|
sequence([
|
|
13
13
|
surround('[', str(/^(?:\\[^\n]|[^\\[\](){}"\n])+/), ']'),
|
|
14
14
|
surround('(', str(/^(?:\\[^\n]|[^\\[\](){}"\n])+/), ')'),
|
|
@@ -51,7 +51,7 @@ export const ruby: RubyParser = lazy(() => validate('[', creation(syntax(Syntax.
|
|
|
51
51
|
}
|
|
52
52
|
})))));
|
|
53
53
|
|
|
54
|
-
const text: RubyParser.TextParser = creation(1,
|
|
54
|
+
const text: RubyParser.TextParser = creation(1, Recursion.ignore, ({ source, context }) => {
|
|
55
55
|
const acc = [''];
|
|
56
56
|
while (source !== '') {
|
|
57
57
|
assert(source[0] !== '\n');
|
|
@@ -3,14 +3,14 @@ import { union, some, syntax, creation, surround, open, lazy } from '../../combi
|
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { emstrong } from './emstrong';
|
|
5
5
|
import { str } from '../source';
|
|
6
|
-
import {
|
|
6
|
+
import { State, Recursion } from '../context';
|
|
7
7
|
import { startTight, blankWith } from '../visibility';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
10
|
|
|
11
|
-
export const strong: StrongParser = lazy(() => creation(surround(
|
|
11
|
+
export const strong: StrongParser = lazy(() => creation(1, Recursion.inline, surround(
|
|
12
12
|
str('**', '*'),
|
|
13
|
-
syntax(
|
|
13
|
+
syntax(1, State.none,
|
|
14
14
|
startTight(some(union([
|
|
15
15
|
some(inline, blankWith('**'), [[/^\\?\n/, 9]]),
|
|
16
16
|
open(some(inline, '*', [[/^\\?\n/, 9]]), union([
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { TemplateParser } from '../inline';
|
|
2
2
|
import { union, some, syntax, creation, precedence, surround, lazy } from '../../combinator';
|
|
3
3
|
import { escsource, str } from '../source';
|
|
4
|
-
import {
|
|
4
|
+
import { State, Recursion } from '../context';
|
|
5
5
|
import { unshift } from 'spica/array';
|
|
6
6
|
import { html } from 'typed-dom/dom';
|
|
7
7
|
|
|
8
|
-
export const template: TemplateParser = lazy(() => creation(surround(
|
|
8
|
+
export const template: TemplateParser = lazy(() => creation(1, Recursion.ignore, surround(
|
|
9
9
|
'{{',
|
|
10
|
-
syntax(
|
|
10
|
+
syntax(6, State.all, some(union([bracket, escsource]), '}', [['}}', 6]])),
|
|
11
11
|
'}}',
|
|
12
12
|
true,
|
|
13
13
|
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest])));
|
|
14
14
|
|
|
15
|
-
const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
|
|
15
|
+
const bracket: TemplateParser.BracketParser = lazy(() => creation(0, Recursion.terminal, union([
|
|
16
16
|
surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true,
|
|
17
17
|
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
18
18
|
surround(str('['), some(union([bracket, escsource]), ']'), str(']'), true,
|
package/src/parser/inline.ts
CHANGED
|
@@ -70,6 +70,7 @@ export const inline: InlineParser = lazy(() => union([
|
|
|
70
70
|
|
|
71
71
|
export { indexee } from './inline/extension/indexee';
|
|
72
72
|
export { indexer } from './inline/extension/indexer';
|
|
73
|
+
export { dataindex } from './inline/extension/index';
|
|
73
74
|
export { medialink } from './inline/link';
|
|
74
75
|
export { media } from './inline/media';
|
|
75
76
|
export { shortmedia } from './inline/shortmedia';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { EscapableSourceParser } from '../source';
|
|
2
2
|
import { creation } from '../../combinator';
|
|
3
3
|
import { nonWhitespace } from './text';
|
|
4
|
+
import { Recursion } from '../context';
|
|
4
5
|
|
|
5
6
|
const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
|
|
6
7
|
|
|
7
|
-
export const escsource: EscapableSourceParser = creation(1,
|
|
8
|
+
export const escsource: EscapableSourceParser = creation(1, Recursion.ignore, ({ source, context }) => {
|
|
8
9
|
if (source === '') return;
|
|
9
10
|
const i = source.search(delimiter);
|
|
10
11
|
switch (i) {
|
package/src/parser/source/str.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { StrParser } from '../source';
|
|
2
2
|
import { Parser, Context } from '../../combinator/data/parser';
|
|
3
3
|
import { creation } from '../../combinator';
|
|
4
|
+
import { Recursion } from '../context';
|
|
4
5
|
|
|
5
6
|
export function str(pattern: string | RegExp, not?: string): StrParser;
|
|
6
7
|
export function str(pattern: string | RegExp, not?: string): Parser<string, Context<StrParser>, []> {
|
|
7
8
|
assert(pattern);
|
|
8
9
|
return typeof pattern === 'string'
|
|
9
|
-
? creation(1,
|
|
10
|
+
? creation(1, Recursion.ignore, ({ source }) => {
|
|
10
11
|
if (source === '') return;
|
|
11
12
|
if (not && source.slice(pattern.length, pattern.length + not.length) === not) return;
|
|
12
13
|
return source.slice(0, pattern.length) === pattern
|
|
13
14
|
? [[pattern], source.slice(pattern.length)]
|
|
14
15
|
: undefined;
|
|
15
16
|
})
|
|
16
|
-
: creation(1,
|
|
17
|
+
: creation(1, Recursion.ignore, ({ source }) => {
|
|
17
18
|
if (source === '') return;
|
|
18
19
|
const m = source.match(pattern);
|
|
19
20
|
if (m && not && source.slice(m[0].length, m[0].length + not.length) === not) return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TextParser, TxtParser, LinebreakParser } from '../source';
|
|
2
2
|
import { union, creation, focus } from '../../combinator';
|
|
3
3
|
import { str } from './str';
|
|
4
|
+
import { Recursion } from '../context';
|
|
4
5
|
import { html } from 'typed-dom/dom';
|
|
5
6
|
|
|
6
7
|
export const delimiter = /[\s\x00-\x7F()[]{}“”‘’「」『』]|\S[#>]/u;
|
|
@@ -8,7 +9,7 @@ export const nonWhitespace = /[\S\n]|$/u;
|
|
|
8
9
|
export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/u;
|
|
9
10
|
const repeat = str(/^(.)\1*/);
|
|
10
11
|
|
|
11
|
-
export const text: TextParser = creation(1,
|
|
12
|
+
export const text: TextParser = creation(1, Recursion.ignore, ({ source, context }) => {
|
|
12
13
|
if (source === '') return;
|
|
13
14
|
const i = source.search(delimiter);
|
|
14
15
|
switch (i) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { UnescapableSourceParser } from '../source';
|
|
2
2
|
import { creation } from '../../combinator';
|
|
3
3
|
import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
|
|
4
|
+
import { Recursion } from '../context';
|
|
4
5
|
|
|
5
|
-
export const unescsource: UnescapableSourceParser = creation(1,
|
|
6
|
+
export const unescsource: UnescapableSourceParser = creation(1, Recursion.ignore, ({ source, context }) => {
|
|
6
7
|
assert(source[0] !== '\x1B');
|
|
7
8
|
if (source === '') return;
|
|
8
9
|
const i = source.search(delimiter);
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { max } from 'spica/alias';
|
|
2
|
-
|
|
3
|
-
export class Memo {
|
|
4
|
-
constructor(
|
|
5
|
-
public readonly targets = ~0,
|
|
6
|
-
public readonly margin = 0,
|
|
7
|
-
) {
|
|
8
|
-
}
|
|
9
|
-
private memory: Record<number, Record<number, Record<number, readonly [unknown[], number] | readonly []>> | undefined> = {};
|
|
10
|
-
private count = 0;
|
|
11
|
-
private $length = 0;
|
|
12
|
-
public get length(): number {
|
|
13
|
-
return this.$length;
|
|
14
|
-
}
|
|
15
|
-
public get(
|
|
16
|
-
position: number,
|
|
17
|
-
syntax: number,
|
|
18
|
-
state: number,
|
|
19
|
-
): readonly [unknown[], number] | readonly [] | undefined {
|
|
20
|
-
assert(position > 0);
|
|
21
|
-
if (this.count === 0) return;
|
|
22
|
-
//console.log('get', position, syntax, state, this.memory[position - 1]?.[syntax]?.[state]);
|
|
23
|
-
const cache = this.memory[position - 1]?.[syntax]?.[state];
|
|
24
|
-
return cache?.length === 2
|
|
25
|
-
? [cache[0].slice(), cache[1]]
|
|
26
|
-
: cache;
|
|
27
|
-
}
|
|
28
|
-
public set(
|
|
29
|
-
position: number,
|
|
30
|
-
syntax: number,
|
|
31
|
-
state: number,
|
|
32
|
-
nodes: unknown[] | undefined,
|
|
33
|
-
offset: number,
|
|
34
|
-
): void {
|
|
35
|
-
assert(position > 0);
|
|
36
|
-
this.$length = max(this.$length, position);
|
|
37
|
-
const record = this.memory[position - 1] ??= (++this.count, {});
|
|
38
|
-
assert(!record[syntax]?.[state]);
|
|
39
|
-
(record[syntax] ??= {})[state] = nodes
|
|
40
|
-
? [nodes.slice(), offset]
|
|
41
|
-
: [];
|
|
42
|
-
//console.log('set', position, syntax, state, record[syntax]?.[state]);
|
|
43
|
-
}
|
|
44
|
-
public resize(position: number): void {
|
|
45
|
-
const memory = this.memory;
|
|
46
|
-
for (let i = this.$length; i > position; this.$length = --i) {
|
|
47
|
-
if (!(i in memory)) continue;
|
|
48
|
-
memory[i] &&= (--this.count, undefined);
|
|
49
|
-
}
|
|
50
|
-
//console.log('resize', position + 1);
|
|
51
|
-
}
|
|
52
|
-
public clear(): void {
|
|
53
|
-
this.memory = {};
|
|
54
|
-
this.count = 0;
|
|
55
|
-
this.$length = 0;
|
|
56
|
-
}
|
|
57
|
-
}
|