securemark 0.276.1 → 0.276.3
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 +8 -0
- package/design.md +1 -0
- package/dist/index.js +207 -160
- package/package.json +10 -10
- package/src/combinator/control/manipulation/fence.ts +1 -1
- package/src/parser/api/bind.test.ts +3 -3
- package/src/parser/api/parse.test.ts +33 -33
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/extension/example.test.ts +1 -1
- package/src/parser/inline/link.ts +13 -13
- package/src/parser/inline/mark.ts +2 -6
- package/src/parser/inline/ruby.ts +1 -1
- package/src/parser/processor/note.test.ts +25 -30
- package/src/parser/processor/note.ts +34 -21
- package/src/parser/visibility.ts +17 -17
- package/webpack.config.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "securemark",
|
|
3
|
-
"version": "0.276.
|
|
3
|
+
"version": "0.276.3",
|
|
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",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
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.59.
|
|
37
|
+
"@typescript-eslint/parser": "^5.59.7",
|
|
38
38
|
"babel-loader": "^9.1.2",
|
|
39
39
|
"babel-plugin-unassert": "^3.2.0",
|
|
40
40
|
"concurrently": "^8.0.1",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^8.41.0",
|
|
42
42
|
"eslint-plugin-redos": "^4.4.5",
|
|
43
43
|
"eslint-webpack-plugin": "^4.0.1",
|
|
44
|
-
"glob": "^10.2.
|
|
44
|
+
"glob": "^10.2.6",
|
|
45
45
|
"karma": "^6.4.2",
|
|
46
46
|
"karma-chrome-launcher": "^3.2.0",
|
|
47
47
|
"karma-coverage": "^2.2.0",
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"karma-power-assert": "^1.0.0",
|
|
51
51
|
"mocha": "^10.2.0",
|
|
52
52
|
"npm-check-updates": "^16.10.12",
|
|
53
|
-
"semver": "^7.5.
|
|
54
|
-
"spica": "0.0.
|
|
55
|
-
"ts-loader": "^9.4.
|
|
56
|
-
"typed-dom": "
|
|
53
|
+
"semver": "^7.5.1",
|
|
54
|
+
"spica": "0.0.728",
|
|
55
|
+
"ts-loader": "^9.4.3",
|
|
56
|
+
"typed-dom": "0.0.335",
|
|
57
57
|
"typescript": "5.0.4",
|
|
58
|
-
"webpack": "^5.
|
|
58
|
+
"webpack": "^5.84.1",
|
|
59
59
|
"webpack-cli": "^5.1.1",
|
|
60
|
-
"webpack-merge": "^5.
|
|
60
|
+
"webpack-merge": "^5.9.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"update": "ncu -u && npm i --no-shrinkwrap && bundle update",
|
|
@@ -10,7 +10,7 @@ export function fence<C extends Ctx, D extends Parser<unknown, C>[]>(opener: Reg
|
|
|
10
10
|
assert(matches[0] === firstline(source));
|
|
11
11
|
const delim = matches[1];
|
|
12
12
|
assert(delim && delim === delim.trim());
|
|
13
|
-
if (matches[0].
|
|
13
|
+
if (matches[0].includes(delim, delim.length)) return;
|
|
14
14
|
let rest = source.slice(matches[0].length);
|
|
15
15
|
// Prevent annoying parsing in editing.
|
|
16
16
|
if (isBlank(firstline(rest)) && firstline(rest.slice(firstline(rest).length)).trimEnd() !== delim) return;
|
|
@@ -193,19 +193,19 @@ describe('Unit: parser/api/bind', () => {
|
|
|
193
193
|
[
|
|
194
194
|
html('p', [
|
|
195
195
|
html('sup', { class: "reference", id: "reference::ref:1:1", title: "1" }, [
|
|
196
|
-
html('span'
|
|
196
|
+
html('span'),
|
|
197
197
|
html('a', { href: "#reference::def:1" }, '[1]'),
|
|
198
198
|
]),
|
|
199
199
|
]).outerHTML,
|
|
200
200
|
html('p', [
|
|
201
201
|
html('sup', { class: "reference", id: "reference::ref:2:1", title: "2" }, [
|
|
202
|
-
html('span'
|
|
202
|
+
html('span'),
|
|
203
203
|
html('a', { href: "#reference::def:2" }, '[2]'),
|
|
204
204
|
]),
|
|
205
205
|
]).outerHTML,
|
|
206
206
|
html('p', [
|
|
207
207
|
html('sup', { class: "reference", id: "reference::ref:3:1", title: "3" }, [
|
|
208
|
-
html('span'
|
|
208
|
+
html('span'),
|
|
209
209
|
html('a', { href: "#reference::def:3" }, '[3]'),
|
|
210
210
|
]),
|
|
211
211
|
]).outerHTML,
|
|
@@ -124,7 +124,7 @@ describe('Unit: parser/api/parse', () => {
|
|
|
124
124
|
'<p><a class="index" href="#index::a">a</a></p>',
|
|
125
125
|
'<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>',
|
|
126
126
|
'<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
|
|
127
|
-
'<p><sup class="annotation" id="annotation::ref:a:1" title="a"><span
|
|
127
|
+
'<p><sup class="annotation" id="annotation::ref:a:1" title="a"><span></span><a href="#annotation::def:a:1">*1</a></sup></p>',
|
|
128
128
|
'<p><a class="url" href="https://source/x/a" target="_blank">a</a></p>',
|
|
129
129
|
'<p><a class="url" href="https://source/a" target="_blank">/a</a></p>',
|
|
130
130
|
'<p><a class="url" href="/z/a">^/a</a></p>',
|
|
@@ -207,8 +207,8 @@ describe('Unit: parser/api/parse', () => {
|
|
|
207
207
|
[...parse('$-a\n$$\n$$\n\n(($-a[[^B]]))[[^B|$-a]]', { notes }).children].map(el => el.outerHTML),
|
|
208
208
|
[
|
|
209
209
|
'<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>',
|
|
210
|
-
'<p><sup class="annotation" id="annotation::ref:[$-a]:1" title="(1)"><span
|
|
211
|
-
'<ol class="annotations"><li id="annotation::def:[$-a]:1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B" id="reference::ref:B:2" title="(1)"><span
|
|
210
|
+
'<p><sup class="annotation" id="annotation::ref:[$-a]:1" title="(1)"><span></span><a href="#annotation::def:[$-a]:1">*1</a></sup><sup class="reference" data-abbr="B" id="reference::ref:B:1" title="(1)"><span></span><a href="#reference::def:B">[B]</a></sup></p>',
|
|
211
|
+
'<ol class="annotations"><li id="annotation::def:[$-a]:1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B" id="reference::ref:B:2" title="(1)"><span></span><a href="#reference::def:B">[B]</a></sup></span><sup><a href="#annotation::ref:[$-a]:1">^1</a></sup></li></ol>',
|
|
212
212
|
]);
|
|
213
213
|
assert.deepStrictEqual(
|
|
214
214
|
notes.references.outerHTML,
|
|
@@ -247,36 +247,36 @@ describe('Unit: parser/api/parse', () => {
|
|
|
247
247
|
'[[^Constitution, art. 2, sec. 1|b]]',
|
|
248
248
|
].join('\n\n'), { notes }).children].map(el => el.outerHTML),
|
|
249
249
|
[
|
|
250
|
-
'<p><sup class="reference" data-abbr="A 1" id="reference::ref:A_1:1" title="b"><span
|
|
251
|
-
'<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:2" title="b"><span
|
|
252
|
-
'<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:3" title="b"><span
|
|
253
|
-
'<p><sup class="reference" data-abbr="Xyz 2020" id="reference::ref:Xyz_2020:1" title="b"><span
|
|
254
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1" id="reference::ref:Xyz_2020:2" title="b"><span
|
|
255
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1, 2" id="reference::ref:Xyz_2020:3" title="b"><span
|
|
256
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1" id="reference::ref:Xyz_2020:4" title="b"><span
|
|
257
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b" id="reference::ref:Xyz_2020:5" title="b"><span
|
|
258
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b" id="reference::ref:Xyz_2020:6" title="b"><span
|
|
259
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1-2" id="reference::ref:Xyz_2020:7" title="b"><span
|
|
260
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1:1-2" id="reference::ref:Xyz_2020:8" title="b"><span
|
|
261
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1n" id="reference::ref:Xyz_2020:9" title="b"><span
|
|
262
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1n1" id="reference::ref:Xyz_2020:10" title="b"><span
|
|
263
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, 1nn1-2" id="reference::ref:Xyz_2020:11" title="b"><span
|
|
264
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, i" id="reference::ref:Xyz_2020:12" title="b"><span
|
|
265
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, capter 1" id="reference::ref:Xyz_2020:13" title="b"><span
|
|
266
|
-
'<p><sup class="reference" data-abbr="Xyz 2020, cap. 1" id="reference::ref:Xyz_2020:14" title="b"><span
|
|
267
|
-
'<p><sup class="reference" data-abbr="Xyz 2020a" id="reference::ref:Xyz_2020a:1" title="b"><span
|
|
268
|
-
'<p><sup class="reference" data-abbr="Xyz 2020a, 1" id="reference::ref:Xyz_2020a:2" title="b"><span
|
|
269
|
-
'<p><sup class="reference" data-abbr="Xyz 2020-2021a" id="reference::ref:Xyz_2020-2021a:1" title="b"><span
|
|
270
|
-
'<p><sup class="reference" data-abbr="Xyz 2020-2021a, 1" id="reference::ref:Xyz_2020-2021a:2" title="b"><span
|
|
271
|
-
'<p><sup class="reference" data-abbr="Xyz, April 1, 2020" id="reference::ref:Xyz,_April_1,_2020:1" title="b"><span
|
|
272
|
-
'<p><sup class="reference" data-abbr="Xyz, April 1, 2020, 1" id="reference::ref:Xyz,_April_1,_2020:2" title="b"><span
|
|
273
|
-
'<p><sup class="reference" data-abbr="Xyz n.d." id="reference::ref:Xyz_n.d.:1" title="b"><span
|
|
274
|
-
'<p><sup class="reference" data-abbr="Xyz n.d., 1" id="reference::ref:Xyz_n.d.:2" title="b"><span
|
|
275
|
-
'<p><sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2" id="reference::ref:X._Y.,_and_Z_et_al._2020:1" title="b"><span
|
|
276
|
-
'<p><sup class="reference" data-abbr="A title 2020" id="reference::ref:A_title_2020:1" title="b"><span
|
|
277
|
-
'<p><sup class="reference" data-abbr="A title 2020, 1" id="reference::ref:A_title_2020:2" title="b"><span
|
|
278
|
-
'<p><sup class="reference" data-abbr="Constitution, art. 2" id="reference::ref:Constitution:1" title="b"><span
|
|
279
|
-
'<p><sup class="reference" data-abbr="Constitution, art. 2, sec. 1" id="reference::ref:Constitution:2" title="b"><span
|
|
250
|
+
'<p><sup class="reference" data-abbr="A 1" id="reference::ref:A_1:1" title="b"><span></span><a href="#reference::def:A_1">[A 1]</a></sup></p>',
|
|
251
|
+
'<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:2" title="b"><span></span><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
|
|
252
|
+
'<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:3" title="b"><span></span><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
|
|
253
|
+
'<p><sup class="reference" data-abbr="Xyz 2020" id="reference::ref:Xyz_2020:1" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020]</a></sup></p>',
|
|
254
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1" id="reference::ref:Xyz_2020:2" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1]</a></sup></p>',
|
|
255
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1, 2" id="reference::ref:Xyz_2020:3" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, 2]</a></sup></p>',
|
|
256
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1" id="reference::ref:Xyz_2020:4" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1]</a></sup></p>',
|
|
257
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b" id="reference::ref:Xyz_2020:5" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1-2.1b]</a></sup></p>',
|
|
258
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b" id="reference::ref:Xyz_2020:6" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1a-b]</a></sup></p>',
|
|
259
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1-2" id="reference::ref:Xyz_2020:7" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1-2]</a></sup></p>',
|
|
260
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1:1-2" id="reference::ref:Xyz_2020:8" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1:1-2]</a></sup></p>',
|
|
261
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1n" id="reference::ref:Xyz_2020:9" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n]</a></sup></p>',
|
|
262
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1n1" id="reference::ref:Xyz_2020:10" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n1]</a></sup></p>',
|
|
263
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, 1nn1-2" id="reference::ref:Xyz_2020:11" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1nn1-2]</a></sup></p>',
|
|
264
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, i" id="reference::ref:Xyz_2020:12" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, i]</a></sup></p>',
|
|
265
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, capter 1" id="reference::ref:Xyz_2020:13" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, capter 1]</a></sup></p>',
|
|
266
|
+
'<p><sup class="reference" data-abbr="Xyz 2020, cap. 1" id="reference::ref:Xyz_2020:14" title="b"><span></span><a href="#reference::def:Xyz_2020">[Xyz 2020, cap. 1]</a></sup></p>',
|
|
267
|
+
'<p><sup class="reference" data-abbr="Xyz 2020a" id="reference::ref:Xyz_2020a:1" title="b"><span></span><a href="#reference::def:Xyz_2020a">[Xyz 2020a]</a></sup></p>',
|
|
268
|
+
'<p><sup class="reference" data-abbr="Xyz 2020a, 1" id="reference::ref:Xyz_2020a:2" title="b"><span></span><a href="#reference::def:Xyz_2020a">[Xyz 2020a, 1]</a></sup></p>',
|
|
269
|
+
'<p><sup class="reference" data-abbr="Xyz 2020-2021a" id="reference::ref:Xyz_2020-2021a:1" title="b"><span></span><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a]</a></sup></p>',
|
|
270
|
+
'<p><sup class="reference" data-abbr="Xyz 2020-2021a, 1" id="reference::ref:Xyz_2020-2021a:2" title="b"><span></span><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a, 1]</a></sup></p>',
|
|
271
|
+
'<p><sup class="reference" data-abbr="Xyz, April 1, 2020" id="reference::ref:Xyz,_April_1,_2020:1" title="b"><span></span><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020]</a></sup></p>',
|
|
272
|
+
'<p><sup class="reference" data-abbr="Xyz, April 1, 2020, 1" id="reference::ref:Xyz,_April_1,_2020:2" title="b"><span></span><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020, 1]</a></sup></p>',
|
|
273
|
+
'<p><sup class="reference" data-abbr="Xyz n.d." id="reference::ref:Xyz_n.d.:1" title="b"><span></span><a href="#reference::def:Xyz_n.d.">[Xyz n.d.]</a></sup></p>',
|
|
274
|
+
'<p><sup class="reference" data-abbr="Xyz n.d., 1" id="reference::ref:Xyz_n.d.:2" title="b"><span></span><a href="#reference::def:Xyz_n.d.">[Xyz n.d., 1]</a></sup></p>',
|
|
275
|
+
'<p><sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2" id="reference::ref:X._Y.,_and_Z_et_al._2020:1" title="b"><span></span><a href="#reference::def:X._Y.,_and_Z_et_al._2020">[X. Y., and Z et al. 2020, 1-2]</a></sup></p>',
|
|
276
|
+
'<p><sup class="reference" data-abbr="A title 2020" id="reference::ref:A_title_2020:1" title="b"><span></span><a href="#reference::def:A_title_2020">[A title 2020]</a></sup></p>',
|
|
277
|
+
'<p><sup class="reference" data-abbr="A title 2020, 1" id="reference::ref:A_title_2020:2" title="b"><span></span><a href="#reference::def:A_title_2020">[A title 2020, 1]</a></sup></p>',
|
|
278
|
+
'<p><sup class="reference" data-abbr="Constitution, art. 2" id="reference::ref:Constitution:1" title="b"><span></span><a href="#reference::def:Constitution">[Constitution, art. 2]</a></sup></p>',
|
|
279
|
+
'<p><sup class="reference" data-abbr="Constitution, art. 2, sec. 1" id="reference::ref:Constitution:2" title="b"><span></span><a href="#reference::def:Constitution">[Constitution, art. 2, sec. 1]</a></sup></p>',
|
|
280
280
|
]);
|
|
281
281
|
});
|
|
282
282
|
|
|
@@ -96,7 +96,7 @@ describe('Unit: parser/block/blockquote', () => {
|
|
|
96
96
|
assert.deepStrictEqual(inspect(parser('!>> ## a\n> ## a')), [['<blockquote><blockquote><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></blockquote><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
97
97
|
assert.deepStrictEqual(inspect(parser('!>> ~ a\n> ~ a')), [['<blockquote><blockquote><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
98
98
|
assert.deepStrictEqual(inspect(parser('!>> ~~~figure $test-a\n>> > \n>>\n~~~\n> ~~~figure $test-a\n> > \n>\n[#a]\n~~~')), [['<blockquote><blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span><span class="figtext"></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span><span class="figtext"><a class="index">a</a></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
99
|
-
assert.deepStrictEqual(inspect(parser('!>> ((a))\n> ((a))')), [['<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><span
|
|
99
|
+
assert.deepStrictEqual(inspect(parser('!>> ((a))\n> ((a))')), [['<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
});
|
|
@@ -23,7 +23,7 @@ describe('Unit: parser/block/extension/example', () => {
|
|
|
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>'], '']);
|
|
25
25
|
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n~ a\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">~ a</pre><hr><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
|
|
26
|
-
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n((a))[[b]]\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">((a))[[b]]</pre><hr><section><p><sup class="annotation disabled" title="a"><span
|
|
26
|
+
assert.deepStrictEqual(inspect(parser('~~~example/markdown\n((a))[[b]]\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">((a))[[b]]</pre><hr><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup><sup class="reference disabled" title="b"><span></span><a>[1]</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"><li><span>b</span><sup><a>^1</a></sup></li></ol></section></aside>'], '']);
|
|
27
27
|
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>'], '']);
|
|
28
28
|
assert.deepStrictEqual(inspect(parser('~~~example/math\na\n~~~')), [['<aside class="example" data-type="math"><pre translate="no">a</pre><hr><div class="math" translate="no">$$\na\n$$</div></aside>'], '']);
|
|
29
29
|
assert.deepStrictEqual(inspect(parser(`~~~example/math\n0${'\n'.repeat(100)}~~~`), '>'), [['<aside class="example" data-type="math">'], '']);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { MarkdownParser } from '../../../markdown';
|
|
2
2
|
import { LinkParser } from '../inline';
|
|
3
|
-
import { Result } from '../../combinator/data/parser';
|
|
4
3
|
import { union, inits, tails, sequence, some, constraint, syntax, creation, precedence, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
|
|
5
4
|
import { inline, media, shortmedia } from '../inline';
|
|
6
5
|
import { attributes } from './html';
|
|
7
6
|
import { linebreak, unescsource, str } from '../source';
|
|
8
7
|
import { Syntax, State } from '../context';
|
|
9
|
-
import {
|
|
8
|
+
import { trimBlankStart, trimNodeEnd } from '../visibility';
|
|
10
9
|
import { stringify } from '../util';
|
|
11
10
|
import { ReadonlyURL } from 'spica/url';
|
|
12
11
|
import { html, define, defrag } from 'typed-dom/dom';
|
|
@@ -27,14 +26,16 @@ export const textlink: LinkParser.TextLinkParser = lazy(() =>
|
|
|
27
26
|
bind(reverse(tails([
|
|
28
27
|
dup(surround(
|
|
29
28
|
'[',
|
|
30
|
-
some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]),
|
|
29
|
+
trimBlankStart(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]])),
|
|
31
30
|
']',
|
|
32
31
|
true)),
|
|
33
32
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
34
33
|
])),
|
|
35
34
|
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
|
|
36
35
|
assert(!html('div', content).querySelector('a, .media, .annotation, .reference'));
|
|
37
|
-
|
|
36
|
+
assert(content[0] !== '');
|
|
37
|
+
if (content.length !== 0 && trimNodeEnd(content = defrag(content)).length === 0) return;
|
|
38
|
+
return [[parse(content, params, context)], rest];
|
|
38
39
|
}))));
|
|
39
40
|
|
|
40
41
|
export const medialink: LinkParser.MediaLinkParser = lazy(() =>
|
|
@@ -48,7 +49,7 @@ export const medialink: LinkParser.MediaLinkParser = lazy(() =>
|
|
|
48
49
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
49
50
|
])),
|
|
50
51
|
([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) =>
|
|
51
|
-
parse(content, params,
|
|
52
|
+
[[parse(defrag(content), params, context)], rest]))));
|
|
52
53
|
|
|
53
54
|
export const linemedialink: LinkParser.LineMediaLinkParser = surround(
|
|
54
55
|
linebreak,
|
|
@@ -65,7 +66,7 @@ export const unsafelink: LinkParser.UnsafeLinkParser = lazy(() =>
|
|
|
65
66
|
dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
|
|
66
67
|
])),
|
|
67
68
|
([params, content = []], rest, context) =>
|
|
68
|
-
parse(content, params,
|
|
69
|
+
[[parse(defrag(content), params, context)], rest]))));
|
|
69
70
|
|
|
70
71
|
export const uri: LinkParser.ParameterParser.UriParser = union([
|
|
71
72
|
open(/^[^\S\n]+/, str(/^\S+/)),
|
|
@@ -79,14 +80,12 @@ export const option: LinkParser.ParameterParser.OptionParser = union([
|
|
|
79
80
|
]);
|
|
80
81
|
|
|
81
82
|
function parse(
|
|
82
|
-
content: (string | HTMLElement)[],
|
|
83
|
+
content: readonly (string | HTMLElement)[],
|
|
83
84
|
params: string[],
|
|
84
|
-
rest: string,
|
|
85
85
|
context: MarkdownParser.Context,
|
|
86
|
-
):
|
|
86
|
+
): HTMLAnchorElement {
|
|
87
87
|
assert(params.length > 0);
|
|
88
88
|
assert(params.every(p => typeof p === 'string'));
|
|
89
|
-
if (content.length !== 0 && trimNode(content).length === 0) return;
|
|
90
89
|
const INSECURE_URI = params.shift()!;
|
|
91
90
|
assert(INSECURE_URI === INSECURE_URI.trim());
|
|
92
91
|
assert(!INSECURE_URI.match(/\s/));
|
|
@@ -95,11 +94,12 @@ function parse(
|
|
|
95
94
|
context.host?.href || location.href);
|
|
96
95
|
const el = elem(
|
|
97
96
|
INSECURE_URI,
|
|
98
|
-
|
|
97
|
+
content,
|
|
99
98
|
uri,
|
|
100
99
|
context.host?.origin || location.origin);
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
return el.className === 'invalid'
|
|
101
|
+
? el
|
|
102
|
+
: define(el, attributes('link', [], optspec, params));
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
function elem(
|
|
@@ -17,14 +17,10 @@ export const mark: MarkParser = lazy(() => surround(
|
|
|
17
17
|
open(some(inline, '=', [[/^\\?\n/, 9]]), mark),
|
|
18
18
|
]))))),
|
|
19
19
|
str('=='), false,
|
|
20
|
-
([, bs], rest, { id
|
|
20
|
+
([, bs], rest, { id }) => {
|
|
21
21
|
const el = html('mark', defrag(bs));
|
|
22
22
|
return [[
|
|
23
|
-
define(el, {
|
|
24
|
-
id: state! & (State.annotation | State.reference)
|
|
25
|
-
? undefined
|
|
26
|
-
: identity(id, signature(el), 'mark'),
|
|
27
|
-
}),
|
|
23
|
+
define(el, { id: identity(id, signature(el), 'mark') }),
|
|
28
24
|
el.id && html('a', { href: `#${el.id}` }),
|
|
29
25
|
], rest];
|
|
30
26
|
},
|
|
@@ -89,7 +89,7 @@ function attributes(texts: string[], rubies: string[]): Record<string, string> {
|
|
|
89
89
|
let attrs: Record<string, string> | undefined;
|
|
90
90
|
for (const ss of [texts, rubies]) {
|
|
91
91
|
for (let i = 0; i < ss.length; ++i) {
|
|
92
|
-
if (ss[i].
|
|
92
|
+
if (!ss[i].includes('\x1B')) continue;
|
|
93
93
|
ss[i] = ss[i].replace(/\x1B/g, '');
|
|
94
94
|
attrs ??= {
|
|
95
95
|
class: 'invalid',
|
|
@@ -28,7 +28,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
28
28
|
[
|
|
29
29
|
html('p', [
|
|
30
30
|
html('sup', { class: 'annotation', id: 'annotation::ref:a_b:1', title: 'a b' }, [
|
|
31
|
-
html('span'
|
|
31
|
+
html('span'),
|
|
32
32
|
html('a', { href: '#annotation::def:a_b:1' }, '*1')
|
|
33
33
|
]),
|
|
34
34
|
]).outerHTML,
|
|
@@ -54,11 +54,11 @@ describe('Unit: parser/processor/note', () => {
|
|
|
54
54
|
[
|
|
55
55
|
html('p', [
|
|
56
56
|
html('sup', { class: 'annotation', id: 'annotation::ref:1:1', title: '1' }, [
|
|
57
|
-
html('span'
|
|
57
|
+
html('span'),
|
|
58
58
|
html('a', { href: '#annotation::def:1:1' }, '*1')
|
|
59
59
|
]),
|
|
60
60
|
html('sup', { class: 'annotation', id: 'annotation::ref:12345678901234567890:1', title: '12345678901234567890' }, [
|
|
61
|
-
html('span'
|
|
61
|
+
html('span'),
|
|
62
62
|
html('a', { href: '#annotation::def:12345678901234567890:1' }, '*2')
|
|
63
63
|
]),
|
|
64
64
|
]).outerHTML,
|
|
@@ -88,23 +88,23 @@ describe('Unit: parser/processor/note', () => {
|
|
|
88
88
|
[
|
|
89
89
|
html('p', [
|
|
90
90
|
html('sup', { class: 'annotation', id: 'annotation::ref:1:1', title: '1' }, [
|
|
91
|
-
html('span'
|
|
91
|
+
html('span'),
|
|
92
92
|
html('a', { href: '#annotation::def:1:1' }, '*1')
|
|
93
93
|
]),
|
|
94
94
|
html('sup', { class: 'annotation', id: 'annotation::ref:2:1', title: '2' }, [
|
|
95
|
-
html('span'
|
|
95
|
+
html('span'),
|
|
96
96
|
html('a', { href: '#annotation::def:2:1' }, '*2')
|
|
97
97
|
]),
|
|
98
98
|
html('sup', { class: 'annotation', id: 'annotation::ref:3:1', title: '3' }, [
|
|
99
|
-
html('span'
|
|
99
|
+
html('span'),
|
|
100
100
|
html('a', { href: '#annotation::def:3:1' }, '*3')
|
|
101
101
|
]),
|
|
102
102
|
html('sup', { class: 'annotation', id: 'annotation::ref:2:2', title: '2' }, [
|
|
103
|
-
html('span'
|
|
103
|
+
html('span'),
|
|
104
104
|
html('a', { href: '#annotation::def:2:1' }, '*2')
|
|
105
105
|
]),
|
|
106
106
|
html('sup', { class: 'annotation', id: 'annotation::ref:4:1', title: '4' }, [
|
|
107
|
-
html('span'
|
|
107
|
+
html('span'),
|
|
108
108
|
html('a', { href: '#annotation::def:4:1' }, '*4')
|
|
109
109
|
]),
|
|
110
110
|
]).outerHTML,
|
|
@@ -151,9 +151,9 @@ describe('Unit: parser/processor/note', () => {
|
|
|
151
151
|
assert.deepStrictEqual(
|
|
152
152
|
[...target.children].map(el => el.outerHTML),
|
|
153
153
|
[
|
|
154
|
-
'<blockquote><blockquote><section><p><sup class="annotation disabled" title="1"><span
|
|
155
|
-
'<aside class="example" data-type="markdown"><pre translate="no">((3))</pre><hr><section><p><sup class="annotation disabled" title="3"><span
|
|
156
|
-
'<p><sup class="annotation" id="annotation::ref:4:1" title="4"><span
|
|
154
|
+
'<blockquote><blockquote><section><p><sup class="annotation disabled" title="1"><span></span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>1</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="2"><span></span><a>*1</a></sup><br>~~~</p><ol class="annotations"><li data-marker="*1"><span>2</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>',
|
|
155
|
+
'<aside class="example" data-type="markdown"><pre translate="no">((3))</pre><hr><section><p><sup class="annotation disabled" title="3"><span></span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>3</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></aside>',
|
|
156
|
+
'<p><sup class="annotation" id="annotation::ref:4:1" title="4"><span></span><a href="#annotation::def:4:1">*1</a></sup></p>',
|
|
157
157
|
]);
|
|
158
158
|
assert.deepStrictEqual(
|
|
159
159
|
note.outerHTML,
|
|
@@ -170,7 +170,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
170
170
|
[
|
|
171
171
|
html('p', [
|
|
172
172
|
html('sup', { class: 'annotation', id: 'annotation::ref:1:1', title: '1' }, [
|
|
173
|
-
html('span'
|
|
173
|
+
html('span'),
|
|
174
174
|
html('a', { href: '#annotation::def:1:1' }, '*1')
|
|
175
175
|
]),
|
|
176
176
|
]).outerHTML,
|
|
@@ -183,19 +183,19 @@ describe('Unit: parser/processor/note', () => {
|
|
|
183
183
|
html('h2', { id: 'index::a' }, 'a').outerHTML,
|
|
184
184
|
html('p', [
|
|
185
185
|
html('sup', { class: 'annotation', id: 'annotation::ref:2:1', title: '2' }, [
|
|
186
|
-
html('span'
|
|
186
|
+
html('span'),
|
|
187
187
|
html('a', { href: '#annotation::def:2:1' }, '*2')
|
|
188
188
|
]),
|
|
189
189
|
html('sup', { class: 'annotation', id: 'annotation::ref:1:2', title: '1' }, [
|
|
190
|
-
html('span'
|
|
190
|
+
html('span'),
|
|
191
191
|
html('a', { href: '#annotation::def:1:2' }, '*3')
|
|
192
192
|
]),
|
|
193
193
|
html('sup', { class: 'annotation', id: 'annotation::ref:3:1', title: '3' }, [
|
|
194
|
-
html('span'
|
|
194
|
+
html('span'),
|
|
195
195
|
html('a', { href: '#annotation::def:3:1' }, '*4')
|
|
196
196
|
]),
|
|
197
197
|
html('sup', { class: 'annotation', id: 'annotation::ref:2:2', title: '2' }, [
|
|
198
|
-
html('span'
|
|
198
|
+
html('span'),
|
|
199
199
|
html('a', { href: '#annotation::def:2:1' }, '*2')
|
|
200
200
|
]),
|
|
201
201
|
]).outerHTML,
|
|
@@ -219,7 +219,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
219
219
|
html('h2', { id: 'index::b' }, 'b').outerHTML,
|
|
220
220
|
html('p', [
|
|
221
221
|
html('sup', { class: 'annotation', id: 'annotation::ref:2:3', title: '2' }, [
|
|
222
|
-
html('span'
|
|
222
|
+
html('span'),
|
|
223
223
|
html('a', { href: '#annotation::def:2:2' }, '*5')
|
|
224
224
|
]),
|
|
225
225
|
]).outerHTML,
|
|
@@ -243,7 +243,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
243
243
|
[
|
|
244
244
|
html('p', [
|
|
245
245
|
html('sup', { class: 'annotation', id: 'annotation:0:ref:a_b:1', title: 'a b' }, [
|
|
246
|
-
html('span'
|
|
246
|
+
html('span'),
|
|
247
247
|
html('a', { href: '#annotation:0:def:a_b:1' }, '*1')
|
|
248
248
|
]),
|
|
249
249
|
]).outerHTML,
|
|
@@ -272,7 +272,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
272
272
|
[
|
|
273
273
|
html('p', [
|
|
274
274
|
html('sup', { class: 'reference', id: 'reference::ref:a_b:1', title: 'a b' }, [
|
|
275
|
-
html('span'
|
|
275
|
+
html('span'),
|
|
276
276
|
html('a', { href: '#reference::def:a_b' }, '[1]')
|
|
277
277
|
]),
|
|
278
278
|
]).outerHTML,
|
|
@@ -298,15 +298,15 @@ describe('Unit: parser/processor/note', () => {
|
|
|
298
298
|
[
|
|
299
299
|
html('p', [
|
|
300
300
|
html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:1', title: 'b' }, [
|
|
301
|
-
html('span'
|
|
301
|
+
html('span'),
|
|
302
302
|
html('a', { href: '#reference::def:A_1' }, '[A 1]')
|
|
303
303
|
]),
|
|
304
304
|
html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:2', title: 'b' }, [
|
|
305
|
-
html('span'
|
|
305
|
+
html('span'),
|
|
306
306
|
html('a', { href: '#reference::def:A_1' }, '[A 1]')
|
|
307
307
|
]),
|
|
308
308
|
html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:3', title: 'b' }, [
|
|
309
|
-
html('span'
|
|
309
|
+
html('span'),
|
|
310
310
|
html('a', { href: '#reference::def:A_1' }, '[A 1]')
|
|
311
311
|
]),
|
|
312
312
|
]).outerHTML,
|
|
@@ -337,16 +337,11 @@ describe('Unit: parser/processor/note', () => {
|
|
|
337
337
|
[
|
|
338
338
|
html('p', [
|
|
339
339
|
html('sup', { class: 'annotation', id: 'annotation::ref:a:1', title: 'a' }, [
|
|
340
|
-
html('span',
|
|
341
|
-
'a',
|
|
342
|
-
html('sup', { class: 'reference', 'data-abbr': 'B' }, [
|
|
343
|
-
html('span'),
|
|
344
|
-
]),
|
|
345
|
-
]),
|
|
340
|
+
html('span'),
|
|
346
341
|
html('a', { href: '#annotation::def:a:1' }, '*1')
|
|
347
342
|
]),
|
|
348
343
|
html('sup', { class: 'reference', 'data-abbr': 'B', id: 'reference::ref:B:1', title: 'c' }, [
|
|
349
|
-
html('span'
|
|
344
|
+
html('span'),
|
|
350
345
|
html('a', { href: '#reference::def:B' }, '[B]')
|
|
351
346
|
]),
|
|
352
347
|
]).outerHTML,
|
|
@@ -355,7 +350,7 @@ describe('Unit: parser/processor/note', () => {
|
|
|
355
350
|
html('span', [
|
|
356
351
|
'a',
|
|
357
352
|
html('sup', { class: 'reference', 'data-abbr': 'B', id: 'reference::ref:B:2', title: 'c' }, [
|
|
358
|
-
html('span'
|
|
353
|
+
html('span'),
|
|
359
354
|
html('a', { href: '#reference::def:B' }, '[B]')
|
|
360
355
|
]),
|
|
361
356
|
]),
|