securemark 0.263.0 → 0.264.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 +10 -0
- package/dist/index.js +1483 -3326
- package/index.ts +0 -1
- package/markdown.d.ts +1 -1
- package/package.json +19 -19
- package/src/combinator/control/constraint/block.ts +1 -2
- package/src/combinator/control/constraint/contract.ts +3 -3
- package/src/combinator/control/constraint/line.ts +1 -2
- package/src/combinator/control/manipulation/indent.ts +0 -1
- package/src/combinator/control/manipulation/match.ts +1 -2
- package/src/combinator/control/manipulation/scope.ts +3 -4
- package/src/combinator/control/manipulation/surround.ts +1 -2
- package/src/combinator/control/monad/bind.ts +2 -3
- package/src/combinator/data/parser/context.ts +3 -3
- package/src/combinator/data/parser/inits.ts +1 -2
- package/src/combinator/data/parser/sequence.ts +1 -2
- package/src/combinator/data/parser/some.ts +1 -2
- package/src/combinator/data/parser/union.ts +4 -12
- package/src/parser/api/bind.test.ts +1 -1
- package/src/parser/api/bind.ts +0 -1
- package/src/parser/api/parse.test.ts +3 -3
- package/src/parser/api/parse.ts +0 -1
- package/src/parser/block/blockquote.test.ts +3 -3
- package/src/parser/block/codeblock.ts +0 -1
- package/src/parser/block/dlist.ts +2 -3
- package/src/parser/block/extension/example.test.ts +1 -1
- package/src/parser/block/extension/fig.ts +2 -1
- package/src/parser/block/extension/figure.ts +2 -4
- package/src/parser/block/extension/table.ts +2 -4
- package/src/parser/block/heading.test.ts +1 -1
- package/src/parser/block/mathblock.ts +0 -1
- package/src/parser/block/olist.ts +0 -1
- package/src/parser/block/paragraph.test.ts +1 -1
- package/src/parser/block/paragraph.ts +2 -3
- package/src/parser/block/reply.ts +2 -3
- package/src/parser/block.ts +0 -1
- package/src/parser/context.ts +15 -19
- package/src/parser/inline/annotation.ts +1 -2
- package/src/parser/inline/bracket.test.ts +1 -1
- package/src/parser/inline/bracket.ts +1 -2
- package/src/parser/inline/deletion.test.ts +2 -2
- package/src/parser/inline/emphasis.test.ts +2 -2
- package/src/parser/inline/emphasis.ts +2 -2
- package/src/parser/inline/extension/index.test.ts +28 -32
- package/src/parser/inline/extension/index.ts +1 -2
- package/src/parser/inline/extension/indexee.ts +22 -13
- package/src/parser/inline/extension/label.ts +0 -1
- package/src/parser/inline/extension/placeholder.test.ts +10 -12
- package/src/parser/inline/extension/placeholder.ts +7 -7
- package/src/parser/inline/html.test.ts +1 -1
- package/src/parser/inline/html.ts +2 -3
- package/src/parser/inline/htmlentity.ts +0 -1
- package/src/parser/inline/insertion.test.ts +2 -2
- package/src/parser/inline/link.test.ts +6 -5
- package/src/parser/inline/link.ts +43 -43
- package/src/parser/inline/mark.test.ts +11 -11
- package/src/parser/inline/mark.ts +12 -6
- package/src/parser/inline/media.ts +0 -1
- package/src/parser/inline/reference.ts +0 -1
- package/src/parser/inline/ruby.ts +0 -1
- package/src/parser/inline/strong.test.ts +2 -2
- package/src/parser/inline/strong.ts +2 -2
- package/src/parser/inline/template.ts +0 -1
- package/src/parser/inline.test.ts +8 -7
- package/src/parser/processor/figure.ts +0 -1
- package/src/parser/processor/footnote.ts +0 -1
- package/src/parser/segment.ts +0 -1
- package/src/parser/source/escapable.test.ts +1 -1
- package/src/parser/source/escapable.ts +7 -1
- package/src/parser/source/line.ts +0 -1
- package/src/parser/source/str.ts +0 -1
- package/src/parser/source/text.test.ts +24 -35
- package/src/parser/source/text.ts +2 -16
- package/src/parser/visibility.ts +1 -7
- package/src/renderer/render/math.ts +0 -1
- package/src/renderer/render/media/image.ts +0 -1
- package/src/renderer/render/media/twitter.ts +0 -1
- package/src/renderer/render/media/video.ts +0 -1
- package/src/renderer/render/media/youtube.ts +0 -1
- package/src/renderer/render.ts +0 -1
- package/src/util/quote.ts +0 -1
- package/src/util/scope.ts +0 -2
- package/src/util/toc.ts +0 -1
- package/webpack.config.js +1 -1
- package/src/parser/locale/ja.test.ts +0 -14
- package/src/parser/locale/ja.ts +0 -3
- package/src/parser/locale.test.ts +0 -26
- package/src/parser/locale.ts +0 -61
package/index.ts
CHANGED
package/markdown.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "securemark",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.264.0",
|
|
4
4
|
"description": "Secure markdown renderer working on browsers for user input data.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/falsandtru/securemark",
|
|
@@ -28,35 +28,35 @@
|
|
|
28
28
|
"LICENSE"
|
|
29
29
|
],
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/dompurify": "2.
|
|
32
|
-
"@types/jquery": "3.5.
|
|
31
|
+
"@types/dompurify": "2.4.0",
|
|
32
|
+
"@types/jquery": "3.5.16",
|
|
33
33
|
"@types/mathjax": "0.0.37",
|
|
34
|
-
"@types/mocha": "
|
|
34
|
+
"@types/mocha": "10.0.1",
|
|
35
35
|
"@types/power-assert": "1.5.8",
|
|
36
36
|
"@types/prismjs": "1.26.0",
|
|
37
|
-
"@typescript-eslint/parser": "^5.
|
|
38
|
-
"babel-loader": "^
|
|
37
|
+
"@typescript-eslint/parser": "^5.49.0",
|
|
38
|
+
"babel-loader": "^9.1.2",
|
|
39
39
|
"babel-plugin-unassert": "^3.2.0",
|
|
40
|
-
"concurrently": "^7.
|
|
41
|
-
"eslint": "^8.
|
|
42
|
-
"eslint-plugin-redos": "^4.4.
|
|
40
|
+
"concurrently": "^7.6.0",
|
|
41
|
+
"eslint": "^8.32.0",
|
|
42
|
+
"eslint-plugin-redos": "^4.4.3",
|
|
43
43
|
"eslint-webpack-plugin": "^3.2.0",
|
|
44
|
-
"glob": "^8.0
|
|
44
|
+
"glob": "^8.1.0",
|
|
45
45
|
"karma": "^6.4.1",
|
|
46
46
|
"karma-chrome-launcher": "^3.1.1",
|
|
47
47
|
"karma-coverage": "^2.2.0",
|
|
48
48
|
"karma-firefox-launcher": "^2.1.2",
|
|
49
49
|
"karma-mocha": "^2.0.1",
|
|
50
50
|
"karma-power-assert": "^1.0.0",
|
|
51
|
-
"mocha": "^10.
|
|
52
|
-
"npm-check-updates": "^16.3
|
|
53
|
-
"semver": "^7.3.
|
|
54
|
-
"spica": "0.0.
|
|
55
|
-
"ts-loader": "^9.4.
|
|
56
|
-
"typed-dom": "^0.0.
|
|
57
|
-
"typescript": "4.
|
|
58
|
-
"webpack": "^5.
|
|
59
|
-
"webpack-cli": "^
|
|
51
|
+
"mocha": "^10.2.0",
|
|
52
|
+
"npm-check-updates": "^16.6.3",
|
|
53
|
+
"semver": "^7.3.8",
|
|
54
|
+
"spica": "0.0.719",
|
|
55
|
+
"ts-loader": "^9.4.2",
|
|
56
|
+
"typed-dom": "^0.0.315",
|
|
57
|
+
"typescript": "4.9.4",
|
|
58
|
+
"webpack": "^5.75.0",
|
|
59
|
+
"webpack-cli": "^5.0.1",
|
|
60
60
|
"webpack-merge": "^5.8.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, exec } from '../../data/parser';
|
|
3
2
|
import { Memo } from '../../data/parser/context/memo';
|
|
4
3
|
import { firstline, isEmpty } from './line';
|
|
@@ -10,7 +9,7 @@ export function block<T>(parser: Parser<T>, separation = true): Parser<T> {
|
|
|
10
9
|
if (source === '') return;
|
|
11
10
|
context.memo ??= new Memo();
|
|
12
11
|
const result = parser({ source, context });
|
|
13
|
-
if (
|
|
12
|
+
if (result === undefined) return;
|
|
14
13
|
const rest = exec(result);
|
|
15
14
|
if (separation && !isEmpty(firstline(rest))) return;
|
|
16
15
|
assert(rest === '' || source[source.length - rest.length - 1] === '\n');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'spica/global';
|
|
2
2
|
import { isArray } from 'spica/alias';
|
|
3
3
|
import { Parser, Ctx, Tree, Context, eval, exec, check } from '../../data/parser';
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ export function validate<T>(patterns: string | RegExp | (string | RegExp)[], has
|
|
|
27
27
|
if (!match(source)) return;
|
|
28
28
|
const result = parser!({ source, context });
|
|
29
29
|
assert(check(source, result));
|
|
30
|
-
if (
|
|
30
|
+
if (result === undefined) return;
|
|
31
31
|
assert(exec(result).length < source.length);
|
|
32
32
|
return exec(result).length < source.length
|
|
33
33
|
? result
|
|
@@ -42,7 +42,7 @@ export function verify<T>(parser: Parser<T>, cond: (results: readonly T[], rest:
|
|
|
42
42
|
if (source === '') return;
|
|
43
43
|
const result = parser({ source, context });
|
|
44
44
|
assert(check(source, result));
|
|
45
|
-
if (
|
|
45
|
+
if (result === undefined) return;
|
|
46
46
|
if (!cond(eval(result), exec(result), context)) return;
|
|
47
47
|
assert(exec(result).length < source.length);
|
|
48
48
|
return exec(result).length < source.length
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, eval, exec, check } from '../../data/parser';
|
|
3
2
|
import { Memo } from '../../data/parser/context/memo';
|
|
4
3
|
|
|
@@ -14,7 +13,7 @@ export function line<T>(parser: Parser<T>): Parser<T> {
|
|
|
14
13
|
const result = parser({ source: line, context });
|
|
15
14
|
assert(check(line, result));
|
|
16
15
|
context.offset -= source.length - line.length;
|
|
17
|
-
if (
|
|
16
|
+
if (result === undefined) return;
|
|
18
17
|
return isEmpty(exec(result))
|
|
19
18
|
? [eval(result), source.slice(line.length)]
|
|
20
19
|
: undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, exec, check } from '../../data/parser';
|
|
3
2
|
|
|
4
3
|
export function match<P extends Parser<unknown>>(pattern: RegExp, f: (matched: RegExpMatchArray) => P): P;
|
|
@@ -11,7 +10,7 @@ export function match<T>(pattern: RegExp, f: (matched: RegExpMatchArray) => Pars
|
|
|
11
10
|
assert(source.startsWith(param[0]));
|
|
12
11
|
const result = f(param)({ source, context });
|
|
13
12
|
assert(check(source, result, false));
|
|
14
|
-
if (
|
|
13
|
+
if (result === undefined) return;
|
|
15
14
|
return exec(result).length < source.length && exec(result).length <= source.length
|
|
16
15
|
? result
|
|
17
16
|
: undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, Context, eval, exec, check } from '../../data/parser';
|
|
3
2
|
|
|
4
3
|
export function focus<P extends Parser<unknown>>(scope: string | RegExp, parser: P): P;
|
|
@@ -18,7 +17,7 @@ export function focus<T>(scope: string | RegExp, parser: Parser<T>): Parser<T> {
|
|
|
18
17
|
const result = parser({ source: src, context });
|
|
19
18
|
assert(check(src, result));
|
|
20
19
|
context.offset -= source.length - src.length;
|
|
21
|
-
if (
|
|
20
|
+
if (result === undefined) return;
|
|
22
21
|
assert(exec(result).length < src.length);
|
|
23
22
|
return exec(result).length < src.length
|
|
24
23
|
? [eval(result), exec(result) + source.slice(src.length)]
|
|
@@ -38,7 +37,7 @@ export function rewrite<T>(scope: Parser<unknown>, parser: Parser<T>): Parser<T>
|
|
|
38
37
|
const res1 = scope({ source, context });
|
|
39
38
|
assert(check(source, res1));
|
|
40
39
|
context.memo = memo;
|
|
41
|
-
if (
|
|
40
|
+
if (res1 === undefined || exec(res1).length >= source.length) return;
|
|
42
41
|
const src = source.slice(0, source.length - exec(res1).length);
|
|
43
42
|
assert(src !== '');
|
|
44
43
|
assert(source.startsWith(src));
|
|
@@ -47,7 +46,7 @@ export function rewrite<T>(scope: Parser<unknown>, parser: Parser<T>): Parser<T>
|
|
|
47
46
|
const res2 = parser({ source: src, context });
|
|
48
47
|
assert(check(src, res2));
|
|
49
48
|
context.offset -= source.length - src.length;
|
|
50
|
-
if (
|
|
49
|
+
if (res2 === undefined) return;
|
|
51
50
|
assert(exec(res2) === '');
|
|
52
51
|
return exec(res2).length < src.length
|
|
53
52
|
? [eval(res2), exec(res2) + exec(res1)]
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, Input, Result, Ctx, Tree, Context, SubParsers, SubTree, IntermediateParser, eval, exec, check } from '../../data/parser';
|
|
3
2
|
import { fmap } from '../monad/fmap';
|
|
4
3
|
import { unshift, push } from 'spica/array';
|
|
@@ -43,7 +42,7 @@ export function surround<T>(
|
|
|
43
42
|
if (lmr_ === '') return;
|
|
44
43
|
const res1 = opener({ source: lmr_, context });
|
|
45
44
|
assert(check(lmr_, res1, false));
|
|
46
|
-
if (
|
|
45
|
+
if (res1 === undefined) return;
|
|
47
46
|
const rl = eval(res1);
|
|
48
47
|
const mr_ = exec(res1);
|
|
49
48
|
const res2 = mr_ !== '' ? parser({ source: mr_, context }) : undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, Result, Ctx, Tree, Context, SubParsers, SubTree, IntermediateParser, eval, exec, check } from '../../data/parser';
|
|
3
2
|
|
|
4
3
|
export function bind<P extends Parser<unknown>>(parser: IntermediateParser<P>, f: (nodes: SubTree<P>[], rest: string, context: Context<P>) => Result<Tree<P>, Context<P>, SubParsers<P>>): P;
|
|
@@ -11,11 +10,11 @@ export function bind<T, U>(parser: Parser<T>, f: (nodes: T[], rest: string, cont
|
|
|
11
10
|
if (source === '') return;
|
|
12
11
|
const res1 = parser({ source, context });
|
|
13
12
|
assert(check(source, res1));
|
|
14
|
-
if (
|
|
13
|
+
if (res1 === undefined) return;
|
|
15
14
|
const res2 = f(eval(res1), exec(res1), context);
|
|
16
15
|
assert(check(source, res2));
|
|
17
16
|
assert(check(exec(res1), res2, false));
|
|
18
|
-
if (
|
|
17
|
+
if (res2 === undefined) return;
|
|
19
18
|
return exec(res2).length <= exec(res1).length
|
|
20
19
|
? res2
|
|
21
20
|
: undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { undefined, Array, Object } from 'spica/global';
|
|
2
1
|
import { hasOwnProperty, ObjectCreate } from 'spica/alias';
|
|
3
|
-
import { Parser, Result, Ctx, Context, eval, exec
|
|
2
|
+
import { Parser, Result, Ctx, Tree, Context, eval, exec } from '../../data/parser';
|
|
4
3
|
import { Memo } from './context/memo';
|
|
5
4
|
|
|
6
5
|
export function reset<P extends Parser<unknown>>(base: Context<P>, parser: P): P;
|
|
@@ -39,10 +38,11 @@ function apply<T>(parser: Parser<T>, source: string, context: Ctx, changes: [str
|
|
|
39
38
|
if (prop in context && !hasOwnProperty(context, prop)) break;
|
|
40
39
|
context[prop as string] = ObjectCreate(change[1]);
|
|
41
40
|
break;
|
|
41
|
+
// @ts-expect-error
|
|
42
42
|
case 'memo':
|
|
43
43
|
if (!reset) break;
|
|
44
44
|
context.memo = new Memo({ targets: context.memo?.targets });
|
|
45
|
-
|
|
45
|
+
// fallthrough
|
|
46
46
|
default:
|
|
47
47
|
values[i] = context[prop];
|
|
48
48
|
context[prop] = change[1];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, Ctx, Tree, Context, SubParsers, SubTree, eval, exec, check } from '../parser';
|
|
3
2
|
import { push } from 'spica/array';
|
|
4
3
|
|
|
@@ -14,7 +13,7 @@ export function inits<T, D extends Parser<T>[]>(parsers: D, resume?: (nodes: T[]
|
|
|
14
13
|
if (context.delimiters?.match(rest, context.precedence)) break;
|
|
15
14
|
const result = parsers[i]({ source: rest, context });
|
|
16
15
|
assert(check(rest, result));
|
|
17
|
-
if (
|
|
16
|
+
if (result === undefined) break;
|
|
18
17
|
nodes = nodes
|
|
19
18
|
? push(nodes, eval(result))
|
|
20
19
|
: eval(result);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, Ctx, Tree, Context, SubParsers, SubTree, eval, exec, check } from '../parser';
|
|
3
2
|
import { push } from 'spica/array';
|
|
4
3
|
|
|
@@ -14,7 +13,7 @@ export function sequence<T, D extends Parser<T>[]>(parsers: D, resume?: (nodes:
|
|
|
14
13
|
if (context.delimiters?.match(rest, context.precedence)) return;
|
|
15
14
|
const result = parsers[i]({ source: rest, context });
|
|
16
15
|
assert(check(rest, result));
|
|
17
|
-
if (
|
|
16
|
+
if (result === undefined) return;
|
|
18
17
|
nodes = nodes
|
|
19
18
|
? push(nodes, eval(result))
|
|
20
19
|
: eval(result);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, eval, exec, check } from '../parser';
|
|
3
2
|
import { Delimiters } from './context/delimiter';
|
|
4
3
|
import { unshift, push } from 'spica/array';
|
|
@@ -30,7 +29,7 @@ export function some<T>(parser: Parser<T>, end?: string | RegExp | number, delim
|
|
|
30
29
|
if (context.delimiters?.match(rest, context.precedence)) break;
|
|
31
30
|
const result = parser({ source: rest, context });
|
|
32
31
|
assert.doesNotThrow(() => limit < 0 && check(rest, result));
|
|
33
|
-
if (
|
|
32
|
+
if (result === undefined) break;
|
|
34
33
|
nodes = nodes
|
|
35
34
|
? nodes.length < eval(result).length
|
|
36
35
|
? unshift(nodes, eval(result))
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { Parser, Ctx, Tree, Context, SubParsers, SubTree } from '../parser';
|
|
3
2
|
|
|
4
3
|
export function union<P extends Parser<unknown>>(parsers: SubParsers<P>): SubTree<P> extends Tree<P> ? P : Parser<SubTree<P>, Context<P>, SubParsers<P>>;
|
|
@@ -9,17 +8,10 @@ export function union<T, D extends Parser<T>[]>(parsers: D): Parser<T, Ctx, D> {
|
|
|
9
8
|
return () => undefined;
|
|
10
9
|
case 1:
|
|
11
10
|
return parsers[0];
|
|
12
|
-
case 2:
|
|
13
|
-
return input => parsers[0](input) ?? parsers[1](input);
|
|
14
|
-
case 3:
|
|
15
|
-
return input => parsers[0](input) ?? parsers[1](input) ?? parsers[2](input);
|
|
16
11
|
default:
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (result) return result;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
12
|
+
return eval([
|
|
13
|
+
'input =>',
|
|
14
|
+
parsers.map((_, i) => `|| parsers[${i}](input)`).join('').slice(2),
|
|
15
|
+
].join(''));
|
|
24
16
|
}
|
|
25
17
|
}
|
|
@@ -126,7 +126,7 @@ describe('Unit: parser/api/bind', () => {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
it('normalize', () => {
|
|
129
|
-
assert.deepStrictEqual(inspect(bind(html('div'), cfgs).parse('a\\\r\nb')), ['<p>a<
|
|
129
|
+
assert.deepStrictEqual(inspect(bind(html('div'), cfgs).parse('a\\\r\nb')), ['<p>a<br>b</p>']);
|
|
130
130
|
});
|
|
131
131
|
|
|
132
132
|
it('reentrant', () => {
|
package/src/parser/api/bind.ts
CHANGED
|
@@ -71,7 +71,7 @@ describe('Unit: parser/api/parse', () => {
|
|
|
71
71
|
['<p>a <br>b</p>']);
|
|
72
72
|
assert.deepStrictEqual(
|
|
73
73
|
[...parse('a\\\nb').children].map(el => el.outerHTML),
|
|
74
|
-
['<p>a<
|
|
74
|
+
['<p>a<br>b</p>']);
|
|
75
75
|
assert.deepStrictEqual(
|
|
76
76
|
[...parse('a\n\\ \nb').children].map(el => el.outerHTML),
|
|
77
77
|
['<p>a<br>\\<br>b</p>']);
|
|
@@ -209,7 +209,7 @@ describe('Unit: parser/api/parse', () => {
|
|
|
209
209
|
[...parse('$-a\n$$\n$$\n\n(($-a[[b]][[c_d_]]))', { footnotes }).children].map(el => el.outerHTML),
|
|
210
210
|
[
|
|
211
211
|
'<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span><span class="figtext"></span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
|
|
212
|
-
'<p><sup class="annotation" id="annotation:ref:1" title="(1)
|
|
212
|
+
'<p><sup class="annotation" id="annotation:ref:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" id="reference:ref:1" title="b"><span hidden="">b</span><a href="#reference:def:1">[1]</a></sup><sup class="reference" id="reference:ref:2" title="cd"><span hidden="">c<em>d</em></span><a href="#reference:def:2">[2]</a></sup></span><a href="#annotation:def:1">*1</a></sup></p>',
|
|
213
213
|
'<ol class="annotations"><li id="annotation:def:1" data-marker="*1"><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" id="reference:ref:1" title="b"><span hidden="">b</span><a href="#reference:def:1">[1]</a></sup><sup class="reference" id="reference:ref:2" title="cd"><span hidden="">c<em>d</em></span><a href="#reference:def:2">[2]</a></sup><sup><a href="#annotation:ref:1">^1</a></sup></li></ol>',
|
|
214
214
|
]);
|
|
215
215
|
assert.deepStrictEqual(
|
|
@@ -220,7 +220,7 @@ describe('Unit: parser/api/parse', () => {
|
|
|
220
220
|
it('normalize', () => {
|
|
221
221
|
assert.deepStrictEqual(
|
|
222
222
|
[...parse('a\\\r\nb').children].map(el => el.outerHTML),
|
|
223
|
-
['<p>a<
|
|
223
|
+
['<p>a<br>b</p>']);
|
|
224
224
|
});
|
|
225
225
|
|
|
226
226
|
it('backtrack', () => {
|
package/src/parser/api/parse.ts
CHANGED
|
@@ -69,9 +69,9 @@ describe('Unit: parser/block/blockquote', () => {
|
|
|
69
69
|
assert.deepStrictEqual(inspect(parser('!> \\\n')), [['<blockquote><section><p>\\</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
70
70
|
assert.deepStrictEqual(inspect(parser('!> a')), [['<blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
71
71
|
assert.deepStrictEqual(inspect(parser('!> a\n')), [['<blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
72
|
-
assert.deepStrictEqual(inspect(parser('!> a\\\nb')), [['<blockquote><section><p>a<
|
|
73
|
-
assert.deepStrictEqual(inspect(parser('!>
|
|
74
|
-
assert.deepStrictEqual(inspect(parser('!>
|
|
72
|
+
assert.deepStrictEqual(inspect(parser('!> a\\\nb')), [['<blockquote><section><p>a<br>b</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
73
|
+
assert.deepStrictEqual(inspect(parser('!> ++a\nb++')), [['<blockquote><section><p><ins>a<br>b</ins></p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
74
|
+
assert.deepStrictEqual(inspect(parser('!> ++a\n> b++')), [['<blockquote><section><p><ins>a<br>b</ins></p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
75
75
|
assert.deepStrictEqual(inspect(parser('!> a \n b c ')), [['<blockquote><section><p> a<br> b c</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
76
76
|
assert.deepStrictEqual(inspect(parser('!>> a')), [['<blockquote><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote></blockquote>'], '']);
|
|
77
77
|
assert.deepStrictEqual(inspect(parser('!>> a\n> b')), [['<blockquote><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote><section><p>b</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
@@ -3,19 +3,18 @@ import { union, inits, some, creation, state, block, line, validate, rewrite, op
|
|
|
3
3
|
import { inline, indexee, indexer } from '../inline';
|
|
4
4
|
import { anyline } from '../source';
|
|
5
5
|
import { State } from '../context';
|
|
6
|
-
import { localize } from '../locale';
|
|
7
6
|
import { visualize, trimBlank } from '../visibility';
|
|
8
7
|
import { push } from 'spica/array';
|
|
9
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
10
9
|
|
|
11
|
-
export const dlist: DListParser = lazy(() => block(
|
|
10
|
+
export const dlist: DListParser = lazy(() => block(fmap(validate(
|
|
12
11
|
/^~[^\S\n]+(?=\S)/,
|
|
13
12
|
some(inits([
|
|
14
13
|
state(State.annotation | State.reference | State.index | State.label | State.link | State.media,
|
|
15
14
|
some(term)),
|
|
16
15
|
some(desc),
|
|
17
16
|
]))),
|
|
18
|
-
es => [html('dl', fillTrailingDescription(es))])))
|
|
17
|
+
es => [html('dl', fillTrailingDescription(es))])));
|
|
19
18
|
|
|
20
19
|
const term: DListParser.TermParser = creation(1, false, line(indexee(fmap(open(
|
|
21
20
|
/^~[^\S\n]+(?=\S)/,
|
|
@@ -18,7 +18,7 @@ describe('Unit: parser/block/extension/example', () => {
|
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no"></pre><hr><section><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no"></pre><hr><section><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\na\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">a</pre><hr><section><p>a</p><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
21
|
-
assert.deepStrictEqual(inspect(parser('~~~example/markdown\
|
|
21
|
+
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n++a\nb++\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">++a\nb++</pre><hr><section><p><ins>a<br>b</ins></p><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
22
22
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n$fig-a\n!https://host\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">$fig-a\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
23
23
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n[$fig-a]\n!https://host\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">[$fig-a]\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
24
24
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n## a\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">## a</pre><hr><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
@@ -27,7 +27,8 @@ export const segment: FigParser.SegmentParser = block(validate(['[$', '$'],
|
|
|
27
27
|
|
|
28
28
|
export const fig: FigParser = block(rewrite(segment, verify(convert(
|
|
29
29
|
(source, context) => {
|
|
30
|
-
|
|
30
|
+
// Bug: TypeScript
|
|
31
|
+
const fence = (/^[^\n]*\n!?>+\s/.test(source) && source.match(/^~{3,}(?=[^\S\n]*$)/mg) as string[] || [])
|
|
31
32
|
.reduce((max, fence) => fence > max ? fence : max, '~~') + '~';
|
|
32
33
|
return parser({ source, context })
|
|
33
34
|
? `${fence}figure ${source.replace(/^(.+\n.+\n)([\S\s]+?)\n?$/, '$1\n$2')}\n${fence}`
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { ExtensionParser } from '../../block';
|
|
3
2
|
import { union, inits, sequence, some, state, block, line, fence, rewrite, close, match, convert, trimEnd, fallback, fmap } from '../../../combinator';
|
|
4
3
|
import { str, contentline, emptyline } from '../../source';
|
|
@@ -14,7 +13,6 @@ import { blockquote, segment as seg_blockquote } from '../blockquote';
|
|
|
14
13
|
import { placeholder, segment_ as seg_placeholder } from './placeholder';
|
|
15
14
|
import { inline, media, shortmedia } from '../../inline';
|
|
16
15
|
import { State } from '../../context';
|
|
17
|
-
import { localize } from '../../locale';
|
|
18
16
|
import { visualize, trimBlank } from '../../visibility';
|
|
19
17
|
import { memoize } from 'spica/memoize';
|
|
20
18
|
import { html, defrag } from 'typed-dom/dom';
|
|
@@ -66,9 +64,9 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
66
64
|
line(shortmedia),
|
|
67
65
|
])),
|
|
68
66
|
emptyline,
|
|
69
|
-
block(
|
|
67
|
+
block(
|
|
70
68
|
state(State.media,
|
|
71
|
-
visualize(trimBlank(trimEnd(some(inline))))))
|
|
69
|
+
visualize(trimBlank(trimEnd(some(inline)))))),
|
|
72
70
|
]),
|
|
73
71
|
])),
|
|
74
72
|
([label, param, content, ...caption]: [HTMLAnchorElement, string, ...HTMLElement[]]) => [
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { undefined, BigInt, Array } from 'spica/global';
|
|
2
1
|
import { max, min, isArray } from 'spica/alias';
|
|
3
2
|
import { ExtensionParser } from '../../block';
|
|
4
3
|
import { Tree, eval } from '../../../combinator/data/parser';
|
|
5
4
|
import { union, subsequence, inits, some, creation, block, line, validate, fence, rewrite, open, clear, convert, trim, dup, lazy, fmap } from '../../../combinator';
|
|
6
5
|
import { inline } from '../../inline';
|
|
7
6
|
import { str, anyline, emptyline, contentline } from '../../source';
|
|
8
|
-
import { localize } from '../../locale';
|
|
9
7
|
import { visualize } from '../../visibility';
|
|
10
8
|
import { unshift, splice } from 'spica/array';
|
|
11
9
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
@@ -53,9 +51,9 @@ export const table: TableParser = block(validate('~~~', fmap(
|
|
|
53
51
|
}
|
|
54
52
|
})));
|
|
55
53
|
|
|
56
|
-
const parser: TableParser = lazy(() => block(
|
|
54
|
+
const parser: TableParser = lazy(() => block(fmap(
|
|
57
55
|
some(union([row])),
|
|
58
|
-
rows => [html('table', format(rows))])))
|
|
56
|
+
rows => [html('table', format(rows))])));
|
|
59
57
|
|
|
60
58
|
const row: RowParser = lazy(() => dup(fmap(
|
|
61
59
|
subsequence([
|
|
@@ -75,7 +75,7 @@ describe('Unit: parser/block/heading', () => {
|
|
|
75
75
|
assert.deepStrictEqual(inspect(parser('# a [#!http://host]')), [['<h1 id="index:!http://host">a<span class="indexer" data-index="!http://host"></span></h1>'], '']);
|
|
76
76
|
assert.deepStrictEqual(inspect(parser('# a [#a((b))]')), [['<h1 id="index:a((b))">a<span class="indexer" data-index="a((b))"></span></h1>'], '']);
|
|
77
77
|
assert.deepStrictEqual(inspect(parser('# a [#a[[b]]]')), [['<h1 id="index:a[[b]]">a<span class="indexer" data-index="a[[b]]"></span></h1>'], '']);
|
|
78
|
-
assert.deepStrictEqual(inspect(parser('# a [#b
|
|
78
|
+
assert.deepStrictEqual(inspect(parser('# a [#b |c]')), [['<h1 id="index:c">a<span class="indexer" data-index="c"></span></h1>'], '']);
|
|
79
79
|
assert.deepStrictEqual(inspect(parser('# a [#b] [#c]')), [['<h1 id="index:c">a [#b]<span class="indexer" data-index="c"></span></h1>'], '']);
|
|
80
80
|
assert.deepStrictEqual(inspect(parser('# a [#b] \n')), [['<h1 id="index:b">a<span class="indexer" data-index="b"></span></h1>'], '']);
|
|
81
81
|
assert.deepStrictEqual(inspect(parser('# a \\[#b]')), [['<h1 id="index:a_[#b]">a [#b]</h1>'], '']);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { undefined } from 'spica/global';
|
|
2
1
|
import { OListParser } from '../block';
|
|
3
2
|
import { Parser } from '../../combinator/data/parser';
|
|
4
3
|
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, match, fallback, lazy, fmap } from '../../combinator';
|
|
@@ -19,7 +19,7 @@ describe('Unit: parser/block/paragraph', () => {
|
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('a\\ ')), [['<p>a</p>'], '']);
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('a\\ \n')), [['<p>a</p>'], '']);
|
|
21
21
|
assert.deepStrictEqual(inspect(parser('a\\\n')), [['<p>a</p>'], '']);
|
|
22
|
-
assert.deepStrictEqual(inspect(parser('a\\\nb')), [['<p>a<
|
|
22
|
+
assert.deepStrictEqual(inspect(parser('a\\\nb')), [['<p>a<br>b</p>'], '']);
|
|
23
23
|
assert.deepStrictEqual(inspect(parser('a
b')), [['<p>a b</p>'], '']);
|
|
24
24
|
assert.deepStrictEqual(inspect(parser('	
')), [['<p>&Tab;&NewLine;</p>'], '']);
|
|
25
25
|
assert.deepStrictEqual(inspect(parser('<wbr>')), [['<p><wbr></p>'], '']);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ParagraphParser } from '../block';
|
|
2
2
|
import { union, some, block, trimEnd, fmap } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
|
-
import { localize } from '../locale';
|
|
5
4
|
import { visualize } from '../visibility';
|
|
6
5
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
6
|
|
|
8
|
-
export const paragraph: ParagraphParser = block(
|
|
7
|
+
export const paragraph: ParagraphParser = block(fmap(
|
|
9
8
|
visualize(trimEnd(some(union([inline])))),
|
|
10
|
-
ns => [html('p', defrag(ns))]))
|
|
9
|
+
ns => [html('p', defrag(ns))]));
|
|
@@ -4,7 +4,6 @@ import { cite } from './reply/cite';
|
|
|
4
4
|
import { quote, syntax as delimiter } from './reply/quote';
|
|
5
5
|
import { inline } from '../inline';
|
|
6
6
|
import { anyline } from '../source';
|
|
7
|
-
import { localize } from '../locale';
|
|
8
7
|
import { visualize } from '../visibility';
|
|
9
8
|
import { push, pop } from 'spica/array';
|
|
10
9
|
import { html, defrag } from 'typed-dom/dom';
|
|
@@ -16,7 +15,7 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
16
15
|
対象と引用は1:N(分割)、N:1(統合)のみ可能、N:N(混合)は不可能
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
|
-
export const reply: ReplyParser = block(validate('>',
|
|
18
|
+
export const reply: ReplyParser = block(validate('>', fmap(
|
|
20
19
|
inits([
|
|
21
20
|
some(inits([
|
|
22
21
|
cite,
|
|
@@ -30,4 +29,4 @@ export const reply: ReplyParser = block(validate('>', localize(fmap(
|
|
|
30
29
|
ns => push(ns, [html('br')])),
|
|
31
30
|
])),
|
|
32
31
|
]),
|
|
33
|
-
ns => [html('p', defrag(pop(ns)[0]))])))
|
|
32
|
+
ns => [html('p', defrag(pop(ns)[0]))])));
|
package/src/parser/block.ts
CHANGED
package/src/parser/context.ts
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
export const enum Syntax {
|
|
2
|
-
reference = 1 <<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
media = 1 << 6,
|
|
10
|
-
annotation = 1 << 5,
|
|
11
|
-
mathbracket = 1 << 4,
|
|
12
|
-
html = 1 << 3,
|
|
13
|
-
math = 1 << 2,
|
|
2
|
+
reference = 1 << 8,
|
|
3
|
+
index = 1 << 7,
|
|
4
|
+
placeholder = 1 << 6,
|
|
5
|
+
ruby = 1 << 5,
|
|
6
|
+
link = 1 << 4,
|
|
7
|
+
bracket = 1 << 3,
|
|
8
|
+
media = 1 << 2,
|
|
14
9
|
autolink = 1 << 1,
|
|
15
|
-
quote = 1 << 0,
|
|
16
10
|
none = 0,
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
export const enum State {
|
|
20
|
-
annotation = 1 <<
|
|
21
|
-
reference = 1 <<
|
|
22
|
-
index = 1 <<
|
|
23
|
-
label = 1 <<
|
|
24
|
-
link = 1 <<
|
|
25
|
-
media = 1 <<
|
|
14
|
+
annotation = 1 << 8,
|
|
15
|
+
reference = 1 << 7,
|
|
16
|
+
index = 1 << 6,
|
|
17
|
+
label = 1 << 5,
|
|
18
|
+
link = 1 << 4,
|
|
19
|
+
media = 1 << 3,
|
|
20
|
+
mark = 1 << 2,
|
|
26
21
|
autolink = 1 << 1,
|
|
27
22
|
shortcut = 1 << 0,
|
|
28
23
|
none = 0,
|
|
@@ -33,6 +28,7 @@ export const enum State {
|
|
|
33
28
|
| State.index
|
|
34
29
|
| State.label
|
|
35
30
|
| State.link
|
|
31
|
+
| State.mark
|
|
36
32
|
| State.autolink,
|
|
37
33
|
backtrackers = 0
|
|
38
34
|
| State.annotation
|