securemark 0.291.1 → 0.292.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 +4 -0
- package/design.md +13 -2
- package/dist/index.js +1093 -756
- package/markdown.d.ts +17 -17
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.test.ts +8 -5
- package/src/combinator/control/constraint/block.ts +9 -9
- package/src/combinator/control/constraint/contract.ts +20 -28
- package/src/combinator/control/constraint/line.test.ts +9 -6
- package/src/combinator/control/constraint/line.ts +21 -22
- package/src/combinator/control/manipulation/convert.ts +29 -13
- package/src/combinator/control/manipulation/fence.ts +18 -15
- package/src/combinator/control/manipulation/indent.test.ts +17 -14
- package/src/combinator/control/manipulation/indent.ts +15 -8
- package/src/combinator/control/manipulation/match.ts +11 -10
- package/src/combinator/control/manipulation/recovery.ts +6 -2
- package/src/combinator/control/manipulation/scope.ts +37 -38
- package/src/combinator/control/manipulation/surround.ts +78 -60
- package/src/combinator/control/manipulation/trim.test.ts +12 -9
- package/src/combinator/control/monad/bind.ts +16 -16
- package/src/combinator/control/monad/fmap.ts +6 -6
- package/src/combinator/data/parser/context/delimiter.ts +8 -7
- package/src/combinator/data/parser/context.test.ts +19 -14
- package/src/combinator/data/parser/context.ts +20 -16
- package/src/combinator/data/parser/inits.ts +13 -14
- package/src/combinator/data/parser/sequence.test.ts +16 -15
- package/src/combinator/data/parser/sequence.ts +13 -14
- package/src/combinator/data/parser/some.test.ts +19 -18
- package/src/combinator/data/parser/some.ts +13 -15
- package/src/combinator/data/parser/subsequence.test.ts +22 -21
- package/src/combinator/data/parser/subsequence.ts +3 -3
- package/src/combinator/data/parser/tails.ts +3 -3
- package/src/combinator/data/parser/union.test.ts +16 -15
- package/src/combinator/data/parser/union.ts +2 -2
- package/src/combinator/data/parser.ts +66 -28
- package/src/debug.test.ts +3 -3
- package/src/parser/api/bind.ts +3 -3
- package/src/parser/api/header.ts +7 -6
- package/src/parser/api/normalize.ts +2 -2
- package/src/parser/api/parse.test.ts +14 -15
- package/src/parser/api/parse.ts +3 -3
- package/src/parser/autolink.test.ts +19 -17
- package/src/parser/block/blockquote.test.ts +86 -84
- package/src/parser/block/blockquote.ts +4 -2
- package/src/parser/block/codeblock.test.ts +58 -56
- package/src/parser/block/codeblock.ts +3 -3
- package/src/parser/block/dlist.test.ts +58 -56
- package/src/parser/block/extension/aside.test.ts +10 -8
- package/src/parser/block/extension/aside.ts +1 -1
- package/src/parser/block/extension/example.test.ts +20 -18
- package/src/parser/block/extension/example.ts +3 -3
- package/src/parser/block/extension/fig.test.ts +38 -36
- package/src/parser/block/extension/fig.ts +1 -1
- package/src/parser/block/extension/figbase.test.ts +17 -15
- package/src/parser/block/extension/figure.test.ts +64 -62
- package/src/parser/block/extension/figure.ts +3 -2
- package/src/parser/block/extension/message.test.ts +15 -13
- package/src/parser/block/extension/message.ts +3 -3
- package/src/parser/block/extension/placeholder.test.ts +3 -1
- package/src/parser/block/extension/table.test.ts +73 -71
- package/src/parser/block/extension/table.ts +5 -5
- package/src/parser/block/extension.test.ts +3 -1
- package/src/parser/block/heading.test.ts +65 -64
- package/src/parser/block/heading.ts +3 -3
- package/src/parser/block/ilist.test.ts +3 -1
- package/src/parser/block/ilist.ts +3 -3
- package/src/parser/block/mathblock.test.ts +33 -31
- package/src/parser/block/mathblock.ts +1 -1
- package/src/parser/block/mediablock.ts +2 -2
- package/src/parser/block/olist.test.ts +99 -97
- package/src/parser/block/olist.ts +2 -2
- package/src/parser/block/pagebreak.test.ts +17 -15
- package/src/parser/block/pagebreak.ts +1 -1
- package/src/parser/block/paragraph.test.ts +60 -57
- package/src/parser/block/reply/cite.test.ts +41 -39
- package/src/parser/block/reply/cite.ts +3 -3
- package/src/parser/block/reply/quote.test.ts +52 -50
- package/src/parser/block/reply.test.ts +21 -19
- package/src/parser/block/sidefence.test.ts +51 -49
- package/src/parser/block/table.test.ts +51 -50
- package/src/parser/block/table.ts +6 -6
- package/src/parser/block/ulist.test.ts +52 -50
- package/src/parser/block/ulist.ts +2 -2
- package/src/parser/block.ts +6 -5
- package/src/parser/context.ts +1 -0
- package/src/parser/header.test.ts +22 -21
- package/src/parser/header.ts +25 -13
- package/src/parser/inline/annotation.test.ts +44 -42
- package/src/parser/inline/annotation.ts +2 -2
- package/src/parser/inline/autolink/account.test.ts +32 -30
- package/src/parser/inline/autolink/account.ts +1 -1
- package/src/parser/inline/autolink/anchor.test.ts +23 -21
- package/src/parser/inline/autolink/anchor.ts +1 -1
- package/src/parser/inline/autolink/channel.test.ts +16 -14
- package/src/parser/inline/autolink/channel.ts +2 -2
- package/src/parser/inline/autolink/email.test.ts +38 -36
- package/src/parser/inline/autolink/email.ts +2 -2
- package/src/parser/inline/autolink/hashnum.test.ts +39 -37
- package/src/parser/inline/autolink/hashnum.ts +1 -1
- package/src/parser/inline/autolink/hashtag.test.ts +58 -56
- package/src/parser/inline/autolink/hashtag.ts +1 -1
- package/src/parser/inline/autolink/url.test.ts +76 -74
- package/src/parser/inline/autolink/url.ts +6 -6
- package/src/parser/inline/bracket.test.ts +69 -67
- package/src/parser/inline/bracket.ts +32 -32
- package/src/parser/inline/code.test.ts +32 -29
- package/src/parser/inline/code.ts +20 -13
- package/src/parser/inline/deletion.test.ts +29 -27
- package/src/parser/inline/deletion.ts +2 -2
- package/src/parser/inline/emphasis.test.ts +40 -36
- package/src/parser/inline/emphasis.ts +2 -2
- package/src/parser/inline/emstrong.test.ts +102 -96
- package/src/parser/inline/emstrong.ts +96 -36
- package/src/parser/inline/extension/index.test.ts +91 -89
- package/src/parser/inline/extension/index.ts +18 -30
- package/src/parser/inline/extension/indexee.ts +1 -1
- package/src/parser/inline/extension/indexer.test.ts +26 -24
- package/src/parser/inline/extension/indexer.ts +1 -1
- package/src/parser/inline/extension/label.test.ts +34 -32
- package/src/parser/inline/extension/placeholder.test.ts +44 -42
- package/src/parser/inline/extension/placeholder.ts +11 -8
- package/src/parser/inline/html.test.ts +108 -106
- package/src/parser/inline/html.ts +24 -23
- package/src/parser/inline/htmlentity.test.ts +39 -37
- package/src/parser/inline/htmlentity.ts +9 -3
- package/src/parser/inline/insertion.test.ts +29 -27
- package/src/parser/inline/insertion.ts +2 -2
- package/src/parser/inline/italic.test.ts +55 -53
- package/src/parser/inline/italic.ts +2 -2
- package/src/parser/inline/link.test.ts +187 -185
- package/src/parser/inline/link.ts +30 -12
- package/src/parser/inline/mark.test.ts +31 -29
- package/src/parser/inline/mark.ts +3 -3
- package/src/parser/inline/math.test.ts +133 -131
- package/src/parser/inline/math.ts +2 -2
- package/src/parser/inline/media.test.ts +93 -91
- package/src/parser/inline/media.ts +41 -17
- package/src/parser/inline/reference.test.ts +110 -108
- package/src/parser/inline/reference.ts +48 -39
- package/src/parser/inline/remark.test.ts +53 -51
- package/src/parser/inline/remark.ts +3 -3
- package/src/parser/inline/ruby.test.ts +46 -44
- package/src/parser/inline/ruby.ts +24 -27
- package/src/parser/inline/shortmedia.test.ts +11 -9
- package/src/parser/inline/strong.test.ts +37 -33
- package/src/parser/inline/strong.ts +6 -3
- package/src/parser/inline/template.test.ts +24 -22
- package/src/parser/inline/template.ts +20 -11
- package/src/parser/inline.test.ts +221 -220
- package/src/parser/inline.ts +13 -8
- package/src/parser/segment.ts +13 -8
- package/src/parser/source/escapable.test.ts +24 -22
- package/src/parser/source/escapable.ts +26 -41
- package/src/parser/source/line.test.ts +19 -17
- package/src/parser/source/line.ts +3 -3
- package/src/parser/source/str.ts +28 -11
- package/src/parser/source/text.test.ts +85 -83
- package/src/parser/source/text.ts +26 -54
- package/src/parser/source/unescapable.test.ts +24 -22
- package/src/parser/source/unescapable.ts +18 -33
- package/src/parser/source.ts +1 -1
- package/src/parser/util.ts +36 -33
- package/src/parser/visibility.ts +19 -15
- package/src/util/quote.ts +4 -2
|
@@ -1,66 +1,38 @@
|
|
|
1
1
|
import { TextParser, TxtParser, LinebreakParser } from '../source';
|
|
2
2
|
import { Command } from '../context';
|
|
3
3
|
import { union, consume, focus } from '../../combinator';
|
|
4
|
-
import { str } from './str';
|
|
5
4
|
import { html } from 'typed-dom/dom';
|
|
6
5
|
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
case
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
assert(!source.includes('\r', 1));
|
|
24
|
-
consume(-1, context);
|
|
25
|
-
return [[], source.slice(1)];
|
|
26
|
-
case Command.Escape:
|
|
27
|
-
case '\\':
|
|
28
|
-
switch (source[1]) {
|
|
29
|
-
case undefined:
|
|
30
|
-
return [[], ''];
|
|
31
|
-
case '\n':
|
|
32
|
-
assert(source[0] !== Command.Escape);
|
|
33
|
-
return [[], source.slice(1)];
|
|
34
|
-
default:
|
|
35
|
-
consume(1, context);
|
|
36
|
-
return [[source.slice(1, 2)], source.slice(2)];
|
|
37
|
-
}
|
|
6
|
+
export const text: TextParser = input => {
|
|
7
|
+
const { context } = input;
|
|
8
|
+
const { source, position } = context;
|
|
9
|
+
if (position === source.length) return;
|
|
10
|
+
consume(1, context);
|
|
11
|
+
context.position += 1;
|
|
12
|
+
switch (source[position]) {
|
|
13
|
+
case '\r':
|
|
14
|
+
assert(!source.includes('\r', position + 1));
|
|
15
|
+
consume(-1, context);
|
|
16
|
+
return [[]];
|
|
17
|
+
case Command.Escape:
|
|
18
|
+
case '\\':
|
|
19
|
+
switch (source[position + 1]) {
|
|
20
|
+
case undefined:
|
|
21
|
+
return [[]];
|
|
38
22
|
case '\n':
|
|
39
|
-
|
|
40
|
-
return [[
|
|
41
|
-
case '*':
|
|
42
|
-
case '`':
|
|
43
|
-
return source[1] === source[0]
|
|
44
|
-
? repeat({ source, context })
|
|
45
|
-
: [[source[0]], source.slice(1)];
|
|
23
|
+
assert(source[0] !== Command.Escape);
|
|
24
|
+
return [[]];
|
|
46
25
|
default:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
? source.search(b ? nonWhitespace : nonAlphanumeric) || 1
|
|
51
|
-
: 1;
|
|
52
|
-
assert(i > 0);
|
|
53
|
-
assert(!['\\', '\n'].includes(source[0]));
|
|
54
|
-
consume(i - 1, context);
|
|
55
|
-
return b && i === source.length
|
|
56
|
-
|| b && source[i] === '\n'
|
|
57
|
-
|| b && source[i] === '\\' && source[i + 1] === '\n'
|
|
58
|
-
? [[], source.slice(i)]
|
|
59
|
-
: [[source.slice(0, i - +b || 1)], source.slice(i - +b || 1)];
|
|
26
|
+
consume(1, context);
|
|
27
|
+
context.position += 1;
|
|
28
|
+
return [[source.slice(position + 1, position + 2)]];
|
|
60
29
|
}
|
|
30
|
+
case '\n':
|
|
31
|
+
context.linebreak ||= source.length - position;
|
|
32
|
+
return [[html('br')]];
|
|
61
33
|
default:
|
|
62
|
-
|
|
63
|
-
return [[source
|
|
34
|
+
assert(source[position] !== '\n');
|
|
35
|
+
return [[source[position]]];
|
|
64
36
|
}
|
|
65
37
|
};
|
|
66
38
|
|
|
@@ -1,45 +1,47 @@
|
|
|
1
1
|
import { unescsource } from './unescapable';
|
|
2
2
|
import { some } from '../../combinator';
|
|
3
|
+
import { input } from '../../combinator/data/parser';
|
|
3
4
|
import { inspect } from '../../debug.test';
|
|
4
5
|
|
|
5
6
|
describe('Unit: parser/source/unescapable', () => {
|
|
6
7
|
describe('unescsource', () => {
|
|
7
|
-
const parser = (source: string) => some(unescsource)(
|
|
8
|
+
const parser = (source: string) => some(unescsource)(input(source, ctx));
|
|
9
|
+
const { context: ctx } = input('', {});
|
|
8
10
|
|
|
9
11
|
it('invalid', () => {
|
|
10
|
-
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
12
|
+
assert.deepStrictEqual(inspect(parser(''), ctx), undefined);
|
|
11
13
|
});
|
|
12
14
|
|
|
13
15
|
it('basic', () => {
|
|
14
|
-
assert.deepStrictEqual(inspect(parser('a')), [['a'], '']);
|
|
15
|
-
assert.deepStrictEqual(inspect(parser('ab')), [['
|
|
16
|
-
assert.deepStrictEqual(inspect(parser('09あいAZaz')), [['
|
|
16
|
+
assert.deepStrictEqual(inspect(parser('a'), ctx), [['a'], '']);
|
|
17
|
+
assert.deepStrictEqual(inspect(parser('ab'), ctx), [['a', 'b'], '']);
|
|
18
|
+
assert.deepStrictEqual(inspect(parser('09あいAZaz'), ctx), [['0', '9', 'あ', 'い', 'A', 'Z', 'a', 'z'], '']);
|
|
17
19
|
});
|
|
18
20
|
|
|
19
21
|
it('space', () => {
|
|
20
|
-
assert.deepStrictEqual(inspect(parser(' ')), [[' '], '']);
|
|
21
|
-
assert.deepStrictEqual(inspect(parser(' ')), [[' ', ' '], '']);
|
|
22
|
-
assert.deepStrictEqual(inspect(parser(' ')), [['
|
|
23
|
-
assert.deepStrictEqual(inspect(parser(' \n')), [[' ', '<br>'], '']);
|
|
24
|
-
assert.deepStrictEqual(inspect(parser(' \n')), [[' ', ' ', '<br>'], '']);
|
|
25
|
-
assert.deepStrictEqual(inspect(parser(' \n')), [['
|
|
22
|
+
assert.deepStrictEqual(inspect(parser(' '), ctx), [[' '], '']);
|
|
23
|
+
assert.deepStrictEqual(inspect(parser(' '), ctx), [[' ', ' '], '']);
|
|
24
|
+
assert.deepStrictEqual(inspect(parser(' '), ctx), [[' ', ' ', ' '], '']);
|
|
25
|
+
assert.deepStrictEqual(inspect(parser(' \n'), ctx), [[' ', '<br>'], '']);
|
|
26
|
+
assert.deepStrictEqual(inspect(parser(' \n'), ctx), [[' ', ' ', '<br>'], '']);
|
|
27
|
+
assert.deepStrictEqual(inspect(parser(' \n'), ctx), [[' ', ' ', ' ', '<br>'], '']);
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
it('linebreak', () => {
|
|
29
|
-
assert.deepStrictEqual(inspect(parser('\n\n')), [['<br>', '<br>'], '']);
|
|
31
|
+
assert.deepStrictEqual(inspect(parser('\n\n'), ctx), [['<br>', '<br>'], '']);
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
it('\\', () => {
|
|
33
|
-
assert.deepStrictEqual(inspect(parser('\\')), [['\\'], '']);
|
|
34
|
-
assert.deepStrictEqual(inspect(parser('\\\\')), [['\\', '\\'], '']);
|
|
35
|
-
assert.deepStrictEqual(inspect(parser('\\\\\\')), [['\\', '\\', '\\'], '']);
|
|
36
|
-
assert.deepStrictEqual(inspect(parser('\\ ')), [['\\', ' '], '']);
|
|
37
|
-
assert.deepStrictEqual(inspect(parser('\\_')), [['\\', '_'], '']);
|
|
38
|
-
assert.deepStrictEqual(inspect(parser('\\0')), [['\\', '0'], '']);
|
|
39
|
-
assert.deepStrictEqual(inspect(parser('\\a')), [['\\', 'a'], '']);
|
|
40
|
-
assert.deepStrictEqual(inspect(parser('\\`')), [['\\', '`'], '']);
|
|
41
|
-
assert.deepStrictEqual(inspect(parser('\\ ')), [['\\', ' '], '']);
|
|
42
|
-
assert.deepStrictEqual(inspect(parser('\\\n')), [['\\', '<br>'], '']);
|
|
35
|
+
assert.deepStrictEqual(inspect(parser('\\'), ctx), [['\\'], '']);
|
|
36
|
+
assert.deepStrictEqual(inspect(parser('\\\\'), ctx), [['\\', '\\'], '']);
|
|
37
|
+
assert.deepStrictEqual(inspect(parser('\\\\\\'), ctx), [['\\', '\\', '\\'], '']);
|
|
38
|
+
assert.deepStrictEqual(inspect(parser('\\ '), ctx), [['\\', ' '], '']);
|
|
39
|
+
assert.deepStrictEqual(inspect(parser('\\_'), ctx), [['\\', '_'], '']);
|
|
40
|
+
assert.deepStrictEqual(inspect(parser('\\0'), ctx), [['\\', '0'], '']);
|
|
41
|
+
assert.deepStrictEqual(inspect(parser('\\a'), ctx), [['\\', 'a'], '']);
|
|
42
|
+
assert.deepStrictEqual(inspect(parser('\\`'), ctx), [['\\', '`'], '']);
|
|
43
|
+
assert.deepStrictEqual(inspect(parser('\\ '), ctx), [['\\', ' '], '']);
|
|
44
|
+
assert.deepStrictEqual(inspect(parser('\\\n'), ctx), [['\\', '<br>'], '']);
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
});
|
|
@@ -1,42 +1,27 @@
|
|
|
1
1
|
import { UnescapableSourceParser } from '../source';
|
|
2
2
|
import { Command } from '../context';
|
|
3
3
|
import { consume } from '../../combinator';
|
|
4
|
-
import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
|
|
5
4
|
import { html } from 'typed-dom/dom';
|
|
6
5
|
|
|
7
|
-
export const unescsource: UnescapableSourceParser = ({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export const unescsource: UnescapableSourceParser = ({ context }) => {
|
|
7
|
+
const { source, position } = context;
|
|
8
|
+
if (position === source.length) return;
|
|
9
|
+
consume(1, context);
|
|
10
|
+
context.position += 1;
|
|
11
|
+
switch (source[position]) {
|
|
12
|
+
case '\r':
|
|
13
|
+
assert(!source.includes('\r', position + 1));
|
|
14
|
+
consume(-1, context);
|
|
15
|
+
return [[]];
|
|
16
|
+
case Command.Escape:
|
|
15
17
|
consume(1, context);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
case Command.Escape:
|
|
22
|
-
consume(1, context);
|
|
23
|
-
return [[source.slice(1, 2)], source.slice(2)];
|
|
24
|
-
case '\n':
|
|
25
|
-
context.linebreak ||= source.length;
|
|
26
|
-
return [[html('br')], source.slice(1)];
|
|
27
|
-
default:
|
|
28
|
-
assert(source[0] !== '\n');
|
|
29
|
-
const b = source[0].trimStart() === '';
|
|
30
|
-
const i = b || isAlphanumeric(source[0])
|
|
31
|
-
? source.search(b ? nonWhitespace : nonAlphanumeric) || 1
|
|
32
|
-
: 1;
|
|
33
|
-
assert(i > 0);
|
|
34
|
-
consume(i - 1, context);
|
|
35
|
-
return [[source.slice(0, i - +b || 1)], source.slice(i - +b || 1)];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
18
|
+
context.position += 1;
|
|
19
|
+
return [[source.slice(position + 1, position + 2)]];
|
|
20
|
+
case '\n':
|
|
21
|
+
context.linebreak ||= source.length - position;
|
|
22
|
+
return [[html('br')]];
|
|
38
23
|
default:
|
|
39
|
-
|
|
40
|
-
return [[source
|
|
24
|
+
assert(source[position] !== '\n');
|
|
25
|
+
return [[source[position]]];
|
|
41
26
|
}
|
|
42
27
|
};
|
package/src/parser/source.ts
CHANGED
|
@@ -14,5 +14,5 @@ export import AnyLineParser = SourceParser.AnyLineParser;
|
|
|
14
14
|
export { text, txt, linebreak } from './source/text';
|
|
15
15
|
export { escsource } from './source/escapable';
|
|
16
16
|
export { unescsource } from './source/unescapable';
|
|
17
|
-
export { str } from './source/str';
|
|
17
|
+
export { str, strs } from './source/str';
|
|
18
18
|
export { contentline, emptyline, anyline } from './source/line';
|
package/src/parser/util.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { min } from 'spica/alias';
|
|
2
|
+
import { MarkdownParser } from '../../markdown';
|
|
2
3
|
import { Command } from './context';
|
|
3
|
-
import { Parser, Result, Ctx, Node, Context, eval,
|
|
4
|
+
import { Parser, Result, Ctx, Node, Context, eval, failsafe } from '../combinator/data/parser';
|
|
4
5
|
import { convert } from '../combinator';
|
|
5
6
|
import { define } from 'typed-dom/dom';
|
|
6
7
|
|
|
@@ -22,67 +23,69 @@ export function lineable<N extends HTMLElement | string>(parser: Parser<N>, trim
|
|
|
22
23
|
trim === 0);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export function repeat<P extends Parser<HTMLElement |
|
|
26
|
-
export function repeat<N extends HTMLElement |
|
|
27
|
-
const
|
|
26
|
+
export function repeat<P extends Parser<HTMLElement | string, MarkdownParser.Context>>(symbol: string, parser: P, cons: (nodes: Node<P>[], context: Context<P>) => Node<P>[], termination?: (acc: Node<P>[], context: Ctx, prefix: number, postfix: number, state: boolean) => Result<string | Node<P>>): P;
|
|
27
|
+
export function repeat<N extends HTMLElement | string>(symbol: string, parser: Parser<N>, cons: (nodes: N[], context: MarkdownParser.Context) => N[], termination: (acc: N[], context: Ctx, prefix: number, postfix: number, state: boolean) => Result<string | N, MarkdownParser.Context> = (nodes, context, prefix, postfix) => {
|
|
28
|
+
const acc = [];
|
|
28
29
|
if (prefix > 0) {
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
for (let i = 0; i < acc.length; ++i) {
|
|
32
|
-
nodes.push(...acc[i]);
|
|
30
|
+
acc.push(symbol[0].repeat(prefix));
|
|
33
31
|
}
|
|
32
|
+
acc.push(...nodes);
|
|
34
33
|
if (postfix > 0) {
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const { source, position } = context;
|
|
35
|
+
acc.push(source.slice(position, position + postfix));
|
|
36
|
+
context.position += postfix;
|
|
37
37
|
}
|
|
38
|
-
return [
|
|
39
|
-
}): Parser<string | N> {
|
|
40
|
-
return input => {
|
|
41
|
-
const {
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
return [acc];
|
|
39
|
+
}): Parser<string | N, MarkdownParser.Context> {
|
|
40
|
+
return failsafe(input => {
|
|
41
|
+
const { context } = input;
|
|
42
|
+
const { source, position } = context;
|
|
43
|
+
assert(source.startsWith(symbol, context.position));
|
|
44
|
+
let nodes: N[] = [];
|
|
44
45
|
let i = symbol.length;
|
|
45
|
-
while (source[i] === source[
|
|
46
|
-
|
|
46
|
+
while (source[context.position + i] === source[context.position]) ++i;
|
|
47
|
+
context.position += i;
|
|
47
48
|
let state = false;
|
|
48
49
|
for (; i >= symbol.length; i -= symbol.length) {
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (nodes.length > 0 && source.startsWith(symbol, context.position)) {
|
|
51
|
+
nodes = cons(nodes, context);
|
|
52
|
+
context.position += symbol.length;
|
|
52
53
|
continue;
|
|
53
54
|
}
|
|
54
|
-
const
|
|
55
|
+
const buf = context.buffer;
|
|
56
|
+
context.buffer = nodes;
|
|
57
|
+
const result = parser(input);
|
|
58
|
+
context.buffer = buf;
|
|
55
59
|
if (result === undefined) break;
|
|
56
|
-
|
|
57
|
-
rest = exec(result);
|
|
58
|
-
acc.push(nodes);
|
|
60
|
+
nodes = eval(result);
|
|
59
61
|
switch (nodes.at(-1)) {
|
|
60
|
-
case Command.
|
|
61
|
-
assert(!
|
|
62
|
+
case Command.Cancel:
|
|
63
|
+
assert(!source.startsWith(symbol, context.position));
|
|
62
64
|
nodes.pop();
|
|
63
65
|
state = false;
|
|
64
66
|
break;
|
|
65
67
|
case Command.Separator:
|
|
66
|
-
assert(!
|
|
68
|
+
assert(!source.startsWith(symbol, context.position));
|
|
67
69
|
nodes.pop();
|
|
68
70
|
state = true;
|
|
69
71
|
continue;
|
|
70
72
|
default:
|
|
71
|
-
|
|
73
|
+
nodes = cons(nodes, context);
|
|
72
74
|
state = true;
|
|
73
75
|
continue;
|
|
74
76
|
}
|
|
75
77
|
break;
|
|
76
78
|
}
|
|
77
|
-
if (
|
|
79
|
+
if (nodes.length === 0) return;
|
|
78
80
|
const prefix = i;
|
|
79
81
|
i = 0;
|
|
80
|
-
for (let len = min(prefix,
|
|
82
|
+
for (let len = min(prefix, source.length - context.position); i < len && source[context.position + i] === symbol[0];) {
|
|
81
83
|
++i;
|
|
82
84
|
}
|
|
83
85
|
const postfix = i;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
context.range = context.position - position;
|
|
87
|
+
return termination(nodes, context, prefix, postfix, state);
|
|
88
|
+
});
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
export function invalid(
|
package/src/parser/visibility.ts
CHANGED
|
@@ -22,7 +22,7 @@ export function visualize<N extends HTMLElement | string>(parser: Parser<N>): Pa
|
|
|
22
22
|
return union([
|
|
23
23
|
convert(
|
|
24
24
|
source => source.replace(blank.line, line => line.replace(/[\\&<]/g, `${Command.Escape}$&`)),
|
|
25
|
-
verify(parser, (ns,
|
|
25
|
+
verify(parser, (ns, { source, position }) => position === source.length && hasVisible(ns)),
|
|
26
26
|
false),
|
|
27
27
|
some(union([linebreak, unescsource])),
|
|
28
28
|
]);
|
|
@@ -37,6 +37,7 @@ function hasVisible(
|
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
if (node.innerText.trimStart()) return true;
|
|
40
|
+
if (node.classList.contains('reference')) return true;
|
|
40
41
|
//if (state & State.media ^ State.media &&
|
|
41
42
|
// (node.classList.contains('media') || node.getElementsByClassName('media')[0])) return true;
|
|
42
43
|
}
|
|
@@ -79,35 +80,38 @@ export function tightStart<N>(parser: Parser<N>, except?: string): Parser<N> {
|
|
|
79
80
|
: undefined;
|
|
80
81
|
}
|
|
81
82
|
function isTightStart(input: Input<MarkdownParser.Context>, except?: string): boolean {
|
|
82
|
-
const {
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
83
|
+
const { context } = input;
|
|
84
|
+
const { source, position } = context;
|
|
85
|
+
if (position === source.length) return true;
|
|
86
|
+
if (except && source.startsWith(except, position)) return false;
|
|
87
|
+
switch (source[position]) {
|
|
86
88
|
case ' ':
|
|
87
89
|
case ' ':
|
|
88
90
|
case '\t':
|
|
89
91
|
case '\n':
|
|
90
92
|
return false;
|
|
91
93
|
case '\\':
|
|
92
|
-
return source[1]?.trimStart() !== '';
|
|
94
|
+
return source[position + 1]?.trimStart() !== '';
|
|
93
95
|
case '&':
|
|
94
96
|
switch (true) {
|
|
95
|
-
case source.length > 2
|
|
96
|
-
&& source[1] !== ' '
|
|
97
|
+
case source.length - position > 2
|
|
98
|
+
&& source[position + 1] !== ' '
|
|
97
99
|
&& eval(unsafehtmlentity(input))?.[0]?.trimStart() === '':
|
|
100
|
+
context.position = position;
|
|
98
101
|
return false;
|
|
99
102
|
}
|
|
103
|
+
context.position = position;
|
|
100
104
|
return true;
|
|
101
105
|
case '<':
|
|
102
106
|
switch (true) {
|
|
103
|
-
case source.length >= 5
|
|
104
|
-
&& source.
|
|
105
|
-
&& (source[5] === '>' || /^<wbr[^\S\n]*>/.test(source)):
|
|
107
|
+
case source.length - position >= 5
|
|
108
|
+
&& source.startsWith('<wbr', position)
|
|
109
|
+
&& (source[position + 5] === '>' || /^<wbr[^\S\n]*>/.test(source.slice(position))):
|
|
106
110
|
return false;
|
|
107
111
|
}
|
|
108
112
|
return true;
|
|
109
113
|
default:
|
|
110
|
-
return source[
|
|
114
|
+
return source[position].trimStart() !== '';
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
|
|
@@ -199,9 +203,9 @@ export function trimBlankNodeEnd<N extends HTMLElement | string>(nodes: N[]): N[
|
|
|
199
203
|
: [];
|
|
200
204
|
for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes.at(-1)!, -1);) {
|
|
201
205
|
if (typeof node === 'string') {
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
204
|
-
nodes[nodes.length - 1] =
|
|
206
|
+
const str = node.trimEnd();
|
|
207
|
+
if (str.length > 0) {
|
|
208
|
+
nodes[nodes.length - 1] = str as N;
|
|
205
209
|
break;
|
|
206
210
|
}
|
|
207
211
|
}
|
package/src/util/quote.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { input } from '../combinator/data/parser';
|
|
2
2
|
import { cite } from '../parser/block/reply/cite';
|
|
3
3
|
|
|
4
4
|
export function quote(anchor: string, range: Range): string {
|
|
5
|
-
|
|
5
|
+
const { context } = input('', {});
|
|
6
|
+
cite(input(`>>${anchor}`, context));
|
|
7
|
+
if (context.position !== context.source.length) throw new Error(`Invalid anchor: ${anchor}`);
|
|
6
8
|
fit(range);
|
|
7
9
|
const node = trim(range.cloneContents());
|
|
8
10
|
if (!node.firstChild) return '';
|