securemark 0.255.1 → 0.257.1
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 +14 -0
- package/dist/index.js +243 -208
- package/markdown.d.ts +39 -17
- package/package.json +1 -1
- package/src/combinator/control/constraint/contract.ts +3 -13
- package/src/combinator/control/manipulation/context.ts +13 -2
- package/src/combinator/control/manipulation/resource.ts +37 -3
- package/src/combinator/control/manipulation/surround.ts +6 -6
- package/src/combinator/data/parser/inits.ts +1 -1
- package/src/combinator/data/parser/sequence.ts +1 -1
- package/src/combinator/data/parser/some.ts +16 -38
- package/src/combinator/data/parser.ts +34 -18
- package/src/debug.test.ts +2 -2
- package/src/parser/api/bind.ts +9 -11
- package/src/parser/api/parse.test.ts +51 -9
- package/src/parser/block.ts +1 -1
- package/src/parser/inline/annotation.test.ts +7 -5
- package/src/parser/inline/annotation.ts +10 -6
- package/src/parser/inline/autolink/account.ts +3 -7
- package/src/parser/inline/autolink/anchor.ts +3 -7
- package/src/parser/inline/autolink/hashnum.ts +3 -7
- package/src/parser/inline/autolink/hashtag.ts +3 -7
- package/src/parser/inline/autolink/url.test.ts +1 -0
- package/src/parser/inline/autolink/url.ts +7 -8
- package/src/parser/inline/bracket.test.ts +11 -7
- package/src/parser/inline/bracket.ts +11 -11
- package/src/parser/inline/comment.test.ts +4 -3
- package/src/parser/inline/comment.ts +4 -4
- package/src/parser/inline/deletion.ts +3 -3
- package/src/parser/inline/emphasis.ts +3 -3
- package/src/parser/inline/emstrong.ts +4 -5
- package/src/parser/inline/extension/index.test.ts +1 -0
- package/src/parser/inline/extension/index.ts +8 -7
- package/src/parser/inline/extension/indexer.ts +3 -5
- package/src/parser/inline/extension/label.ts +1 -1
- package/src/parser/inline/extension/placeholder.test.ts +8 -7
- package/src/parser/inline/extension/placeholder.ts +4 -4
- package/src/parser/inline/html.test.ts +2 -0
- package/src/parser/inline/html.ts +5 -5
- package/src/parser/inline/insertion.ts +3 -3
- package/src/parser/inline/link.test.ts +1 -0
- package/src/parser/inline/link.ts +58 -16
- package/src/parser/inline/mark.ts +3 -3
- package/src/parser/inline/math.test.ts +21 -14
- package/src/parser/inline/math.ts +4 -15
- package/src/parser/inline/media.test.ts +0 -2
- package/src/parser/inline/media.ts +10 -10
- package/src/parser/inline/reference.test.ts +10 -9
- package/src/parser/inline/reference.ts +12 -8
- package/src/parser/inline/ruby.ts +29 -27
- package/src/parser/inline/strong.ts +3 -3
- package/src/parser/inline/template.ts +4 -4
- package/src/parser/inline.test.ts +13 -10
- package/src/parser/inline.ts +1 -0
- package/src/parser/util.ts +34 -18
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { undefined, Object } from 'spica/global';
|
|
2
2
|
import { HTMLParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, validate, focus, creator, surround, open, match, lazy } from '../../combinator';
|
|
3
|
+
import { union, subsequence, some, validate, focus, precedence, creator, surround, open, match, lazy } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { str } from '../source';
|
|
6
6
|
import { isStartLooseNodes, blankWith } from '../util';
|
|
@@ -18,7 +18,7 @@ const attrspecs = {
|
|
|
18
18
|
Object.setPrototypeOf(attrspecs, null);
|
|
19
19
|
Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
|
|
20
20
|
|
|
21
|
-
export const html: HTMLParser = lazy(() =>
|
|
21
|
+
export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, creator(precedence(5, union([
|
|
22
22
|
focus(
|
|
23
23
|
'<wbr>',
|
|
24
24
|
() => [[h('wbr')], '']),
|
|
@@ -34,7 +34,7 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
34
34
|
str(`<${tag}`), some(attribute), str(/^[^\S\n]*>/), true),
|
|
35
35
|
subsequence([
|
|
36
36
|
focus(/^[^\S\n]*\n/, some(inline)),
|
|
37
|
-
some(open(/^\n?/, some(inline, blankWith('\n', `</${tag}>`)), true)),
|
|
37
|
+
some(open(/^\n?/, some(inline, blankWith('\n', `</${tag}>`), [[blankWith('\n', `</${tag}>`), 5]]), true)),
|
|
38
38
|
]),
|
|
39
39
|
str(`</${tag}>`), true,
|
|
40
40
|
([as, bs = [], cs], rest) =>
|
|
@@ -50,7 +50,7 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
50
50
|
str(`<${tag}`), some(attribute), str(/^[^\S\n]*>/), true),
|
|
51
51
|
subsequence([
|
|
52
52
|
focus(/^[^\S\n]*\n/, some(inline)),
|
|
53
|
-
some(inline, `</${tag}
|
|
53
|
+
some(inline, `</${tag}>`, [[`</${tag}>`, 5]]),
|
|
54
54
|
]),
|
|
55
55
|
str(`</${tag}>`), true,
|
|
56
56
|
([as, bs = [], cs], rest) =>
|
|
@@ -59,7 +59,7 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
59
59
|
[[elem(tag, as, bs, [])], rest]),
|
|
60
60
|
([, tag]) => tag,
|
|
61
61
|
new Cache(10000))),
|
|
62
|
-
])))));
|
|
62
|
+
]))))));
|
|
63
63
|
|
|
64
64
|
export const attribute: HTMLParser.TagParser.AttributeParser = union([
|
|
65
65
|
str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { InsertionParser } from '../inline';
|
|
2
|
-
import { union, some, creator, surround, open, lazy } from '../../combinator';
|
|
2
|
+
import { union, some, precedence, creator, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
5
|
import { blankWith } from '../util';
|
|
6
6
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
|
|
9
|
-
export const insertion: InsertionParser = lazy(() => creator(surround(
|
|
9
|
+
export const insertion: InsertionParser = lazy(() => creator(precedence(2, surround(
|
|
10
10
|
str('++'),
|
|
11
11
|
some(union([
|
|
12
12
|
some(inline, blankWith('\n', '++')),
|
|
@@ -14,4 +14,4 @@ export const insertion: InsertionParser = lazy(() => creator(surround(
|
|
|
14
14
|
])),
|
|
15
15
|
str('++'), false,
|
|
16
16
|
([, bs], rest) => [[html('ins', defrag(bs))], rest],
|
|
17
|
-
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
17
|
+
([as, bs], rest) => [unshift(as, bs), rest]))));
|
|
@@ -151,6 +151,7 @@ describe('Unit: parser/inline/link', () => {
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
it('nest', () => {
|
|
154
|
+
assert.deepStrictEqual(inspect(parser('[*]{/}')), [['<a href="/">*</a>'], '']);
|
|
154
155
|
assert.deepStrictEqual(inspect(parser('[\\[]{/}')), [['<a href="/">[</a>'], '']);
|
|
155
156
|
assert.deepStrictEqual(inspect(parser('[\\]]{/}')), [['<a href="/">]</a>'], '']);
|
|
156
157
|
assert.deepStrictEqual(inspect(parser('[[]{a}]{a}')), [['<a href="a">[]{a}</a>'], '']);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
|
-
import { LinkParser } from '../inline';
|
|
3
|
-
import { eval } from '../../combinator/data/parser';
|
|
4
|
-
import { union, inits, tails, some, validate, guard, context, creator, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
2
|
+
import { LinkParser, TextLinkParser } from '../inline';
|
|
3
|
+
import { Result, eval } from '../../combinator/data/parser';
|
|
4
|
+
import { union, inits, tails, subsequence, some, validate, guard, context, precedence, creator, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
5
5
|
import { inline, media, shortmedia } from '../inline';
|
|
6
6
|
import { attributes } from './html';
|
|
7
7
|
import { autolink } from '../autolink';
|
|
8
|
-
import { str } from '../source';
|
|
9
|
-
import {
|
|
8
|
+
import { unescsource, str } from '../source';
|
|
9
|
+
import { trimNode, stringify } from '../util';
|
|
10
10
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
11
11
|
import { ReadonlyURL } from 'spica/url';
|
|
12
12
|
|
|
@@ -15,9 +15,9 @@ const optspec = {
|
|
|
15
15
|
} as const;
|
|
16
16
|
Object.setPrototypeOf(optspec, null);
|
|
17
17
|
|
|
18
|
-
export const link: LinkParser = lazy(() =>
|
|
18
|
+
export const link: LinkParser = lazy(() => validate(['[', '{'], creator(10, precedence(3, bind(
|
|
19
19
|
guard(context => context.syntax?.inline?.link ?? true,
|
|
20
|
-
|
|
20
|
+
fmap(subsequence([
|
|
21
21
|
context({ syntax: { inline: {
|
|
22
22
|
link: false,
|
|
23
23
|
}}},
|
|
@@ -36,14 +36,22 @@ export const link: LinkParser = lazy(() => creator(10, validate(['[', '{'], '}',
|
|
|
36
36
|
media: false,
|
|
37
37
|
autolink: false,
|
|
38
38
|
}}},
|
|
39
|
-
|
|
39
|
+
some(inline, ']', [[/^\\?\n/, 9], [']', 3]])),
|
|
40
40
|
']',
|
|
41
|
-
true
|
|
41
|
+
true,
|
|
42
|
+
undefined,
|
|
43
|
+
([, ns = [], rest], next) => next[0] === ']' ? undefined : optimize('[', ns, rest)),
|
|
42
44
|
]))),
|
|
45
|
+
// 全体の失敗が確定した時も解析し予算を浪費している
|
|
43
46
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
44
|
-
])
|
|
45
|
-
([
|
|
47
|
+
]),
|
|
48
|
+
([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []])),
|
|
49
|
+
([content, params]: [(HTMLElement | string)[], string[]], rest, context) => {
|
|
50
|
+
if (params.length === 0) return;
|
|
51
|
+
assert(content[0] !== '' || params.length === 0);
|
|
52
|
+
if (content[0] === '') return [content, rest];
|
|
46
53
|
assert(params.every(p => typeof p === 'string'));
|
|
54
|
+
if (content.length !== 0 && trimNode(content).length === 0) return;
|
|
47
55
|
if (eval(some(autolink)(stringify(content), context))?.some(node => typeof node === 'object')) return;
|
|
48
56
|
assert(!html('div', content).querySelector('a, .media, .annotation, .reference') || (content[0] as HTMLElement).matches('.media'));
|
|
49
57
|
const INSECURE_URI = params.shift()!;
|
|
@@ -59,12 +67,37 @@ export const link: LinkParser = lazy(() => creator(10, validate(['[', '{'], '}',
|
|
|
59
67
|
if (el.classList.contains('invalid')) return [[el], rest];
|
|
60
68
|
assert(el.classList.length === 0);
|
|
61
69
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
62
|
-
}))));
|
|
70
|
+
})))));
|
|
63
71
|
|
|
64
|
-
export const
|
|
72
|
+
export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], creator(10, precedence(3, bind(
|
|
73
|
+
reverse(tails([
|
|
74
|
+
dup(surround('[', some(union([unescsource]), ']'), ']')),
|
|
75
|
+
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
76
|
+
])),
|
|
77
|
+
([params, content = []], rest, context) => {
|
|
78
|
+
assert(params[0] === '\r');
|
|
79
|
+
params.shift();
|
|
80
|
+
assert(params.every(p => typeof p === 'string'));
|
|
81
|
+
trimNode(content);
|
|
82
|
+
const INSECURE_URI = params.shift()!;
|
|
83
|
+
assert(INSECURE_URI === INSECURE_URI.trim());
|
|
84
|
+
assert(!INSECURE_URI.match(/\s/));
|
|
85
|
+
const el = elem(
|
|
86
|
+
INSECURE_URI,
|
|
87
|
+
defrag(content),
|
|
88
|
+
new ReadonlyURL(
|
|
89
|
+
resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
|
|
90
|
+
context.host?.href || location.href),
|
|
91
|
+
context.host?.origin || location.origin);
|
|
92
|
+
assert(!el.classList.contains('invalid'));
|
|
93
|
+
assert(el.classList.length === 0);
|
|
94
|
+
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
95
|
+
})))));
|
|
96
|
+
|
|
97
|
+
export const uri: LinkParser.ParameterParser.UriParser = fmap(union([
|
|
65
98
|
open(/^[^\S\n]+/, str(/^\S+/)),
|
|
66
99
|
str(/^[^\s{}]+/),
|
|
67
|
-
]);
|
|
100
|
+
]), ([uri]) => ['\r', uri]);
|
|
68
101
|
|
|
69
102
|
export const option: LinkParser.ParameterParser.OptionParser = union([
|
|
70
103
|
fmap(str(/^[^\S\n]+nofollow(?=[^\S\n]|})/), () => [` rel="nofollow"`]),
|
|
@@ -89,8 +122,8 @@ export function resolve(uri: string, host: URL | Location, source: URL | Locatio
|
|
|
89
122
|
default:
|
|
90
123
|
const target = new ReadonlyURL(uri, source.href);
|
|
91
124
|
return target.origin === host.origin
|
|
92
|
-
|
|
93
|
-
|
|
125
|
+
? target.href.slice(target.origin.length)
|
|
126
|
+
: target.href;
|
|
94
127
|
}
|
|
95
128
|
}
|
|
96
129
|
|
|
@@ -162,3 +195,12 @@ function decode(uri: string): string {
|
|
|
162
195
|
return uri.replace(/\s+/g, encodeURI);
|
|
163
196
|
}
|
|
164
197
|
}
|
|
198
|
+
|
|
199
|
+
export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string): Result<string> {
|
|
200
|
+
let count = 0;
|
|
201
|
+
for (let i = 0; i < ns.length - 1; i += 2) {
|
|
202
|
+
if (ns[i] !== '' || ns[i + 1] !== opener[0]) break;
|
|
203
|
+
++count;
|
|
204
|
+
}
|
|
205
|
+
return [['', opener[0].repeat(opener.length + count)], rest.slice(count)];
|
|
206
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { MarkParser } from '../inline';
|
|
2
|
-
import { union, some, creator, surround, open, lazy } from '../../combinator';
|
|
2
|
+
import { union, some, precedence, creator, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { str } from '../source';
|
|
5
5
|
import { startTight, blankWith } from '../util';
|
|
6
6
|
import { html, defrag } from 'typed-dom/dom';
|
|
7
7
|
import { unshift } from 'spica/array';
|
|
8
8
|
|
|
9
|
-
export const mark: MarkParser = lazy(() => creator(surround(
|
|
9
|
+
export const mark: MarkParser = lazy(() => creator(precedence(2, surround(
|
|
10
10
|
str('=='),
|
|
11
11
|
startTight(some(union([
|
|
12
12
|
some(inline, blankWith('==')),
|
|
@@ -14,4 +14,4 @@ export const mark: MarkParser = lazy(() => creator(surround(
|
|
|
14
14
|
]))),
|
|
15
15
|
str('=='), false,
|
|
16
16
|
([, bs], rest) => [[html('mark', defrag(bs))], rest],
|
|
17
|
-
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
17
|
+
([as, bs], rest) => [unshift(as, bs), rest]))));
|
|
@@ -18,6 +18,12 @@ describe('Unit: parser/inline/math', () => {
|
|
|
18
18
|
assert.deepStrictEqual(inspect(parser('$-a $-b')), undefined);
|
|
19
19
|
assert.deepStrictEqual(inspect(parser('$-a\\ $-b')), undefined);
|
|
20
20
|
assert.deepStrictEqual(inspect(parser('$a $')), undefined);
|
|
21
|
+
assert.deepStrictEqual(inspect(parser('$-a `$`')), undefined);
|
|
22
|
+
assert.deepStrictEqual(inspect(parser('$-a ``$``')), undefined);
|
|
23
|
+
// (``" + ``" + $-b") or (``"`` + "$-b")
|
|
24
|
+
assert.deepStrictEqual(inspect(parser('$-a ``"``"$-b"')), undefined);
|
|
25
|
+
// (``b`` + "c" + $-d) or (``b``"c" + $-d)
|
|
26
|
+
assert.deepStrictEqual(inspect(parser('$-a ``b``"c"$-d')), undefined);
|
|
21
27
|
assert.deepStrictEqual(inspect(parser('$-a"$-b"')), undefined);
|
|
22
28
|
assert.deepStrictEqual(inspect(parser('$-a\\"$-b\\"')), undefined);
|
|
23
29
|
assert.deepStrictEqual(inspect(parser('$a"$')), undefined);
|
|
@@ -28,7 +34,6 @@ describe('Unit: parser/inline/math', () => {
|
|
|
28
34
|
assert.deepStrictEqual(inspect(parser('$-a\\[$-b\\]')), undefined);
|
|
29
35
|
assert.deepStrictEqual(inspect(parser('$a[$')), undefined);
|
|
30
36
|
assert.deepStrictEqual(inspect(parser('$-a{$-b}')), undefined);
|
|
31
|
-
assert.deepStrictEqual(inspect(parser('$-a\\{$-b\\}')), undefined);
|
|
32
37
|
assert.deepStrictEqual(inspect(parser('$a{$')), undefined);
|
|
33
38
|
assert.deepStrictEqual(inspect(parser('$a$b')), undefined);
|
|
34
39
|
assert.deepStrictEqual(inspect(parser('$a$b$')), undefined);
|
|
@@ -38,13 +43,25 @@ describe('Unit: parser/inline/math', () => {
|
|
|
38
43
|
assert.deepStrictEqual(inspect(parser('$\n$')), undefined);
|
|
39
44
|
assert.deepStrictEqual(inspect(parser('$a\\$\nb$')), undefined);
|
|
40
45
|
assert.deepStrictEqual(inspect(parser('$a\\$\\\nb$')), undefined);
|
|
41
|
-
assert.deepStrictEqual(inspect(parser('
|
|
46
|
+
assert.deepStrictEqual(inspect(parser('$`$')), undefined);
|
|
47
|
+
assert.deepStrictEqual(inspect(parser('$`a"$')), undefined);
|
|
48
|
+
assert.deepStrictEqual(inspect(parser('$`a"b$')), undefined);
|
|
49
|
+
assert.deepStrictEqual(inspect(parser('$``$')), undefined);
|
|
50
|
+
assert.deepStrictEqual(inspect(parser('$``$"$')), undefined);
|
|
51
|
+
assert.deepStrictEqual(inspect(parser('$``a$')), undefined);
|
|
42
52
|
assert.deepStrictEqual(inspect(parser('$``a"$0')), undefined);
|
|
53
|
+
assert.deepStrictEqual(inspect(parser('$``a""b$')), undefined);
|
|
43
54
|
assert.deepStrictEqual(inspect(parser('$``a""$')), undefined);
|
|
55
|
+
assert.deepStrictEqual(inspect(parser('$```a"$')), undefined);
|
|
44
56
|
assert.deepStrictEqual(inspect(parser('$```a""$')), undefined);
|
|
45
57
|
assert.deepStrictEqual(inspect(parser('$``\n"$')), undefined);
|
|
46
58
|
assert.deepStrictEqual(inspect(parser('$``a\\$\nb"$')), undefined);
|
|
47
59
|
assert.deepStrictEqual(inspect(parser('$``a\\$\\\nb"$')), undefined);
|
|
60
|
+
assert.deepStrictEqual(inspect(parser('$``"$')), undefined);
|
|
61
|
+
assert.deepStrictEqual(inspect(parser('$``a"$')), undefined);
|
|
62
|
+
assert.deepStrictEqual(inspect(parser('$``\\"$')), undefined);
|
|
63
|
+
assert.deepStrictEqual(inspect(parser('$``a``b"c"$')), undefined);
|
|
64
|
+
assert.deepStrictEqual(inspect(parser('$````""$')), undefined);
|
|
48
65
|
assert.deepStrictEqual(inspect(parser('$"$')), undefined);
|
|
49
66
|
assert.deepStrictEqual(inspect(parser('$}$')), undefined);
|
|
50
67
|
assert.deepStrictEqual(inspect(parser('${')), undefined);
|
|
@@ -104,18 +121,8 @@ describe('Unit: parser/inline/math', () => {
|
|
|
104
121
|
assert.deepStrictEqual(inspect(parser('$f(x)$')), [['<span class="math" translate="no" data-src="$f(x)$">$f(x)$</span>'], '']);
|
|
105
122
|
assert.deepStrictEqual(inspect(parser('$f: x \\to y$')), [['<span class="math" translate="no" data-src="$f: x \\to y$">$f: x \\to y$</span>'], '']);
|
|
106
123
|
assert.deepStrictEqual(inspect(parser('$k$-space')), [['<span class="math" translate="no" data-src="$k$">$k$</span>'], '-space']);
|
|
107
|
-
assert.deepStrictEqual(inspect(parser('$`$')), [['<span class="math" translate="no" data-src="$`$">$`$</span>'], '']);
|
|
108
|
-
assert.deepStrictEqual(inspect(parser('$`"a$')), [['<span class="math" translate="no" data-src="$`"a$">$`"a$</span>'], '']);
|
|
109
|
-
assert.deepStrictEqual(inspect(parser('$``$')), [['<span class="math" translate="no" data-src="$``$">$``$</span>'], '']);
|
|
110
|
-
assert.deepStrictEqual(inspect(parser('$``"$')), [['<span class="math" translate="no" data-src="$``"$">$``"$</span>'], '']);
|
|
111
|
-
assert.deepStrictEqual(inspect(parser('$``""a$')), [['<span class="math" translate="no" data-src="$``""a$">$``""a$</span>'], '']);
|
|
112
|
-
assert.deepStrictEqual(inspect(parser('$``a"$')), [['<span class="math" translate="no" data-src="$``a"$">$``a"$</span>'], '']);
|
|
113
|
-
assert.deepStrictEqual(inspect(parser('$``$"$')), [['<span class="math" translate="no" data-src="$``$">$``$</span>'], '"$']);
|
|
114
|
-
assert.deepStrictEqual(inspect(parser('$``\\"$')), [['<span class="math" translate="no" data-src="$``\\"$">$``\\"$</span>'], '']);
|
|
115
|
-
assert.deepStrictEqual(inspect(parser('$``a``b"c"$')), [['<span class="math" translate="no" data-src="$``a``b"c"$">$``a``b"c"$</span>'], '']);
|
|
116
|
-
assert.deepStrictEqual(inspect(parser('$```"$')), [['<span class="math" translate="no" data-src="$```"$">$```"$</span>'], '']);
|
|
117
|
-
assert.deepStrictEqual(inspect(parser('$````""$')), [['<span class="math" translate="no" data-src="$````""$">$````""$</span>'], '']);
|
|
118
124
|
assert.deepStrictEqual(inspect(parser('$a{b}$')), [['<span class="math" translate="no" data-src="$a{b}$">$a{b}$</span>'], '']);
|
|
125
|
+
assert.deepStrictEqual(inspect(parser('$a\\{$\\}')), [['<span class="math" translate="no" data-src="$a\\{$">$a\\{$</span>'], '\\}']);
|
|
119
126
|
assert.deepStrictEqual(inspect(parser('${}$')), [['<span class="math" translate="no" data-src="${}$">${}$</span>'], '']);
|
|
120
127
|
assert.deepStrictEqual(inspect(parser('${ }$')), [['<span class="math" translate="no" data-src="${ }$">${ }$</span>'], '']);
|
|
121
128
|
assert.deepStrictEqual(inspect(parser('${a}$')), [['<span class="math" translate="no" data-src="${a}$">${a}$</span>'], '']);
|
|
@@ -127,7 +134,7 @@ describe('Unit: parser/inline/math', () => {
|
|
|
127
134
|
assert.deepStrictEqual(inspect(parser('${a }$')), [['<span class="math" translate="no" data-src="${a }$">${a }$</span>'], '']);
|
|
128
135
|
assert.deepStrictEqual(inspect(parser('${ a}$')), [['<span class="math" translate="no" data-src="${ a}$">${ a}$</span>'], '']);
|
|
129
136
|
assert.deepStrictEqual(inspect(parser('${ a }$')), [['<span class="math" translate="no" data-src="${ a }$">${ a }$</span>'], '']);
|
|
130
|
-
assert.deepStrictEqual(inspect(parser('${``
|
|
137
|
+
assert.deepStrictEqual(inspect(parser('${``"}$')), [['<span class="math" translate="no" data-src="${``"}$">${``"}$</span>'], '']);
|
|
131
138
|
assert.deepStrictEqual(inspect(parser('${\\a}$')), [['<span class="math" translate="no" data-src="${\\a}$">${\\a}$</span>'], '']);
|
|
132
139
|
assert.deepStrictEqual(inspect(parser('${\\$}$')), [['<span class="math" translate="no" data-src="${\\$}$">${\\$}$</span>'], '']);
|
|
133
140
|
assert.deepStrictEqual(inspect(parser('${\\\\}$')), [['<span class="math" translate="no" data-src="${\\\\}$">${\\\\}$</span>'], '']);
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { MathParser } from '../inline';
|
|
2
|
-
import { union, some, validate,
|
|
2
|
+
import { union, some, validate, rewrite, precedence, creator, surround, lazy } from '../../combinator';
|
|
3
3
|
import { escsource, str } from '../source';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
|
|
6
|
-
const syntax = /^(?:[
|
|
6
|
+
const syntax = /^(?:[ ([](?!\$)|\\[\\{}$]?|[!#%&')\x2A-\x5A\]^_\x61-\x7A|~])+/;
|
|
7
7
|
const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
|
|
8
8
|
|
|
9
|
-
export const math: MathParser = lazy(() =>
|
|
9
|
+
export const math: MathParser = lazy(() => validate('$', creator(precedence(7, rewrite(
|
|
10
10
|
union([
|
|
11
11
|
surround('$', bracket, '$'),
|
|
12
12
|
surround(
|
|
13
13
|
/^\$(?![\s{}])/,
|
|
14
14
|
some(union([
|
|
15
15
|
bracket,
|
|
16
|
-
quote,
|
|
17
16
|
str(syntax),
|
|
18
17
|
])),
|
|
19
18
|
/^\$(?![0-9A-Za-z])/),
|
|
@@ -31,7 +30,7 @@ export const math: MathParser = lazy(() => creator(validate('$', rewrite(
|
|
|
31
30
|
'data-invalid-message': `"${source.match(forbiddenCommand)![0]}" command is forbidden`,
|
|
32
31
|
},
|
|
33
32
|
source)
|
|
34
|
-
], '']))));
|
|
33
|
+
], ''])))));
|
|
35
34
|
|
|
36
35
|
const bracket: MathParser.BracketParser = lazy(() => creator(surround(
|
|
37
36
|
'{',
|
|
@@ -41,13 +40,3 @@ const bracket: MathParser.BracketParser = lazy(() => creator(surround(
|
|
|
41
40
|
])),
|
|
42
41
|
'}',
|
|
43
42
|
true)));
|
|
44
|
-
|
|
45
|
-
const quote: MathParser.QuoteParser = lazy(() => creator(surround(
|
|
46
|
-
'``',
|
|
47
|
-
some(union([
|
|
48
|
-
quote,
|
|
49
|
-
bracket,
|
|
50
|
-
focus(/^(?:\\[\\{}$]|`(?!`)|[^`{}"$\n\P{ASCII}])*/u, str(syntax)),
|
|
51
|
-
])),
|
|
52
|
-
/^"?/,
|
|
53
|
-
true)));
|
|
@@ -45,8 +45,6 @@ describe('Unit: parser/inline/media', () => {
|
|
|
45
45
|
assert.deepStrictEqual(inspect(parser('![[]{b}')), undefined);
|
|
46
46
|
assert.deepStrictEqual(inspect(parser('![]]{b}')), undefined);
|
|
47
47
|
assert.deepStrictEqual(inspect(parser('![a]{}')), undefined);
|
|
48
|
-
assert.deepStrictEqual(inspect(parser('![\\ a ]{b}')), undefined);
|
|
49
|
-
assert.deepStrictEqual(inspect(parser('![ \\ a ]{b}')), undefined);
|
|
50
48
|
assert.deepStrictEqual(inspect(parser('![a\nb]{b}')), undefined);
|
|
51
49
|
assert.deepStrictEqual(inspect(parser('![a\\\nb]{b}')), undefined);
|
|
52
50
|
assert.deepStrictEqual(inspect(parser('![]{ttp://host}')), [['<img class="media invalid" data-src="ttp://host" alt="">'], '']);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { undefined, location } from 'spica/global';
|
|
2
2
|
import { MediaParser } from '../inline';
|
|
3
|
-
import { union, inits, tails, some, validate, verify, guard, creator, surround, open, dup, lazy, fmap, bind } from '../../combinator';
|
|
4
|
-
import {
|
|
3
|
+
import { union, inits, tails, some, validate, verify, guard, precedence, creator, surround, open, dup, lazy, fmap, bind } from '../../combinator';
|
|
4
|
+
import { textlink, uri, option as linkoption, resolve } from './link';
|
|
5
5
|
import { attributes } from './html';
|
|
6
6
|
import { unsafehtmlentity } from './htmlentity';
|
|
7
7
|
import { txt, str } from '../source';
|
|
8
8
|
import { html, define } from 'typed-dom/dom';
|
|
9
9
|
import { ReadonlyURL } from 'spica/url';
|
|
10
|
-
import { unshift, push } from 'spica/array';
|
|
10
|
+
import { unshift, shift, push } from 'spica/array';
|
|
11
11
|
|
|
12
12
|
const optspec = {
|
|
13
13
|
'width': [],
|
|
@@ -17,18 +17,18 @@ const optspec = {
|
|
|
17
17
|
} as const;
|
|
18
18
|
Object.setPrototypeOf(optspec, null);
|
|
19
19
|
|
|
20
|
-
export const media: MediaParser = lazy(() =>
|
|
20
|
+
export const media: MediaParser = lazy(() => validate(['![', '!{'], creator(10, precedence(3, bind(verify(fmap(open(
|
|
21
21
|
'!',
|
|
22
22
|
guard(context => context.syntax?.inline?.media ?? true,
|
|
23
23
|
tails([
|
|
24
24
|
dup(surround(
|
|
25
|
-
|
|
26
|
-
some(union([unsafehtmlentity, bracket, txt]), ']', /^\\?\n
|
|
25
|
+
'[',
|
|
26
|
+
some(union([unsafehtmlentity, bracket, txt]), ']', [[/^\\?\n/, 9]]),
|
|
27
27
|
']',
|
|
28
28
|
true)),
|
|
29
29
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
30
30
|
]))),
|
|
31
|
-
([as, bs]) => bs ? [[as.join('').trim() || as.join('')], bs] : [[''], as]),
|
|
31
|
+
([as, bs]) => bs ? [[as.join('').trim() || as.join('')], shift(bs)[1]] : [[''], shift(as)[1]]),
|
|
32
32
|
([[text]]) => text === '' || text.trim() !== ''),
|
|
33
33
|
([[text], params], rest, context) => {
|
|
34
34
|
assert(text === text.trim());
|
|
@@ -54,16 +54,16 @@ export const media: MediaParser = lazy(() => creator(10, validate(['![', '!{'],
|
|
|
54
54
|
}
|
|
55
55
|
if (context.syntax?.inline?.link === false || cache && cache.tagName !== 'IMG') return [[el], rest];
|
|
56
56
|
return fmap(
|
|
57
|
-
|
|
57
|
+
textlink as MediaParser,
|
|
58
58
|
([link]) => [define(link, { target: '_blank' }, [el])])
|
|
59
59
|
(`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
|
|
60
|
-
}))));
|
|
60
|
+
})))));
|
|
61
61
|
|
|
62
62
|
const bracket: MediaParser.TextParser.BracketParser = lazy(() => union([
|
|
63
63
|
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
64
64
|
surround(str('['), some(union([unsafehtmlentity, bracket, txt]), ']'), str(']'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
65
65
|
surround(str('{'), some(union([unsafehtmlentity, bracket, txt]), '}'), str('}'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
66
|
-
surround(str('"'), some(union([unsafehtmlentity, txt]), '"'), str('"'), true),
|
|
66
|
+
surround(str('"'), precedence(8, some(union([unsafehtmlentity, txt]), '"')), str('"'), true),
|
|
67
67
|
]));
|
|
68
68
|
|
|
69
69
|
const option: MediaParser.ParameterParser.OptionParser = union([
|
|
@@ -14,14 +14,15 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
14
14
|
assert.deepStrictEqual(inspect(parser('[[]]')), undefined);
|
|
15
15
|
assert.deepStrictEqual(inspect(parser('[[]]]')), undefined);
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('[[ ]]')), undefined);
|
|
17
|
+
assert.deepStrictEqual(inspect(parser('[[ [a')), [['', '[['], ' [a']);
|
|
17
18
|
assert.deepStrictEqual(inspect(parser('[[\n]]')), undefined);
|
|
18
19
|
assert.deepStrictEqual(inspect(parser('[[\na]]')), undefined);
|
|
19
20
|
assert.deepStrictEqual(inspect(parser('[[\\\na]]')), undefined);
|
|
20
|
-
assert.deepStrictEqual(inspect(parser('[[a\n]]')),
|
|
21
|
-
assert.deepStrictEqual(inspect(parser('[[a\\\n]]')),
|
|
22
|
-
assert.deepStrictEqual(inspect(parser('[[a\nb]]')),
|
|
23
|
-
assert.deepStrictEqual(inspect(parser('[[a\\\nb]]')),
|
|
24
|
-
assert.deepStrictEqual(inspect(parser('[[*a\nb*]]')),
|
|
21
|
+
assert.deepStrictEqual(inspect(parser('[[a\n]]')), [['', '[['], 'a\n]]']);
|
|
22
|
+
assert.deepStrictEqual(inspect(parser('[[a\\\n]]')), [['', '[['], 'a\\\n]]']);
|
|
23
|
+
assert.deepStrictEqual(inspect(parser('[[a\nb]]')), [['', '[['], 'a\nb]]']);
|
|
24
|
+
assert.deepStrictEqual(inspect(parser('[[a\\\nb]]')), [['', '[['], 'a\\\nb]]']);
|
|
25
|
+
assert.deepStrictEqual(inspect(parser('[[*a\nb*]]')), [['', '[['], '*a\nb*]]']);
|
|
25
26
|
assert.deepStrictEqual(inspect(parser('[[\\]]')), undefined);
|
|
26
27
|
assert.deepStrictEqual(inspect(parser('[[a]b]]')), undefined);
|
|
27
28
|
assert.deepStrictEqual(inspect(parser('[[[a]]')), undefined);
|
|
@@ -57,7 +58,7 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
57
58
|
assert.deepStrictEqual(inspect(parser('[[^a,]]')), [['<sup class="reference" data-abbr="a,"><span></span></sup>'], '']);
|
|
58
59
|
assert.deepStrictEqual(inspect(parser('[[^a, ]]')), [['<sup class="reference" data-abbr="a,"><span></span></sup>'], '']);
|
|
59
60
|
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
|
|
60
|
-
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="invalid"><span>^a
|
|
61
|
+
assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="invalid"><span>^a</span></sup>'], '']);
|
|
61
62
|
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="reference" data-abbr="a b"><span></span></sup>'], '']);
|
|
62
63
|
assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="invalid"><span>^a b</span></sup>'], '']);
|
|
63
64
|
assert.deepStrictEqual(inspect(parser('[[^a|]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
|
|
@@ -75,7 +76,7 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
75
76
|
assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
|
|
76
77
|
assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="invalid"><span>^1</span></sup>'], '']);
|
|
77
78
|
assert.deepStrictEqual(inspect(parser('[[^1a]]')), [['<sup class="reference" data-abbr="1a"><span></span></sup>'], '']);
|
|
78
|
-
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid"><span>^1
|
|
79
|
+
assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid"><span>^1</span></sup>'], '']);
|
|
79
80
|
assert.deepStrictEqual(inspect(parser('[[^1 a]]')), [['<sup class="reference" data-abbr="1 a"><span></span></sup>'], '']);
|
|
80
81
|
assert.deepStrictEqual(inspect(parser('[[^1|]]')), [['<sup class="invalid"><span>^1|</span></sup>'], '']);
|
|
81
82
|
assert.deepStrictEqual(inspect(parser('[[^1 |]]')), [['<sup class="invalid"><span>^1 |</span></sup>'], '']);
|
|
@@ -86,11 +87,11 @@ describe('Unit: parser/inline/reference', () => {
|
|
|
86
87
|
assert.deepStrictEqual(inspect(parser(`[[^A's, Aces']]`)), [[`<sup class="reference" data-abbr="A's, Aces'"><span></span></sup>`], '']);
|
|
87
88
|
assert.deepStrictEqual(inspect(parser('[[^^]]')), [['<sup class="invalid"><span>^^</span></sup>'], '']);
|
|
88
89
|
assert.deepStrictEqual(inspect(parser('[[\\^]]')), [['<sup class="reference"><span>^</span></sup>'], '']);
|
|
89
|
-
assert.deepStrictEqual(inspect(parser('[[^ ]]')), [['<sup class="invalid"><span
|
|
90
|
+
assert.deepStrictEqual(inspect(parser('[[^ ]]')), [['<sup class="invalid"><span>^</span></sup>'], '']);
|
|
90
91
|
assert.deepStrictEqual(inspect(parser('[[^ a]]')), [['<sup class="invalid"><span>^ a</span></sup>'], '']);
|
|
91
92
|
assert.deepStrictEqual(inspect(parser('[[^ |]]')), [['<sup class="invalid"><span>^ |</span></sup>'], '']);
|
|
92
93
|
assert.deepStrictEqual(inspect(parser('[[^ |b]]')), [['<sup class="invalid"><span>^ |b</span></sup>'], '']);
|
|
93
|
-
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid"><span>^
|
|
94
|
+
assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid"><span>^ |</span></sup>'], '']);
|
|
94
95
|
assert.deepStrictEqual(inspect(parser('[[^ | b]]')), [['<sup class="invalid"><span>^ | b</span></sup>'], '']);
|
|
95
96
|
});
|
|
96
97
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ReferenceParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, validate, guard, context, creator, surround, open, lazy,
|
|
3
|
+
import { union, subsequence, some, validate, guard, context, precedence, creator, recursion, surround, open, lazy, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
|
+
import { optimize } from './link';
|
|
5
6
|
import { str, stropt } from '../source';
|
|
6
|
-
import { regBlankStart,
|
|
7
|
+
import { regBlankStart, startLoose, trimNode, stringify } from '../util';
|
|
7
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
9
|
|
|
9
|
-
export const reference: ReferenceParser = lazy(() =>
|
|
10
|
+
export const reference: ReferenceParser = lazy(() => validate('[[', creator(recursion(precedence(6, surround(
|
|
10
11
|
'[[',
|
|
11
12
|
guard(context => context.syntax?.inline?.reference ?? true,
|
|
13
|
+
startLoose(
|
|
12
14
|
context({ syntax: { inline: {
|
|
13
15
|
annotation: false,
|
|
14
16
|
reference: false,
|
|
@@ -21,11 +23,13 @@ export const reference: ReferenceParser = lazy(() => creator(validate('[[', ']]'
|
|
|
21
23
|
}}, delimiters: undefined },
|
|
22
24
|
subsequence([
|
|
23
25
|
abbr,
|
|
24
|
-
open(stropt(/^(?=\^)/), some(inline, ']', /^\\?\n
|
|
25
|
-
|
|
26
|
-
]))),
|
|
27
|
-
']]'
|
|
28
|
-
|
|
26
|
+
open(stropt(/^(?=\^)/), some(inline, ']', [[/^\\?\n/, 9], [']', 3], [']]', 6]])),
|
|
27
|
+
some(inline, ']', [[/^\\?\n/, 9], [']', 3], [']]', 6]]),
|
|
28
|
+
])), ']')),
|
|
29
|
+
']]',
|
|
30
|
+
false,
|
|
31
|
+
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest],
|
|
32
|
+
([, ns, rest], next) => next[0] === ']' ? undefined : optimize('[[', ns, rest)))))));
|
|
29
33
|
|
|
30
34
|
const abbr: ReferenceParser.AbbrParser = creator(bind(surround(
|
|
31
35
|
'^',
|
|
@@ -1,47 +1,49 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { RubyParser } from '../inline';
|
|
3
3
|
import { eval, exec } from '../../combinator/data/parser';
|
|
4
|
-
import { sequence, validate, verify, focus, creator, surround, lazy,
|
|
4
|
+
import { sequence, validate, verify, focus, creator, surround, lazy, fmap } from '../../combinator';
|
|
5
5
|
import { unsafehtmlentity } from './htmlentity';
|
|
6
6
|
import { text as txt } from '../source';
|
|
7
7
|
import { isStartTightNodes } from '../util';
|
|
8
8
|
import { html, defrag } from 'typed-dom/dom';
|
|
9
9
|
import { unshift, push } from 'spica/array';
|
|
10
10
|
|
|
11
|
-
export const ruby: RubyParser = lazy(() =>
|
|
11
|
+
export const ruby: RubyParser = lazy(() => validate('[', creator(fmap(verify(
|
|
12
12
|
sequence([
|
|
13
|
-
surround('[', focus(/^(?:\\[^\n]|[
|
|
14
|
-
surround('(', focus(/^(?:\\[^\n]|[
|
|
13
|
+
surround('[', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=]\()/, text), ']'),
|
|
14
|
+
surround('(', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=\))/, text), ')'),
|
|
15
15
|
]),
|
|
16
16
|
([texts]) => isStartTightNodes(texts)),
|
|
17
|
-
([texts, rubies]
|
|
18
|
-
|
|
19
|
-
? [texts.pop()!]
|
|
20
|
-
: [];
|
|
21
|
-
tail.length === 0 && texts[texts.length - 1] === '' && texts.pop();
|
|
17
|
+
([texts, rubies]) => {
|
|
18
|
+
texts[texts.length - 1] === '' && texts.pop();
|
|
22
19
|
switch (true) {
|
|
23
20
|
case rubies.length <= texts.length:
|
|
24
|
-
return [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
return [
|
|
22
|
+
html('ruby', attributes(texts, rubies), defrag(texts
|
|
23
|
+
.reduce((acc, _, i) =>
|
|
24
|
+
push(acc, unshift([texts[i]],
|
|
25
|
+
i < rubies.length && rubies[i]
|
|
26
|
+
? [html('rp', '('), html('rt', rubies[i]), html('rp', ')')]
|
|
27
|
+
: [html('rt')]))
|
|
28
|
+
, []))),
|
|
29
|
+
];
|
|
31
30
|
case texts.length === 1 && [...texts[0]].length >= rubies.length:
|
|
32
|
-
return [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
return [
|
|
32
|
+
html('ruby', attributes(texts, rubies), defrag([...texts[0]]
|
|
33
|
+
.reduce((acc, _, i, texts) =>
|
|
34
|
+
push(acc, unshift([texts[i]],
|
|
35
|
+
i < rubies.length && rubies[i]
|
|
36
|
+
? [html('rp', '('), html('rt', rubies[i]), html('rp', ')')]
|
|
37
|
+
: [html('rt')]))
|
|
38
|
+
, []))),
|
|
39
|
+
];
|
|
39
40
|
default:
|
|
40
41
|
assert(rubies.length > 0);
|
|
41
|
-
return [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
return [
|
|
43
|
+
html('ruby', attributes(texts, rubies), defrag(unshift(
|
|
44
|
+
[texts.join(' ')],
|
|
45
|
+
[html('rp', '('), html('rt', rubies.join(' ').trim()), html('rp', ')')]))),
|
|
46
|
+
];
|
|
45
47
|
}
|
|
46
48
|
}))));
|
|
47
49
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StrongParser } from '../inline';
|
|
2
|
-
import { union, some, creator, surround, open, lazy } from '../../combinator';
|
|
2
|
+
import { union, some, precedence, creator, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
4
|
import { emstrong } from './emstrong';
|
|
5
5
|
import { str } from '../source';
|
|
@@ -7,7 +7,7 @@ import { startTight, blankWith } from '../util';
|
|
|
7
7
|
import { html, defrag } from 'typed-dom/dom';
|
|
8
8
|
import { unshift } from 'spica/array';
|
|
9
9
|
|
|
10
|
-
export const strong: StrongParser = lazy(() => creator(surround(
|
|
10
|
+
export const strong: StrongParser = lazy(() => creator(precedence(1, surround(
|
|
11
11
|
str('**'),
|
|
12
12
|
startTight(some(union([
|
|
13
13
|
some(inline, blankWith('**')),
|
|
@@ -18,4 +18,4 @@ export const strong: StrongParser = lazy(() => creator(surround(
|
|
|
18
18
|
])), '*'),
|
|
19
19
|
str('**'), false,
|
|
20
20
|
([, bs], rest) => [[html('strong', defrag(bs))], rest],
|
|
21
|
-
([as, bs], rest) => [unshift(as, bs), rest])));
|
|
21
|
+
([as, bs], rest) => [unshift(as, bs), rest]))));
|