securemark 0.299.3 → 0.300.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/design.md +0 -6
- package/dist/index.js +3479 -2750
- package/index.d.ts +2 -1
- package/index.ts +2 -2
- package/markdown.d.ts +209 -183
- package/package.json +1 -1
- package/src/{parser/api → api}/bind.test.ts +2 -24
- package/src/{parser/api → api}/bind.ts +18 -13
- package/src/{parser/api → api}/body.test.ts +1 -1
- package/src/{parser/api → api}/cache.ts +1 -1
- package/src/{parser/api → api}/header.test.ts +1 -1
- package/src/{parser/api → api}/header.ts +9 -6
- package/src/{parser/api → api}/normalize.test.ts +1 -1
- package/src/{parser/api → api}/parse.test.ts +120 -124
- package/src/api/parse.ts +30 -0
- package/src/api/run.ts +6 -0
- package/src/{parser/api.ts → api.ts} +1 -0
- package/src/combinator/control/inits.ts +26 -0
- package/src/combinator/control/sequence.test.ts +38 -0
- package/src/combinator/control/sequence.ts +17 -0
- package/src/combinator/control/some.test.ts +41 -0
- package/src/combinator/{data/parser → control}/some.ts +39 -26
- package/src/combinator/control/state.ts +42 -0
- package/src/combinator/control/subsequence.test.ts +47 -0
- package/src/combinator/control/subsequence.ts +16 -0
- package/src/combinator/control/tails.ts +8 -0
- package/src/combinator/control/union.test.ts +37 -0
- package/src/combinator/control/union.ts +18 -0
- package/src/combinator/{data/delimiter.ts → delimiter.ts} +40 -60
- package/src/combinator/effect/backtrack.ts +64 -0
- package/src/combinator/effect/clock.ts +10 -0
- package/src/combinator/effect/precedence.ts +50 -0
- package/src/combinator/effect/recursion.ts +30 -0
- package/src/combinator/effect/scope.ts +100 -0
- package/src/combinator/effect/state.ts +72 -0
- package/src/combinator/{data/node.ts → parser/list.ts} +38 -13
- package/src/combinator/parser.ts +293 -0
- package/src/combinator/process/bind.ts +34 -0
- package/src/combinator/process/block.test.ts +20 -0
- package/src/combinator/process/block.ts +33 -0
- package/src/combinator/process/clear.ts +16 -0
- package/src/combinator/process/contract.ts +35 -0
- package/src/combinator/process/duplicate.ts +7 -0
- package/src/combinator/process/error.ts +13 -0
- package/src/combinator/{control/manipulation → process}/fallback.ts +3 -3
- package/src/combinator/process/fence.ts +59 -0
- package/src/combinator/process/fmap.ts +10 -0
- package/src/combinator/process/indent.test.ts +31 -0
- package/src/combinator/process/indent.ts +51 -0
- package/src/combinator/process/lazy.ts +8 -0
- package/src/combinator/process/line.test.ts +21 -0
- package/src/combinator/process/line.ts +55 -0
- package/src/combinator/process/match.ts +37 -0
- package/src/combinator/process/reverse.ts +7 -0
- package/src/combinator/process/scope.ts +102 -0
- package/src/combinator/process/surround.ts +271 -0
- package/src/combinator.ts +28 -24
- package/src/debug.test.ts +11 -8
- package/src/parser/autolink.test.ts +17 -18
- package/src/parser/block/blockquote.test.ts +78 -79
- package/src/parser/block/blockquote.ts +32 -25
- package/src/parser/block/codeblock.test.ts +56 -57
- package/src/parser/block/codeblock.ts +44 -26
- package/src/parser/block/dlist.test.ts +56 -57
- package/src/parser/block/dlist.ts +5 -5
- package/src/parser/block/extension/aside.test.ts +8 -9
- package/src/parser/block/extension/aside.ts +76 -47
- package/src/parser/block/extension/example.test.ts +18 -19
- package/src/parser/block/extension/example.ts +88 -48
- package/src/parser/block/extension/fig.test.ts +37 -36
- package/src/parser/block/extension/fig.ts +20 -25
- package/src/parser/block/extension/figbase.test.ts +18 -19
- package/src/parser/block/extension/figbase.ts +3 -3
- package/src/parser/block/extension/figure.test.ts +62 -63
- package/src/parser/block/extension/figure.ts +23 -21
- package/src/parser/block/extension/message.test.ts +13 -14
- package/src/parser/block/extension/message.ts +52 -39
- package/src/parser/block/extension/placeholder.test.ts +13 -13
- package/src/parser/block/extension/placeholder.ts +23 -21
- package/src/parser/block/extension/table.test.ts +70 -71
- package/src/parser/block/extension/table.ts +43 -31
- package/src/parser/block/extension.test.ts +24 -24
- package/src/parser/block/extension.ts +3 -3
- package/src/parser/block/heading.test.ts +58 -59
- package/src/parser/block/heading.ts +19 -18
- package/src/parser/block/ilist.test.ts +8 -8
- package/src/parser/block/ilist.ts +9 -7
- package/src/parser/block/mathblock.test.ts +31 -32
- package/src/parser/block/mathblock.ts +24 -23
- package/src/parser/block/mediablock.ts +7 -7
- package/src/parser/block/olist.test.ts +102 -103
- package/src/parser/block/olist.ts +11 -12
- package/src/parser/block/pagebreak.test.ts +15 -16
- package/src/parser/block/pagebreak.ts +5 -5
- package/src/parser/block/paragraph.test.ts +57 -58
- package/src/parser/block/paragraph.ts +1 -1
- package/src/parser/block/reply/cite.test.ts +39 -40
- package/src/parser/block/reply/cite.ts +5 -5
- package/src/parser/block/reply/quote.test.ts +50 -51
- package/src/parser/block/reply/quote.ts +8 -7
- package/src/parser/block/reply.test.ts +19 -20
- package/src/parser/block/reply.ts +2 -2
- package/src/parser/block/sidefence.test.ts +41 -48
- package/src/parser/block/sidefence.ts +17 -11
- package/src/parser/block/table.test.ts +48 -49
- package/src/parser/block/table.ts +10 -9
- package/src/parser/block/ulist.test.ts +52 -53
- package/src/parser/block/ulist.ts +9 -8
- package/src/parser/block.ts +63 -51
- package/src/parser/context.ts +35 -32
- package/src/parser/document.ts +48 -0
- package/src/parser/header.test.ts +19 -20
- package/src/parser/header.ts +31 -25
- package/src/parser/inline/annotation.test.ts +49 -50
- package/src/parser/inline/annotation.ts +14 -16
- package/src/parser/inline/autolink/account.test.ts +32 -33
- package/src/parser/inline/autolink/account.ts +18 -19
- package/src/parser/inline/autolink/anchor.test.ts +21 -22
- package/src/parser/inline/autolink/anchor.ts +7 -8
- package/src/parser/inline/autolink/channel.test.ts +14 -15
- package/src/parser/inline/autolink/email.test.ts +36 -37
- package/src/parser/inline/autolink/email.ts +6 -6
- package/src/parser/inline/autolink/hashnum.test.ts +32 -33
- package/src/parser/inline/autolink/hashnum.ts +7 -8
- package/src/parser/inline/autolink/hashtag.test.ts +59 -60
- package/src/parser/inline/autolink/hashtag.ts +8 -9
- package/src/parser/inline/autolink/url.test.ts +75 -76
- package/src/parser/inline/autolink/url.ts +13 -14
- package/src/parser/inline/autolink.ts +24 -11
- package/src/parser/inline/bracket.test.ts +73 -74
- package/src/parser/inline/bracket.ts +88 -63
- package/src/parser/inline/code.test.ts +30 -31
- package/src/parser/inline/code.ts +6 -6
- package/src/parser/inline/deletion.test.ts +27 -28
- package/src/parser/inline/deletion.ts +5 -5
- package/src/parser/inline/emphasis.test.ts +39 -40
- package/src/parser/inline/emphasis.ts +5 -5
- package/src/parser/inline/emstrong.test.ts +101 -102
- package/src/parser/inline/emstrong.ts +103 -85
- package/src/parser/inline/extension/index.test.ts +91 -92
- package/src/parser/inline/extension/index.ts +17 -13
- package/src/parser/inline/extension/indexee.ts +4 -4
- package/src/parser/inline/extension/indexer.test.ts +23 -24
- package/src/parser/inline/extension/indexer.ts +6 -5
- package/src/parser/inline/extension/label.test.ts +32 -33
- package/src/parser/inline/extension/label.ts +14 -5
- package/src/parser/inline/extension/placeholder.test.ts +42 -43
- package/src/parser/inline/extension/placeholder.ts +8 -9
- package/src/parser/inline/html.test.ts +109 -109
- package/src/parser/inline/html.ts +27 -27
- package/src/parser/inline/htmlentity.test.ts +37 -38
- package/src/parser/inline/htmlentity.ts +6 -7
- package/src/parser/inline/insertion.test.ts +27 -28
- package/src/parser/inline/insertion.ts +5 -5
- package/src/parser/inline/italic.test.ts +55 -56
- package/src/parser/inline/italic.ts +5 -5
- package/src/parser/inline/link.test.ts +186 -187
- package/src/parser/inline/link.ts +31 -32
- package/src/parser/inline/mark.test.ts +31 -32
- package/src/parser/inline/mark.ts +6 -6
- package/src/parser/inline/math.test.ts +140 -141
- package/src/parser/inline/math.ts +6 -7
- package/src/parser/inline/media.test.ts +92 -93
- package/src/parser/inline/media.ts +32 -38
- package/src/parser/inline/reference.test.ts +111 -112
- package/src/parser/inline/reference.ts +61 -32
- package/src/parser/inline/remark.test.ts +49 -50
- package/src/parser/inline/remark.ts +13 -13
- package/src/parser/inline/ruby.test.ts +49 -50
- package/src/parser/inline/ruby.ts +60 -49
- package/src/parser/inline/shortmedia.test.ts +9 -10
- package/src/parser/inline/shortmedia.ts +11 -9
- package/src/parser/inline/strong.test.ts +36 -37
- package/src/parser/inline/strong.ts +5 -5
- package/src/parser/inline/template.test.ts +22 -23
- package/src/parser/inline/template.ts +13 -16
- package/src/parser/inline.test.ts +225 -226
- package/src/parser/inline.ts +68 -34
- package/src/parser/node.ts +1 -1
- package/src/parser/parser.ts +51 -0
- package/src/parser/repeat.ts +118 -91
- package/src/parser/segment.test.ts +0 -11
- package/src/parser/segment.ts +25 -28
- package/src/parser/source/escapable.test.ts +23 -24
- package/src/parser/source/escapable.ts +20 -20
- package/src/parser/source/line.test.ts +17 -18
- package/src/parser/source/line.ts +19 -24
- package/src/parser/source/str.ts +17 -10
- package/src/parser/source/text.test.ts +88 -89
- package/src/parser/source/text.ts +19 -20
- package/src/parser/source/unescapable.test.ts +23 -24
- package/src/parser/source/unescapable.ts +16 -16
- package/src/parser/util.ts +1 -1
- package/src/parser/visibility.ts +36 -15
- package/src/{parser/processor → processor}/figure.test.ts +23 -23
- package/src/{parser/processor → processor}/figure.ts +20 -12
- package/src/{parser/processor → processor}/note.test.ts +15 -15
- package/src/{parser/processor → processor}/note.ts +6 -4
- package/src/renderer/render/media/pdf.ts +2 -2
- package/src/renderer/render/media/twitter.ts +2 -2
- package/src/renderer/render/media.test.ts +12 -13
- package/src/renderer/render.test.ts +11 -11
- package/src/util/info.test.ts +2 -2
- package/src/util/quote.test.ts +3 -3
- package/src/util/quote.ts +6 -5
- package/src/util/toc.test.ts +12 -12
- package/src/combinator/control/constraint/block.test.ts +0 -20
- package/src/combinator/control/constraint/block.ts +0 -28
- package/src/combinator/control/constraint/contract.ts +0 -27
- package/src/combinator/control/constraint/line.test.ts +0 -21
- package/src/combinator/control/constraint/line.ts +0 -42
- package/src/combinator/control/manipulation/clear.ts +0 -5
- package/src/combinator/control/manipulation/convert.ts +0 -22
- package/src/combinator/control/manipulation/duplicate.ts +0 -7
- package/src/combinator/control/manipulation/fence.ts +0 -54
- package/src/combinator/control/manipulation/indent.test.ts +0 -31
- package/src/combinator/control/manipulation/indent.ts +0 -39
- package/src/combinator/control/manipulation/lazy.ts +0 -8
- package/src/combinator/control/manipulation/match.ts +0 -27
- package/src/combinator/control/manipulation/recovery.ts +0 -18
- package/src/combinator/control/manipulation/reverse.ts +0 -8
- package/src/combinator/control/manipulation/scope.ts +0 -61
- package/src/combinator/control/manipulation/surround.ts +0 -223
- package/src/combinator/control/monad/bind.ts +0 -26
- package/src/combinator/control/monad/fmap.ts +0 -10
- package/src/combinator/data/parser/context.ts +0 -96
- package/src/combinator/data/parser/inits.ts +0 -20
- package/src/combinator/data/parser/sequence.test.ts +0 -33
- package/src/combinator/data/parser/sequence.ts +0 -20
- package/src/combinator/data/parser/some.test.ts +0 -37
- package/src/combinator/data/parser/subsequence.test.ts +0 -41
- package/src/combinator/data/parser/subsequence.ts +0 -13
- package/src/combinator/data/parser/tails.ts +0 -8
- package/src/combinator/data/parser/union.test.ts +0 -33
- package/src/combinator/data/parser/union.ts +0 -18
- package/src/combinator/data/parser.ts +0 -144
- package/src/parser/api/parse.ts +0 -48
- package/src/parser.ts +0 -1
- /package/src/{parser/api → api}/body.ts +0 -0
- /package/src/{parser/api → api}/normalize.ts +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../block';
|
|
2
2
|
import { Segment } from '../../context';
|
|
3
|
-
import { List, Node
|
|
4
|
-
import { union, inits, sequence, some, block, line, fence, rewrite, close, match,
|
|
3
|
+
import { List, Node } from '../../../combinator/parser';
|
|
4
|
+
import { union, inits, sequence, some, scope, block, line, fence, rewrite, close, match, fallback, fmap } from '../../../combinator';
|
|
5
5
|
import { str, contentline, emptyline } from '../../source';
|
|
6
|
-
import { label,
|
|
6
|
+
import { label, test as test_label } from '../../inline/extension/label';
|
|
7
7
|
import { ulist } from '../ulist';
|
|
8
8
|
import { olist } from '../olist';
|
|
9
9
|
import { table as styled_table } from '../table';
|
|
@@ -48,9 +48,9 @@ export const segment: FigureParser.SegmentParser = block(match(
|
|
|
48
48
|
([, fence]) => fence.length - 1, [], 2 ** 4 - 1)), true, Segment.figure);
|
|
49
49
|
|
|
50
50
|
export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
51
|
-
|
|
51
|
+
scope(({ source }) => source.slice(source.match(/^~+(?:\w+\s+)?/)![0].length, source.trimEnd().lastIndexOf('\n')),
|
|
52
52
|
sequence([
|
|
53
|
-
line(sequence([label, str(/(?!\S)[^\r\n]*\r?\n/y)])),
|
|
53
|
+
line(sequence([label, str(/(?!\S)[^\r\n]*\r?\n/y)]), false),
|
|
54
54
|
inits([
|
|
55
55
|
block(union([
|
|
56
56
|
ulist,
|
|
@@ -62,13 +62,13 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
62
62
|
table,
|
|
63
63
|
blockquote,
|
|
64
64
|
placeholder,
|
|
65
|
-
line(media),
|
|
66
|
-
line(lineshortmedia),
|
|
65
|
+
line(media, false),
|
|
66
|
+
line(lineshortmedia, false),
|
|
67
67
|
])),
|
|
68
68
|
emptyline,
|
|
69
69
|
block(visualize(trimBlank(some(inline)))),
|
|
70
70
|
]),
|
|
71
|
-
])),
|
|
71
|
+
]), false),
|
|
72
72
|
nodes => {
|
|
73
73
|
const [label, param, content, ...caption] = unwrap(nodes) as [HTMLAnchorElement, string, ...HTMLElement[]];
|
|
74
74
|
return new List([
|
|
@@ -83,10 +83,10 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
83
83
|
]))
|
|
84
84
|
]);
|
|
85
85
|
})),
|
|
86
|
-
|
|
87
|
-
fence(/(~{3,})(?:figure(?=$|[ \r\n])|\[?\$)[^\r\n]*(?:$|\r?\n)/y, 300),
|
|
88
|
-
(
|
|
89
|
-
const [body, overflow, closer, opener, delim] = unwrap
|
|
86
|
+
inits([
|
|
87
|
+
fence(/(~{3,})(?:figure(?=$|[ \r\n])|\[?\$)[^\r\n]*(?:$|\r?\n)/y, true, 300),
|
|
88
|
+
(_, output) => {
|
|
89
|
+
const [body, overflow, closer, opener, delim] = unwrap(output.pop()) as string[];
|
|
90
90
|
const violation =
|
|
91
91
|
!closer && [
|
|
92
92
|
'fence',
|
|
@@ -96,7 +96,7 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
96
96
|
'fence',
|
|
97
97
|
`Invalid trailing line after the closing delimiter "${delim}"`,
|
|
98
98
|
] ||
|
|
99
|
-
!
|
|
99
|
+
!test_label(opener.match(/^~+(?:figure )?(\[?\$\S+)/)?.[1] ?? '') && [
|
|
100
100
|
'label',
|
|
101
101
|
'Invalid label',
|
|
102
102
|
] ||
|
|
@@ -108,14 +108,16 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
108
108
|
'content',
|
|
109
109
|
'Invalid content',
|
|
110
110
|
];
|
|
111
|
-
return
|
|
112
|
-
new Node(html('pre',
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
return output.append(
|
|
112
|
+
new Node(html('pre',
|
|
113
|
+
{
|
|
114
|
+
class: 'invalid',
|
|
115
|
+
translate: 'no',
|
|
116
|
+
...invalid('figure', violation[0], violation[1]),
|
|
117
|
+
},
|
|
118
|
+
`${opener}${body}${overflow || closer}`)));
|
|
119
|
+
},
|
|
120
|
+
])));
|
|
119
121
|
|
|
120
122
|
function attributes(label: string, param: string, content: HTMLElement, caption: readonly HTMLElement[]): Record<string, string | undefined> {
|
|
121
123
|
const group = label.split('-', 1)[0];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { message } from './message';
|
|
2
2
|
import { some } from '../../../combinator';
|
|
3
|
-
import { input } from '
|
|
4
|
-
import { Context } from '../../context';
|
|
3
|
+
import { input } from '../../context';
|
|
5
4
|
import { inspect } from '../../../debug.test';
|
|
6
5
|
|
|
7
6
|
describe('Unit: parser/block/extension/message', () => {
|
|
@@ -9,21 +8,21 @@ describe('Unit: parser/block/extension/message', () => {
|
|
|
9
8
|
const parser = some(message);
|
|
10
9
|
|
|
11
10
|
it('invalid', () => {
|
|
12
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message\n~~~'
|
|
13
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/\n~~~'
|
|
14
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/a\n~~~'
|
|
15
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/note a\n~~~'
|
|
16
|
-
assert.deepStrictEqual(inspect(parser, input(`~~~message/note\n0${'\n'.repeat(301)}
|
|
11
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message\n~~~')), undefined);
|
|
12
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/\n~~~')), undefined);
|
|
13
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/a\n~~~')), [['<pre class="invalid" translate="no">~~~message/a\n~~~</pre>'], '']);
|
|
14
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/note a\n~~~')), [['<pre class="invalid" translate="no">~~~message/note a\n~~~</pre>'], '']);
|
|
15
|
+
assert.deepStrictEqual(inspect(parser, input(`~~~message/note\n0${'\n'.repeat(301)}~~~`), '>'), [['<pre class="invalid" translate="no">'], '']);
|
|
17
16
|
});
|
|
18
17
|
|
|
19
18
|
it('valid', () => {
|
|
20
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/note\n~~~'
|
|
21
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/note\n\n~~~'
|
|
22
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/note\na\n~~~'
|
|
23
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/note\na\n\n- \n~~~'
|
|
24
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/note\n# a\n~~~'
|
|
25
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/caution\n~~~'
|
|
26
|
-
assert.deepStrictEqual(inspect(parser, input('~~~message/warning\n~~~'
|
|
19
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/note\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1></section>'], '']);
|
|
20
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/note\n\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1></section>'], '']);
|
|
21
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/note\na\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1><p>a</p></section>'], '']);
|
|
22
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/note\na\n\n- \n~~~')), [['<section class="message" data-type="note"><h1>Note</h1><p>a</p><ul><li></li></ul></section>'], '']);
|
|
23
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/note\n# a\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1><p># a</p></section>'], '']);
|
|
24
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/caution\n~~~')), [['<section class="message" data-type="caution"><h1>Caution!</h1></section>'], '']);
|
|
25
|
+
assert.deepStrictEqual(inspect(parser, input('~~~message/warning\n~~~')), [['<section class="message" data-type="warning"><h1>WARNING!!</h1></section>'], '']);
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../block';
|
|
2
|
-
import {
|
|
3
|
-
import { union, block, fence,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { Node } from '../../../combinator/parser';
|
|
3
|
+
import { union, inits, force, block, fence, lazy } from '../../../combinator';
|
|
4
|
+
import { build } from '../../parser';
|
|
5
|
+
import { parser as segment } from '../../segment';
|
|
6
|
+
import { emptysegment } from '../../source';
|
|
6
7
|
import { ulist } from '../ulist';
|
|
7
8
|
import { olist } from '../olist';
|
|
8
9
|
import { ilist } from '../ilist';
|
|
@@ -14,54 +15,66 @@ import { blockquote } from '../blockquote';
|
|
|
14
15
|
import { mediablock } from '../mediablock';
|
|
15
16
|
import { paragraph } from '../paragraph';
|
|
16
17
|
import { unwrap, invalid } from '../../util';
|
|
17
|
-
import { push } from 'spica/array';
|
|
18
18
|
import { html } from 'typed-dom/dom';
|
|
19
19
|
|
|
20
20
|
import MessageParser = ExtensionParser.MessageParser;
|
|
21
21
|
|
|
22
|
-
export const message: MessageParser = block(
|
|
23
|
-
fence(/(~{3,})message\/(\S+)(?!\S)([^\r\n]*)(?:$|\r?\n)/y, 300),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
export const message: MessageParser = block(inits([
|
|
23
|
+
fence(/(~{3,})message\/(\S+)(?!\S)([^\r\n]*)(?:$|\r?\n)/y, true, 300),
|
|
24
|
+
(input, output) => {
|
|
25
|
+
const [body, overflow, closer, opener, delim, type, param] = unwrap(output.pop()) as string[];
|
|
26
|
+
if (!closer || overflow || param.trimStart()) {
|
|
27
|
+
output.append(
|
|
28
|
+
new Node(html('pre',
|
|
29
|
+
{
|
|
30
|
+
class: 'invalid',
|
|
31
|
+
translate: 'no',
|
|
32
|
+
...invalid(
|
|
33
|
+
'message',
|
|
34
|
+
!closer || overflow ? 'fence' : 'argument',
|
|
35
|
+
!closer ? `Missing the closing delimiter "${delim}"` :
|
|
36
|
+
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
37
|
+
'Invalid argument'),
|
|
38
|
+
},
|
|
39
|
+
`${opener}${body}${overflow || closer}`)));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
39
42
|
switch (type) {
|
|
40
43
|
case 'note':
|
|
41
44
|
case 'caution':
|
|
42
45
|
case 'warning':
|
|
43
46
|
break;
|
|
44
47
|
default:
|
|
45
|
-
|
|
46
|
-
new Node(html('pre',
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
output.append(
|
|
49
|
+
new Node(html('pre',
|
|
50
|
+
{
|
|
51
|
+
class: 'invalid',
|
|
52
|
+
translate: 'no',
|
|
53
|
+
...invalid('message', 'type', 'Invalid message type'),
|
|
54
|
+
},
|
|
55
|
+
`${opener}${body}${closer}`)));
|
|
56
|
+
return;
|
|
52
57
|
}
|
|
53
|
-
|
|
58
|
+
output.append(
|
|
54
59
|
new Node(html('section',
|
|
55
60
|
{
|
|
56
61
|
class: `message`,
|
|
57
62
|
'data-type': type,
|
|
58
63
|
},
|
|
59
|
-
[
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
64
|
+
[html('h1', title(type))])));
|
|
65
|
+
const src = body.slice(0, body.at(-2) === '\r' ? -2 : -1);
|
|
66
|
+
input.scope.focus(src);
|
|
67
|
+
output.push();
|
|
68
|
+
return output.context;
|
|
69
|
+
},
|
|
70
|
+
force(() => cont),
|
|
71
|
+
(input, output) => {
|
|
72
|
+
input.scope.unfocus();
|
|
73
|
+
const content = output.pop();
|
|
74
|
+
output.peek().last!.value.append(...unwrap(content));
|
|
75
|
+
return output.context;
|
|
76
|
+
},
|
|
77
|
+
]));
|
|
65
78
|
|
|
66
79
|
function title(type: string): string {
|
|
67
80
|
switch (type) {
|
|
@@ -75,8 +88,8 @@ function title(type: string): string {
|
|
|
75
88
|
}
|
|
76
89
|
|
|
77
90
|
// Must not have indexed blocks.
|
|
78
|
-
const
|
|
79
|
-
|
|
91
|
+
const cont = build(lazy(() => segment), lazy(() => union([
|
|
92
|
+
emptysegment,
|
|
80
93
|
ulist,
|
|
81
94
|
olist,
|
|
82
95
|
ilist,
|
|
@@ -87,4 +100,4 @@ const content: MessageParser.ContentParser = union([
|
|
|
87
100
|
blockquote,
|
|
88
101
|
mediablock,
|
|
89
102
|
paragraph,
|
|
90
|
-
]);
|
|
103
|
+
])));
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { placeholder } from './placeholder';
|
|
2
2
|
import { some } from '../../../combinator';
|
|
3
|
-
import { input } from '
|
|
4
|
-
import {
|
|
3
|
+
import { input } from '../../context';
|
|
4
|
+
import { inspect } from '../../../debug.test';
|
|
5
5
|
|
|
6
6
|
describe('Unit: parser/block/extension/placeholder', () => {
|
|
7
7
|
describe('placeholder', () => {
|
|
8
8
|
const parser = some(placeholder);
|
|
9
9
|
|
|
10
10
|
it('invalid', () => {
|
|
11
|
-
assert(!parser
|
|
12
|
-
assert(!parser
|
|
13
|
-
assert(!parser
|
|
14
|
-
assert(!parser
|
|
15
|
-
assert(!parser
|
|
11
|
+
assert(!inspect(parser, input('')));
|
|
12
|
+
assert(!inspect(parser, input('\n')));
|
|
13
|
+
assert(!inspect(parser, input('~~~')));
|
|
14
|
+
assert(!inspect(parser, input('~~~\n')));
|
|
15
|
+
assert(!inspect(parser, input('~~~a ~~~\n~~~')));
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('valid', () => {
|
|
19
|
-
assert(parser
|
|
20
|
-
assert(parser
|
|
21
|
-
assert(parser
|
|
22
|
-
assert(parser
|
|
23
|
-
assert(parser
|
|
24
|
-
assert(parser
|
|
19
|
+
assert(inspect(parser, input('~~~\n~~~')));
|
|
20
|
+
assert(inspect(parser, input('~~~a\n~~~')));
|
|
21
|
+
assert(inspect(parser, input('~~~a \n~~~')));
|
|
22
|
+
assert(inspect(parser, input('~~~a b \n~~~')));
|
|
23
|
+
assert(inspect(parser, input('~~~~a\n~~~~')));
|
|
24
|
+
assert(inspect(parser, input('~~~~a\n~~~~\n')));
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
});
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../block';
|
|
2
|
-
import {
|
|
3
|
-
import { block, fence
|
|
2
|
+
import { Node } from '../../../combinator/parser';
|
|
3
|
+
import { inits, block, fence } from '../../../combinator';
|
|
4
4
|
import { unwrap, invalid } from '../../util';
|
|
5
5
|
import { html } from 'typed-dom/dom';
|
|
6
6
|
|
|
7
7
|
const opener = /(~{3,})(?!~)[^\r\n]*(?:$|\r?\n)/y;
|
|
8
8
|
|
|
9
9
|
export const segment: ExtensionParser.PlaceholderParser.SegmentParser = block(
|
|
10
|
-
|
|
10
|
+
fence(opener, false, 300));
|
|
11
11
|
|
|
12
12
|
export const segment_: ExtensionParser.PlaceholderParser.SegmentParser = block(
|
|
13
|
-
|
|
13
|
+
fence(opener, false, 300, false), false);
|
|
14
14
|
|
|
15
|
-
export const placeholder: ExtensionParser.PlaceholderParser = block(
|
|
16
|
-
fence(opener,
|
|
17
|
-
|
|
18
|
-
const [body, overflow, closer, opener, delim] = unwrap(
|
|
19
|
-
return
|
|
20
|
-
new Node(html('pre',
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
export const placeholder: ExtensionParser.PlaceholderParser = block(inits([
|
|
16
|
+
fence(opener, true, 300),
|
|
17
|
+
(_, output) => {
|
|
18
|
+
const [body, overflow, closer, opener, delim] = unwrap(output.pop()) as string[];
|
|
19
|
+
return output.append(
|
|
20
|
+
new Node(html('pre',
|
|
21
|
+
{
|
|
22
|
+
class: 'invalid',
|
|
23
|
+
translate: 'no',
|
|
24
|
+
...invalid(
|
|
25
|
+
'extension',
|
|
26
|
+
'fence',
|
|
27
|
+
!closer ? `Missing the closing delimiter "${delim}"` :
|
|
28
|
+
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
29
|
+
'Invalid argument'),
|
|
30
|
+
},
|
|
31
|
+
`${opener}${body}${overflow || closer}`)));
|
|
32
|
+
},
|
|
33
|
+
]));
|