securemark 0.294.9 → 0.294.11
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/.eslintrc.json +0 -5
- package/CHANGELOG.md +8 -0
- package/dist/index.js +138 -122
- package/markdown.d.ts +1 -1
- package/package.json +1 -1
- package/src/combinator/control/manipulation/convert.ts +9 -19
- package/src/combinator/control/manipulation/scope.ts +23 -7
- package/src/parser/api/body.test.ts +1 -1
- package/src/parser/api/header.test.ts +2 -2
- package/src/parser/api/normalize.test.ts +2 -0
- package/src/parser/api/normalize.ts +1 -1
- package/src/parser/block/blockquote.ts +4 -4
- package/src/parser/block/extension/fig.ts +2 -3
- package/src/parser/block/extension/figure.ts +1 -1
- package/src/parser/block/extension/table.ts +2 -2
- package/src/parser/block/heading.ts +3 -3
- package/src/parser/block/paragraph.test.ts +1 -1
- package/src/parser/block/reply/quote.ts +2 -4
- package/src/parser/block/sidefence.ts +2 -2
- package/src/parser/block/table.ts +4 -4
- package/src/parser/block/ulist.ts +3 -3
- package/src/parser/context.ts +9 -6
- package/src/parser/header.test.ts +2 -2
- package/src/parser/header.ts +5 -5
- package/src/parser/inline/annotation.ts +1 -1
- package/src/parser/inline/autolink/account.ts +7 -4
- package/src/parser/inline/autolink/anchor.ts +1 -1
- package/src/parser/inline/autolink/email.ts +1 -1
- package/src/parser/inline/autolink/hashnum.ts +1 -1
- package/src/parser/inline/autolink/hashtag.ts +1 -1
- package/src/parser/inline/autolink/url.ts +11 -11
- package/src/parser/inline/bracket.ts +11 -8
- package/src/parser/inline/extension/index.ts +3 -3
- package/src/parser/inline/extension/label.ts +1 -1
- package/src/parser/inline/extension/placeholder.ts +1 -1
- package/src/parser/inline/htmlentity.ts +1 -1
- package/src/parser/inline/link.ts +11 -13
- package/src/parser/inline/math.ts +2 -2
- package/src/parser/inline/media.ts +15 -17
- package/src/parser/inline/reference.ts +3 -3
- package/src/parser/inline/ruby.ts +3 -3
- package/src/parser/inline/shortmedia.ts +3 -5
- package/src/parser/inline/template.ts +6 -10
- package/src/parser/visibility.ts +8 -26
|
@@ -22,7 +22,7 @@ export const index: IndexParser = lazy(() => constraint(State.index, fmap(indexe
|
|
|
22
22
|
]), ']', [[']', 1]])))),
|
|
23
23
|
str(']'),
|
|
24
24
|
false,
|
|
25
|
-
[3 | Backtrack.
|
|
25
|
+
[3 | Backtrack.common],
|
|
26
26
|
([, bs], context) =>
|
|
27
27
|
context.linebreak === 0 && trimBlankNodeEnd(bs).length > 0
|
|
28
28
|
? new List([new Data(html('a', { 'data-index': dataindex(bs) }, defrag(unwrap(bs))))])
|
|
@@ -50,11 +50,11 @@ export const signature: IndexParser.SignatureParser = lazy(() => validate('|', s
|
|
|
50
50
|
str(/\|(?!\\?\s)/y),
|
|
51
51
|
some(union([
|
|
52
52
|
unsafehtmlentity,
|
|
53
|
-
some(txt, /(?:[$"`\[\](){}
|
|
53
|
+
some(txt, /(?:[$"`\[\](){}<>()[]{}|])/y),
|
|
54
54
|
]), ']'),
|
|
55
55
|
/(?=])/y,
|
|
56
56
|
false,
|
|
57
|
-
[3 | Backtrack.
|
|
57
|
+
[3 | Backtrack.escapable],
|
|
58
58
|
([, ns], context) => {
|
|
59
59
|
const index = identity('index', undefined, ns.foldl((acc, { value }) => acc + value, ''))?.slice(7);
|
|
60
60
|
return index && context.linebreak === 0
|
|
@@ -14,7 +14,7 @@ export const segment: ExtensionParser.LabelParser.SegmentParser = clear(union([
|
|
|
14
14
|
|
|
15
15
|
export const label: ExtensionParser.LabelParser = constraint(State.label, fmap(
|
|
16
16
|
union([
|
|
17
|
-
surround('[', body, ']', false, [1 | Backtrack.
|
|
17
|
+
surround('[', body, ']', false, [1 | Backtrack.common]),
|
|
18
18
|
body,
|
|
19
19
|
]),
|
|
20
20
|
([{ value }]) => new List([
|
|
@@ -19,7 +19,7 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => surroun
|
|
|
19
19
|
tightStart(some(union([inline]), ']', [[']', 1]])))),
|
|
20
20
|
str(']'),
|
|
21
21
|
false,
|
|
22
|
-
[3 | Backtrack.
|
|
22
|
+
[3 | Backtrack.common],
|
|
23
23
|
(_, context) => new List([
|
|
24
24
|
new Data(html('span',
|
|
25
25
|
{
|
|
@@ -9,7 +9,7 @@ import { html } from 'typed-dom/dom';
|
|
|
9
9
|
export const unsafehtmlentity: UnsafeHTMLEntityParser = surround(
|
|
10
10
|
str('&'), str(/[0-9A-Za-z]+/y), str(';'),
|
|
11
11
|
false,
|
|
12
|
-
[3 | Backtrack.
|
|
12
|
+
[3 | Backtrack.unescapable],
|
|
13
13
|
([as, bs, cs]) =>
|
|
14
14
|
new List([new Data(parser(as.head!.value + bs.head!.value + cs.head!.value))]),
|
|
15
15
|
([as, bs]) =>
|
|
@@ -24,26 +24,24 @@ export const textlink: LinkParser.TextLinkParser = lazy(() => constraint(State.l
|
|
|
24
24
|
trimBlankStart(some(union([inline]), ']', [[']', 1]])),
|
|
25
25
|
']',
|
|
26
26
|
true,
|
|
27
|
-
[3 | Backtrack.
|
|
28
|
-
([, ns = new List()], context) =>
|
|
29
|
-
context.linebreak
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
[3 | Backtrack.common, 3 | Backtrack.link, 2 | Backtrack.ruby],
|
|
28
|
+
([, ns = new List()], context) => {
|
|
29
|
+
if (context.linebreak !== 0) {
|
|
30
|
+
const head = context.position - context.range!;
|
|
31
|
+
return void setBacktrack(context, [2 | Backtrack.link, 2 | Backtrack.ruby], head);
|
|
32
|
+
}
|
|
33
|
+
return ns.push(new Data(Command.Separator)) && ns;
|
|
34
|
+
})),
|
|
32
35
|
// `{ `と`{`で個別にバックトラックが発生し+1nされる。
|
|
33
36
|
// 自己再帰的にパースしてもオプションの不要なパースによる計算量の増加により相殺される。
|
|
34
37
|
dup(surround(
|
|
35
38
|
/{(?![{}])/y,
|
|
36
39
|
inits([uri, some(option)]),
|
|
37
40
|
/ ?}/y,
|
|
38
|
-
false,
|
|
39
|
-
[3 | Backtrack.link],
|
|
41
|
+
false, [],
|
|
40
42
|
undefined,
|
|
41
|
-
([as, bs]
|
|
42
|
-
|
|
43
|
-
const head = context.position - context.range!;
|
|
44
|
-
setBacktrack(context, [2 | Backtrack.link], head);
|
|
45
|
-
return as.import(bs).push(new Data(Command.Cancel)) && as;
|
|
46
|
-
})),
|
|
43
|
+
([as, bs]) =>
|
|
44
|
+
bs && as.import(bs).push(new Data(Command.Cancel)) && as)),
|
|
47
45
|
]),
|
|
48
46
|
([{ value: content }, { value: params = undefined } = {}], context) => {
|
|
49
47
|
if (content.last!.value === Command.Separator) {
|
|
@@ -15,7 +15,7 @@ export const math: MathParser = lazy(() => rewrite(
|
|
|
15
15
|
precedence(4, bracket),
|
|
16
16
|
'$',
|
|
17
17
|
false,
|
|
18
|
-
[3 | Backtrack.
|
|
18
|
+
[3 | Backtrack.escapable]),
|
|
19
19
|
surround(
|
|
20
20
|
/\$(?![\s{}])/y,
|
|
21
21
|
precedence(2, some(union([
|
|
@@ -24,7 +24,7 @@ export const math: MathParser = lazy(() => rewrite(
|
|
|
24
24
|
]))),
|
|
25
25
|
/\$(?![-0-9A-Za-z])/y,
|
|
26
26
|
false,
|
|
27
|
-
[3 | Backtrack.
|
|
27
|
+
[3 | Backtrack.escapable]),
|
|
28
28
|
]),
|
|
29
29
|
({ context: { source, caches: { math: cache } = {} } }) => new List([
|
|
30
30
|
new Data(cache?.get(source)?.cloneNode(true) ||
|
|
@@ -30,24 +30,22 @@ export const media: MediaParser = lazy(() => constraint(State.media, open(
|
|
|
30
30
|
]), ']')),
|
|
31
31
|
']',
|
|
32
32
|
true,
|
|
33
|
-
[3 | Backtrack.
|
|
34
|
-
([, ns = new List()], context) =>
|
|
35
|
-
context.linebreak
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
[3 | Backtrack.escapable, 2 | Backtrack.ruby],
|
|
34
|
+
([, ns = new List()], context) => {
|
|
35
|
+
if (context.linebreak !== 0) {
|
|
36
|
+
const head = context.position - context.range!;
|
|
37
|
+
return void setBacktrack(context, [2 | Backtrack.link, 2 | Backtrack.ruby], head);
|
|
38
|
+
}
|
|
39
|
+
return ns;
|
|
40
|
+
})),
|
|
38
41
|
dup(surround(
|
|
39
42
|
/{(?![{}])/y,
|
|
40
43
|
inits([uri, some(option)]),
|
|
41
44
|
/ ?}/y,
|
|
42
|
-
false,
|
|
43
|
-
[3 | Backtrack.link],
|
|
45
|
+
false, [],
|
|
44
46
|
undefined,
|
|
45
|
-
([as, bs]
|
|
46
|
-
|
|
47
|
-
const head = context.position - context.range!;
|
|
48
|
-
setBacktrack(context, [2 | Backtrack.link], head);
|
|
49
|
-
return as.import(bs).push(new Data(Command.Cancel)) && as;
|
|
50
|
-
})),
|
|
47
|
+
([as, bs]) =>
|
|
48
|
+
bs && as.import(bs).push(new Data(Command.Cancel)) && as)),
|
|
51
49
|
]),
|
|
52
50
|
nodes =>
|
|
53
51
|
nodes.length === 1
|
|
@@ -111,13 +109,13 @@ export const media: MediaParser = lazy(() => constraint(State.media, open(
|
|
|
111
109
|
|
|
112
110
|
const bracket: MediaParser.TextParser.BracketParser = lazy(() => recursion(Recursion.terminal, union([
|
|
113
111
|
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'),
|
|
114
|
-
true, [3 | Backtrack.
|
|
112
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
115
113
|
surround(str('['), some(union([unsafehtmlentity, bracket, txt]), ']'), str(']'),
|
|
116
|
-
true, [3 | Backtrack.
|
|
114
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
117
115
|
surround(str('{'), some(union([unsafehtmlentity, bracket, txt]), '}'), str('}'),
|
|
118
|
-
true, [3 | Backtrack.
|
|
116
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
119
117
|
surround(str('"'), precedence(2, some(union([unsafehtmlentity, txt]), '"')), str('"'),
|
|
120
|
-
true, [3 | Backtrack.
|
|
118
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
121
119
|
])));
|
|
122
120
|
|
|
123
121
|
const option: MediaParser.ParameterParser.OptionParser = lazy(() => union([
|
|
@@ -18,7 +18,7 @@ export const reference: ReferenceParser = lazy(() => constraint(State.reference,
|
|
|
18
18
|
]))),
|
|
19
19
|
']]',
|
|
20
20
|
false,
|
|
21
|
-
[1 | Backtrack.
|
|
21
|
+
[1 | Backtrack.common, 3 | Backtrack.doublebracket],
|
|
22
22
|
([, ns], context) => {
|
|
23
23
|
const { position, range = 0, linebreak = 0 } = context;
|
|
24
24
|
if (linebreak === 0) {
|
|
@@ -34,10 +34,10 @@ export const reference: ReferenceParser = lazy(() => constraint(State.reference,
|
|
|
34
34
|
const { source, position, range = 0, linebreak = 0, state = 0 } = context;
|
|
35
35
|
const head = position - range;
|
|
36
36
|
if (source[position] !== ']') {
|
|
37
|
-
setBacktrack(context, [2 | Backtrack.
|
|
37
|
+
setBacktrack(context, [2 | Backtrack.common], head, 2);
|
|
38
38
|
}
|
|
39
39
|
else if (linebreak !== 0) {
|
|
40
|
-
setBacktrack(context, [2 | Backtrack.link], head, 2);
|
|
40
|
+
setBacktrack(context, [2 | Backtrack.link, 2 | Backtrack.ruby], head, 2);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
assert(source[position] === ']');
|
|
@@ -13,7 +13,7 @@ export const ruby: RubyParser = lazy(() => bind(
|
|
|
13
13
|
dup(surround(
|
|
14
14
|
'[', text, ']',
|
|
15
15
|
false,
|
|
16
|
-
[1 | Backtrack.
|
|
16
|
+
[1 | Backtrack.common, 3 | Backtrack.ruby],
|
|
17
17
|
([, ns]) => {
|
|
18
18
|
ns && ns.last?.value === '' && ns.pop();
|
|
19
19
|
return isTightNodeStart(ns) ? ns : undefined;
|
|
@@ -21,7 +21,7 @@ export const ruby: RubyParser = lazy(() => bind(
|
|
|
21
21
|
dup(surround(
|
|
22
22
|
'(', text, ')',
|
|
23
23
|
false,
|
|
24
|
-
[1 | Backtrack.
|
|
24
|
+
[1 | Backtrack.common, 3 | Backtrack.ruby])),
|
|
25
25
|
]),
|
|
26
26
|
([{ value: texts }, { value: rubies = undefined } = {}], context) => {
|
|
27
27
|
if (rubies === undefined) {
|
|
@@ -62,7 +62,7 @@ export const ruby: RubyParser = lazy(() => bind(
|
|
|
62
62
|
}
|
|
63
63
|
}));
|
|
64
64
|
|
|
65
|
-
const delimiter = /[$"`\[\](){}
|
|
65
|
+
const delimiter = /[$"`\[\](){}<>()[]{}|]|\\?\n/y;
|
|
66
66
|
|
|
67
67
|
const text: RubyParser.TextParser = input => {
|
|
68
68
|
const { context } = input;
|
|
@@ -8,12 +8,10 @@ export const shortmedia: ShortMediaParser = constraint(State.media, rewrite(
|
|
|
8
8
|
open('!', url),
|
|
9
9
|
convert(
|
|
10
10
|
source => `!{ ${source.slice(1)} }`,
|
|
11
|
-
union([media])
|
|
12
|
-
false)));
|
|
11
|
+
union([media]))));
|
|
13
12
|
|
|
14
|
-
export const lineshortmedia: ShortMediaParser.LineShortMediaParser = focus(
|
|
13
|
+
export const lineshortmedia: ShortMediaParser.LineShortMediaParser = constraint(State.media, focus(
|
|
15
14
|
/(?<=^|[\r\n])!https?:\/\/\S+(?=[^\S\n]*(?:$|\n))/y,
|
|
16
15
|
convert(
|
|
17
16
|
source => `!{ ${source.slice(1)} }`,
|
|
18
|
-
union([media])
|
|
19
|
-
false));
|
|
17
|
+
union([media]))));
|
|
@@ -11,8 +11,7 @@ export const template: TemplateParser = lazy(() => surround(
|
|
|
11
11
|
precedence(1,
|
|
12
12
|
some(union([bracket, escsource]), '}')),
|
|
13
13
|
str('}}'),
|
|
14
|
-
true,
|
|
15
|
-
[3 | Backtrack.doublebracket, 3 | Backtrack.escbracket],
|
|
14
|
+
true, [],
|
|
16
15
|
([as, bs = new List(), cs]) => new List([
|
|
17
16
|
new Data(html('span', { class: 'template' }, defrag(unwrap(as.import(bs as List<Data<string>>).import(cs)))))
|
|
18
17
|
]),
|
|
@@ -28,20 +27,17 @@ export const template: TemplateParser = lazy(() => surround(
|
|
|
28
27
|
|
|
29
28
|
const bracket: TemplateParser.BracketParser = lazy(() => union([
|
|
30
29
|
surround(str('('), recursion(Recursion.terminal, some(union([bracket, escsource]), ')')), str(')'),
|
|
31
|
-
true, [3 | Backtrack.
|
|
30
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
32
31
|
surround(str('['), recursion(Recursion.terminal, some(union([bracket, escsource]), ']')), str(']'),
|
|
33
|
-
true, [3 | Backtrack.
|
|
32
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
34
33
|
surround(str('{'), recursion(Recursion.terminal, some(union([bracket, escsource]), '}')), str('}'),
|
|
35
|
-
true, [3 | Backtrack.
|
|
34
|
+
true, [3 | Backtrack.escapable], undefined, () => new List()),
|
|
36
35
|
surround(
|
|
37
36
|
str('"'),
|
|
38
37
|
precedence(2, recursion(Recursion.terminal, some(escsource, /["\n]/y, [['"', 2], ['\n', 3]]))),
|
|
39
38
|
str('"'),
|
|
40
39
|
true,
|
|
41
|
-
[3 | Backtrack.
|
|
42
|
-
|
|
43
|
-
context.linebreak === 0
|
|
44
|
-
? as.import(bs as List<Data<string>>).import(cs)
|
|
45
|
-
: (context.position -= 1, as.import(bs as List<Data<string>>)),
|
|
40
|
+
[3 | Backtrack.escapable],
|
|
41
|
+
undefined,
|
|
46
42
|
([as, bs]) => bs && as.import(bs as List<Data<string>>)),
|
|
47
43
|
]));
|
package/src/parser/visibility.ts
CHANGED
|
@@ -5,41 +5,23 @@ import { convert, fmap } from '../combinator';
|
|
|
5
5
|
import { unsafehtmlentity } from './inline/htmlentity';
|
|
6
6
|
import { invisibleHTMLEntityNames } from './api/normalize';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
namespace blank {
|
|
9
9
|
export const line = new RegExp(
|
|
10
|
-
|
|
11
|
-
/^(\\?[^\S\r\n]|&IHN;|<wbr ?>|\\$)+$/mg.source
|
|
10
|
+
/((?:^|\n)[^\S\n]*(?=\S))((?:[^\S\n]|\\(?=$|\s)|&IHN;|<wbr ?>)+(?=$|\n))/g.source
|
|
12
11
|
.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
|
|
13
|
-
'
|
|
12
|
+
'g');
|
|
14
13
|
export const start = new RegExp(
|
|
15
|
-
/(
|
|
16
|
-
.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
|
|
14
|
+
/(?:[^\S\n]|\\(?=$|\s)|&IHN;|<wbr ?>)+/y.source
|
|
15
|
+
.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
|
|
16
|
+
'y');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
20
20
|
export function visualize<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
|
|
21
21
|
return convert(
|
|
22
|
-
source => source.replace(blank.line, `${Command.Escape}$
|
|
23
|
-
parser
|
|
24
|
-
false);
|
|
22
|
+
source => source.replace(blank.line, `$1${Command.Escape}$2`),
|
|
23
|
+
parser);
|
|
25
24
|
}
|
|
26
|
-
//function hasVisible(
|
|
27
|
-
// nodes: readonly (HTMLElement | string)[],
|
|
28
|
-
//): boolean {
|
|
29
|
-
// for (let i = 0; i < nodes.length; ++i) {
|
|
30
|
-
// const node = nodes[i];
|
|
31
|
-
// if (typeof node === 'string') {
|
|
32
|
-
// if (node && node.trimStart()) return true;
|
|
33
|
-
// }
|
|
34
|
-
// else {
|
|
35
|
-
// if (node.innerText.trimStart()) return true;
|
|
36
|
-
// if (node.classList.contains('reference')) return true;
|
|
37
|
-
// //if (state & State.media ^ State.media &&
|
|
38
|
-
// // (node.classList.contains('media') || node.getElementsByClassName('media')[0])) return true;
|
|
39
|
-
// }
|
|
40
|
-
// }
|
|
41
|
-
// return false;
|
|
42
|
-
//}
|
|
43
25
|
|
|
44
26
|
export function blankWith(delimiter: string | RegExp): RegExp;
|
|
45
27
|
export function blankWith(starts: '' | '\n', delimiter: string | RegExp): RegExp;
|