securemark 0.259.0 → 0.260.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 +13 -0
- package/design.md +16 -5
- package/dist/index.js +625 -318
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.test.ts +5 -5
- package/src/combinator/control/constraint/block.ts +2 -2
- package/src/combinator/control/constraint/contract.ts +4 -4
- package/src/combinator/control/constraint/line.test.ts +6 -6
- package/src/combinator/control/constraint/line.ts +5 -5
- package/src/combinator/control/manipulation/convert.ts +5 -5
- package/src/combinator/control/manipulation/fence.ts +1 -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 +2 -2
- package/src/combinator/control/manipulation/recovery.ts +6 -6
- package/src/combinator/control/manipulation/scope.ts +11 -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 +2 -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 +33 -33
- package/src/combinator/data/parser/inits.ts +2 -2
- package/src/combinator/data/parser/sequence.test.ts +10 -10
- package/src/combinator/data/parser/sequence.ts +2 -2
- package/src/combinator/data/parser/some.test.ts +13 -13
- package/src/combinator/data/parser/some.ts +2 -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.test.ts +19 -19
- package/src/parser/api/parse.ts +3 -3
- package/src/parser/autolink.test.ts +7 -7
- package/src/parser/autolink.ts +2 -2
- package/src/parser/block/blockquote.test.ts +9 -9
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/codeblock.test.ts +5 -5
- package/src/parser/block/codeblock.ts +1 -1
- package/src/parser/block/dlist.test.ts +2 -2
- 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 +2 -2
- 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 +8 -8
- 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 +2 -2
- package/src/parser/block/olist.ts +5 -5
- package/src/parser/block/paragraph.test.ts +15 -15
- package/src/parser/block/reply/cite.test.ts +12 -12
- package/src/parser/block/reply/cite.ts +2 -2
- package/src/parser/block/reply/quote.test.ts +4 -4
- package/src/parser/block/reply/quote.ts +2 -2
- package/src/parser/block/reply.test.ts +9 -9
- package/src/parser/block/sidefence.test.ts +7 -7
- package/src/parser/block/table.test.ts +1 -1
- package/src/parser/block/table.ts +1 -1
- package/src/parser/block/ulist.test.ts +2 -2
- package/src/parser/block/ulist.ts +1 -1
- package/src/parser/block.ts +2 -2
- package/src/parser/context.ts +23 -13
- package/src/parser/header.test.ts +1 -1
- package/src/parser/header.ts +3 -3
- package/src/parser/inline/annotation.test.ts +4 -4
- package/src/parser/inline/annotation.ts +3 -4
- package/src/parser/inline/autolink/account.test.ts +12 -12
- package/src/parser/inline/autolink/account.ts +4 -2
- package/src/parser/inline/autolink/anchor.test.ts +10 -10
- package/src/parser/inline/autolink/anchor.ts +14 -11
- package/src/parser/inline/autolink/channel.test.ts +4 -4
- 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/hashnum.ts +4 -2
- package/src/parser/inline/autolink/hashtag.test.ts +21 -21
- package/src/parser/inline/autolink/hashtag.ts +4 -2
- package/src/parser/inline/autolink/url.test.ts +56 -56
- package/src/parser/inline/autolink/url.ts +5 -3
- 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 -3
- package/src/parser/inline/html.ts +3 -3
- 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 +111 -111
- package/src/parser/inline/link.ts +12 -12
- 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 +2 -1
- package/src/parser/inline/media.ts +4 -4
- package/src/parser/inline/reference.test.ts +4 -4
- 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 +52 -52
- 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/renderer/render/media/pdf.ts +1 -0
- package/src/util/info.ts +2 -4
- package/src/util/quote.ts +1 -1
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { AutolinkParser } from '../../inline';
|
|
2
|
-
import { union, some, creation, precedence, validate, focus, rewrite, convert, surround, open, lazy } from '../../../combinator';
|
|
2
|
+
import { union, some, creation, precedence, validate, focus, rewrite, convert, surround, open, lazy, fmap } from '../../../combinator';
|
|
3
3
|
import { unsafelink } from '../link';
|
|
4
4
|
import { unescsource } from '../../source';
|
|
5
|
+
import { define } from 'typed-dom/dom';
|
|
5
6
|
|
|
6
7
|
const closer = /^[-+*=~^,.;:!?]*(?=[\\"`|\[\](){}<>]|$)/;
|
|
7
8
|
|
|
8
|
-
export const url: AutolinkParser.UrlParser = lazy(() => validate(['http://', 'https://'], rewrite(
|
|
9
|
+
export const url: AutolinkParser.UrlParser = lazy(() => validate(['http://', 'https://'], fmap(rewrite(
|
|
9
10
|
open(
|
|
10
11
|
/^https?:\/\/(?=[\x21-\x7E])/,
|
|
11
12
|
focus(/^[\x21-\x7E]+/, some(union([bracket, some(unescsource, closer)])))),
|
|
12
13
|
convert(
|
|
13
14
|
url => `{ ${url} }`,
|
|
14
|
-
union([unsafelink])))
|
|
15
|
+
union([unsafelink]))),
|
|
16
|
+
([el]) => [define(el, { class: 'url' })])));
|
|
15
17
|
|
|
16
18
|
const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() => creation(precedence(2, union([
|
|
17
19
|
surround('(', some(union([bracket, unescsource]), ')'), ')', true),
|
|
@@ -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);
|
|
@@ -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,18 +4,16 @@ 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>'], '']);
|
|
11
11
|
assert.deepStrictEqual(inspect(parser('<script>alert()<script>')), [['<span class="invalid"><script>alert<span class="paren">()</span><span class="invalid"><script></span></span>'], '']);
|
|
12
12
|
assert.deepStrictEqual(inspect(parser('<script>alert()</script>')), [['<span class="invalid"><script>alert<span class="paren">()</span></script></span>'], '']);
|
|
13
|
-
assert.deepStrictEqual(inspect(parser('<script src="\\""></script>')), [['<span class="invalid"><script src="\\""></script></span>'], '']);
|
|
14
13
|
assert.deepStrictEqual(inspect(parser('<bdi onclick="alert()">')), [['<span class="invalid"><bdi onclick="alert()"></span>'], '']);
|
|
15
14
|
assert.deepStrictEqual(inspect(parser('<bdi onclick="alert()"></bdi>')), [['<span class="invalid"><bdi onclick="alert()"></bdi></span>'], '']);
|
|
16
15
|
assert.deepStrictEqual(inspect(parser('<bdi onclick="alert()">a</bdi>')), [['<span class="invalid"><bdi onclick="alert()">a</bdi></span>'], '']);
|
|
17
16
|
assert.deepStrictEqual(inspect(parser('<bdi><bdi onclick="alert()">a</bdi></bdi>')), [['<bdi><span class="invalid"><bdi onclick="alert()">a</bdi></span></bdi>'], '']);
|
|
18
|
-
assert.deepStrictEqual(inspect(parser('<bdo dir="rtl\\"><">a</bdo>')), [['<span class="invalid"><bdo dir="rtl\\"><">a</bdo></span>'], '']);
|
|
19
17
|
});
|
|
20
18
|
|
|
21
19
|
it('invalid', () => {
|
|
@@ -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')], '']),
|
|
@@ -64,7 +64,7 @@ export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^
|
|
|
64
64
|
])))));
|
|
65
65
|
|
|
66
66
|
export const attribute: HTMLParser.AttributeParser = union([
|
|
67
|
-
str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="
|
|
67
|
+
str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="[^"\n]*")?(?=[^\S\n]|>)/i),
|
|
68
68
|
]);
|
|
69
69
|
|
|
70
70
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element
|
|
@@ -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),
|