securemark 0.258.3 → 0.258.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.js +130 -78
- package/markdown.d.ts +11 -13
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.ts +3 -1
- package/src/combinator/control/constraint/line.ts +6 -1
- package/src/combinator/control/manipulation/indent.ts +3 -0
- package/src/combinator/data/parser/context/delimiter.ts +6 -3
- package/src/combinator/data/parser/context/memo.ts +1 -1
- package/src/combinator/data/parser/context.test.ts +13 -13
- package/src/combinator/data/parser/context.ts +32 -23
- package/src/combinator/data/parser.ts +1 -1
- package/src/parser/autolink.test.ts +3 -2
- package/src/parser/autolink.ts +17 -1
- package/src/parser/block/extension/table.ts +1 -1
- package/src/parser/block/olist.ts +1 -1
- package/src/parser/block/paragraph.test.ts +3 -1
- package/src/parser/block/reply/quote.ts +2 -2
- package/src/parser/block/table.ts +1 -1
- package/src/parser/block/ulist.ts +3 -3
- package/src/parser/block.ts +1 -1
- package/src/parser/inline/annotation.ts +3 -3
- package/src/parser/inline/autolink/email.test.ts +3 -3
- package/src/parser/inline/autolink/url.test.ts +6 -6
- package/src/parser/inline/autolink.ts +4 -4
- package/src/parser/inline/extension/index.ts +2 -2
- package/src/parser/inline/extension/label.ts +2 -2
- package/src/parser/inline/html.test.ts +16 -16
- package/src/parser/inline/html.ts +9 -8
- package/src/parser/inline/link.ts +20 -7
- package/src/parser/inline/media.ts +2 -2
- package/src/parser/inline/reference.ts +3 -3
- package/src/parser/inline/shortmedia.ts +2 -2
- package/src/parser/inline/template.ts +1 -1
- package/src/parser/inline.test.ts +3 -3
- package/src/parser/source/text.test.ts +16 -1
- package/src/parser/source/text.ts +5 -4
- package/src/parser/visibility.ts +5 -5
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
|
+
import { MarkdownParser } from '../../../markdown';
|
|
2
3
|
import { LinkParser, TextLinkParser } from '../inline';
|
|
3
4
|
import { Result, eval, exec } from '../../combinator/data/parser';
|
|
4
|
-
import { union, inits, tails, subsequence, some,
|
|
5
|
+
import { union, inits, tails, subsequence, some, constraint, syntax, creation, precedence, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
5
6
|
import { inline, media, shortmedia } from '../inline';
|
|
6
7
|
import { attributes } from './html';
|
|
7
8
|
import { autolink } from '../autolink';
|
|
9
|
+
import { bracket } from './bracket';
|
|
8
10
|
import { unescsource, str } from '../source';
|
|
9
11
|
import { Syntax, State } from '../context';
|
|
10
12
|
import { trimNode } from '../visibility';
|
|
@@ -18,7 +20,7 @@ const optspec = {
|
|
|
18
20
|
Object.setPrototypeOf(optspec, null);
|
|
19
21
|
|
|
20
22
|
export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
|
|
21
|
-
|
|
23
|
+
constraint(State.link, false,
|
|
22
24
|
syntax(Syntax.link, 2, 10,
|
|
23
25
|
fmap(subsequence([
|
|
24
26
|
state(State.link,
|
|
@@ -32,7 +34,7 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
|
|
|
32
34
|
']',
|
|
33
35
|
true,
|
|
34
36
|
undefined,
|
|
35
|
-
([, ns = [], rest], next) => next[0] === ']' ? undefined : optimize('[', ns, rest, next)),
|
|
37
|
+
([, ns = [], rest], next, context) => next[0] === ']' ? undefined : optimize('[', ns, rest, next, context)),
|
|
36
38
|
]))),
|
|
37
39
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
38
40
|
], nodes => nodes[0][0] !== ''),
|
|
@@ -59,7 +61,7 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
|
|
|
59
61
|
resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
|
|
60
62
|
context.host?.href || location.href),
|
|
61
63
|
context.host?.origin || location.origin);
|
|
62
|
-
if (el.
|
|
64
|
+
if (el.className === 'invalid') return [[el], rest];
|
|
63
65
|
assert(el.classList.length === 0);
|
|
64
66
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
65
67
|
})));
|
|
@@ -85,7 +87,7 @@ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], bind(
|
|
|
85
87
|
resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
|
|
86
88
|
context.host?.href || location.href),
|
|
87
89
|
context.host?.origin || location.origin);
|
|
88
|
-
assert(
|
|
90
|
+
assert(el.className !== 'invalid');
|
|
89
91
|
assert(el.classList.length === 0);
|
|
90
92
|
return [[define(el, attributes('link', [], optspec, params))], rest];
|
|
91
93
|
})));
|
|
@@ -192,8 +194,19 @@ function decode(uri: string): string {
|
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
196
|
|
|
195
|
-
export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string, next: string): Result<string> {
|
|
196
|
-
if (next[+(next[0] === '\\')] === '\n')
|
|
197
|
+
export function optimize(opener: string, ns: readonly (string | HTMLElement)[], rest: string, next: string, context: MarkdownParser.Context): Result<string> {
|
|
198
|
+
if (next[+(next[0] === '\\')] === '\n') {
|
|
199
|
+
if (rest[0] !== opener[0]) return;
|
|
200
|
+
const delimiters = context.delimiters;
|
|
201
|
+
delimiters?.push({
|
|
202
|
+
signature: '!\n',
|
|
203
|
+
matcher: source => !/^\\?\n/.test(source) && undefined,
|
|
204
|
+
precedence: 9,
|
|
205
|
+
});
|
|
206
|
+
const paired = eval(state(~0, bracket)(rest[0] + rest.slice(rest.search(`[^${rest[0]}]|$`)), context), [])[0] !== '';
|
|
207
|
+
delimiters?.pop();
|
|
208
|
+
if (paired) return;
|
|
209
|
+
}
|
|
197
210
|
let count = 0;
|
|
198
211
|
for (let i = 0; i < ns.length - 1; i += 2) {
|
|
199
212
|
const fst = ns[i];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { undefined, location } from 'spica/global';
|
|
2
2
|
import { MediaParser } from '../inline';
|
|
3
|
-
import { union, inits, tails, some, creation, precedence,
|
|
3
|
+
import { union, inits, tails, some, syntax, creation, precedence, constraint, validate, verify, surround, open, dup, lazy, fmap, bind } from '../../combinator';
|
|
4
4
|
import { textlink, uri, option as linkoption, resolve } from './link';
|
|
5
5
|
import { attributes } from './html';
|
|
6
6
|
import { unsafehtmlentity } from './htmlentity';
|
|
@@ -20,7 +20,7 @@ Object.setPrototypeOf(optspec, null);
|
|
|
20
20
|
|
|
21
21
|
export const media: MediaParser = lazy(() => validate(['![', '!{'], bind(verify(fmap(open(
|
|
22
22
|
'!',
|
|
23
|
-
|
|
23
|
+
constraint(State.media, false,
|
|
24
24
|
syntax(Syntax.media, 2, 10,
|
|
25
25
|
tails([
|
|
26
26
|
dup(surround(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ReferenceParser } from '../inline';
|
|
3
|
-
import { union, subsequence, some, context,
|
|
3
|
+
import { union, subsequence, some, context, syntax, creation, constraint, state, surround, open, lazy, bind } from '../../combinator';
|
|
4
4
|
import { inline } from '../inline';
|
|
5
5
|
import { optimize } from './link';
|
|
6
6
|
import { str, stropt } from '../source';
|
|
@@ -11,7 +11,7 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
11
11
|
|
|
12
12
|
export const reference: ReferenceParser = lazy(() => surround(
|
|
13
13
|
'[[',
|
|
14
|
-
|
|
14
|
+
constraint(State.reference, false,
|
|
15
15
|
syntax(Syntax.reference, 6, 1,
|
|
16
16
|
state(State.annotation | State.reference | State.media,
|
|
17
17
|
startLoose(
|
|
@@ -24,7 +24,7 @@ export const reference: ReferenceParser = lazy(() => surround(
|
|
|
24
24
|
']]',
|
|
25
25
|
false,
|
|
26
26
|
([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest],
|
|
27
|
-
([, ns, rest], next) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next)));
|
|
27
|
+
([, ns, rest], next, context) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next, context)));
|
|
28
28
|
|
|
29
29
|
const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
|
|
30
30
|
'^',
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ShortmediaParser } from '../inline';
|
|
2
|
-
import { union,
|
|
2
|
+
import { union, constraint, rewrite, open, convert } from '../../combinator';
|
|
3
3
|
import { url } from './autolink/url';
|
|
4
4
|
import { media } from './media';
|
|
5
5
|
import { State } from '../context';
|
|
6
6
|
|
|
7
7
|
export const shortmedia: ShortmediaParser = rewrite(
|
|
8
|
-
|
|
8
|
+
constraint(State.media, false,
|
|
9
9
|
open('!', url)),
|
|
10
10
|
convert(
|
|
11
11
|
source => `!{ ${source.slice(1)} }`,
|
|
@@ -10,7 +10,7 @@ import { unshift } from 'spica/array';
|
|
|
10
10
|
export const template: TemplateParser = lazy(() => surround(
|
|
11
11
|
'{{', syntax(Syntax.none, 2, 1, some(union([bracket, escsource]), '}')), '}}', true,
|
|
12
12
|
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest],
|
|
13
|
-
([, ns = [], rest], next) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next)));
|
|
13
|
+
([, ns = [], rest], next, context) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next, context)));
|
|
14
14
|
|
|
15
15
|
const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
|
|
16
16
|
surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
@@ -110,7 +110,7 @@ describe('Unit: parser/inline', () => {
|
|
|
110
110
|
assert.deepStrictEqual(inspect(parser('[@a]')), [['[', '<a href="/@a" class="account">@a</a>', ']'], '']);
|
|
111
111
|
assert.deepStrictEqual(inspect(parser('[#1][#2]')), [['<a class="index" href="#index:1">1</a>', '<a class="index" href="#index:2">2</a>'], '']);
|
|
112
112
|
assert.deepStrictEqual(inspect(parser('[$1]')), [['[', '$', '1', ']'], '']);
|
|
113
|
-
assert.deepStrictEqual(inspect(parser('[$1-2]')), [['[', '$', '1
|
|
113
|
+
assert.deepStrictEqual(inspect(parser('[$1-2]')), [['[', '$', '1-2', ']'], '']);
|
|
114
114
|
assert.deepStrictEqual(inspect(parser('[$-1][$-2]')), [['<a class="label" data-label="$-1">$-1</a>', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
115
115
|
assert.deepStrictEqual(inspect(parser('$-1, $-2')), [['<a class="label" data-label="$-1">$-1</a>', ',', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
116
116
|
assert.deepStrictEqual(inspect(parser('$-1 and $-2')), [['<a class="label" data-label="$-1">$-1</a>', ' ', 'and', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
@@ -225,10 +225,10 @@ describe('Unit: parser/inline', () => {
|
|
|
225
225
|
assert.deepStrictEqual(inspect(parser('#a\nb\n#c\n[#d]')), [['<a href="/hashtags/a" class="hashtag">#a</a>', '<br>', 'b', '<br>', '<a href="/hashtags/c" class="hashtag">#c</a>', '<br>', '<a class="index" href="#index:d">d</a>'], '']);
|
|
226
226
|
assert.deepStrictEqual(inspect(parser('##a')), [['##a'], '']);
|
|
227
227
|
assert.deepStrictEqual(inspect(parser('a#b')), [['a#b'], '']);
|
|
228
|
-
assert.deepStrictEqual(inspect(parser('0a#b')), [['
|
|
228
|
+
assert.deepStrictEqual(inspect(parser('0a#b')), [['0a#b'], '']);
|
|
229
229
|
assert.deepStrictEqual(inspect(parser('あ#b')), [['あ#b'], '']);
|
|
230
230
|
assert.deepStrictEqual(inspect(parser('あい#b')), [['あ', 'い#b'], '']);
|
|
231
|
-
assert.deepStrictEqual(inspect(parser('0aあ#b')), [['0a
|
|
231
|
+
assert.deepStrictEqual(inspect(parser('0aあ#b')), [['0aあ#b'], '']);
|
|
232
232
|
assert.deepStrictEqual(inspect(parser('0aあい#b')), [['0a', 'あ', 'い#b'], '']);
|
|
233
233
|
assert.deepStrictEqual(inspect(parser('「#あ」')), [['「', '<a href="/hashtags/あ" class="hashtag">#あ</a>', '」'], '']);
|
|
234
234
|
assert.deepStrictEqual(inspect(parser('a\n#b')), [['a', '<br>', '<a href="/hashtags/b" class="hashtag">#b</a>'], '']);
|
|
@@ -82,7 +82,7 @@ describe('Unit: parser/text/text', () => {
|
|
|
82
82
|
assert.deepStrictEqual(inspect(parser('0@0')), [['0', '@', '0'], '']);
|
|
83
83
|
assert.deepStrictEqual(inspect(parser('a@0')), [['a', '@', '0'], '']);
|
|
84
84
|
assert.deepStrictEqual(inspect(parser('A@0')), [['A', '@', '0'], '']);
|
|
85
|
-
assert.deepStrictEqual(inspect(parser('
|
|
85
|
+
assert.deepStrictEqual(inspect(parser('aA@0')), [['aA', '@', '0'], '']);
|
|
86
86
|
assert.deepStrictEqual(inspect(parser(' @0')), [[' ', '@', '0'], '']);
|
|
87
87
|
assert.deepStrictEqual(inspect(parser('@@0')), [['@', '@', '0'], '']);
|
|
88
88
|
});
|
|
@@ -96,10 +96,25 @@ describe('Unit: parser/text/text', () => {
|
|
|
96
96
|
assert.deepStrictEqual(inspect(parser('0#0')), [['0', '#', '0'], '']);
|
|
97
97
|
assert.deepStrictEqual(inspect(parser('a#0')), [['a', '#', '0'], '']);
|
|
98
98
|
assert.deepStrictEqual(inspect(parser('A#0')), [['A', '#', '0'], '']);
|
|
99
|
+
assert.deepStrictEqual(inspect(parser('aA#0')), [['a', 'A', '#', '0'], '']);
|
|
99
100
|
assert.deepStrictEqual(inspect(parser(' #0')), [[' ', '#', '0'], '']);
|
|
100
101
|
assert.deepStrictEqual(inspect(parser('##0')), [['#', '#', '0'], '']);
|
|
101
102
|
});
|
|
102
103
|
|
|
104
|
+
it('anchor', () => {
|
|
105
|
+
assert.deepStrictEqual(inspect(parser('>>0')), [['>', '>', '0'], '']);
|
|
106
|
+
assert.deepStrictEqual(inspect(parser('_>>0')), [['_', '>', '>', '0'], '']);
|
|
107
|
+
assert.deepStrictEqual(inspect(parser('$>>0')), [['$', '>', '>', '0'], '']);
|
|
108
|
+
assert.deepStrictEqual(inspect(parser('+>>0')), [['+', '>', '>', '0'], '']);
|
|
109
|
+
assert.deepStrictEqual(inspect(parser('->>0')), [['-', '>', '>', '0'], '']);
|
|
110
|
+
assert.deepStrictEqual(inspect(parser('0>>0')), [['0', '>', '>', '0'], '']);
|
|
111
|
+
assert.deepStrictEqual(inspect(parser('a>>0')), [['a', '>', '>', '0'], '']);
|
|
112
|
+
assert.deepStrictEqual(inspect(parser('A>>0')), [['A', '>', '>', '0'], '']);
|
|
113
|
+
assert.deepStrictEqual(inspect(parser('aA>>0')), [['a', 'A', '>', '>', '0'], '']);
|
|
114
|
+
assert.deepStrictEqual(inspect(parser(' >>0')), [[' ', '>', '>', '0'], '']);
|
|
115
|
+
assert.deepStrictEqual(inspect(parser('>>>>0')), [['>', '>', '>', '>', '0'], '']);
|
|
116
|
+
});
|
|
117
|
+
|
|
103
118
|
it('localize', () => {
|
|
104
119
|
assert.deepStrictEqual(inspect(parser('.\\\n0')), [['.', '<span class="linebreak"> </span>', '0'], '']);
|
|
105
120
|
assert.deepStrictEqual(inspect(parser('。\\\n0')), [['。', '<span class="linebreak"></span>', '0'], '']);
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { TextParser, TxtParser, LinebreakParser } from '../source';
|
|
3
|
-
import { union,
|
|
3
|
+
import { union, syntax, focus } from '../../combinator';
|
|
4
4
|
import { str } from './str';
|
|
5
|
+
import { Syntax } from '../context';
|
|
5
6
|
import { html } from 'typed-dom/dom';
|
|
6
7
|
|
|
7
|
-
export const delimiter = /[\s\x00-\x7F]|\S
|
|
8
|
+
export const delimiter = /[\s\x00-\x7F]|\S[#>]|[()、。!?][^\S\n]*(?=\\\n)/;
|
|
8
9
|
export const nonWhitespace = /[\S\n]|$/;
|
|
9
|
-
export const nonAlphanumeric = /[^0-9A-Za-z]|\S
|
|
10
|
+
export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/;
|
|
10
11
|
const repeat = str(/^(.)\1*/);
|
|
11
12
|
|
|
12
|
-
export const text: TextParser =
|
|
13
|
+
export const text: TextParser = syntax(Syntax.none, 1, 1, (source, context) => {
|
|
13
14
|
if (source === '') return;
|
|
14
15
|
const i = source.search(delimiter);
|
|
15
16
|
switch (i) {
|
package/src/parser/visibility.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { push } from 'spica/array';
|
|
|
12
12
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
13
13
|
export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
14
14
|
const blankline = new RegExp(
|
|
15
|
-
/^(?:\\$|\\?[^\S\n]|&IHN;|<wbr
|
|
15
|
+
/^(?:\\$|\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+$/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
|
|
16
16
|
'gm');
|
|
17
17
|
return union([
|
|
18
18
|
convert(
|
|
@@ -40,7 +40,7 @@ function hasVisible(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export const regBlankStart = new RegExp(
|
|
43
|
-
/^(?:\\?[^\S\n]|&IHN;|<wbr
|
|
43
|
+
/^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`));
|
|
44
44
|
|
|
45
45
|
export function blankWith(delimiter: string | RegExp): RegExp;
|
|
46
46
|
export function blankWith(starting: '' | '\n', delimiter: string | RegExp): RegExp;
|
|
@@ -49,7 +49,7 @@ export function blankWith(starting: '' | '\n', delimiter?: string | RegExp): Reg
|
|
|
49
49
|
return new RegExp(String.raw
|
|
50
50
|
`^(?:(?=${
|
|
51
51
|
starting
|
|
52
|
-
})(?:\\?\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr
|
|
52
|
+
})(?:\\?\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr[^\S\n]*>)${starting && '+'})?${
|
|
53
53
|
typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source
|
|
54
54
|
}`);
|
|
55
55
|
}
|
|
@@ -94,8 +94,8 @@ const isStartTight = reduce((source: string, context: MarkdownParser.Context, ex
|
|
|
94
94
|
case '<':
|
|
95
95
|
switch (true) {
|
|
96
96
|
case source.length >= 5
|
|
97
|
-
&& source
|
|
98
|
-
&& source
|
|
97
|
+
&& source.slice(0, 4) === '<wbr'
|
|
98
|
+
&& (source[5] === '>' || /^<wbr[^\S\n]*>/.test(source)):
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
return true;
|