securemark 0.258.9 → 0.259.2
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/design.md +6 -5
- package/dist/index.js +535 -278
- package/markdown.d.ts +4 -3
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.test.ts +5 -5
- package/src/combinator/control/constraint/block.ts +3 -2
- package/src/combinator/control/constraint/contract.ts +7 -5
- package/src/combinator/control/constraint/line.test.ts +6 -6
- package/src/combinator/control/constraint/line.ts +6 -5
- package/src/combinator/control/manipulation/convert.ts +6 -5
- package/src/combinator/control/manipulation/fence.ts +2 -1
- package/src/combinator/control/manipulation/indent.test.ts +14 -14
- package/src/combinator/control/manipulation/indent.ts +5 -5
- package/src/combinator/control/manipulation/lazy.ts +2 -2
- package/src/combinator/control/manipulation/match.ts +3 -2
- package/src/combinator/control/manipulation/recovery.ts +6 -6
- package/src/combinator/control/manipulation/scope.ts +13 -10
- package/src/combinator/control/manipulation/surround.ts +9 -8
- package/src/combinator/control/manipulation/trim.test.ts +9 -9
- package/src/combinator/control/monad/bind.ts +3 -2
- package/src/combinator/data/parser/context/memo.ts +3 -4
- package/src/combinator/data/parser/context.test.ts +9 -9
- package/src/combinator/data/parser/context.ts +38 -34
- package/src/combinator/data/parser/inits.ts +3 -2
- package/src/combinator/data/parser/sequence.test.ts +10 -10
- package/src/combinator/data/parser/sequence.ts +3 -2
- package/src/combinator/data/parser/some.test.ts +13 -13
- package/src/combinator/data/parser/some.ts +3 -2
- package/src/combinator/data/parser/subsequence.test.ts +14 -14
- package/src/combinator/data/parser/union.test.ts +10 -10
- package/src/combinator/data/parser/union.ts +2 -2
- package/src/combinator/data/parser.ts +6 -1
- package/src/parser/api/bind.ts +3 -3
- package/src/parser/api/header.ts +1 -1
- package/src/parser/api/normalize.ts +1 -1
- package/src/parser/api/parse.ts +3 -3
- package/src/parser/autolink.test.ts +1 -1
- package/src/parser/autolink.ts +2 -2
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/codeblock.test.ts +1 -1
- package/src/parser/block/codeblock.ts +1 -1
- package/src/parser/block/dlist.test.ts +1 -1
- package/src/parser/block/extension/aside.test.ts +1 -1
- package/src/parser/block/extension/example.test.ts +1 -1
- package/src/parser/block/extension/example.ts +1 -1
- package/src/parser/block/extension/fig.test.ts +1 -1
- package/src/parser/block/extension/figbase.test.ts +1 -1
- package/src/parser/block/extension/figure.test.ts +1 -1
- package/src/parser/block/extension/figure.ts +1 -1
- package/src/parser/block/extension/message.test.ts +1 -1
- package/src/parser/block/extension/message.ts +1 -1
- package/src/parser/block/extension/placeholder.test.ts +1 -1
- package/src/parser/block/extension/table.test.ts +1 -1
- package/src/parser/block/extension/table.ts +1 -1
- package/src/parser/block/extension.test.ts +1 -1
- package/src/parser/block/heading.test.ts +3 -3
- package/src/parser/block/heading.ts +1 -1
- package/src/parser/block/horizontalrule.test.ts +1 -1
- package/src/parser/block/ilist.test.ts +1 -1
- package/src/parser/block/mathblock.test.ts +1 -1
- package/src/parser/block/olist.test.ts +1 -1
- package/src/parser/block/olist.ts +5 -5
- package/src/parser/block/paragraph.test.ts +1 -1
- package/src/parser/block/reply/cite.test.ts +4 -2
- package/src/parser/block/reply/cite.ts +2 -1
- package/src/parser/block/reply/quote.test.ts +1 -1
- package/src/parser/block/reply/quote.ts +2 -2
- package/src/parser/block/reply.test.ts +1 -1
- package/src/parser/block/sidefence.test.ts +1 -1
- package/src/parser/block/table.test.ts +1 -1
- package/src/parser/block/table.ts +1 -1
- package/src/parser/block/ulist.test.ts +1 -1
- package/src/parser/block/ulist.ts +1 -1
- package/src/parser/block.ts +2 -2
- package/src/parser/context.ts +15 -6
- package/src/parser/header.test.ts +1 -1
- package/src/parser/header.ts +3 -3
- package/src/parser/inline/annotation.test.ts +1 -1
- package/src/parser/inline/annotation.ts +3 -4
- package/src/parser/inline/autolink/account.test.ts +1 -1
- package/src/parser/inline/autolink/anchor.test.ts +1 -1
- package/src/parser/inline/autolink/channel.test.ts +1 -1
- package/src/parser/inline/autolink/email.test.ts +1 -1
- package/src/parser/inline/autolink/email.ts +1 -1
- package/src/parser/inline/autolink/hashnum.test.ts +1 -1
- package/src/parser/inline/autolink/hashtag.test.ts +1 -1
- package/src/parser/inline/autolink/url.test.ts +1 -1
- package/src/parser/inline/autolink.ts +1 -1
- package/src/parser/inline/bracket.test.ts +1 -1
- package/src/parser/inline/bracket.ts +8 -8
- package/src/parser/inline/code.test.ts +1 -1
- package/src/parser/inline/code.ts +2 -2
- package/src/parser/inline/comment.test.ts +1 -1
- package/src/parser/inline/comment.ts +2 -2
- package/src/parser/inline/deletion.test.ts +1 -1
- package/src/parser/inline/deletion.ts +2 -2
- package/src/parser/inline/emphasis.test.ts +1 -1
- package/src/parser/inline/emphasis.ts +2 -2
- package/src/parser/inline/emstrong.ts +4 -4
- package/src/parser/inline/escape.ts +3 -3
- package/src/parser/inline/extension/index.test.ts +1 -1
- package/src/parser/inline/extension/index.ts +3 -4
- package/src/parser/inline/extension/indexer.test.ts +1 -1
- package/src/parser/inline/extension/label.test.ts +1 -1
- package/src/parser/inline/extension/placeholder.test.ts +1 -1
- package/src/parser/inline/extension/placeholder.ts +2 -2
- package/src/parser/inline/html.test.ts +1 -1
- package/src/parser/inline/html.ts +2 -2
- package/src/parser/inline/htmlentity.test.ts +1 -1
- package/src/parser/inline/htmlentity.ts +1 -1
- package/src/parser/inline/insertion.test.ts +1 -1
- package/src/parser/inline/insertion.ts +2 -2
- package/src/parser/inline/link.test.ts +1 -1
- package/src/parser/inline/link.ts +14 -22
- package/src/parser/inline/mark.test.ts +1 -1
- package/src/parser/inline/mark.ts +2 -2
- package/src/parser/inline/math.test.ts +1 -1
- package/src/parser/inline/math.ts +1 -1
- package/src/parser/inline/media.test.ts +1 -1
- package/src/parser/inline/media.ts +3 -3
- package/src/parser/inline/reference.test.ts +1 -1
- package/src/parser/inline/reference.ts +3 -4
- package/src/parser/inline/ruby.test.ts +1 -1
- package/src/parser/inline/ruby.ts +5 -5
- package/src/parser/inline/shortmedia.test.ts +1 -1
- package/src/parser/inline/strong.test.ts +1 -1
- package/src/parser/inline/strong.ts +2 -2
- package/src/parser/inline/template.test.ts +1 -1
- package/src/parser/inline/template.ts +2 -2
- package/src/parser/inline.test.ts +1 -1
- package/src/parser/locale.test.ts +1 -1
- package/src/parser/segment.ts +1 -1
- package/src/parser/source/escapable.test.ts +1 -1
- package/src/parser/source/escapable.ts +1 -1
- package/src/parser/source/line.test.ts +1 -1
- package/src/parser/source/line.ts +2 -2
- package/src/parser/source/str.ts +4 -4
- package/src/parser/source/text.test.ts +1 -1
- package/src/parser/source/text.ts +4 -4
- package/src/parser/source/unescapable.test.ts +1 -1
- package/src/parser/source/unescapable.ts +1 -1
- package/src/parser/visibility.ts +13 -13
- package/src/util/quote.ts +1 -1
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/extension/figure', () => {
|
|
6
6
|
describe('figure', () => {
|
|
7
|
-
const parser = (source: string) => some(figure)(source, {});
|
|
7
|
+
const parser = (source: string) => some(figure)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('~~~figure\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure\n!https://host\n~~~</pre>'], '']);
|
|
@@ -98,7 +98,7 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
98
98
|
'data-invalid-type': 'fence',
|
|
99
99
|
'data-invalid-message': `Invalid trailing line after the closing delimiter "${delim}"`,
|
|
100
100
|
} ||
|
|
101
|
-
!seg_label(opener.match(/^~+(?:figure[^\S\n]+)?(\[?\$\S+)/)?.[1] ?? '', context) && {
|
|
101
|
+
!seg_label({ source: opener.match(/^~+(?:figure[^\S\n]+)?(\[?\$\S+)/)?.[1] ?? '', context }) && {
|
|
102
102
|
'data-invalid-type': 'label',
|
|
103
103
|
'data-invalid-message': 'Invalid label',
|
|
104
104
|
} ||
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/extension/message', () => {
|
|
6
6
|
describe('message', () => {
|
|
7
|
-
const parser = (source: string) => some(message)(source, {});
|
|
7
|
+
const parser = (source: string) => some(message)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('~~~message\n~~~')), undefined);
|
|
@@ -48,7 +48,7 @@ export const message: MessageParser = block(validate('~~~', fmap(
|
|
|
48
48
|
return [
|
|
49
49
|
html('section', { class: `message`, 'data-type': type }, unshift(
|
|
50
50
|
[html('h1', title(type))],
|
|
51
|
-
[...segment(body)].reduce((acc, seg) => push(acc, eval(content(seg, context), [])), []))),
|
|
51
|
+
[...segment(body)].reduce((acc, seg) => push(acc, eval(content({ source: seg, context }), [])), []))),
|
|
52
52
|
];
|
|
53
53
|
})));
|
|
54
54
|
|
|
@@ -3,7 +3,7 @@ import { some } from '../../../combinator';
|
|
|
3
3
|
|
|
4
4
|
describe('Unit: parser/block/extension/placeholder', () => {
|
|
5
5
|
describe('placeholder', () => {
|
|
6
|
-
const parser = (source: string) => some(placeholder)(source, {});
|
|
6
|
+
const parser = (source: string) => some(placeholder)({ source, context: {} });
|
|
7
7
|
|
|
8
8
|
it('invalid', () => {
|
|
9
9
|
assert(!parser(''));
|
|
@@ -5,7 +5,7 @@ import { html } from 'typed-dom/dom';
|
|
|
5
5
|
|
|
6
6
|
describe('Unit: parser/block/extension/table', () => {
|
|
7
7
|
describe('table', () => {
|
|
8
|
-
const parser = (source: string) => some(table)(source, {});
|
|
8
|
+
const parser = (source: string) => some(table)({ source, context: {} });
|
|
9
9
|
|
|
10
10
|
it('invalid', () => {
|
|
11
11
|
assert.deepStrictEqual(inspect(parser('~~~table a\n-\n~~~')), [['<pre class="invalid" translate="no">~~~table a\n-\n~~~</pre>'], '']);
|
|
@@ -40,7 +40,7 @@ export const table: TableParser = block(validate('~~~', fmap(
|
|
|
40
40
|
switch (type) {
|
|
41
41
|
case 'grid':
|
|
42
42
|
case undefined:
|
|
43
|
-
return (eval(parser(body, context)) ?? [html('table')])
|
|
43
|
+
return (eval(parser({ source: body, context })) ?? [html('table')])
|
|
44
44
|
.map(el => define(el, { 'data-type': type }));
|
|
45
45
|
default:
|
|
46
46
|
return [html('pre', {
|
|
@@ -3,7 +3,7 @@ import { some } from '../../combinator';
|
|
|
3
3
|
|
|
4
4
|
describe('Unit: parser/block/extension', () => {
|
|
5
5
|
describe('extension', () => {
|
|
6
|
-
const parser = (source: string) => some(extension)(source, {});
|
|
6
|
+
const parser = (source: string) => some(extension)({ source, context: {} });
|
|
7
7
|
|
|
8
8
|
it('invalid', () => {
|
|
9
9
|
assert(!parser(''));
|
|
@@ -6,10 +6,10 @@ import { inspect } from '../../debug.test';
|
|
|
6
6
|
describe('Unit: parser/block/heading', () => {
|
|
7
7
|
describe('heading', () => {
|
|
8
8
|
const parser = (source: string) => {
|
|
9
|
-
const result = segment(source, {});
|
|
9
|
+
const result = segment({ source, context: {} });
|
|
10
10
|
return result
|
|
11
|
-
? [eval(result).flatMap(seg => eval<HTMLElement | string>(heading(seg, {}), [seg])), exec(result)] as const
|
|
12
|
-
: some(heading)(source, {});
|
|
11
|
+
? [eval(result).flatMap(seg => eval<HTMLElement | string>(heading({ source: seg, context: {} }), [seg])), exec(result)] as const
|
|
12
|
+
: some(heading)({ source, context: {} });
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
it('invalid', () => {
|
|
@@ -8,7 +8,7 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
8
8
|
|
|
9
9
|
export const segment: HeadingParser.SegmentParser = block(validate('#', focus(
|
|
10
10
|
/^#+[^\S\n]+\S[^\n]*(?:\n#+(?!\S)[^\n]*)*(?:$|\n)/,
|
|
11
|
-
some(line(source => [[source], ''])))));
|
|
11
|
+
some(line(({ source }) => [[source], ''])))));
|
|
12
12
|
|
|
13
13
|
export const heading: HeadingParser = block(rewrite(segment,
|
|
14
14
|
state(State.annotation | State.reference | State.index | State.label | State.link | State.media,
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/horizontalrule', () => {
|
|
6
6
|
describe('horizontalrule', () => {
|
|
7
|
-
const parser = (source: string) => some(horizontalrule)(source, {});
|
|
7
|
+
const parser = (source: string) => some(horizontalrule)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -3,7 +3,7 @@ import { some } from '../../combinator';
|
|
|
3
3
|
|
|
4
4
|
describe('Unit: parser/block/ilist', () => {
|
|
5
5
|
describe('ilist', () => {
|
|
6
|
-
const parser = (source: string) => some(ilist)(source, {});
|
|
6
|
+
const parser = (source: string) => some(ilist)({ source, context: {} });
|
|
7
7
|
|
|
8
8
|
it('single', () => {
|
|
9
9
|
assert(!parser('-'));
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/mathblock', () => {
|
|
6
6
|
describe('mathblock', () => {
|
|
7
|
-
const parser = (source: string) => some(mathblock)(source, {});
|
|
7
|
+
const parser = (source: string) => some(mathblock)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/olist', () => {
|
|
6
6
|
describe('olist', () => {
|
|
7
|
-
const parser = (source: string) => some(olist)(source, {});
|
|
7
|
+
const parser = (source: string) => some(olist)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { OListParser } from '../block';
|
|
3
|
+
import { Parser } from '../../combinator/data/parser';
|
|
3
4
|
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, match, fallback, lazy, fmap } from '../../combinator';
|
|
4
5
|
import { checkbox, ulist_, fillFirstLine } from './ulist';
|
|
5
6
|
import { ilist_ } from './ilist';
|
|
@@ -11,7 +12,6 @@ import { html, define, defrag } from 'typed-dom/dom';
|
|
|
11
12
|
import { memoize } from 'spica/memoize';
|
|
12
13
|
import { duffbk } from 'spica/duff';
|
|
13
14
|
import { shift } from 'spica/array';
|
|
14
|
-
import { tuple } from 'spica/tuple';
|
|
15
15
|
|
|
16
16
|
const openers = {
|
|
17
17
|
'.': /^([0-9]+|[a-z]+|[A-Z]+)(?:-(?!-)[0-9]*)*(?![^\S\n])\.?(?:$|\s)/,
|
|
@@ -51,15 +51,15 @@ const list = (type: string, form: string): OListParser.ListParser => fmap(
|
|
|
51
51
|
const heads = {
|
|
52
52
|
'.': focus(
|
|
53
53
|
openers['.'],
|
|
54
|
-
source => [[source.trimEnd().split('.', 1)[0] + '.'], '']),
|
|
54
|
+
({ source }) => [[source.trimEnd().split('.', 1)[0] + '.'], '']),
|
|
55
55
|
'(': focus(
|
|
56
56
|
openers['('],
|
|
57
|
-
source => [[source.trimEnd().replace(/^\($/, '(1)').replace(/^\((\w+)$/, '($1)')], '']),
|
|
57
|
+
({ source }) => [[source.trimEnd().replace(/^\($/, '(1)').replace(/^\((\w+)$/, '($1)')], '']),
|
|
58
58
|
} as const;
|
|
59
59
|
|
|
60
60
|
export const invalid = rewrite(
|
|
61
|
-
inits([contentline, indent((
|
|
62
|
-
source => [[
|
|
61
|
+
inits([contentline, indent<Parser<string>>(({ source }) => [[source], ''])]),
|
|
62
|
+
({ source }) => [[
|
|
63
63
|
'',
|
|
64
64
|
html('span', {
|
|
65
65
|
class: 'invalid',
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/paragraph', () => {
|
|
6
6
|
describe('paragraph', () => {
|
|
7
|
-
const parser = (source: string) => some(paragraph)(source, {});
|
|
7
|
+
const parser = (source: string) => some(paragraph)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('basic', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('a')), [['<p>a</p>'], '']);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/reply/cite', () => {
|
|
6
6
|
describe('cite', () => {
|
|
7
|
-
const parser = (source: string) => some(cite)(source, {});
|
|
7
|
+
const parser = (source: string) => some(cite)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -18,7 +18,7 @@ describe('Unit: parser/block/reply/cite', () => {
|
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('>>\\')), undefined);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('>>01#')), undefined);
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('>>01@')), undefined);
|
|
21
|
-
assert.deepStrictEqual(inspect(parser('>>
|
|
21
|
+
assert.deepStrictEqual(inspect(parser('>>http://')), undefined);
|
|
22
22
|
assert.deepStrictEqual(inspect(parser('>>tel:1234567890')), undefined);
|
|
23
23
|
assert.deepStrictEqual(inspect(parser('>>..')), undefined);
|
|
24
24
|
assert.deepStrictEqual(inspect(parser('>> 0')), undefined);
|
|
@@ -43,6 +43,8 @@ describe('Unit: parser/block/reply/cite', () => {
|
|
|
43
43
|
assert.deepStrictEqual(inspect(parser('>>#a')), [['<span class="cite">><a class="anchor" data-depth="1">>#a</a></span>', '<br>'], '']);
|
|
44
44
|
assert.deepStrictEqual(inspect(parser('>>#index:a')), [['<span class="cite">><a class="anchor" data-depth="1">>#index:a</a></span>', '<br>'], '']);
|
|
45
45
|
assert.deepStrictEqual(inspect(parser('>>#:~:text=a')), [['<span class="cite">><a class="anchor" data-depth="1">>#:~:text=a</a></span>', '<br>'], '']);
|
|
46
|
+
assert.deepStrictEqual(inspect(parser('>>http://host')), [['<span class="cite">><a class="anchor" href="http://host" target="_blank" data-depth="1">>http://host</a></span>', '<br>'], '']);
|
|
47
|
+
assert.deepStrictEqual(inspect(parser('>>https://host')), [['<span class="cite">><a class="anchor" href="https://host" target="_blank" data-depth="1">>https://host</a></span>', '<br>'], '']);
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
});
|
|
@@ -13,7 +13,8 @@ export const cite: ReplyParser.CiteParser = creation(line(fmap(validate(
|
|
|
13
13
|
// Subject page representation.
|
|
14
14
|
// リンクの実装は後で検討
|
|
15
15
|
focus(/^>>\.[^\S\n]*(?:$|\n)/, () => [[html('a', { class: 'anchor' }, '>>.')], '']),
|
|
16
|
-
focus(/^>>#\S*[^\S\n]*(?:$|\n)/, source => [[html('a', { class: 'anchor' }, source)], '']),
|
|
16
|
+
focus(/^>>#\S*[^\S\n]*(?:$|\n)/, ({ source }) => [[html('a', { class: 'anchor' }, source)], '']),
|
|
17
|
+
focus(/^>>https?:\/\/\w\S*[^\S\n]*(?:$|\n)/, ({ source }) => [[html('a', { class: 'anchor', href: source.slice(2).trimEnd(), target: '_blank' }, source)], '']),
|
|
17
18
|
]),
|
|
18
19
|
]))),
|
|
19
20
|
([el, quotes = '']: [HTMLElement, string?]) => [
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/reply/quote', () => {
|
|
6
6
|
describe('quote', () => {
|
|
7
|
-
const parser = (source: string) => some(quote)(source, {});
|
|
7
|
+
const parser = (source: string) => some(quote)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -33,7 +33,7 @@ export const quote: ReplyParser.QuoteParser = lazy(() => creation(block(fmap(val
|
|
|
33
33
|
]),
|
|
34
34
|
false)));
|
|
35
35
|
|
|
36
|
-
const qblock: ReplyParser.QuoteParser.BlockParser = (source, context) => {
|
|
36
|
+
const qblock: ReplyParser.QuoteParser.BlockParser = ({ source, context }) => {
|
|
37
37
|
source = source.replace(/\n$/, '');
|
|
38
38
|
const lines = source.match(/^.*\n?/mg)!;
|
|
39
39
|
assert(lines);
|
|
@@ -41,7 +41,7 @@ const qblock: ReplyParser.QuoteParser.BlockParser = (source, context) => {
|
|
|
41
41
|
assert(quotes);
|
|
42
42
|
assert(quotes.length > 0);
|
|
43
43
|
const content = lines.reduce((acc, line, row) => acc + line.slice(quotes[row].length), '');
|
|
44
|
-
const nodes = eval(some(text)(content, context), []);
|
|
44
|
+
const nodes = eval(some(text)({ source: content, context }), []);
|
|
45
45
|
nodes.unshift(quotes.shift()!);
|
|
46
46
|
for (let i = 0; i < nodes.length; ++i) {
|
|
47
47
|
const child = nodes[i] as string | Text | Element;
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/reply', () => {
|
|
6
6
|
describe('reply', () => {
|
|
7
|
-
const parser = (source: string) => some(reply)(source, {});
|
|
7
|
+
const parser = (source: string) => some(reply)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('basic', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('>>1')), [['<p><span class="cite">><a href="?at=1" class="anchor" data-depth="1">>1</a></span></p>'], '']);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/sidefence', () => {
|
|
6
6
|
describe('sidefence', () => {
|
|
7
|
-
const parser = (source: string) => some(sidefence)(source, {});
|
|
7
|
+
const parser = (source: string) => some(sidefence)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/table', () => {
|
|
6
6
|
describe('table', () => {
|
|
7
|
-
const parser = (source: string) => some(table)(source, {});
|
|
7
|
+
const parser = (source: string) => some(table)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -28,7 +28,7 @@ export const table: TableParser = lazy(() => block(fmap(validate(
|
|
|
28
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
|
-
rewrite(contentline, source => [[
|
|
31
|
+
rewrite(contentline, ({ source }) => [[
|
|
32
32
|
html('tr', {
|
|
33
33
|
class: 'invalid',
|
|
34
34
|
'data-invalid-syntax': 'table-row',
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/block/ulist', () => {
|
|
6
6
|
describe('ulist', () => {
|
|
7
|
-
const parser = (source: string) => some(ulist)(source, {});
|
|
7
|
+
const parser = (source: string) => some(ulist)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -28,7 +28,7 @@ export const ulist_: UListParser = lazy(() => block(fmap(validate(
|
|
|
28
28
|
|
|
29
29
|
export const checkbox = creation(focus(
|
|
30
30
|
/^\[[xX ]\](?=$|\s)/,
|
|
31
|
-
source => [[
|
|
31
|
+
({ source }) => [[
|
|
32
32
|
html('span', { class: 'checkbox' }, source[1].trimStart() ? '☑' : '☐'),
|
|
33
33
|
], '']));
|
|
34
34
|
|
package/src/parser/block.ts
CHANGED
|
@@ -57,9 +57,9 @@ export const block: BlockParser = creation(error(
|
|
|
57
57
|
|
|
58
58
|
function error(parser: BlockParser): BlockParser {
|
|
59
59
|
return recover<BlockParser>(fallback(
|
|
60
|
-
open('\x07', source => { throw new Error(source.split('\n', 1)[0]); }),
|
|
60
|
+
open('\x07', ({source}) => { throw new Error(source.split('\n', 1)[0]); }),
|
|
61
61
|
parser),
|
|
62
|
-
(source, { id }, reason) => [[
|
|
62
|
+
({ source, context: { id } }, reason) => [[
|
|
63
63
|
html('h1',
|
|
64
64
|
{
|
|
65
65
|
id: id !== '' ? `error:${rnd0Z(8)}` : undefined,
|
package/src/parser/context.ts
CHANGED
|
@@ -23,10 +23,19 @@ export const enum State {
|
|
|
23
23
|
link = 1 << 2,
|
|
24
24
|
media = 1 << 1,
|
|
25
25
|
autolink = 1 << 0,
|
|
26
|
+
none = 0,
|
|
27
|
+
linkable = 0
|
|
28
|
+
| State.annotation
|
|
29
|
+
| State.reference
|
|
30
|
+
| State.index
|
|
31
|
+
| State.label
|
|
32
|
+
| State.link
|
|
33
|
+
| State.media
|
|
34
|
+
| State.autolink,
|
|
35
|
+
backtrackable = 0
|
|
36
|
+
| State.annotation
|
|
37
|
+
| State.reference
|
|
38
|
+
| State.index
|
|
39
|
+
| State.link
|
|
40
|
+
| State.media,
|
|
26
41
|
}
|
|
27
|
-
export const backtrackable = 0
|
|
28
|
-
| State.annotation
|
|
29
|
-
| State.reference
|
|
30
|
-
| State.index
|
|
31
|
-
| State.link
|
|
32
|
-
| State.media;
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/header', () => {
|
|
6
6
|
describe('header', () => {
|
|
7
|
-
const parser = (source: string) => some(header)(source, {});
|
|
7
|
+
const parser = (source: string) => some(header)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
package/src/parser/header.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const header: MarkdownParser.HeaderParser = lazy(() => validate(
|
|
|
9
9
|
/^---+[^\S\v\f\r\n]*\r?\n[^\S\n]*(?=\S)/,
|
|
10
10
|
inits([
|
|
11
11
|
rewrite(
|
|
12
|
-
(source, context) =>
|
|
12
|
+
({ source, context }) =>
|
|
13
13
|
[[], context.header ?? true ? source.slice(segment(source).next().value!.length) : ''],
|
|
14
14
|
block(
|
|
15
15
|
union([
|
|
@@ -27,7 +27,7 @@ export const header: MarkdownParser.HeaderParser = lazy(() => validate(
|
|
|
27
27
|
])),
|
|
28
28
|
]),
|
|
29
29
|
])))),
|
|
30
|
-
source => [[
|
|
30
|
+
({ source }) => [[
|
|
31
31
|
html('pre', {
|
|
32
32
|
class: 'invalid',
|
|
33
33
|
translate: 'no',
|
|
@@ -40,7 +40,7 @@ export const header: MarkdownParser.HeaderParser = lazy(() => validate(
|
|
|
40
40
|
clear(str(/^[^\S\v\f\r\n]*\r?\n/)),
|
|
41
41
|
])));
|
|
42
42
|
|
|
43
|
-
const field: MarkdownParser.HeaderParser.FieldParser = line(source => {
|
|
43
|
+
const field: MarkdownParser.HeaderParser.FieldParser = line(({ source }) => {
|
|
44
44
|
const name = source.slice(0, source.indexOf(':'));
|
|
45
45
|
const value = source.slice(name.length + 1).trim();
|
|
46
46
|
return [[
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/annotation', () => {
|
|
6
6
|
describe('annotation', () => {
|
|
7
|
-
const parser = (source: string) => some(annotation)(source, {});
|
|
7
|
+
const parser = (source: string) => some(annotation)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { AnnotationParser } from '../inline';
|
|
3
|
-
import { union, some, context, syntax, constraint,
|
|
3
|
+
import { union, some, context, syntax, constraint, surround, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { Syntax, State } from '../context';
|
|
6
6
|
import { startLoose, trimNode } from '../visibility';
|
|
@@ -9,11 +9,10 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
9
9
|
export const annotation: AnnotationParser = lazy(() => surround(
|
|
10
10
|
'((',
|
|
11
11
|
constraint(State.annotation, false,
|
|
12
|
-
|
|
13
|
-
syntax(Syntax.annotation, 6, 1,
|
|
12
|
+
syntax(Syntax.annotation, 6, 1, State.annotation | State.media,
|
|
14
13
|
startLoose(
|
|
15
14
|
context({ delimiters: undefined },
|
|
16
|
-
some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')')))
|
|
15
|
+
some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])), ')'))),
|
|
17
16
|
'))',
|
|
18
17
|
false,
|
|
19
18
|
([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNode(defrag(ns)))])], rest]));
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/account', () => {
|
|
6
6
|
describe('account', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/anchor', () => {
|
|
6
6
|
describe('anchor', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/channel', () => {
|
|
6
6
|
describe('channel', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/email', () => {
|
|
6
6
|
describe('email', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -8,4 +8,4 @@ import { html } from 'typed-dom/dom';
|
|
|
8
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
|
-
source => [[html('a', { class: 'email', href: `mailto:${source}` }, source)], '']));
|
|
11
|
+
({ source }) => [[html('a', { class: 'email', href: `mailto:${source}` }, source)], '']));
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/hashnum', () => {
|
|
6
6
|
describe('hashnum', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/hashtag', () => {
|
|
6
6
|
describe('hashtag', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/autolink/url', () => {
|
|
6
6
|
describe('url', () => {
|
|
7
|
-
const parser = (source: string) => some(autolink)(source, {});
|
|
7
|
+
const parser = (source: string) => some(autolink)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -14,7 +14,7 @@ import { stringify } from '../util';
|
|
|
14
14
|
export const autolink: AutolinkParser = fmap(
|
|
15
15
|
validate(/^(?:[@#>0-9A-Za-z]|\S[#>])/,
|
|
16
16
|
constraint(State.autolink, false,
|
|
17
|
-
syntax(Syntax.autolink, 1, 1,
|
|
17
|
+
syntax(Syntax.autolink, 1, 1, State.none,
|
|
18
18
|
some(union([
|
|
19
19
|
url,
|
|
20
20
|
email,
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/bracket', () => {
|
|
6
6
|
describe('bracket', () => {
|
|
7
|
-
const parser = (source: string) => some(bracket)(source, {});
|
|
7
|
+
const parser = (source: string) => some(bracket)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('(', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('(')), [['', '('], '']);
|
|
@@ -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 { Syntax } from '../context';
|
|
6
|
+
import { Syntax, State } 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(Syntax.none, 2, 1, str(index)), str(')')),
|
|
14
|
-
surround(str('('), syntax(Syntax.bracket, 2, 1, some(inline, ')', [[')', 2]])), str(')'), true,
|
|
13
|
+
surround(str('('), syntax(Syntax.none, 2, 1, State.none, str(index)), str(')')),
|
|
14
|
+
surround(str('('), syntax(Syntax.bracket, 2, 1, State.none, 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(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,
|
|
17
|
+
surround(str('('), syntax(Syntax.none, 2, 1, State.none, 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, State.none, 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(Syntax.bracket, 2, 1, some(inline, ']', [[']', 2]])), str(']'), true,
|
|
21
|
+
surround(str('['), syntax(Syntax.bracket, 2, 1, State.none, some(inline, ']', [[']', 2]])), str(']'), true,
|
|
22
22
|
undefined,
|
|
23
23
|
([as, bs = []], rest) => [unshift([''], unshift(as, bs)), rest]),
|
|
24
|
-
surround(str('{'), syntax(Syntax.bracket, 2, 1, some(inline, '}', [['}', 2]])), str('}'), true,
|
|
24
|
+
surround(str('{'), syntax(Syntax.bracket, 2, 1, State.none, 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(Syntax.quote, 8, 1, some(inline, '"', [['"', 8]])), str('"'), true,
|
|
28
|
+
surround(str('"'), syntax(Syntax.quote, 8, 1, State.none, some(inline, '"', [['"', 8]])), str('"'), true,
|
|
29
29
|
undefined,
|
|
30
30
|
([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
31
31
|
]));
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/code', () => {
|
|
6
6
|
describe('code', () => {
|
|
7
|
-
const parser = (source: string) => some(code)(source, {});
|
|
7
|
+
const parser = (source: string) => some(code)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,8 +4,8 @@ import { html } from 'typed-dom/dom';
|
|
|
4
4
|
|
|
5
5
|
export const code: CodeParser = creation(validate('`', match(
|
|
6
6
|
/^(`+)(?!`)([^\n]*?[^`\n])\1(?!`)/,
|
|
7
|
-
([whole, , body]) =>
|
|
8
|
-
[[html('code', { 'data-src': whole }, format(body))],
|
|
7
|
+
([whole, , body]) => ({ source }) =>
|
|
8
|
+
[[html('code', { 'data-src': whole }, format(body))], source.slice(whole.length)])));
|
|
9
9
|
|
|
10
10
|
function format(text: string): string {
|
|
11
11
|
assert(text.length > 0);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/comment', () => {
|
|
6
6
|
describe('comment', () => {
|
|
7
|
-
const parser = (source: string) => some(comment)(source, {});
|
|
7
|
+
const parser = (source: string) => some(comment)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|