securemark 0.258.2 → 0.258.5
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 +210 -183
- package/markdown.d.ts +8 -10
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.ts +3 -1
- package/src/combinator/control/constraint/line.ts +6 -1
- package/src/combinator/control/manipulation/indent.ts +3 -0
- package/src/combinator/data/parser/context/memo.ts +7 -4
- package/src/combinator/data/parser/context.test.ts +16 -16
- package/src/combinator/data/parser/context.ts +40 -37
- package/src/combinator/data/parser/some.ts +4 -2
- package/src/combinator/data/parser.ts +2 -2
- package/src/parser/api/bind.ts +1 -1
- package/src/parser/api/parse.test.ts +4 -4
- package/src/parser/api/parse.ts +1 -1
- package/src/parser/autolink.test.ts +3 -2
- package/src/parser/autolink.ts +17 -1
- package/src/parser/block/blockquote.ts +4 -4
- package/src/parser/block/dlist.ts +3 -3
- package/src/parser/block/extension/table.ts +4 -4
- package/src/parser/block/ilist.ts +2 -2
- package/src/parser/block/olist.ts +2 -2
- package/src/parser/block/paragraph.test.ts +3 -1
- package/src/parser/block/reply/cite.ts +2 -2
- package/src/parser/block/reply/quote.ts +3 -3
- package/src/parser/block/sidefence.ts +2 -2
- package/src/parser/block/table.ts +5 -5
- package/src/parser/block/ulist.ts +4 -4
- package/src/parser/block.ts +3 -3
- package/src/parser/context.ts +1 -1
- package/src/parser/inline/annotation.ts +7 -6
- package/src/parser/inline/autolink/email.test.ts +3 -3
- package/src/parser/inline/autolink/email.ts +2 -2
- package/src/parser/inline/autolink/url.test.ts +6 -6
- package/src/parser/inline/autolink/url.ts +2 -2
- package/src/parser/inline/autolink.ts +6 -6
- package/src/parser/inline/bracket.ts +8 -8
- package/src/parser/inline/code.ts +2 -2
- package/src/parser/inline/comment.ts +2 -2
- 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 +9 -8
- package/src/parser/inline/extension/indexer.ts +2 -2
- package/src/parser/inline/extension/label.ts +3 -3
- package/src/parser/inline/extension/placeholder.ts +5 -4
- package/src/parser/inline/html.test.ts +1 -1
- package/src/parser/inline/html.ts +4 -4
- package/src/parser/inline/htmlentity.ts +2 -2
- package/src/parser/inline/insertion.ts +5 -4
- package/src/parser/inline/link.ts +11 -9
- package/src/parser/inline/mark.ts +5 -4
- package/src/parser/inline/math.ts +3 -3
- package/src/parser/inline/media.ts +8 -7
- package/src/parser/inline/reference.ts +8 -7
- package/src/parser/inline/ruby.ts +4 -4
- package/src/parser/inline/shortmedia.ts +2 -2
- package/src/parser/inline/strong.ts +5 -4
- package/src/parser/inline/template.ts +6 -6
- package/src/parser/inline.test.ts +5 -3
- package/src/parser/source/escapable.ts +2 -2
- package/src/parser/source/str.ts +5 -5
- package/src/parser/source/text.test.ts +16 -1
- package/src/parser/source/text.ts +5 -4
- package/src/parser/source/unescapable.ts +2 -2
- package/src/parser/visibility.ts +5 -5
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
2
|
import { LinkParser, TextLinkParser } from '../inline';
|
|
3
3
|
import { Result, eval, exec } from '../../combinator/data/parser';
|
|
4
|
-
import { union, inits, tails, subsequence, some,
|
|
4
|
+
import { union, inits, tails, subsequence, some, constraint, syntax, creation, precedence, 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 { Syntax, State } from '../context';
|
|
10
10
|
import { trimNode } from '../visibility';
|
|
11
11
|
import { stringify } from '../util';
|
|
12
12
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
@@ -17,8 +17,9 @@ const optspec = {
|
|
|
17
17
|
} as const;
|
|
18
18
|
Object.setPrototypeOf(optspec, null);
|
|
19
19
|
|
|
20
|
-
export const link: LinkParser = lazy(() => validate(['[', '{'],
|
|
21
|
-
|
|
20
|
+
export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
|
|
21
|
+
constraint(State.link, false,
|
|
22
|
+
syntax(Syntax.link, 2, 10,
|
|
22
23
|
fmap(subsequence([
|
|
23
24
|
state(State.link,
|
|
24
25
|
dup(union([
|
|
@@ -35,7 +36,7 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link
|
|
|
35
36
|
]))),
|
|
36
37
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
37
38
|
], nodes => nodes[0][0] !== ''),
|
|
38
|
-
([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []])),
|
|
39
|
+
([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []]))),
|
|
39
40
|
([content, params]: [(HTMLElement | string)[], string[]], rest, context) => {
|
|
40
41
|
assert(content[0] !== '' || params.length === 0);
|
|
41
42
|
if (content[0] === '') return [content, rest];
|
|
@@ -61,13 +62,14 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link
|
|
|
61
62
|
if (el.classList.contains('invalid')) return [[el], rest];
|
|
62
63
|
assert(el.classList.length === 0);
|
|
63
64
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
64
|
-
})))
|
|
65
|
+
})));
|
|
65
66
|
|
|
66
|
-
export const textlink: TextLinkParser = lazy(() => validate(['[', '{'],
|
|
67
|
+
export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], bind(
|
|
68
|
+
creation(10, precedence(2,
|
|
67
69
|
reverse(tails([
|
|
68
70
|
dup(surround('[', some(union([unescsource]), ']'), ']')),
|
|
69
71
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
70
|
-
])),
|
|
72
|
+
])))),
|
|
71
73
|
([params, content = []], rest, context) => {
|
|
72
74
|
assert(params[0] === '\r');
|
|
73
75
|
params.shift();
|
|
@@ -86,7 +88,7 @@ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], syntax(R
|
|
|
86
88
|
assert(!el.classList.contains('invalid'));
|
|
87
89
|
assert(el.classList.length === 0);
|
|
88
90
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
89
|
-
})))
|
|
91
|
+
})));
|
|
90
92
|
|
|
91
93
|
export const uri: LinkParser.ParameterParser.UriParser = fmap(union([
|
|
92
94
|
open(/^[^\S\n]+/, str(/^\S+/)),
|
|
@@ -3,16 +3,17 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
5
|
import { startTight, blankWith } from '../visibility';
|
|
6
|
-
import {
|
|
6
|
+
import { Syntax } from '../context';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
export const mark: MarkParser = lazy(() =>
|
|
10
|
+
export const mark: MarkParser = lazy(() => surround(
|
|
11
11
|
str('=='),
|
|
12
|
+
syntax(Syntax.none, 1, 1,
|
|
12
13
|
startTight(some(union([
|
|
13
14
|
some(inline, blankWith('==')),
|
|
14
15
|
open(some(inline, '='), mark),
|
|
15
|
-
]))),
|
|
16
|
+
])))),
|
|
16
17
|
str('=='), false,
|
|
17
18
|
([, bs], rest) => [[html('mark', defrag(bs))], rest],
|
|
18
|
-
([as, bs], rest) => [unshift(as, bs), rest]))
|
|
19
|
+
([as, bs], rest) => [unshift(as, bs), rest]));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MathParser } from '../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, creation, 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
|
|
|
6
6
|
const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
|
|
7
7
|
|
|
8
|
-
export const math: MathParser = lazy(() => validate('$',
|
|
8
|
+
export const math: MathParser = lazy(() => validate('$', creation(rewrite(
|
|
9
9
|
union([
|
|
10
10
|
surround('$', precedence(6, bracket), '$'),
|
|
11
11
|
surround(
|
|
@@ -31,7 +31,7 @@ export const math: MathParser = lazy(() => validate('$', creator(rewrite(
|
|
|
31
31
|
source)
|
|
32
32
|
], '']))));
|
|
33
33
|
|
|
34
|
-
const bracket: MathParser.BracketParser = lazy(() =>
|
|
34
|
+
const bracket: MathParser.BracketParser = lazy(() => creation(surround(
|
|
35
35
|
'{',
|
|
36
36
|
some(union([
|
|
37
37
|
bracket,
|
|
@@ -1,11 +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, syntax, creation, precedence, constraint, 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 {
|
|
8
|
+
import { Syntax, State } from '../context';
|
|
9
9
|
import { html, define } from 'typed-dom/dom';
|
|
10
10
|
import { ReadonlyURL } from 'spica/url';
|
|
11
11
|
import { unshift, shift, push } from 'spica/array';
|
|
@@ -18,9 +18,10 @@ const optspec = {
|
|
|
18
18
|
} as const;
|
|
19
19
|
Object.setPrototypeOf(optspec, null);
|
|
20
20
|
|
|
21
|
-
export const media: MediaParser = lazy(() => validate(['![', '!{'],
|
|
21
|
+
export const media: MediaParser = lazy(() => validate(['![', '!{'], bind(verify(fmap(open(
|
|
22
22
|
'!',
|
|
23
|
-
|
|
23
|
+
constraint(State.media, false,
|
|
24
|
+
syntax(Syntax.media, 2, 10,
|
|
24
25
|
tails([
|
|
25
26
|
dup(surround(
|
|
26
27
|
'[',
|
|
@@ -28,7 +29,7 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], syntax(Rule.
|
|
|
28
29
|
']',
|
|
29
30
|
true)),
|
|
30
31
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
31
|
-
]))),
|
|
32
|
+
])))),
|
|
32
33
|
([as, bs]) => bs ? [[as.join('').trim() || as.join('')], shift(bs)[1]] : [[''], shift(as)[1]]),
|
|
33
34
|
([[text]]) => text === '' || text.trim() !== ''),
|
|
34
35
|
([[text], params], rest, context) => {
|
|
@@ -58,9 +59,9 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], syntax(Rule.
|
|
|
58
59
|
textlink as MediaParser,
|
|
59
60
|
([link]) => [define(link, { target: '_blank' }, [el])])
|
|
60
61
|
(`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
|
|
61
|
-
})))
|
|
62
|
+
})));
|
|
62
63
|
|
|
63
|
-
const bracket: MediaParser.TextParser.BracketParser = lazy(() =>
|
|
64
|
+
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union([
|
|
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('{'), some(union([unsafehtmlentity, bracket, txt]), '}'), str('}'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ReferenceParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, context,
|
|
3
|
+
import { union, subsequence, some, context, syntax, creation, constraint, state, surround, open, lazy, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { optimize } from './link';
|
|
6
6
|
import { str, stropt } from '../source';
|
|
7
|
-
import {
|
|
7
|
+
import { Syntax, State } from '../context';
|
|
8
8
|
import { regBlankStart, startLoose, trimNode } from '../visibility';
|
|
9
9
|
import { stringify } from '../util';
|
|
10
10
|
import { html, defrag } from 'typed-dom/dom';
|
|
11
11
|
|
|
12
|
-
export const reference: ReferenceParser = lazy(() =>
|
|
12
|
+
export const reference: ReferenceParser = lazy(() => surround(
|
|
13
13
|
'[[',
|
|
14
|
-
|
|
14
|
+
constraint(State.reference, false,
|
|
15
|
+
syntax(Syntax.reference, 6, 1,
|
|
15
16
|
state(State.annotation | State.reference | State.media,
|
|
16
17
|
startLoose(
|
|
17
18
|
context({ delimiters: undefined },
|
|
@@ -19,13 +20,13 @@ export const reference: ReferenceParser = lazy(() => validate('[[', syntax(Rule.
|
|
|
19
20
|
abbr,
|
|
20
21
|
open(stropt(/^(?=\^)/), some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])),
|
|
21
22
|
some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]]),
|
|
22
|
-
])), ']'))),
|
|
23
|
+
])), ']')))),
|
|
23
24
|
']]',
|
|
24
25
|
false,
|
|
25
26
|
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest],
|
|
26
|
-
([, ns, rest], next) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next)))
|
|
27
|
+
([, ns, rest], next) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next)));
|
|
27
28
|
|
|
28
|
-
const abbr: ReferenceParser.AbbrParser =
|
|
29
|
+
const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
|
|
29
30
|
'^',
|
|
30
31
|
union([str(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]),
|
|
31
32
|
/^\|?(?=]])|^\|[^\S\n]*/),
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { RubyParser } from '../inline';
|
|
3
3
|
import { eval, exec } from '../../combinator/data/parser';
|
|
4
|
-
import { sequence, syntax,
|
|
4
|
+
import { sequence, syntax, creation, validate, verify, focus, surround, lazy, fmap } from '../../combinator';
|
|
5
5
|
import { unsafehtmlentity } from './htmlentity';
|
|
6
6
|
import { text as txt } from '../source';
|
|
7
|
-
import {
|
|
7
|
+
import { Syntax } from '../context';
|
|
8
8
|
import { isStartTightNodes } from '../visibility';
|
|
9
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
10
|
import { unshift, push } from 'spica/array';
|
|
11
11
|
|
|
12
|
-
export const ruby: RubyParser = lazy(() => validate('[', syntax(
|
|
12
|
+
export const ruby: RubyParser = lazy(() => validate('[', syntax(Syntax.none, 2, 1, fmap(verify(
|
|
13
13
|
sequence([
|
|
14
14
|
surround('[', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=]\()/, text), ']'),
|
|
15
15
|
surround('(', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=\))/, text), ')'),
|
|
@@ -48,7 +48,7 @@ export const ruby: RubyParser = lazy(() => validate('[', syntax(Rule.none, 2, fm
|
|
|
48
48
|
}
|
|
49
49
|
}))));
|
|
50
50
|
|
|
51
|
-
const text: RubyParser.TextParser =
|
|
51
|
+
const text: RubyParser.TextParser = creation((source, context) => {
|
|
52
52
|
const acc = [''];
|
|
53
53
|
while (source !== '') {
|
|
54
54
|
assert(source[0] !== '\n');
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ShortmediaParser } from '../inline';
|
|
2
|
-
import { union,
|
|
2
|
+
import { union, constraint, rewrite, open, convert } from '../../combinator';
|
|
3
3
|
import { url } from './autolink/url';
|
|
4
4
|
import { media } from './media';
|
|
5
5
|
import { State } from '../context';
|
|
6
6
|
|
|
7
7
|
export const shortmedia: ShortmediaParser = rewrite(
|
|
8
|
-
|
|
8
|
+
constraint(State.media, false,
|
|
9
9
|
open('!', url)),
|
|
10
10
|
convert(
|
|
11
11
|
source => `!{ ${source.slice(1)} }`,
|
|
@@ -3,20 +3,21 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { emstrong } from './emstrong';
|
|
5
5
|
import { str } from '../source';
|
|
6
|
-
import {
|
|
6
|
+
import { Syntax } from '../context';
|
|
7
7
|
import { startTight, blankWith } from '../visibility';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
9
|
import { unshift } from 'spica/array';
|
|
10
10
|
|
|
11
|
-
export const strong: StrongParser = lazy(() =>
|
|
11
|
+
export const strong: StrongParser = lazy(() => surround(
|
|
12
12
|
str('**'),
|
|
13
|
+
syntax(Syntax.none, 1, 1,
|
|
13
14
|
startTight(some(union([
|
|
14
15
|
some(inline, blankWith('**')),
|
|
15
16
|
open(some(inline, '*'), union([
|
|
16
17
|
emstrong,
|
|
17
18
|
strong,
|
|
18
19
|
])),
|
|
19
|
-
])), '*'),
|
|
20
|
+
])), '*')),
|
|
20
21
|
str('**'), false,
|
|
21
22
|
([, bs], rest) => [[html('strong', defrag(bs))], rest],
|
|
22
|
-
([as, bs], rest) => [unshift(as, bs), rest]))
|
|
23
|
+
([as, bs], rest) => [unshift(as, bs), rest]));
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { TemplateParser } from '../inline';
|
|
3
|
-
import { union, some, syntax,
|
|
3
|
+
import { union, some, syntax, creation, precedence, surround, lazy } from '../../combinator';
|
|
4
4
|
import { optimize } from './link';
|
|
5
5
|
import { escsource, str } from '../source';
|
|
6
|
-
import {
|
|
6
|
+
import { Syntax } from '../context';
|
|
7
7
|
import { html } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
export const template: TemplateParser = lazy(() =>
|
|
11
|
-
'{{', some(union([bracket, escsource]), '}'), '}}', true,
|
|
10
|
+
export const template: TemplateParser = lazy(() => surround(
|
|
11
|
+
'{{', syntax(Syntax.none, 2, 1, some(union([bracket, escsource]), '}')), '}}', true,
|
|
12
12
|
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest],
|
|
13
|
-
([, ns = [], rest], next) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next)))
|
|
13
|
+
([, ns = [], rest], next) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next)));
|
|
14
14
|
|
|
15
|
-
const bracket: TemplateParser.BracketParser = lazy(() =>
|
|
15
|
+
const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
|
|
16
16
|
surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
17
17
|
surround(str('['), some(union([bracket, escsource]), ']'), str(']'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
18
18
|
surround(str('{'), some(union([bracket, escsource]), '}'), str('}'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
@@ -110,7 +110,7 @@ describe('Unit: parser/inline', () => {
|
|
|
110
110
|
assert.deepStrictEqual(inspect(parser('[@a]')), [['[', '<a href="/@a" class="account">@a</a>', ']'], '']);
|
|
111
111
|
assert.deepStrictEqual(inspect(parser('[#1][#2]')), [['<a class="index" href="#index:1">1</a>', '<a class="index" href="#index:2">2</a>'], '']);
|
|
112
112
|
assert.deepStrictEqual(inspect(parser('[$1]')), [['[', '$', '1', ']'], '']);
|
|
113
|
-
assert.deepStrictEqual(inspect(parser('[$1-2]')), [['[', '$', '1
|
|
113
|
+
assert.deepStrictEqual(inspect(parser('[$1-2]')), [['[', '$', '1-2', ']'], '']);
|
|
114
114
|
assert.deepStrictEqual(inspect(parser('[$-1][$-2]')), [['<a class="label" data-label="$-1">$-1</a>', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
115
115
|
assert.deepStrictEqual(inspect(parser('$-1, $-2')), [['<a class="label" data-label="$-1">$-1</a>', ',', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
116
116
|
assert.deepStrictEqual(inspect(parser('$-1 and $-2')), [['<a class="label" data-label="$-1">$-1</a>', ' ', 'and', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
@@ -168,6 +168,8 @@ describe('Unit: parser/inline', () => {
|
|
|
168
168
|
assert.deepStrictEqual(inspect(parser('[^a@b')), [['[^', '<a class="email" href="mailto:a@b">a@b</a>'], '']);
|
|
169
169
|
assert.deepStrictEqual(inspect(parser('[#a*b\nc*]')), [['[', '<a href="/hashtags/a" class="hashtag">#a</a>', '<em>b<br>c</em>', ']'], '']);
|
|
170
170
|
assert.deepStrictEqual(inspect(parser('[*a\nb*]{/}')), [['[', '<em>a<br>b</em>', ']', '<a href="/">/</a>'], '']);
|
|
171
|
+
assert.deepStrictEqual(inspect(parser('[*a\nb]*')), [['[', '*', 'a', '<br>', 'b', ']', '*'], '']);
|
|
172
|
+
assert.deepStrictEqual(inspect(parser('[*[a\nb*]')), [['', '[', '*', '[', 'a', '<br>', 'b', '*', ']'], '']);
|
|
171
173
|
assert.deepStrictEqual(inspect(parser('[[*a\nb*]]')), [['[', '[', '<em>a<br>b</em>', ']', ']'], '']);
|
|
172
174
|
assert.deepStrictEqual(inspect(parser('"[% *"*"*')), [['"', '[%', ' ', '*', '"', '*', '"', '*'], '']);
|
|
173
175
|
assert.deepStrictEqual(inspect(parser('"[% "*"* %]')), [['"', '[%', ' ', '"', '*', '"', '*', ' ', '%', ']'], '']);
|
|
@@ -223,10 +225,10 @@ describe('Unit: parser/inline', () => {
|
|
|
223
225
|
assert.deepStrictEqual(inspect(parser('#a\nb\n#c\n[#d]')), [['<a href="/hashtags/a" class="hashtag">#a</a>', '<br>', 'b', '<br>', '<a href="/hashtags/c" class="hashtag">#c</a>', '<br>', '<a class="index" href="#index:d">d</a>'], '']);
|
|
224
226
|
assert.deepStrictEqual(inspect(parser('##a')), [['##a'], '']);
|
|
225
227
|
assert.deepStrictEqual(inspect(parser('a#b')), [['a#b'], '']);
|
|
226
|
-
assert.deepStrictEqual(inspect(parser('0a#b')), [['
|
|
228
|
+
assert.deepStrictEqual(inspect(parser('0a#b')), [['0a#b'], '']);
|
|
227
229
|
assert.deepStrictEqual(inspect(parser('あ#b')), [['あ#b'], '']);
|
|
228
230
|
assert.deepStrictEqual(inspect(parser('あい#b')), [['あ', 'い#b'], '']);
|
|
229
|
-
assert.deepStrictEqual(inspect(parser('0aあ#b')), [['0a
|
|
231
|
+
assert.deepStrictEqual(inspect(parser('0aあ#b')), [['0aあ#b'], '']);
|
|
230
232
|
assert.deepStrictEqual(inspect(parser('0aあい#b')), [['0a', 'あ', 'い#b'], '']);
|
|
231
233
|
assert.deepStrictEqual(inspect(parser('「#あ」')), [['「', '<a href="/hashtags/あ" class="hashtag">#あ</a>', '」'], '']);
|
|
232
234
|
assert.deepStrictEqual(inspect(parser('a\n#b')), [['a', '<br>', '<a href="/hashtags/b" class="hashtag">#b</a>'], '']);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { EscapableSourceParser } from '../source';
|
|
2
|
-
import {
|
|
2
|
+
import { creation } from '../../combinator';
|
|
3
3
|
import { nonWhitespace } from './text';
|
|
4
4
|
|
|
5
5
|
const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
|
|
6
6
|
|
|
7
|
-
export const escsource: EscapableSourceParser =
|
|
7
|
+
export const escsource: EscapableSourceParser = creation(source => {
|
|
8
8
|
if (source === '') return;
|
|
9
9
|
const i = source.search(delimiter);
|
|
10
10
|
switch (i) {
|
package/src/parser/source/str.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { StrParser } from '../source';
|
|
3
3
|
import { Parser, Context } from '../../combinator/data/parser';
|
|
4
|
-
import {
|
|
4
|
+
import { creation } from '../../combinator';
|
|
5
5
|
|
|
6
6
|
export function str(pattern: string | RegExp): StrParser;
|
|
7
7
|
export function str(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
|
|
8
8
|
assert(pattern);
|
|
9
9
|
return typeof pattern === 'string'
|
|
10
|
-
?
|
|
10
|
+
? creation(source => {
|
|
11
11
|
if (source === '') return;
|
|
12
12
|
return source.slice(0, pattern.length) === pattern
|
|
13
13
|
? [[pattern], source.slice(pattern.length)]
|
|
14
14
|
: undefined;
|
|
15
15
|
})
|
|
16
|
-
:
|
|
16
|
+
: creation(source => {
|
|
17
17
|
if (source === '') return;
|
|
18
18
|
const m = source.match(pattern);
|
|
19
19
|
return m && m[0].length > 0
|
|
@@ -26,13 +26,13 @@ export function stropt(pattern: string | RegExp): StrParser;
|
|
|
26
26
|
export function stropt(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
|
|
27
27
|
assert(pattern);
|
|
28
28
|
return typeof pattern === 'string'
|
|
29
|
-
?
|
|
29
|
+
? creation(source => {
|
|
30
30
|
if (source === '') return;
|
|
31
31
|
return source.slice(0, pattern.length) === pattern
|
|
32
32
|
? [[pattern], source.slice(pattern.length)]
|
|
33
33
|
: undefined;
|
|
34
34
|
})
|
|
35
|
-
:
|
|
35
|
+
: creation(source => {
|
|
36
36
|
if (source === '') return;
|
|
37
37
|
const m = source.match(pattern);
|
|
38
38
|
return m
|
|
@@ -82,7 +82,7 @@ describe('Unit: parser/text/text', () => {
|
|
|
82
82
|
assert.deepStrictEqual(inspect(parser('0@0')), [['0', '@', '0'], '']);
|
|
83
83
|
assert.deepStrictEqual(inspect(parser('a@0')), [['a', '@', '0'], '']);
|
|
84
84
|
assert.deepStrictEqual(inspect(parser('A@0')), [['A', '@', '0'], '']);
|
|
85
|
-
assert.deepStrictEqual(inspect(parser('
|
|
85
|
+
assert.deepStrictEqual(inspect(parser('aA@0')), [['aA', '@', '0'], '']);
|
|
86
86
|
assert.deepStrictEqual(inspect(parser(' @0')), [[' ', '@', '0'], '']);
|
|
87
87
|
assert.deepStrictEqual(inspect(parser('@@0')), [['@', '@', '0'], '']);
|
|
88
88
|
});
|
|
@@ -96,10 +96,25 @@ describe('Unit: parser/text/text', () => {
|
|
|
96
96
|
assert.deepStrictEqual(inspect(parser('0#0')), [['0', '#', '0'], '']);
|
|
97
97
|
assert.deepStrictEqual(inspect(parser('a#0')), [['a', '#', '0'], '']);
|
|
98
98
|
assert.deepStrictEqual(inspect(parser('A#0')), [['A', '#', '0'], '']);
|
|
99
|
+
assert.deepStrictEqual(inspect(parser('aA#0')), [['a', 'A', '#', '0'], '']);
|
|
99
100
|
assert.deepStrictEqual(inspect(parser(' #0')), [[' ', '#', '0'], '']);
|
|
100
101
|
assert.deepStrictEqual(inspect(parser('##0')), [['#', '#', '0'], '']);
|
|
101
102
|
});
|
|
102
103
|
|
|
104
|
+
it('anchor', () => {
|
|
105
|
+
assert.deepStrictEqual(inspect(parser('>>0')), [['>', '>', '0'], '']);
|
|
106
|
+
assert.deepStrictEqual(inspect(parser('_>>0')), [['_', '>', '>', '0'], '']);
|
|
107
|
+
assert.deepStrictEqual(inspect(parser('$>>0')), [['$', '>', '>', '0'], '']);
|
|
108
|
+
assert.deepStrictEqual(inspect(parser('+>>0')), [['+', '>', '>', '0'], '']);
|
|
109
|
+
assert.deepStrictEqual(inspect(parser('->>0')), [['-', '>', '>', '0'], '']);
|
|
110
|
+
assert.deepStrictEqual(inspect(parser('0>>0')), [['0', '>', '>', '0'], '']);
|
|
111
|
+
assert.deepStrictEqual(inspect(parser('a>>0')), [['a', '>', '>', '0'], '']);
|
|
112
|
+
assert.deepStrictEqual(inspect(parser('A>>0')), [['A', '>', '>', '0'], '']);
|
|
113
|
+
assert.deepStrictEqual(inspect(parser('aA>>0')), [['a', 'A', '>', '>', '0'], '']);
|
|
114
|
+
assert.deepStrictEqual(inspect(parser(' >>0')), [[' ', '>', '>', '0'], '']);
|
|
115
|
+
assert.deepStrictEqual(inspect(parser('>>>>0')), [['>', '>', '>', '>', '0'], '']);
|
|
116
|
+
});
|
|
117
|
+
|
|
103
118
|
it('localize', () => {
|
|
104
119
|
assert.deepStrictEqual(inspect(parser('.\\\n0')), [['.', '<span class="linebreak"> </span>', '0'], '']);
|
|
105
120
|
assert.deepStrictEqual(inspect(parser('。\\\n0')), [['。', '<span class="linebreak"></span>', '0'], '']);
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { TextParser, TxtParser, LinebreakParser } from '../source';
|
|
3
|
-
import { union,
|
|
3
|
+
import { union, syntax, focus } from '../../combinator';
|
|
4
4
|
import { str } from './str';
|
|
5
|
+
import { Syntax } from '../context';
|
|
5
6
|
import { html } from 'typed-dom/dom';
|
|
6
7
|
|
|
7
|
-
export const delimiter = /[\s\x00-\x7F]|\S
|
|
8
|
+
export const delimiter = /[\s\x00-\x7F]|\S[#>]|[()、。!?][^\S\n]*(?=\\\n)/;
|
|
8
9
|
export const nonWhitespace = /[\S\n]|$/;
|
|
9
|
-
export const nonAlphanumeric = /[^0-9A-Za-z]|\S
|
|
10
|
+
export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/;
|
|
10
11
|
const repeat = str(/^(.)\1*/);
|
|
11
12
|
|
|
12
|
-
export const text: TextParser =
|
|
13
|
+
export const text: TextParser = syntax(Syntax.none, 1, 1, (source, context) => {
|
|
13
14
|
if (source === '') return;
|
|
14
15
|
const i = source.search(delimiter);
|
|
15
16
|
switch (i) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UnescapableSourceParser } from '../source';
|
|
2
|
-
import {
|
|
2
|
+
import { creation } from '../../combinator';
|
|
3
3
|
import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
|
|
4
4
|
|
|
5
|
-
export const unescsource: UnescapableSourceParser =
|
|
5
|
+
export const unescsource: UnescapableSourceParser = creation(source => {
|
|
6
6
|
assert(source[0] !== '\x1B');
|
|
7
7
|
if (source === '') return;
|
|
8
8
|
const i = source.search(delimiter);
|
package/src/parser/visibility.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { push } from 'spica/array';
|
|
|
12
12
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
13
13
|
export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
14
14
|
const blankline = new RegExp(
|
|
15
|
-
/^(?:\\$|\\?[^\S\n]|&IHN;|<wbr
|
|
15
|
+
/^(?:\\$|\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+$/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
|
|
16
16
|
'gm');
|
|
17
17
|
return union([
|
|
18
18
|
convert(
|
|
@@ -40,7 +40,7 @@ function hasVisible(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export const regBlankStart = new RegExp(
|
|
43
|
-
/^(?:\\?[^\S\n]|&IHN;|<wbr
|
|
43
|
+
/^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`));
|
|
44
44
|
|
|
45
45
|
export function blankWith(delimiter: string | RegExp): RegExp;
|
|
46
46
|
export function blankWith(starting: '' | '\n', delimiter: string | RegExp): RegExp;
|
|
@@ -49,7 +49,7 @@ export function blankWith(starting: '' | '\n', delimiter?: string | RegExp): Reg
|
|
|
49
49
|
return new RegExp(String.raw
|
|
50
50
|
`^(?:(?=${
|
|
51
51
|
starting
|
|
52
|
-
})(?:\\?\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr
|
|
52
|
+
})(?:\\?\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr[^\S\n]*>)${starting && '+'})?${
|
|
53
53
|
typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source
|
|
54
54
|
}`);
|
|
55
55
|
}
|
|
@@ -94,8 +94,8 @@ const isStartTight = reduce((source: string, context: MarkdownParser.Context, ex
|
|
|
94
94
|
case '<':
|
|
95
95
|
switch (true) {
|
|
96
96
|
case source.length >= 5
|
|
97
|
-
&& source
|
|
98
|
-
&& source
|
|
97
|
+
&& source.slice(0, 4) === '<wbr'
|
|
98
|
+
&& (source[5] === '>' || /^<wbr[^\S\n]*>/.test(source)):
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
return true;
|