securemark 0.242.0 → 0.243.2
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/securemark.js +363 -314
- package/markdown.d.ts +20 -2
- package/package-lock.json +10 -10
- package/package.json +1 -1
- package/src/parser/block/blockquote.ts +1 -7
- package/src/parser/block/extension/example.ts +1 -1
- package/src/parser/block/extension/fig.ts +6 -5
- package/src/parser/block/extension/figure.test.ts +21 -21
- package/src/parser/block/extension/figure.ts +55 -30
- package/src/parser/block/extension/message.ts +2 -0
- package/src/parser/block/extension/placeholder.ts +2 -2
- package/src/parser/block/sidefence.test.ts +66 -0
- package/src/parser/block/sidefence.ts +31 -0
- package/src/parser/block/table.ts +2 -2
- package/src/parser/block.ts +3 -0
- package/src/parser/inline/extension/placeholder.ts +2 -2
- package/src/parser/inline/html.test.ts +7 -0
- package/src/parser/inline/html.ts +17 -19
- package/src/parser/inline/link.ts +1 -2
- package/src/parser/inline/media.ts +1 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
|
-
import { isFrozen, ObjectEntries
|
|
2
|
+
import { isFrozen, ObjectEntries } from 'spica/alias';
|
|
3
3
|
import { MarkdownParser } from '../../../markdown';
|
|
4
4
|
import { HTMLParser } from '../inline';
|
|
5
5
|
import { union, some, validate, context, creator, surround, open, match, lazy } from '../../combinator';
|
|
@@ -11,14 +11,14 @@ import { memoize } from 'spica/memoize';
|
|
|
11
11
|
import { Cache } from 'spica/cache';
|
|
12
12
|
import { unshift, push, splice, join } from 'spica/array';
|
|
13
13
|
|
|
14
|
-
const tags =
|
|
14
|
+
const tags = Object.freeze(['wbr', 'sup', 'sub', 'small', 'bdo', 'bdi']);
|
|
15
15
|
const attrspec = {
|
|
16
16
|
bdo: {
|
|
17
|
-
dir:
|
|
17
|
+
dir: Object.freeze(['ltr', 'rtl'] as const),
|
|
18
18
|
},
|
|
19
19
|
} as const;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
Object.setPrototypeOf(attrspec, null);
|
|
21
|
+
Object.values(attrspec).forEach(o => Object.setPrototypeOf(o, null));
|
|
22
22
|
|
|
23
23
|
export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, union([
|
|
24
24
|
match(
|
|
@@ -29,7 +29,7 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
29
29
|
`<${tag}`, some(union([attribute])), /^\s*>/, true,
|
|
30
30
|
([, bs = []], rest) =>
|
|
31
31
|
[[h(tag as 'span', attributes('html', [], attrspec[tag], bs))], rest]),
|
|
32
|
-
([, tag]) => tag)),
|
|
32
|
+
([, tag]) => tags.indexOf(tag), [])),
|
|
33
33
|
match(
|
|
34
34
|
/^(?=<(sup|sub|small)(?=[^\S\n]|>))/,
|
|
35
35
|
memoize(
|
|
@@ -69,7 +69,7 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
69
69
|
str(`</${tag}>`), false,
|
|
70
70
|
([as, bs, cs], rest, context) =>
|
|
71
71
|
[[elem(tag, as, defrag(bs), cs, context)], rest])),
|
|
72
|
-
|
|
72
|
+
([, tag]) => tags.indexOf(tag), [])),
|
|
73
73
|
match(
|
|
74
74
|
/^(?=<(bdo|bdi)(?=[^\S\n]|>))/,
|
|
75
75
|
memoize(
|
|
@@ -82,11 +82,11 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
82
82
|
open(/^\n?/, some(inline, '</'), true),
|
|
83
83
|
]), `</${tag}>`), `</${tag}>`),
|
|
84
84
|
str(`</${tag}>`), false,
|
|
85
|
-
([as, bs, cs], rest) =>
|
|
86
|
-
[[elem(tag, as, defrag(bs), cs,
|
|
85
|
+
([as, bs, cs], rest, context) =>
|
|
86
|
+
[[elem(tag, as, defrag(bs), cs, context)], rest],
|
|
87
87
|
([as, bs], rest) =>
|
|
88
88
|
as.length === 1 ? [unshift(as, bs), rest] : undefined)),
|
|
89
|
-
([, tag]) => tag)),
|
|
89
|
+
([, tag]) => tags.indexOf(tag), [])),
|
|
90
90
|
match(
|
|
91
91
|
/^(?=<([a-z]+)(?=[^\S\n]|>))/,
|
|
92
92
|
memoize(
|
|
@@ -99,12 +99,12 @@ export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-
|
|
|
99
99
|
open(/^\n?/, some(inline, '</'), true),
|
|
100
100
|
]), `</${tag}>`), `</${tag}>`),
|
|
101
101
|
str(`</${tag}>`), false,
|
|
102
|
-
([as, bs, cs], rest) =>
|
|
103
|
-
[[elem(tag, as, defrag(bs), cs,
|
|
102
|
+
([as, bs, cs], rest, context) =>
|
|
103
|
+
[[elem(tag, as, defrag(bs), cs, context)], rest],
|
|
104
104
|
([as, bs], rest) =>
|
|
105
105
|
as.length === 1 ? [unshift(as, bs), rest] : undefined)),
|
|
106
106
|
([, tag]) => tag,
|
|
107
|
-
new Cache(
|
|
107
|
+
new Cache(10000))),
|
|
108
108
|
])))));
|
|
109
109
|
|
|
110
110
|
export const attribute: HTMLParser.TagParser.AttributeParser = union([
|
|
@@ -133,12 +133,11 @@ function elem(tag: string, as: string[], bs: (HTMLElement | string)[], cs: strin
|
|
|
133
133
|
}
|
|
134
134
|
break;
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
const attrs = attributes('html', [], attrspec[tag], as.slice(1, -1));
|
|
137
137
|
switch (true) {
|
|
138
|
-
case 'data-invalid-syntax' in
|
|
138
|
+
case 'data-invalid-syntax' in attrs:
|
|
139
139
|
return invalid('attribute', 'Invalid HTML attribute', as, bs, cs);
|
|
140
140
|
default:
|
|
141
|
-
assert(attrs);
|
|
142
141
|
return h(tag as 'span', attrs, bs);
|
|
143
142
|
}
|
|
144
143
|
}
|
|
@@ -158,7 +157,7 @@ const requiredAttributes = memoize(
|
|
|
158
157
|
|
|
159
158
|
export function attributes(
|
|
160
159
|
syntax: string,
|
|
161
|
-
classes: string[],
|
|
160
|
+
classes: readonly string[],
|
|
162
161
|
spec: Readonly<Record<string, readonly (string | undefined)[] | undefined>> | undefined,
|
|
163
162
|
params: string[],
|
|
164
163
|
): Record<string, string | undefined> {
|
|
@@ -183,8 +182,7 @@ export function attributes(
|
|
|
183
182
|
}
|
|
184
183
|
invalid ||= !!spec && !requiredAttributes(spec).every(name => name in attrs);
|
|
185
184
|
if (invalid) {
|
|
186
|
-
|
|
187
|
-
attrs['class'] = join(classes, ' ');
|
|
185
|
+
attrs['class'] = join(classes.includes('invalid') ? classes : unshift(classes, ['invalid']), ' ');
|
|
188
186
|
attrs['data-invalid-syntax'] = syntax;
|
|
189
187
|
attrs['data-invalid-type'] = 'argument';
|
|
190
188
|
attrs['data-invalid-message'] = 'Invalid argument';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { location, encodeURI, decodeURI, Location } from 'spica/global';
|
|
2
|
-
import { ObjectSetPrototypeOf } from 'spica/alias';
|
|
3
2
|
import { LinkParser } from '../inline';
|
|
4
3
|
import { eval } from '../../combinator/data/parser';
|
|
5
4
|
import { union, inits, tails, some, validate, guard, context, creator, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
@@ -14,7 +13,7 @@ import { ReadonlyURL } from 'spica/url';
|
|
|
14
13
|
const optspec = {
|
|
15
14
|
rel: ['nofollow'],
|
|
16
15
|
} as const;
|
|
17
|
-
|
|
16
|
+
Object.setPrototypeOf(optspec, null);
|
|
18
17
|
|
|
19
18
|
export const link: LinkParser = lazy(() => creator(10, validate(['[', '{'], '}', '\n', bind(
|
|
20
19
|
guard(context => context.syntax?.inline?.link ?? true,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { undefined, location } from 'spica/global';
|
|
2
|
-
import { ObjectSetPrototypeOf } from 'spica/alias';
|
|
3
2
|
import { MediaParser } from '../inline';
|
|
4
3
|
import { union, inits, tails, some, validate, verify, guard, creator, surround, open, dup, lazy, fmap, bind } from '../../combinator';
|
|
5
4
|
import { link, uri, option as linkoption, resolve } from './link';
|
|
@@ -16,7 +15,7 @@ const optspec = {
|
|
|
16
15
|
'aspect-ratio': [],
|
|
17
16
|
rel: undefined,
|
|
18
17
|
} as const;
|
|
19
|
-
|
|
18
|
+
Object.setPrototypeOf(optspec, null);
|
|
20
19
|
|
|
21
20
|
export const media: MediaParser = lazy(() => creator(10, validate(['![', '!{'], '}', '\n', bind(verify(fmap(open(
|
|
22
21
|
'!',
|