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,5 +1,5 @@
|
|
|
1
1
|
import { SidefenceParser } from '../block';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, creation, block, focus, rewrite, convert, lazy, fmap } from '../../combinator';
|
|
3
3
|
import { autolink } from '../autolink';
|
|
4
4
|
import { contentline } from '../source';
|
|
5
5
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
@@ -20,7 +20,7 @@ const opener = /^(?=\|\|+(?:$|\s))/;
|
|
|
20
20
|
const unindent = (source: string) => source.replace(/(^|\n)\|(?:[^\S\n]|(?=\|*(?:$|\s)))|\n$/g, '$1');
|
|
21
21
|
|
|
22
22
|
const source: SidefenceParser.SourceParser = lazy(() => fmap(
|
|
23
|
-
some(
|
|
23
|
+
some(creation(union([
|
|
24
24
|
focus(
|
|
25
25
|
/^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/,
|
|
26
26
|
convert(unindent, source)),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableParser } from '../block';
|
|
2
|
-
import { union, sequence, some,
|
|
2
|
+
import { union, sequence, some, creation, block, line, validate, focus, rewrite, surround, open, fallback, lazy, fmap } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { contentline } from '../source';
|
|
5
5
|
import { trimNode } from '../visibility';
|
|
@@ -25,7 +25,7 @@ export const table: TableParser = lazy(() => block(fmap(validate(
|
|
|
25
25
|
]),
|
|
26
26
|
])));
|
|
27
27
|
|
|
28
|
-
const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean): RowParser<P> =>
|
|
28
|
+
const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean): RowParser<P> => creation(fallback(fmap(
|
|
29
29
|
line(surround(/^(?=\|)/, some(union([parser])), /^[|\\]?\s*$/, optional)),
|
|
30
30
|
es => [html('tr', es)]),
|
|
31
31
|
rewrite(contentline, source => [[
|
|
@@ -37,7 +37,7 @@ const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean):
|
|
|
37
37
|
}, [html('td', source.replace('\n', ''))])
|
|
38
38
|
], ''])));
|
|
39
39
|
|
|
40
|
-
const align: AlignParser =
|
|
40
|
+
const align: AlignParser = creation(fmap(open(
|
|
41
41
|
'|',
|
|
42
42
|
union([
|
|
43
43
|
focus(/^:-+:/, () => [['center'], '']),
|
|
@@ -52,11 +52,11 @@ const cell: CellParser = surround(
|
|
|
52
52
|
some(union([inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]),
|
|
53
53
|
/^[^|]*/, true);
|
|
54
54
|
|
|
55
|
-
const head: CellParser.HeadParser =
|
|
55
|
+
const head: CellParser.HeadParser = creation(fmap(
|
|
56
56
|
cell,
|
|
57
57
|
ns => [html('th', trimNode(defrag(ns)))]));
|
|
58
58
|
|
|
59
|
-
const data: CellParser.DataParser =
|
|
59
|
+
const data: CellParser.DataParser = creation(fmap(
|
|
60
60
|
cell,
|
|
61
61
|
ns => [html('td', trimNode(defrag(ns)))]));
|
|
62
62
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UListParser } from '../block';
|
|
2
|
-
import { union, inits, subsequence, some,
|
|
2
|
+
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, open, fallback, lazy, fmap } from '../../combinator';
|
|
3
3
|
import { olist_, invalid } from './olist';
|
|
4
4
|
import { ilist_ } from './ilist';
|
|
5
5
|
import { inline, indexer, indexee } from '../inline';
|
|
@@ -15,7 +15,7 @@ export const ulist: UListParser = lazy(() => block(validate(
|
|
|
15
15
|
|
|
16
16
|
export const ulist_: UListParser = lazy(() => block(fmap(validate(
|
|
17
17
|
/^-(?=$|\s)/,
|
|
18
|
-
some(
|
|
18
|
+
some(creation(union([
|
|
19
19
|
indexee(fmap(fallback(
|
|
20
20
|
inits([
|
|
21
21
|
line(open(/^-(?:$|\s)/, subsequence([checkbox, trimBlank(some(union([indexer, inline])))]), true)),
|
|
@@ -26,11 +26,11 @@ export const ulist_: UListParser = lazy(() => block(fmap(validate(
|
|
|
26
26
|
])))),
|
|
27
27
|
es => [format(html('ul', es))])));
|
|
28
28
|
|
|
29
|
-
export const checkbox = focus(
|
|
29
|
+
export const checkbox = creation(focus(
|
|
30
30
|
/^\[[xX ]\](?=$|\s)/,
|
|
31
31
|
source => [[
|
|
32
32
|
html('span', { class: 'checkbox' }, source[1].trimStart() ? '☑' : '☐'),
|
|
33
|
-
], '']);
|
|
33
|
+
], '']));
|
|
34
34
|
|
|
35
35
|
export function fillFirstLine(ns: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
36
36
|
return ns.length === 1
|
package/src/parser/block.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { MarkdownParser } from '../../markdown';
|
|
3
|
-
import { union, reset,
|
|
3
|
+
import { union, reset, creation, open, fallback, recover } from '../combinator';
|
|
4
4
|
import { emptyline } from './source';
|
|
5
5
|
import { horizontalrule } from './block/horizontalrule';
|
|
6
6
|
import { heading } from './block/heading';
|
|
@@ -35,8 +35,8 @@ export import BlockquoteParser = BlockParser.BlockquoteParser;
|
|
|
35
35
|
export import ReplyParser = BlockParser.ReplyParser;
|
|
36
36
|
export import ParagraphParser = BlockParser.ParagraphParser;
|
|
37
37
|
|
|
38
|
-
export const block: BlockParser =
|
|
39
|
-
reset({ resources: {
|
|
38
|
+
export const block: BlockParser = creation(error(
|
|
39
|
+
reset({ resources: { clock: 50 * 1000, recursion: 20 } },
|
|
40
40
|
union([
|
|
41
41
|
emptyline,
|
|
42
42
|
horizontalrule,
|
package/src/parser/context.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { AnnotationParser } from '../inline';
|
|
3
|
-
import { union, some,
|
|
3
|
+
import { union, some, context, syntax, constraint, state, surround, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { optimize } from './link';
|
|
6
|
-
import {
|
|
6
|
+
import { Syntax, State } from '../context';
|
|
7
7
|
import { startLoose, trimNode } from '../visibility';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
9
|
|
|
10
|
-
export const annotation: AnnotationParser = lazy(() =>
|
|
10
|
+
export const annotation: AnnotationParser = lazy(() => surround(
|
|
11
11
|
'((',
|
|
12
|
-
|
|
12
|
+
constraint(State.annotation, false,
|
|
13
|
+
syntax(Syntax.annotation, 6, 1,
|
|
13
14
|
state(State.annotation | State.media,
|
|
14
15
|
startLoose(
|
|
15
16
|
context({ delimiters: undefined },
|
|
16
|
-
some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')'))),
|
|
17
|
+
some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')')))),
|
|
17
18
|
'))',
|
|
18
19
|
false,
|
|
19
20
|
([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNode(defrag(ns)))])], rest],
|
|
20
|
-
([, ns, rest], next) => next[0] === ')' ? undefined : optimize('((', ns, rest, next)))
|
|
21
|
+
([, ns, rest], next) => next[0] === ')' ? undefined : optimize('((', ns, rest, next)));
|
|
@@ -20,9 +20,9 @@ describe('Unit: parser/inline/autolink/email', () => {
|
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('a@b#1')), [['a@b#1'], '']);
|
|
21
21
|
assert.deepStrictEqual(inspect(parser('a@@')), [['a@@'], '']);
|
|
22
22
|
assert.deepStrictEqual(inspect(parser('a@@b')), [['a@@b'], '']);
|
|
23
|
-
assert.deepStrictEqual(inspect(parser('a+@b')),
|
|
24
|
-
assert.deepStrictEqual(inspect(parser('a..b@c')),
|
|
25
|
-
assert.deepStrictEqual(inspect(parser('a++b@c')),
|
|
23
|
+
assert.deepStrictEqual(inspect(parser('a+@b')), [['a'], '+@b']);
|
|
24
|
+
assert.deepStrictEqual(inspect(parser('a..b@c')), [['a'], '..b@c']);
|
|
25
|
+
assert.deepStrictEqual(inspect(parser('a++b@c')), [['a'], '++b@c']);
|
|
26
26
|
assert.deepStrictEqual(inspect(parser(`a@${'b'.repeat(64)}`)), [[`a@${'b'.repeat(64)}`], '']);
|
|
27
27
|
assert.deepStrictEqual(inspect(parser(' a@b')), undefined);
|
|
28
28
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
|
-
import {
|
|
2
|
+
import { creation, verify, rewrite } from '../../../combinator';
|
|
3
3
|
import { str } from '../../source';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
|
|
6
6
|
// https://html.spec.whatwg.org/multipage/input.html
|
|
7
7
|
|
|
8
|
-
export const email: AutolinkParser.EmailParser =
|
|
8
|
+
export const email: AutolinkParser.EmailParser = creation(rewrite(verify(
|
|
9
9
|
str(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*@[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*(?![0-9A-Za-z])/),
|
|
10
10
|
([source]) => source.indexOf('@') <= 64 && source.length <= 255),
|
|
11
11
|
source => [[html('a', { class: 'email', href: `mailto:${source}` }, source)], '']));
|
|
@@ -8,12 +8,12 @@ describe('Unit: parser/inline/autolink/url', () => {
|
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
11
|
-
assert.deepStrictEqual(inspect(parser('http')),
|
|
12
|
-
assert.deepStrictEqual(inspect(parser('ttp')),
|
|
13
|
-
assert.deepStrictEqual(inspect(parser('http://')),
|
|
14
|
-
assert.deepStrictEqual(inspect(parser('http://[')),
|
|
15
|
-
assert.deepStrictEqual(inspect(parser('http://]')),
|
|
16
|
-
assert.deepStrictEqual(inspect(parser('Http://host')),
|
|
11
|
+
assert.deepStrictEqual(inspect(parser('http')), [['http'], '']);
|
|
12
|
+
assert.deepStrictEqual(inspect(parser('ttp')), [['ttp'], '']);
|
|
13
|
+
assert.deepStrictEqual(inspect(parser('http://')), [['http'], '://']);
|
|
14
|
+
assert.deepStrictEqual(inspect(parser('http://[')), [['http'], '://[']);
|
|
15
|
+
assert.deepStrictEqual(inspect(parser('http://]')), [['http'], '://]']);
|
|
16
|
+
assert.deepStrictEqual(inspect(parser('Http://host')), [['Http'], '://host']);
|
|
17
17
|
//assert.deepStrictEqual(inspect(parser('http://[::ffff:0:0%1]')), [['<a class="invalid">http://[::ffff:0:0%1]</a>'], '']);
|
|
18
18
|
//assert.deepStrictEqual(inspect(parser('http://[::ffff:0:0/96]')), [['<a class="invalid">http://[::ffff:0:0/96]</a>'], '']);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser(' http://a')), undefined);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
|
-
import { union, some,
|
|
2
|
+
import { union, some, creation, precedence, validate, focus, rewrite, convert, surround, open, lazy } from '../../../combinator';
|
|
3
3
|
import { textlink } from '../link';
|
|
4
4
|
import { unescsource } from '../../source';
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ export const url: AutolinkParser.UrlParser = lazy(() => validate(['http://', 'ht
|
|
|
13
13
|
url => `{ ${url} }`,
|
|
14
14
|
union([textlink])))));
|
|
15
15
|
|
|
16
|
-
const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() =>
|
|
16
|
+
const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() => creation(precedence(2, union([
|
|
17
17
|
surround('(', some(union([bracket, unescsource]), ')'), ')', true),
|
|
18
18
|
surround('[', some(union([bracket, unescsource]), ']'), ']', true),
|
|
19
19
|
surround('{', some(union([bracket, unescsource]), '}'), '}', true),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AutolinkParser } from '../inline';
|
|
2
|
-
import { union, some, syntax,
|
|
2
|
+
import { union, some, syntax, constraint, 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,18 +8,18 @@ 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 {
|
|
11
|
+
import { Syntax, State } from '../context';
|
|
12
12
|
import { stringify } from '../util';
|
|
13
13
|
|
|
14
14
|
export const autolink: AutolinkParser = fmap(
|
|
15
|
-
validate(/^(?:[@#>0-9A-Za-z]|\S
|
|
16
|
-
|
|
17
|
-
syntax(
|
|
15
|
+
validate(/^(?:[@#>0-9A-Za-z]|\S[#>])/,
|
|
16
|
+
constraint(State.autolink, false,
|
|
17
|
+
syntax(Syntax.autolink, 1, 1,
|
|
18
18
|
some(union([
|
|
19
19
|
url,
|
|
20
20
|
email,
|
|
21
21
|
// Escape unmatched email-like strings.
|
|
22
|
-
str(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*(?:@(?:[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?)
|
|
22
|
+
str(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*(?:@(?:[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?)*/),
|
|
23
23
|
channel,
|
|
24
24
|
account,
|
|
25
25
|
// Escape unmatched account-like strings.
|
|
@@ -3,29 +3,29 @@ import { BracketParser } from '../inline';
|
|
|
3
3
|
import { union, some, syntax, surround, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { str } from '../source';
|
|
6
|
-
import {
|
|
6
|
+
import { Syntax } from '../context';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift, push } from 'spica/array';
|
|
9
9
|
|
|
10
10
|
const index = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*/;
|
|
11
11
|
|
|
12
12
|
export const bracket: BracketParser = lazy(() => union([
|
|
13
|
-
surround(str('('), syntax(
|
|
14
|
-
surround(str('('), syntax(
|
|
13
|
+
surround(str('('), syntax(Syntax.none, 2, 1, str(index)), str(')')),
|
|
14
|
+
surround(str('('), syntax(Syntax.bracket, 2, 1, some(inline, ')', [[')', 2]])), str(')'), true,
|
|
15
15
|
([as, bs = [], cs], rest) => [[html('span', { class: 'paren' }, defrag(push(unshift(as, bs), cs)))], rest],
|
|
16
16
|
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
|
|
17
|
-
surround(str('('), syntax(
|
|
18
|
-
surround(str('('), syntax(
|
|
17
|
+
surround(str('('), syntax(Syntax.none, 2, 1, str(new RegExp(index.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => c.trimStart() && String.fromCharCode(c.charCodeAt(0) + 0xFEE0))))), str(')')),
|
|
18
|
+
surround(str('('), syntax(Syntax.bracket, 2, 1, some(inline, ')', [[')', 2]])), str(')'), true,
|
|
19
19
|
([as, bs = [], cs], rest) => [[html('span', { class: 'paren' }, defrag(push(unshift(as, bs), cs)))], rest],
|
|
20
20
|
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
21
|
-
surround(str('['), syntax(
|
|
21
|
+
surround(str('['), syntax(Syntax.bracket, 2, 1, some(inline, ']', [[']', 2]])), str(']'), true,
|
|
22
22
|
undefined,
|
|
23
23
|
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
|
|
24
|
-
surround(str('{'), syntax(
|
|
24
|
+
surround(str('{'), syntax(Syntax.bracket, 2, 1, some(inline, '}', [['}', 2]])), str('}'), true,
|
|
25
25
|
undefined,
|
|
26
26
|
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
27
27
|
// Control media blinking in editing rather than control confusion of pairs of quote marks.
|
|
28
|
-
surround(str('"'), syntax(
|
|
28
|
+
surround(str('"'), syntax(Syntax.quote, 8, 1, some(inline, '"', [['"', 8]])), str('"'), true,
|
|
29
29
|
undefined,
|
|
30
30
|
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
31
31
|
]));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CodeParser } from '../inline';
|
|
2
|
-
import {
|
|
2
|
+
import { creation, validate, match } from '../../combinator';
|
|
3
3
|
import { html } from 'typed-dom/dom';
|
|
4
4
|
|
|
5
|
-
export const code: CodeParser =
|
|
5
|
+
export const code: CodeParser = creation(validate('`', match(
|
|
6
6
|
/^(`+)(?!`)([^\n]*?[^`\n])\1(?!`)/,
|
|
7
7
|
([whole, , body]) => rest =>
|
|
8
8
|
[[html('code', { 'data-src': whole }, format(body))], rest.slice(whole.length)])));
|
|
@@ -2,12 +2,12 @@ import { CommentParser } from '../inline';
|
|
|
2
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 {
|
|
5
|
+
import { Syntax } from '../context';
|
|
6
6
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
7
|
import { memoize } from 'spica/memoize';
|
|
8
8
|
import { unshift, push } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
export const comment: CommentParser = lazy(() => validate('[%', syntax(
|
|
10
|
+
export const comment: CommentParser = lazy(() => validate('[%', syntax(Syntax.none, 4, 1, match(
|
|
11
11
|
/^\[(%+)\s/,
|
|
12
12
|
memoize(
|
|
13
13
|
([, fence]) =>
|
|
@@ -2,17 +2,18 @@ import { DeletionParser } from '../inline';
|
|
|
2
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 { Syntax } from '../context';
|
|
6
6
|
import { blankWith } from '../visibility';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
export const deletion: DeletionParser = lazy(() =>
|
|
10
|
+
export const deletion: DeletionParser = lazy(() => surround(
|
|
11
11
|
str('~~'),
|
|
12
|
+
syntax(Syntax.none, 1, 1,
|
|
12
13
|
some(union([
|
|
13
14
|
some(inline, blankWith('\n', '~~')),
|
|
14
15
|
open('\n', some(inline, '~'), true),
|
|
15
|
-
])),
|
|
16
|
+
]))),
|
|
16
17
|
str('~~'), false,
|
|
17
18
|
([, bs], rest) => [[html('del', defrag(bs))], rest],
|
|
18
|
-
([as, bs], rest) => [unshift(as, bs), rest]))
|
|
19
|
+
([as, bs], rest) => [unshift(as, bs), rest]));
|
|
@@ -4,13 +4,14 @@ 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 { Syntax } from '../context';
|
|
8
8
|
import { startTight, blankWith } from '../visibility';
|
|
9
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
10
|
import { unshift } from 'spica/array';
|
|
11
11
|
|
|
12
|
-
export const emphasis: EmphasisParser = lazy(() =>
|
|
12
|
+
export const emphasis: EmphasisParser = lazy(() => surround(
|
|
13
13
|
str('*'),
|
|
14
|
+
syntax(Syntax.none, 1, 1,
|
|
14
15
|
startTight(some(union([
|
|
15
16
|
strong,
|
|
16
17
|
some(inline, blankWith('*')),
|
|
@@ -19,7 +20,7 @@ export const emphasis: EmphasisParser = lazy(() => syntax(Rule.none, 1, surround
|
|
|
19
20
|
strong,
|
|
20
21
|
emphasis,
|
|
21
22
|
])),
|
|
22
|
-
])), '*'),
|
|
23
|
+
])), '*')),
|
|
23
24
|
str('*'), false,
|
|
24
25
|
([, bs], rest) => [[html('em', defrag(bs))], rest],
|
|
25
|
-
([as, bs], rest) => [unshift(as, bs), rest]))
|
|
26
|
+
([as, bs], rest) => [unshift(as, bs), rest]));
|
|
@@ -5,7 +5,7 @@ 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 { Syntax } from '../context';
|
|
9
9
|
import { startTight, blankWith } from '../visibility';
|
|
10
10
|
import { html, defrag } from 'typed-dom/dom';
|
|
11
11
|
import { unshift } from 'spica/array';
|
|
@@ -27,12 +27,13 @@ const subemphasis: IntermediateParser<EmphasisParser> = lazy(() => some(union([
|
|
|
27
27
|
])),
|
|
28
28
|
])));
|
|
29
29
|
|
|
30
|
-
export const emstrong: EmStrongParser = lazy(() =>
|
|
30
|
+
export const emstrong: EmStrongParser = lazy(() => surround(
|
|
31
31
|
str('***'),
|
|
32
|
+
syntax(Syntax.none, 1, 1,
|
|
32
33
|
startTight(some(union([
|
|
33
34
|
some(inline, blankWith('*')),
|
|
34
35
|
open(some(inline, '*'), inline),
|
|
35
|
-
]))),
|
|
36
|
+
])))),
|
|
36
37
|
str(/^\*{1,3}/), false,
|
|
37
38
|
([, bs, cs], rest, context): Result<HTMLElement | string, typeof context> => {
|
|
38
39
|
assert(cs.length === 1);
|
|
@@ -58,4 +59,4 @@ export const emstrong: EmStrongParser = lazy(() => syntax(Rule.none, 1, surround
|
|
|
58
59
|
}
|
|
59
60
|
assert(false);
|
|
60
61
|
},
|
|
61
|
-
([as, bs], rest) => [unshift(as, bs), rest]))
|
|
62
|
+
([as, bs], rest) => [unshift(as, bs), rest]));
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ExtensionParser } from '../../inline';
|
|
3
|
-
import { union, some, syntax,
|
|
3
|
+
import { union, some, syntax, creation, precedence, constraint, 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 { Syntax, State } from '../../context';
|
|
8
8
|
import { startTight, trimBlankEnd } from '../../visibility';
|
|
9
9
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
10
10
|
|
|
11
11
|
import IndexParser = ExtensionParser.IndexParser;
|
|
12
12
|
|
|
13
|
-
export const index: IndexParser = lazy(() => validate('[#',
|
|
13
|
+
export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surround(
|
|
14
14
|
'[#',
|
|
15
|
-
|
|
15
|
+
constraint(State.index, false,
|
|
16
|
+
syntax(Syntax.index, 2, 1,
|
|
16
17
|
state(State.annotation | State.reference | State.index | State.label | State.link | State.media | State.autolink,
|
|
17
18
|
startTight(
|
|
18
19
|
open(stropt(/^\|?/), trimBlankEnd(some(union([
|
|
19
20
|
signature,
|
|
20
21
|
inline,
|
|
21
|
-
]), ']', [[/^\\?\n/, 9], [']', 2]])), true)))),
|
|
22
|
+
]), ']', [[/^\\?\n/, 9], [']', 2]])), true))))),
|
|
22
23
|
']',
|
|
23
24
|
false,
|
|
24
25
|
([, ns], rest) => [[html('a', defrag(ns))], rest])),
|
|
@@ -30,16 +31,16 @@ export const index: IndexParser = lazy(() => validate('[#', syntax(Rule.index, 2
|
|
|
30
31
|
href: el.id ? `#${el.id}` : undefined,
|
|
31
32
|
},
|
|
32
33
|
el.childNodes),
|
|
33
|
-
])))
|
|
34
|
+
])));
|
|
34
35
|
|
|
35
|
-
const signature: IndexParser.SignatureParser = lazy(() =>
|
|
36
|
+
const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
|
|
36
37
|
'|#',
|
|
37
38
|
startTight(some(union([bracket, txt]), ']'))),
|
|
38
39
|
ns => [
|
|
39
40
|
html('span', { class: 'indexer', 'data-index': identity(ns.join('')).slice(6) }),
|
|
40
41
|
])));
|
|
41
42
|
|
|
42
|
-
const bracket: IndexParser.SignatureParser.BracketParser = lazy(() =>
|
|
43
|
+
const bracket: IndexParser.SignatureParser.BracketParser = lazy(() => creation(union([
|
|
43
44
|
surround(str('('), some(union([bracket, txt]), ')'), str(')'), true),
|
|
44
45
|
surround(str('['), some(union([bracket, txt]), ']'), str(']'), true),
|
|
45
46
|
surround(str('{'), some(union([bracket, txt]), '}'), str('}'), true),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../inline';
|
|
2
|
-
import { union,
|
|
2
|
+
import { union, creation, state, verify, focus, surround, fmap } from '../../../combinator';
|
|
3
3
|
import { index } from './index';
|
|
4
4
|
import { State } from '../../context';
|
|
5
5
|
import { html } from 'typed-dom/dom';
|
|
6
6
|
|
|
7
|
-
export const indexer: ExtensionParser.IndexerParser =
|
|
7
|
+
export const indexer: ExtensionParser.IndexerParser = creation(fmap(verify(surround(
|
|
8
8
|
/^\s+(?=\[#\S)/,
|
|
9
9
|
state(State.index, false,
|
|
10
10
|
union([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array } from 'spica/global';
|
|
2
2
|
import { ExtensionParser } from '../../inline';
|
|
3
|
-
import { union,
|
|
3
|
+
import { union, constraint, creation, validate, surround, clear, fmap } from '../../../combinator';
|
|
4
4
|
import { str } from '../../source';
|
|
5
5
|
import { State } from '../../context';
|
|
6
6
|
import { html } from 'typed-dom/dom';
|
|
@@ -12,8 +12,8 @@ export const segment: ExtensionParser.LabelParser.SegmentParser = clear(validate
|
|
|
12
12
|
body,
|
|
13
13
|
])));
|
|
14
14
|
|
|
15
|
-
export const label: ExtensionParser.LabelParser = validate(['[$', '$'],
|
|
16
|
-
|
|
15
|
+
export const label: ExtensionParser.LabelParser = validate(['[$', '$'], creation(fmap(
|
|
16
|
+
constraint(State.label, false,
|
|
17
17
|
union([
|
|
18
18
|
surround('[', body, ']'),
|
|
19
19
|
body,
|
|
@@ -2,7 +2,7 @@ import { ExtensionParser } from '../../inline';
|
|
|
2
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 { Syntax } from '../../context';
|
|
6
6
|
import { startTight } from '../../visibility';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
@@ -11,9 +11,10 @@ import { unshift } from 'spica/array';
|
|
|
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(['[:', '[^'],
|
|
14
|
+
export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], surround(
|
|
15
15
|
str(/^\[[:^]/),
|
|
16
|
-
|
|
16
|
+
syntax(Syntax.none, 2, 1,
|
|
17
|
+
startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]))),
|
|
17
18
|
str(']'), false,
|
|
18
19
|
([as, bs], rest) => [[
|
|
19
20
|
html('span', {
|
|
@@ -23,4 +24,4 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validat
|
|
|
23
24
|
'data-invalid-message': `Reserved start symbol "${as[0][1]}" cannot be used in "[]"`,
|
|
24
25
|
}, defrag(bs)),
|
|
25
26
|
], rest],
|
|
26
|
-
([as, bs], rest) => [unshift(as, bs), rest])))
|
|
27
|
+
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
@@ -122,7 +122,7 @@ describe('Unit: parser/inline/html', () => {
|
|
|
122
122
|
assert.deepStrictEqual(inspect(parser('<bdo dir="rtl" >a</bdo>')), [['<bdo dir="rtl">a</bdo>'], '']);
|
|
123
123
|
assert.deepStrictEqual(inspect(parser('<bdo dir="rtl">a</bdo>')), [['<bdo dir="rtl">a</bdo>'], '']);
|
|
124
124
|
assert.deepStrictEqual(inspect(parser('<wbr\n>')), undefined);
|
|
125
|
-
assert.deepStrictEqual(inspect(parser('<wbr >')), [['<wbr'], '
|
|
125
|
+
assert.deepStrictEqual(inspect(parser('<wbr >')), [['<wbr>'], '']);
|
|
126
126
|
assert.deepStrictEqual(inspect(parser('<wbr constructor>')), [['<wbr'], ' constructor>']);
|
|
127
127
|
assert.deepStrictEqual(inspect(parser('<wbr X>')), [['<wbr'], ' X>']);
|
|
128
128
|
assert.deepStrictEqual(inspect(parser('<wbr x>')), [['<wbr'], ' x>']);
|
|
@@ -3,7 +3,7 @@ import { HTMLParser } from '../inline';
|
|
|
3
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 { Syntax } from '../context';
|
|
7
7
|
import { isStartLooseNodes, blankWith } from '../visibility';
|
|
8
8
|
import { html as h, defrag } from 'typed-dom/dom';
|
|
9
9
|
import { memoize } from 'spica/memoize';
|
|
@@ -19,9 +19,9 @@ const attrspecs = {
|
|
|
19
19
|
Object.setPrototypeOf(attrspecs, null);
|
|
20
20
|
Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
|
|
21
21
|
|
|
22
|
-
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(
|
|
22
|
+
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(Syntax.none, 5, 1, union([
|
|
23
23
|
focus(
|
|
24
|
-
|
|
24
|
+
/^<wbr[^\S\n]*>/,
|
|
25
25
|
() => [[h('wbr')], '']),
|
|
26
26
|
focus(
|
|
27
27
|
// https://html.spec.whatwg.org/multipage/syntax.html#void-elements
|
|
@@ -62,7 +62,7 @@ export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^
|
|
|
62
62
|
new Cache(10000))),
|
|
63
63
|
])))));
|
|
64
64
|
|
|
65
|
-
export const attribute: HTMLParser.
|
|
65
|
+
export const attribute: HTMLParser.AttributeParser = union([
|
|
66
66
|
str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/),
|
|
67
67
|
]);
|
|
68
68
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
|
|
3
|
-
import { union,
|
|
3
|
+
import { union, creation, validate, focus, fmap } from '../../combinator';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
import { reduce } from 'spica/memoize';
|
|
6
6
|
|
|
7
|
-
export const unsafehtmlentity: UnsafeHTMLEntityParser =
|
|
7
|
+
export const unsafehtmlentity: UnsafeHTMLEntityParser = creation(validate('&', focus(
|
|
8
8
|
/^&[0-9A-Za-z]+;/,
|
|
9
9
|
entity => [[parse(entity) ?? `\x1B${entity}`], ''])));
|
|
10
10
|
|
|
@@ -2,17 +2,18 @@ import { InsertionParser } from '../inline';
|
|
|
2
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 { Syntax } from '../context';
|
|
6
6
|
import { blankWith } from '../visibility';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
export const insertion: InsertionParser = lazy(() =>
|
|
10
|
+
export const insertion: InsertionParser = lazy(() => surround(
|
|
11
11
|
str('++'),
|
|
12
|
+
syntax(Syntax.none, 1, 1,
|
|
12
13
|
some(union([
|
|
13
14
|
some(inline, blankWith('\n', '++')),
|
|
14
15
|
open('\n', some(inline, '+'), true),
|
|
15
|
-
])),
|
|
16
|
+
]))),
|
|
16
17
|
str('++'), false,
|
|
17
18
|
([, bs], rest) => [[html('ins', defrag(bs))], rest],
|
|
18
|
-
([as, bs], rest) => [unshift(as, bs), rest]))
|
|
19
|
+
([as, bs], rest) => [unshift(as, bs), rest]));
|