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
|
@@ -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 { Syntax } from '../context';
|
|
5
|
+
import { Syntax, State } 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(Syntax.none, 4, 1, match(
|
|
10
|
+
export const comment: CommentParser = lazy(() => validate('[%', syntax(Syntax.none, 4, 1, State.none, match(
|
|
11
11
|
/^\[(%+)\s/,
|
|
12
12
|
memoize(
|
|
13
13
|
([, fence]) =>
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/deletion', () => {
|
|
6
6
|
describe('deletion', () => {
|
|
7
|
-
const parser = (source: string) => some(deletion)(source, {});
|
|
7
|
+
const parser = (source: string) => some(deletion)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -2,14 +2,14 @@ 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 { Syntax } from '../context';
|
|
5
|
+
import { Syntax, State } 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
10
|
export const deletion: DeletionParser = lazy(() => surround(
|
|
11
11
|
str('~~'),
|
|
12
|
-
syntax(Syntax.none, 1, 1,
|
|
12
|
+
syntax(Syntax.none, 1, 1, State.none,
|
|
13
13
|
some(union([
|
|
14
14
|
some(inline, blankWith('\n', '~~')),
|
|
15
15
|
open('\n', some(inline, '~'), true),
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/emphasis', () => {
|
|
6
6
|
describe('emphasis', () => {
|
|
7
|
-
const parser = (source: string) => some(emphasis)(source, {});
|
|
7
|
+
const parser = (source: string) => some(emphasis)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('*')), undefined);
|
|
@@ -4,14 +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 { Syntax } from '../context';
|
|
7
|
+
import { Syntax, State } 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
12
|
export const emphasis: EmphasisParser = lazy(() => surround(
|
|
13
13
|
str('*'),
|
|
14
|
-
syntax(Syntax.none, 1, 1,
|
|
14
|
+
syntax(Syntax.none, 1, 1, State.none,
|
|
15
15
|
startTight(some(union([
|
|
16
16
|
strong,
|
|
17
17
|
some(inline, blankWith('*')),
|
|
@@ -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 { Syntax } from '../context';
|
|
8
|
+
import { Syntax, State } 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';
|
|
@@ -29,7 +29,7 @@ const subemphasis: IntermediateParser<EmphasisParser> = lazy(() => some(union([
|
|
|
29
29
|
|
|
30
30
|
export const emstrong: EmStrongParser = lazy(() => surround(
|
|
31
31
|
str('***'),
|
|
32
|
-
syntax(Syntax.none, 1, 1,
|
|
32
|
+
syntax(Syntax.none, 1, 1, State.none,
|
|
33
33
|
startTight(some(union([
|
|
34
34
|
some(inline, blankWith('*')),
|
|
35
35
|
open(some(inline, '*'), inline),
|
|
@@ -47,7 +47,7 @@ export const emstrong: EmStrongParser = lazy(() => surround(
|
|
|
47
47
|
rest.slice(0, 1) === '*'
|
|
48
48
|
? [[html('em', unshift([html('strong', defrag(bs))], defrag(ds)))], rest.slice(1)]
|
|
49
49
|
: [unshift(['*', html('strong', defrag(bs))], ds), rest])
|
|
50
|
-
(rest, context) ?? [['*', html('strong', defrag(bs))], rest];
|
|
50
|
+
({ source: rest, context }) ?? [['*', html('strong', defrag(bs))], rest];
|
|
51
51
|
case '*':
|
|
52
52
|
return bind<StrongParser>(
|
|
53
53
|
substrong,
|
|
@@ -55,7 +55,7 @@ export const emstrong: EmStrongParser = lazy(() => surround(
|
|
|
55
55
|
rest.slice(0, 2) === '**'
|
|
56
56
|
? [[html('strong', unshift([html('em', defrag(bs))], defrag(ds)))], rest.slice(2)]
|
|
57
57
|
: [unshift(['**', html('em', defrag(bs))], ds), rest])
|
|
58
|
-
(rest, context) ?? [['**', html('em', defrag(bs))], rest];
|
|
58
|
+
({ source: rest, context }) ?? [['**', html('em', defrag(bs))], rest];
|
|
59
59
|
}
|
|
60
60
|
assert(false);
|
|
61
61
|
},
|
|
@@ -5,7 +5,7 @@ import { str } from '../source';
|
|
|
5
5
|
|
|
6
6
|
const repeat = str(/^(.)\1*/);
|
|
7
7
|
|
|
8
|
-
export const escape: EscapeParser = union([(source, context) => {
|
|
8
|
+
export const escape: EscapeParser = union([({ source, context }) => {
|
|
9
9
|
if (source.length < 3) return;
|
|
10
10
|
switch (source[0]) {
|
|
11
11
|
case '*':
|
|
@@ -14,7 +14,7 @@ export const escape: EscapeParser = union([(source, context) => {
|
|
|
14
14
|
return source[3] === source[0]
|
|
15
15
|
&& source[2] === source[0]
|
|
16
16
|
&& source[1] === source[0]
|
|
17
|
-
? repeat(source, context)
|
|
17
|
+
? repeat({ source, context })
|
|
18
18
|
: undefined;
|
|
19
19
|
case '+':
|
|
20
20
|
case '~':
|
|
@@ -22,7 +22,7 @@ export const escape: EscapeParser = union([(source, context) => {
|
|
|
22
22
|
assert(source[2]);
|
|
23
23
|
return source[2] === source[0]
|
|
24
24
|
&& source[1] === source[0]
|
|
25
|
-
? repeat(source, context)
|
|
25
|
+
? repeat({ source, context })
|
|
26
26
|
: undefined;
|
|
27
27
|
default:
|
|
28
28
|
return;
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/extension/index', () => {
|
|
6
6
|
describe('index', () => {
|
|
7
|
-
const parser = (source: string) => some(index)(source, {});
|
|
7
|
+
const parser = (source: string) => some(index)({ 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 { ExtensionParser } from '../../inline';
|
|
3
|
-
import { union, some, syntax, creation, precedence, constraint,
|
|
3
|
+
import { union, some, syntax, creation, precedence, constraint, 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';
|
|
@@ -13,13 +13,12 @@ import IndexParser = ExtensionParser.IndexParser;
|
|
|
13
13
|
export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surround(
|
|
14
14
|
'[#',
|
|
15
15
|
constraint(State.index, false,
|
|
16
|
-
|
|
17
|
-
syntax(Syntax.index, 2, 1,
|
|
16
|
+
syntax(Syntax.index, 2, 1, State.linkable,
|
|
18
17
|
startTight(
|
|
19
18
|
open(stropt(/^\|?/), trimBlankEnd(some(union([
|
|
20
19
|
signature,
|
|
21
20
|
inline,
|
|
22
|
-
]), ']', [[/^\\?\n/, 9], [']', 2]])), true))))
|
|
21
|
+
]), ']', [[/^\\?\n/, 9], [']', 2]])), true)))),
|
|
23
22
|
']',
|
|
24
23
|
false,
|
|
25
24
|
([, ns], rest) => [[html('a', defrag(ns))], rest])),
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/extension/indexer', () => {
|
|
6
6
|
describe('indexer', () => {
|
|
7
|
-
const parser = (source: string) => some(indexer)(source, {});
|
|
7
|
+
const parser = (source: string) => some(indexer)({ 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/extension/label', () => {
|
|
6
6
|
describe('label', () => {
|
|
7
|
-
const parser = (source: string) => some(label)(source, {});
|
|
7
|
+
const parser = (source: string) => some(label)({ 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/extension/placeholder', () => {
|
|
6
6
|
describe('placeholder', () => {
|
|
7
|
-
const parser = (source: string) => some(placeholder)(source, {});
|
|
7
|
+
const parser = (source: string) => some(placeholder)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('[]')), undefined);
|
|
@@ -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 { Syntax } from '../../context';
|
|
5
|
+
import { Syntax, State } from '../../context';
|
|
6
6
|
import { startTight } from '../../visibility';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
@@ -13,7 +13,7 @@ import { unshift } from 'spica/array';
|
|
|
13
13
|
|
|
14
14
|
export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], surround(
|
|
15
15
|
str(/^\[[:^]/),
|
|
16
|
-
syntax(Syntax.none, 2, 1,
|
|
16
|
+
syntax(Syntax.none, 2, 1, State.none,
|
|
17
17
|
startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]))),
|
|
18
18
|
str(']'), false,
|
|
19
19
|
([as, bs], rest) => [[
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/html', () => {
|
|
6
6
|
describe('html', () => {
|
|
7
|
-
const parser = (source: string) => some(html)(source, {});
|
|
7
|
+
const parser = (source: string) => some(html)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('xss', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('<script>')), [['<span class="invalid"><script></span>'], '']);
|
|
@@ -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 { Syntax } from '../context';
|
|
6
|
+
import { Syntax, State } 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,7 +19,7 @@ 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]|>)/i, syntax(Syntax.none, 5, 1, union([
|
|
22
|
+
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/i, syntax(Syntax.none, 5, 1, State.none, union([
|
|
23
23
|
focus(
|
|
24
24
|
/^<wbr[^\S\n]*>/i,
|
|
25
25
|
() => [[h('wbr')], '']),
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/htmlentity', () => {
|
|
6
6
|
describe('htmlentity', () => {
|
|
7
|
-
const parser = (source: string) => some(htmlentity)(source, {});
|
|
7
|
+
const parser = (source: string) => some(htmlentity)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -6,7 +6,7 @@ import { reduce } from 'spica/memoize';
|
|
|
6
6
|
|
|
7
7
|
export const unsafehtmlentity: UnsafeHTMLEntityParser = creation(validate('&', focus(
|
|
8
8
|
/^&[0-9A-Za-z]+;/,
|
|
9
|
-
|
|
9
|
+
({ source }) => [[parse(source) ?? `\x1B${source}`], ''])));
|
|
10
10
|
|
|
11
11
|
export const htmlentity: HTMLEntityParser = fmap(
|
|
12
12
|
union([unsafehtmlentity]),
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/insertion', () => {
|
|
6
6
|
describe('insertion', () => {
|
|
7
|
-
const parser = (source: string) => some(insertion)(source, {});
|
|
7
|
+
const parser = (source: string) => some(insertion)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -2,14 +2,14 @@ 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 { Syntax } from '../context';
|
|
5
|
+
import { Syntax, State } 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
10
|
export const insertion: InsertionParser = lazy(() => surround(
|
|
11
11
|
str('++'),
|
|
12
|
-
syntax(Syntax.none, 1, 1,
|
|
12
|
+
syntax(Syntax.none, 1, 1, State.none,
|
|
13
13
|
some(union([
|
|
14
14
|
some(inline, blankWith('\n', '++')),
|
|
15
15
|
open('\n', some(inline, '+'), true),
|
|
@@ -5,7 +5,7 @@ import { MarkdownParser } from '../../../markdown';
|
|
|
5
5
|
|
|
6
6
|
describe('Unit: parser/inline/link', () => {
|
|
7
7
|
describe('link', () => {
|
|
8
|
-
const parser = (source: string, context: MarkdownParser.Context = {}) => some(link)(source, context);
|
|
8
|
+
const parser = (source: string, context: MarkdownParser.Context = {}) => some(link)({ source, context });
|
|
9
9
|
|
|
10
10
|
it('xss', () => {
|
|
11
11
|
assert.deepStrictEqual(inspect(parser('[]{javascript:alert}')), [['<a class="invalid">javascript:alert</a>'], '']);
|
|
@@ -25,8 +25,7 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], union([
|
|
|
25
25
|
|
|
26
26
|
const textlink: LinkParser.TextLinkParser = lazy(() =>
|
|
27
27
|
constraint(State.link, false,
|
|
28
|
-
|
|
29
|
-
syntax(Syntax.link, 2, 10,
|
|
28
|
+
syntax(Syntax.link, 2, 10, State.linkable,
|
|
30
29
|
bind(reverse(tails([
|
|
31
30
|
dup(surround(
|
|
32
31
|
'[',
|
|
@@ -36,22 +35,19 @@ const textlink: LinkParser.TextLinkParser = lazy(() =>
|
|
|
36
35
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
37
36
|
])),
|
|
38
37
|
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
|
|
39
|
-
assert(
|
|
40
|
-
assert(params.every(p => typeof p === 'string'));
|
|
38
|
+
assert(!html('div', content).querySelector('a, .media, .annotation, .reference'));
|
|
41
39
|
if (content.length !== 0 && trimNode(content).length === 0) return;
|
|
42
40
|
for (let source = stringify(content); source;) {
|
|
43
|
-
const result = state(State.autolink, false, autolink)(source, context);
|
|
41
|
+
const result = state(State.autolink, false, autolink)({ source, context });
|
|
44
42
|
if (typeof eval(result!)[0] === 'object') return;
|
|
45
43
|
source = exec(result!);
|
|
46
44
|
}
|
|
47
|
-
assert(!html('div', content).querySelector('a, .media, .annotation, .reference'));
|
|
48
45
|
return parse(content, params, rest, context);
|
|
49
|
-
}))))
|
|
46
|
+
}))));
|
|
50
47
|
|
|
51
48
|
const medialink: LinkParser.MediaLinkParser = lazy(() =>
|
|
52
49
|
constraint(State.link | State.media, false,
|
|
53
|
-
|
|
54
|
-
syntax(Syntax.link, 2, 10,
|
|
50
|
+
syntax(Syntax.link, 2, 10, State.linkable ^ State.media,
|
|
55
51
|
bind(reverse(sequence([
|
|
56
52
|
dup(surround(
|
|
57
53
|
'[',
|
|
@@ -59,26 +55,20 @@ const medialink: LinkParser.MediaLinkParser = lazy(() =>
|
|
|
59
55
|
']')),
|
|
60
56
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
61
57
|
])),
|
|
62
|
-
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) =>
|
|
63
|
-
|
|
64
|
-
assert(params.every(p => typeof p === 'string'));
|
|
65
|
-
assert(content.length === 1);
|
|
66
|
-
return parse(content, params, rest, context);
|
|
67
|
-
})))));
|
|
58
|
+
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) =>
|
|
59
|
+
parse(content, params, rest, context)))));
|
|
68
60
|
|
|
69
|
-
export const unsafelink: LinkParser.UnsafeLinkParser = lazy(() =>
|
|
61
|
+
export const unsafelink: LinkParser.UnsafeLinkParser = lazy(() =>
|
|
70
62
|
creation(10, precedence(2,
|
|
71
|
-
reverse(tails([
|
|
63
|
+
bind(reverse(tails([
|
|
72
64
|
dup(surround(
|
|
73
65
|
'[',
|
|
74
66
|
some(union([unescsource]), ']'),
|
|
75
67
|
']')),
|
|
76
68
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
77
|
-
]))
|
|
78
|
-
([params, content = []], rest, context) =>
|
|
79
|
-
|
|
80
|
-
return parse(content, params, rest, context);
|
|
81
|
-
})));
|
|
69
|
+
])),
|
|
70
|
+
([params, content = []], rest, context) =>
|
|
71
|
+
parse(content, params, rest, context)))));
|
|
82
72
|
|
|
83
73
|
export const uri: LinkParser.ParameterParser.UriParser = union([
|
|
84
74
|
open(/^[^\S\n]+/, str(/^\S+/)),
|
|
@@ -97,6 +87,8 @@ function parse(
|
|
|
97
87
|
rest: string,
|
|
98
88
|
context: MarkdownParser.Context,
|
|
99
89
|
): Result<HTMLAnchorElement, MarkdownParser.Context> {
|
|
90
|
+
assert(params.length > 0);
|
|
91
|
+
assert(params.every(p => typeof p === 'string'));
|
|
100
92
|
const INSECURE_URI = params.shift()!;
|
|
101
93
|
assert(INSECURE_URI === INSECURE_URI.trim());
|
|
102
94
|
assert(!INSECURE_URI.match(/\s/));
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/mark', () => {
|
|
6
6
|
describe('mark', () => {
|
|
7
|
-
const parser = (source: string) => some(mark)(source, {});
|
|
7
|
+
const parser = (source: string) => some(mark)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -3,13 +3,13 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
5
|
import { startTight, blankWith } from '../visibility';
|
|
6
|
-
import { Syntax } from '../context';
|
|
6
|
+
import { Syntax, State } from '../context';
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
10
|
export const mark: MarkParser = lazy(() => surround(
|
|
11
11
|
str('=='),
|
|
12
|
-
syntax(Syntax.none, 1, 1,
|
|
12
|
+
syntax(Syntax.none, 1, 1, State.none,
|
|
13
13
|
startTight(some(union([
|
|
14
14
|
some(inline, blankWith('==')),
|
|
15
15
|
open(some(inline, '='), mark),
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/math', () => {
|
|
6
6
|
describe('math', () => {
|
|
7
|
-
const parser = (source: string) => some(math)(source, {});
|
|
7
|
+
const parser = (source: string) => some(math)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -16,7 +16,7 @@ export const math: MathParser = lazy(() => validate('$', creation(rewrite(
|
|
|
16
16
|
]))),
|
|
17
17
|
/^\$(?![0-9A-Za-z])/),
|
|
18
18
|
]),
|
|
19
|
-
(source, { caches: { math: cache } = {} }) => [[
|
|
19
|
+
({ source, context: { caches: { math: cache } = {} } }) => [[
|
|
20
20
|
cache?.get(source)?.cloneNode(true) ||
|
|
21
21
|
html('span',
|
|
22
22
|
!forbiddenCommand.test(source)
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/media', () => {
|
|
6
6
|
describe('media', () => {
|
|
7
|
-
const parser = (source: string) => some(media)(source, {});
|
|
7
|
+
const parser = (source: string) => some(media)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('xss', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('![]{javascript:alert}')), [['<img class="media invalid" data-src="javascript:alert" alt="">'], '']);
|
|
@@ -21,7 +21,7 @@ Object.setPrototypeOf(optspec, null);
|
|
|
21
21
|
export const media: MediaParser = lazy(() => validate(['![', '!{'], open(
|
|
22
22
|
'!',
|
|
23
23
|
constraint(State.media, false,
|
|
24
|
-
syntax(Syntax.media, 2, 10,
|
|
24
|
+
syntax(Syntax.media, 2, 10, State.none,
|
|
25
25
|
bind(verify(fmap(tails([
|
|
26
26
|
dup(surround(
|
|
27
27
|
'[',
|
|
@@ -55,11 +55,11 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], open(
|
|
|
55
55
|
el.style.aspectRatio = el.getAttribute('aspect-ratio')!;
|
|
56
56
|
}
|
|
57
57
|
if (context.state! & State.link) return [[el], rest];
|
|
58
|
-
if (cache && cache.tagName !== 'IMG') return creation(10, (..._) => [[el!], rest])('!', context);
|
|
58
|
+
if (cache && cache.tagName !== 'IMG') return creation(10, (..._) => [[el!], rest])({ source: '!', context });
|
|
59
59
|
return fmap(
|
|
60
60
|
unsafelink as MediaParser,
|
|
61
61
|
([link]) => [define(link, { target: '_blank' }, [el])])
|
|
62
|
-
(`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
|
|
62
|
+
({ source: `{ ${INSECURE_URI}${params.join('')} }${rest}`, context });
|
|
63
63
|
}))))));
|
|
64
64
|
|
|
65
65
|
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union([
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/reference', () => {
|
|
6
6
|
describe('reference', () => {
|
|
7
|
-
const parser = (source: string) => some(reference)(source, {});
|
|
7
|
+
const parser = (source: string) => some(reference)({ 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 { ReferenceParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, context, syntax, creation, constraint,
|
|
3
|
+
import { union, subsequence, some, context, syntax, creation, constraint, surround, open, lazy, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { str, stropt } from '../source';
|
|
6
6
|
import { Syntax, State } from '../context';
|
|
@@ -11,15 +11,14 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
11
11
|
export const reference: ReferenceParser = lazy(() => surround(
|
|
12
12
|
'[[',
|
|
13
13
|
constraint(State.reference, false,
|
|
14
|
-
|
|
15
|
-
syntax(Syntax.reference, 6, 1,
|
|
14
|
+
syntax(Syntax.reference, 6, 1, State.annotation | State.reference | State.media,
|
|
16
15
|
startLoose(
|
|
17
16
|
context({ delimiters: undefined },
|
|
18
17
|
subsequence([
|
|
19
18
|
abbr,
|
|
20
19
|
open(stropt(/^(?=\^)/), some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])),
|
|
21
20
|
some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]]),
|
|
22
|
-
])), ']')))
|
|
21
|
+
])), ']'))),
|
|
23
22
|
']]',
|
|
24
23
|
false,
|
|
25
24
|
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest]));
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/ruby', () => {
|
|
6
6
|
describe('ruby', () => {
|
|
7
|
-
const parser = (source: string) => some(ruby)(source, {});
|
|
7
|
+
const parser = (source: string) => some(ruby)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -4,12 +4,12 @@ import { eval, exec } from '../../combinator/data/parser';
|
|
|
4
4
|
import { sequence, syntax, creation, validate, verify, focus, surround, lazy, fmap } from '../../combinator';
|
|
5
5
|
import { unsafehtmlentity } from './htmlentity';
|
|
6
6
|
import { text as txt } from '../source';
|
|
7
|
-
import { Syntax } from '../context';
|
|
7
|
+
import { Syntax, State } from '../context';
|
|
8
8
|
import { isStartTightNodes } from '../visibility';
|
|
9
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
10
|
import { unshift, push } from 'spica/array';
|
|
11
11
|
|
|
12
|
-
export const ruby: RubyParser = lazy(() => validate('[', syntax(Syntax.none, 2, 1, fmap(verify(
|
|
12
|
+
export const ruby: RubyParser = lazy(() => validate('[', syntax(Syntax.none, 2, 1, State.none, fmap(verify(
|
|
13
13
|
sequence([
|
|
14
14
|
surround('[', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=]\()/, text), ']'),
|
|
15
15
|
surround('(', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=\))/, text), ')'),
|
|
@@ -48,14 +48,14 @@ export const ruby: RubyParser = lazy(() => validate('[', syntax(Syntax.none, 2,
|
|
|
48
48
|
}
|
|
49
49
|
}))));
|
|
50
50
|
|
|
51
|
-
const text: RubyParser.TextParser = creation((source, context) => {
|
|
51
|
+
const text: RubyParser.TextParser = creation(({ source, context }) => {
|
|
52
52
|
const acc = [''];
|
|
53
53
|
while (source !== '') {
|
|
54
54
|
assert(source[0] !== '\n');
|
|
55
55
|
switch (source[0]) {
|
|
56
56
|
// @ts-expect-error
|
|
57
57
|
case '&': {
|
|
58
|
-
const result = unsafehtmlentity(source, context);
|
|
58
|
+
const result = unsafehtmlentity({ source, context });
|
|
59
59
|
if (result) {
|
|
60
60
|
acc[acc.length - 1] += eval(result)[0];
|
|
61
61
|
source = exec(result, source.slice(1));
|
|
@@ -69,7 +69,7 @@ const text: RubyParser.TextParser = creation((source, context) => {
|
|
|
69
69
|
source = source.slice(1);
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
72
|
-
const result = txt(source, context)!;
|
|
72
|
+
const result = txt({ source, context })!;
|
|
73
73
|
assert(result);
|
|
74
74
|
acc[acc.length - 1] += eval(result)[0] ?? source.slice(0, source.length - exec(result).length);
|
|
75
75
|
source = exec(result);
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/shortmedia', () => {
|
|
6
6
|
describe('shortmedia', () => {
|
|
7
|
-
const parser = (source: string) => some(shortmedia)(source, {});
|
|
7
|
+
const parser = (source: string) => some(shortmedia)({ 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/strong', () => {
|
|
6
6
|
describe('strong', () => {
|
|
7
|
-
const parser = (source: string) => some(strong)(source, {});
|
|
7
|
+
const parser = (source: string) => some(strong)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('**')), undefined);
|
|
@@ -3,14 +3,14 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
|
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { emstrong } from './emstrong';
|
|
5
5
|
import { str } from '../source';
|
|
6
|
-
import { Syntax } from '../context';
|
|
6
|
+
import { Syntax, State } from '../context';
|
|
7
7
|
import { startTight, blankWith } from '../visibility';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
9
|
import { unshift } from 'spica/array';
|
|
10
10
|
|
|
11
11
|
export const strong: StrongParser = lazy(() => surround(
|
|
12
12
|
str('**'),
|
|
13
|
-
syntax(Syntax.none, 1, 1,
|
|
13
|
+
syntax(Syntax.none, 1, 1, State.none,
|
|
14
14
|
startTight(some(union([
|
|
15
15
|
some(inline, blankWith('**')),
|
|
16
16
|
open(some(inline, '*'), union([
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline/template', () => {
|
|
6
6
|
describe('template', () => {
|
|
7
|
-
const parser = (source: string) => some(template)(source, {});
|
|
7
|
+
const parser = (source: string) => some(template)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|
|
@@ -2,12 +2,12 @@ import { undefined } from 'spica/global';
|
|
|
2
2
|
import { TemplateParser } from '../inline';
|
|
3
3
|
import { union, some, syntax, creation, precedence, surround, lazy } from '../../combinator';
|
|
4
4
|
import { escsource, str } from '../source';
|
|
5
|
-
import { Syntax } from '../context';
|
|
5
|
+
import { Syntax, State } from '../context';
|
|
6
6
|
import { html } from 'typed-dom/dom';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
|
|
9
9
|
export const template: TemplateParser = lazy(() => surround(
|
|
10
|
-
'{{', syntax(Syntax.none, 2, 1, some(union([bracket, escsource]), '}')), '}}', true,
|
|
10
|
+
'{{', syntax(Syntax.none, 2, 1, State.none, some(union([bracket, escsource]), '}')), '}}', true,
|
|
11
11
|
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest]));
|
|
12
12
|
|
|
13
13
|
const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
|
|
@@ -4,7 +4,7 @@ import { inspect } from '../debug.test';
|
|
|
4
4
|
|
|
5
5
|
describe('Unit: parser/inline', () => {
|
|
6
6
|
describe('inline', () => {
|
|
7
|
-
const parser = (source: string) => some(inline)(source, {});
|
|
7
|
+
const parser = (source: string) => some(inline)({ source, context: {} });
|
|
8
8
|
|
|
9
9
|
it('empty', () => {
|
|
10
10
|
assert.deepStrictEqual(inspect(parser('')), undefined);
|