securemark 0.272.0 → 0.273.0
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 +4 -0
- package/dist/index.js +28 -28
- package/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/parser/api/bind.test.ts +2 -2
- package/src/parser/api/bind.ts +4 -4
- package/src/parser/api/parse.test.ts +7 -7
- package/src/parser/api/parse.ts +4 -4
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/extension/aside.ts +1 -1
- package/src/parser/block/extension/example.ts +1 -1
- package/src/parser/processor/figure.ts +2 -2
- package/src/parser/processor/{footnote.test.ts → note.test.ts} +148 -96
- package/src/parser/processor/{footnote.ts → note.ts} +14 -14
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.
|
|
1
|
+
/*! securemark v0.273.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
|
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
4
4
|
module.exports = factory(require("Prism"), require("DOMPurify"));
|
|
@@ -3904,7 +3904,7 @@ const block_1 = __webpack_require__(4032);
|
|
|
3904
3904
|
const normalize_1 = __webpack_require__(185);
|
|
3905
3905
|
const header_2 = __webpack_require__(7790);
|
|
3906
3906
|
const figure_1 = __webpack_require__(9123);
|
|
3907
|
-
const
|
|
3907
|
+
const note_1 = __webpack_require__(6745);
|
|
3908
3908
|
const url_1 = __webpack_require__(2261);
|
|
3909
3909
|
const array_1 = __webpack_require__(8112);
|
|
3910
3910
|
function bind(target, settings) {
|
|
@@ -4015,7 +4015,7 @@ function bind(target, settings) {
|
|
|
4015
4015
|
type: 'cancel'
|
|
4016
4016
|
};
|
|
4017
4017
|
}
|
|
4018
|
-
for (const el of (0, figure_1.figure)(next(0)?.parentNode ?? target, settings.
|
|
4018
|
+
for (const el of (0, figure_1.figure)(next(0)?.parentNode ?? target, settings.notes, context)) {
|
|
4019
4019
|
el ? yield {
|
|
4020
4020
|
type: 'figure',
|
|
4021
4021
|
value: el
|
|
@@ -4026,9 +4026,9 @@ function bind(target, settings) {
|
|
|
4026
4026
|
type: 'cancel'
|
|
4027
4027
|
};
|
|
4028
4028
|
}
|
|
4029
|
-
for (const el of (0,
|
|
4029
|
+
for (const el of (0, note_1.note)(next(0)?.parentNode ?? target, settings.notes, context, bottom)) {
|
|
4030
4030
|
el ? yield {
|
|
4031
|
-
type: '
|
|
4031
|
+
type: 'note',
|
|
4032
4032
|
value: el
|
|
4033
4033
|
} : yield {
|
|
4034
4034
|
type: 'break'
|
|
@@ -4229,7 +4229,7 @@ const block_1 = __webpack_require__(4032);
|
|
|
4229
4229
|
const normalize_1 = __webpack_require__(185);
|
|
4230
4230
|
const header_2 = __webpack_require__(7790);
|
|
4231
4231
|
const figure_1 = __webpack_require__(9123);
|
|
4232
|
-
const
|
|
4232
|
+
const note_1 = __webpack_require__(6745);
|
|
4233
4233
|
const url_1 = __webpack_require__(2261);
|
|
4234
4234
|
const dom_1 = __webpack_require__(3252);
|
|
4235
4235
|
function parse(source, opts = {}, context) {
|
|
@@ -4265,8 +4265,8 @@ function parse(source, opts = {}, context) {
|
|
|
4265
4265
|
}), []));
|
|
4266
4266
|
}
|
|
4267
4267
|
if (opts.test) return node;
|
|
4268
|
-
for (const _ of (0, figure_1.figure)(node, opts.
|
|
4269
|
-
for (const _ of (0,
|
|
4268
|
+
for (const _ of (0, figure_1.figure)(node, opts.notes, context));
|
|
4269
|
+
for (const _ of (0, note_1.note)(node, opts.notes, context));
|
|
4270
4270
|
return node;
|
|
4271
4271
|
}
|
|
4272
4272
|
exports.parse = parse;
|
|
@@ -4375,7 +4375,7 @@ const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combina
|
|
|
4375
4375
|
});
|
|
4376
4376
|
const document = (0, parse_1.parse)(source, {
|
|
4377
4377
|
id: '',
|
|
4378
|
-
|
|
4378
|
+
notes: {
|
|
4379
4379
|
references
|
|
4380
4380
|
}
|
|
4381
4381
|
}, context);
|
|
@@ -4525,7 +4525,7 @@ exports.aside = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, co
|
|
|
4525
4525
|
});
|
|
4526
4526
|
const document = (0, parse_1.parse)(body.slice(0, -1), {
|
|
4527
4527
|
id: '',
|
|
4528
|
-
|
|
4528
|
+
notes: {
|
|
4529
4529
|
references
|
|
4530
4530
|
}
|
|
4531
4531
|
}, context);
|
|
@@ -4579,7 +4579,7 @@ exports.example = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0,
|
|
|
4579
4579
|
});
|
|
4580
4580
|
const document = (0, parse_1.parse)(body.slice(0, -1), {
|
|
4581
4581
|
id: '',
|
|
4582
|
-
|
|
4582
|
+
notes: {
|
|
4583
4583
|
references
|
|
4584
4584
|
}
|
|
4585
4585
|
}, context);
|
|
@@ -6928,8 +6928,8 @@ const queue_1 = __webpack_require__(4934);
|
|
|
6928
6928
|
const array_1 = __webpack_require__(8112);
|
|
6929
6929
|
const dom_1 = __webpack_require__(3252);
|
|
6930
6930
|
const query_1 = __webpack_require__(6120);
|
|
6931
|
-
function* figure(target,
|
|
6932
|
-
const refs = new queue_1.MultiQueue((0, array_1.push)((0, query_1.querySelectorAll)(target, 'a.label:not(.disabled)[data-label]'),
|
|
6931
|
+
function* figure(target, notes, opts = {}) {
|
|
6932
|
+
const refs = new queue_1.MultiQueue((0, array_1.push)((0, query_1.querySelectorAll)(target, 'a.label:not(.disabled)[data-label]'), notes && (0, query_1.querySelectorAll)(notes.references, 'a.label:not(.disabled)') || []).map(el => [el.getAttribute('data-label'), el]));
|
|
6933
6933
|
const labels = new Set();
|
|
6934
6934
|
const numbers = new Map();
|
|
6935
6935
|
let base = '0';
|
|
@@ -7080,7 +7080,7 @@ function capitalize(label) {
|
|
|
7080
7080
|
|
|
7081
7081
|
/***/ }),
|
|
7082
7082
|
|
|
7083
|
-
/***/
|
|
7083
|
+
/***/ 6745:
|
|
7084
7084
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7085
7085
|
|
|
7086
7086
|
"use strict";
|
|
@@ -7089,25 +7089,25 @@ function capitalize(label) {
|
|
|
7089
7089
|
Object.defineProperty(exports, "__esModule", ({
|
|
7090
7090
|
value: true
|
|
7091
7091
|
}));
|
|
7092
|
-
exports.reference = exports.annotation = exports.
|
|
7092
|
+
exports.reference = exports.annotation = exports.note = void 0;
|
|
7093
7093
|
const indexee_1 = __webpack_require__(1269);
|
|
7094
7094
|
const dom_1 = __webpack_require__(3252);
|
|
7095
|
-
function*
|
|
7095
|
+
function* note(target, notes, opts = {}, bottom = null) {
|
|
7096
7096
|
for (let es = target.querySelectorAll(`.annotations`), len = es.length, i = 0; i < len; ++i) {
|
|
7097
7097
|
const el = es[i];
|
|
7098
7098
|
el.parentNode === target && el.remove();
|
|
7099
7099
|
}
|
|
7100
|
-
yield* (0, exports.annotation)(target,
|
|
7101
|
-
yield* (0, exports.reference)(target,
|
|
7100
|
+
yield* (0, exports.annotation)(target, notes?.annotations, opts, bottom);
|
|
7101
|
+
yield* (0, exports.reference)(target, notes?.references, opts, bottom);
|
|
7102
7102
|
return;
|
|
7103
7103
|
}
|
|
7104
|
-
exports.
|
|
7104
|
+
exports.note = note;
|
|
7105
7105
|
exports.annotation = build('annotation', n => `*${n}`, 'h1, h2, h3, h4, h5, h6, aside.aside, hr');
|
|
7106
7106
|
exports.reference = build('reference', (n, abbr) => `[${abbr || n}]`);
|
|
7107
7107
|
function build(syntax, marker, splitter = '_') {
|
|
7108
7108
|
// Referenceを含むAnnotationの重複排除は両構文が互いに処理済みであることを必要とするため
|
|
7109
7109
|
// 構文ごとに各1回の処理では不可能
|
|
7110
|
-
return function* (target,
|
|
7110
|
+
return function* (target, note, opts = {}, bottom = null) {
|
|
7111
7111
|
const defs = new Map();
|
|
7112
7112
|
const splitters = [];
|
|
7113
7113
|
for (let es = target.querySelectorAll(splitter), len = es.length, i = 0; i < len; ++i) {
|
|
@@ -7166,7 +7166,7 @@ function build(syntax, marker, splitter = '_') {
|
|
|
7166
7166
|
const refId = opts.id !== '' ? `${syntax}:${opts.id ?? ''}:ref:${refIndex}` : undefined;
|
|
7167
7167
|
const def = false || defs.get(identifier) || defs.set(identifier, (0, dom_1.html)('li', {
|
|
7168
7168
|
id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${identifier}` : undefined,
|
|
7169
|
-
'data-marker': !
|
|
7169
|
+
'data-marker': !note ? marker(total + defs.size + 1, abbr) : undefined
|
|
7170
7170
|
}, [(0, dom_1.define)(ref.firstElementChild.cloneNode(true), {
|
|
7171
7171
|
hidden: null
|
|
7172
7172
|
}), (0, dom_1.html)('sup')])).get(identifier);
|
|
@@ -7191,17 +7191,17 @@ function build(syntax, marker, splitter = '_') {
|
|
|
7191
7191
|
title: abbr && (0, indexee_1.text)((0, dom_1.frag)(ref.firstElementChild.cloneNode(true).childNodes)).trim() || undefined
|
|
7192
7192
|
}, `^${refIndex}`));
|
|
7193
7193
|
}
|
|
7194
|
-
if (defs.size > 0 ||
|
|
7195
|
-
yield* proc(defs,
|
|
7194
|
+
if (defs.size > 0 || note) {
|
|
7195
|
+
yield* proc(defs, note ?? target.insertBefore((0, dom_1.html)('ol', {
|
|
7196
7196
|
class: `${syntax}s`
|
|
7197
7197
|
}), splitters[0] ?? bottom));
|
|
7198
7198
|
}
|
|
7199
7199
|
return;
|
|
7200
7200
|
};
|
|
7201
|
-
function* proc(defs,
|
|
7201
|
+
function* proc(defs, note) {
|
|
7202
7202
|
const {
|
|
7203
7203
|
children
|
|
7204
|
-
} =
|
|
7204
|
+
} = note;
|
|
7205
7205
|
const size = defs.size;
|
|
7206
7206
|
let count = 0;
|
|
7207
7207
|
let length = children.length;
|
|
@@ -7211,16 +7211,16 @@ function build(syntax, marker, splitter = '_') {
|
|
|
7211
7211
|
while (length > size) {
|
|
7212
7212
|
const node = children[count - 1];
|
|
7213
7213
|
if (equal(node, def)) continue I;
|
|
7214
|
-
yield
|
|
7214
|
+
yield note.removeChild(node);
|
|
7215
7215
|
--length;
|
|
7216
7216
|
}
|
|
7217
7217
|
const node = count <= length ? children[count - 1] : null;
|
|
7218
7218
|
if (node && equal(node, def)) continue;
|
|
7219
|
-
yield
|
|
7219
|
+
yield note.insertBefore(def, node);
|
|
7220
7220
|
++length;
|
|
7221
7221
|
}
|
|
7222
7222
|
while (length > size) {
|
|
7223
|
-
yield
|
|
7223
|
+
yield note.removeChild(children[size]);
|
|
7224
7224
|
--length;
|
|
7225
7225
|
}
|
|
7226
7226
|
return;
|
package/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface ParserSettings {
|
|
|
32
32
|
readonly id?: string;
|
|
33
33
|
// For editing.
|
|
34
34
|
readonly caches?: Partial<Caches>;
|
|
35
|
-
readonly
|
|
35
|
+
readonly notes: {
|
|
36
36
|
readonly references: HTMLOListElement;
|
|
37
37
|
};
|
|
38
38
|
readonly chunk?: boolean;
|
|
@@ -42,7 +42,7 @@ export type Progress =
|
|
|
42
42
|
| { readonly type: 'segment'; readonly value: string; }
|
|
43
43
|
| { readonly type: 'block'; readonly value: HTMLElement; }
|
|
44
44
|
| { readonly type: 'figure'; readonly value: HTMLAnchorElement; }
|
|
45
|
-
| { readonly type: '
|
|
45
|
+
| { readonly type: 'note'; readonly value: HTMLLIElement | HTMLElement; }
|
|
46
46
|
| { readonly type: 'break'; }
|
|
47
47
|
| { readonly type: 'cancel'; };
|
|
48
48
|
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ describe('Unit: parser/api/bind', () => {
|
|
|
27
27
|
return acc;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const cfgs = {
|
|
30
|
+
const cfgs = { notes: { references: html('ol') } };
|
|
31
31
|
|
|
32
32
|
it('huge input', () => {
|
|
33
33
|
const iter = bind(html('div'), { ...cfgs, id: '' }).parse(`${'\n'.repeat(10 * 1000 ** 2)}`);
|
|
@@ -211,7 +211,7 @@ describe('Unit: parser/api/bind', () => {
|
|
|
211
211
|
]).outerHTML,
|
|
212
212
|
]);
|
|
213
213
|
assert.deepStrictEqual(
|
|
214
|
-
cfgs.
|
|
214
|
+
cfgs.notes.references?.outerHTML,
|
|
215
215
|
html('ol', [
|
|
216
216
|
html('li', { id: 'reference::def:1' }, [
|
|
217
217
|
html('span', '1'),
|
package/src/parser/api/bind.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { State } from '../context';
|
|
|
9
9
|
import { normalize } from './normalize';
|
|
10
10
|
import { headers } from './header';
|
|
11
11
|
import { figure } from '../processor/figure';
|
|
12
|
-
import {
|
|
12
|
+
import { note } from '../processor/note';
|
|
13
13
|
import { ReadonlyURL } from 'spica/url';
|
|
14
14
|
import { push, splice } from 'spica/array';
|
|
15
15
|
|
|
@@ -116,17 +116,17 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
|
|
|
116
116
|
yield { type: 'block', value: el };
|
|
117
117
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
118
118
|
}
|
|
119
|
-
for (const el of figure(next(0)?.parentNode ?? target, settings.
|
|
119
|
+
for (const el of figure(next(0)?.parentNode ?? target, settings.notes, context)) {
|
|
120
120
|
assert(rev === revision);
|
|
121
121
|
el
|
|
122
122
|
? yield { type: 'figure', value: el }
|
|
123
123
|
: yield { type: 'break' };
|
|
124
124
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
125
125
|
}
|
|
126
|
-
for (const el of
|
|
126
|
+
for (const el of note(next(0)?.parentNode ?? target, settings.notes, context, bottom)) {
|
|
127
127
|
assert(rev === revision);
|
|
128
128
|
el
|
|
129
|
-
? yield { type: '
|
|
129
|
+
? yield { type: 'note', value: el }
|
|
130
130
|
: yield { type: 'break' };
|
|
131
131
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
132
132
|
}
|
|
@@ -201,18 +201,18 @@ describe('Unit: parser/api/parse', () => {
|
|
|
201
201
|
]);
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
-
it('
|
|
205
|
-
const
|
|
204
|
+
it('note', () => {
|
|
205
|
+
const notes = { references: html('ol') };
|
|
206
206
|
assert.deepStrictEqual(
|
|
207
|
-
[...parse('$-a\n$$\n$$\n\n(($-a[[b]][[
|
|
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:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference"><span
|
|
211
|
-
'<ol class="annotations"><li id="annotation::def:(1)" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference"
|
|
210
|
+
'<p><sup class="annotation" id="annotation::ref:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="b"><span></span></sup></span><a href="#annotation::def:(1)">*1</a></sup><sup class="reference" data-abbr="b" id="reference::ref:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><a href="#reference::def:b">[b]</a></sup></p>',
|
|
211
|
+
'<ol class="annotations"><li id="annotation::def:(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:2" title="(1)"><span hidden=""></span><a href="#reference::def:b">[b]</a></sup></span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>',
|
|
212
212
|
]);
|
|
213
213
|
assert.deepStrictEqual(
|
|
214
|
-
|
|
215
|
-
'<ol><li id="reference::def:b"><span>
|
|
214
|
+
notes.references.outerHTML,
|
|
215
|
+
'<ol><li id="reference::def:b"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><sup><a href="#reference::ref:1" title="(1)">^1</a><a href="#reference::ref:2">^2</a></sup></li></ol>');
|
|
216
216
|
});
|
|
217
217
|
|
|
218
218
|
it('normalize', () => {
|
package/src/parser/api/parse.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { State } from '../context';
|
|
|
9
9
|
import { normalize } from './normalize';
|
|
10
10
|
import { headers } from './header';
|
|
11
11
|
import { figure } from '../processor/figure';
|
|
12
|
-
import {
|
|
12
|
+
import { note } from '../processor/note';
|
|
13
13
|
import { ReadonlyURL } from 'spica/url';
|
|
14
14
|
import { frag } from 'typed-dom/dom';
|
|
15
15
|
|
|
@@ -41,9 +41,9 @@ export function parse(source: string, opts: Options = {}, context?: MarkdownPars
|
|
|
41
41
|
}
|
|
42
42
|
assert(opts.id !== '' || !node.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
|
|
43
43
|
if (opts.test) return node;
|
|
44
|
-
for (const _ of figure(node, opts.
|
|
45
|
-
for (const _ of
|
|
44
|
+
for (const _ of figure(node, opts.notes, context));
|
|
45
|
+
for (const _ of note(node, opts.notes, context));
|
|
46
46
|
assert(opts.id !== '' || !node.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
|
|
47
|
-
assert(opts.id !== '' || !opts.
|
|
47
|
+
assert(opts.id !== '' || !opts.notes?.references.querySelector('[id], .index[href], .label[href]'));
|
|
48
48
|
return node;
|
|
49
49
|
}
|
|
@@ -26,7 +26,7 @@ export const example: ExtensionParser.ExampleParser = block(validate('~~~', fmap
|
|
|
26
26
|
const references = html('ol', { class: 'references' });
|
|
27
27
|
const document = parse(body.slice(0, -1), {
|
|
28
28
|
id: '',
|
|
29
|
-
|
|
29
|
+
notes: {
|
|
30
30
|
references,
|
|
31
31
|
},
|
|
32
32
|
}, context);
|
|
@@ -6,12 +6,12 @@ import { querySelectorAll } from 'typed-dom/query';
|
|
|
6
6
|
|
|
7
7
|
export function* figure(
|
|
8
8
|
target: ParentNode & Node,
|
|
9
|
-
|
|
9
|
+
notes?: { readonly references: HTMLOListElement; },
|
|
10
10
|
opts: { readonly id?: string; } = {},
|
|
11
11
|
): Generator<HTMLAnchorElement | undefined, undefined, undefined> {
|
|
12
12
|
const refs = new MultiQueue<string, HTMLAnchorElement>(push(
|
|
13
13
|
querySelectorAll(target, 'a.label:not(.disabled)[data-label]'),
|
|
14
|
-
|
|
14
|
+
notes && querySelectorAll(notes.references, 'a.label:not(.disabled)') || [])
|
|
15
15
|
.map(el => [el.getAttribute('data-label')!, el]));
|
|
16
16
|
const labels = new Set<string>();
|
|
17
17
|
const numbers = new Map<string, string>();
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { note, annotation, reference } from './note';
|
|
2
2
|
import { parse as parse_ } from '../../parser';
|
|
3
3
|
import { html } from 'typed-dom/dom';
|
|
4
4
|
|
|
5
5
|
const parse = (s: string) => parse_(s, { test: true });
|
|
6
6
|
|
|
7
|
-
describe('Unit: parser/processor/
|
|
7
|
+
describe('Unit: parser/processor/note', () => {
|
|
8
8
|
describe('annotation', () => {
|
|
9
9
|
it('empty', () => {
|
|
10
10
|
const target = parse('');
|
|
11
|
-
const
|
|
12
|
-
[...annotation(target,
|
|
11
|
+
const note = html('ol');
|
|
12
|
+
[...annotation(target, note)];
|
|
13
13
|
assert.deepStrictEqual(
|
|
14
14
|
[...target.children].map(el => el.outerHTML),
|
|
15
15
|
[]);
|
|
16
16
|
assert.deepStrictEqual(
|
|
17
|
-
|
|
17
|
+
note.outerHTML,
|
|
18
18
|
html('ol').outerHTML);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('1', () => {
|
|
22
22
|
const target = parse('((a b))');
|
|
23
|
-
const
|
|
23
|
+
const note = html('ol');
|
|
24
24
|
for (let i = 0; i < 3; ++i) {
|
|
25
|
-
assert.deepStrictEqual([...annotation(target,
|
|
25
|
+
assert.deepStrictEqual([...annotation(target, note)].length, i === 0 ? 2 : 1);
|
|
26
26
|
assert.deepStrictEqual(
|
|
27
27
|
[...target.children].map(el => el.outerHTML),
|
|
28
28
|
[
|
|
29
29
|
html('p', [
|
|
30
|
-
html('sup', { class:
|
|
30
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: 'a b' }, [
|
|
31
31
|
html('span', { hidden: '' }, 'a b'),
|
|
32
|
-
html('a', { href:
|
|
32
|
+
html('a', { href: '#annotation::def:a_b' }, '*1')
|
|
33
33
|
]),
|
|
34
34
|
]).outerHTML,
|
|
35
35
|
]);
|
|
36
36
|
assert.deepStrictEqual(
|
|
37
|
-
|
|
37
|
+
note.outerHTML,
|
|
38
38
|
html('ol', [
|
|
39
39
|
html('li', { id: 'annotation::def:a_b' }, [
|
|
40
40
|
html('span', 'a b'),
|
|
41
|
-
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
41
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
42
42
|
]),
|
|
43
43
|
]).outerHTML);
|
|
44
44
|
}
|
|
@@ -46,33 +46,33 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
46
46
|
|
|
47
47
|
it('2', () => {
|
|
48
48
|
const target = parse('((1))((12345678901234567890))');
|
|
49
|
-
const
|
|
49
|
+
const note = html('ol');
|
|
50
50
|
for (let i = 0; i < 3; ++i) {
|
|
51
|
-
assert.deepStrictEqual([...annotation(target,
|
|
51
|
+
assert.deepStrictEqual([...annotation(target, note)].length, i === 0 ? 4 : 2);
|
|
52
52
|
assert.deepStrictEqual(
|
|
53
53
|
[...target.children].map(el => el.outerHTML),
|
|
54
54
|
[
|
|
55
55
|
html('p', [
|
|
56
|
-
html('sup', { class:
|
|
56
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: '1' }, [
|
|
57
57
|
html('span', { hidden: '' }, '1'),
|
|
58
|
-
html('a', { href:
|
|
58
|
+
html('a', { href: '#annotation::def:1' }, '*1')
|
|
59
59
|
]),
|
|
60
|
-
html('sup', { class:
|
|
60
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2', title: '12345678901234567890' }, [
|
|
61
61
|
html('span', { hidden: '' }, '12345678901234567890'),
|
|
62
|
-
html('a', { href:
|
|
62
|
+
html('a', { href: '#annotation::def:12345678901234567890' }, '*2')
|
|
63
63
|
]),
|
|
64
64
|
]).outerHTML,
|
|
65
65
|
]);
|
|
66
66
|
assert.deepStrictEqual(
|
|
67
|
-
|
|
67
|
+
note.outerHTML,
|
|
68
68
|
html('ol', [
|
|
69
69
|
html('li', { id: 'annotation::def:1' }, [
|
|
70
70
|
html('span', '1'),
|
|
71
|
-
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
71
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
72
72
|
]),
|
|
73
73
|
html('li', { id: 'annotation::def:12345678901234567890' }, [
|
|
74
74
|
html('span', '12345678901234567890'),
|
|
75
|
-
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
|
|
75
|
+
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')]),
|
|
76
76
|
]),
|
|
77
77
|
]).outerHTML);
|
|
78
78
|
}
|
|
@@ -80,41 +80,41 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
80
80
|
|
|
81
81
|
it('unify', () => {
|
|
82
82
|
const target = parse('((1))((2))((3))((2))((4))');
|
|
83
|
-
const
|
|
83
|
+
const note = html('ol');
|
|
84
84
|
for (let i = 0; i < 3; ++i) {
|
|
85
|
-
[...annotation(target,
|
|
85
|
+
[...annotation(target, note)];
|
|
86
86
|
assert.deepStrictEqual(
|
|
87
87
|
[...target.children].map(el => el.outerHTML),
|
|
88
88
|
[
|
|
89
89
|
html('p', [
|
|
90
|
-
html('sup', { class:
|
|
90
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: '1' }, [
|
|
91
91
|
html('span', { hidden: '' }, '1'),
|
|
92
|
-
html('a', { href:
|
|
92
|
+
html('a', { href: '#annotation::def:1' }, '*1')
|
|
93
93
|
]),
|
|
94
|
-
html('sup', { class:
|
|
94
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2', title: '2' }, [
|
|
95
95
|
html('span', { hidden: '' }, '2'),
|
|
96
|
-
html('a', { href:
|
|
96
|
+
html('a', { href: '#annotation::def:2' }, '*2')
|
|
97
97
|
]),
|
|
98
|
-
html('sup', { class:
|
|
98
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:3', title: '3' }, [
|
|
99
99
|
html('span', { hidden: '' }, '3'),
|
|
100
|
-
html('a', { href:
|
|
100
|
+
html('a', { href: '#annotation::def:3' }, '*3')
|
|
101
101
|
]),
|
|
102
|
-
html('sup', { class:
|
|
102
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:4', title: '2' }, [
|
|
103
103
|
html('span', { hidden: '' }, '2'),
|
|
104
|
-
html('a', { href:
|
|
104
|
+
html('a', { href: '#annotation::def:2' }, '*2')
|
|
105
105
|
]),
|
|
106
|
-
html('sup', { class:
|
|
106
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:5', title: '4' }, [
|
|
107
107
|
html('span', { hidden: '' }, '4'),
|
|
108
|
-
html('a', { href:
|
|
108
|
+
html('a', { href: '#annotation::def:4' }, '*4')
|
|
109
109
|
]),
|
|
110
110
|
]).outerHTML,
|
|
111
111
|
]);
|
|
112
112
|
assert.deepStrictEqual(
|
|
113
|
-
|
|
113
|
+
note.outerHTML,
|
|
114
114
|
html('ol', [
|
|
115
115
|
html('li', { id: 'annotation::def:1' }, [
|
|
116
116
|
html('span', '1'),
|
|
117
|
-
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
117
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
118
118
|
]),
|
|
119
119
|
html('li', { id: 'annotation::def:2' }, [
|
|
120
120
|
html('span', '2'),
|
|
@@ -125,17 +125,17 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
125
125
|
]),
|
|
126
126
|
html('li', { id: 'annotation::def:3' }, [
|
|
127
127
|
html('span', '3'),
|
|
128
|
-
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
|
|
128
|
+
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')]),
|
|
129
129
|
]),
|
|
130
130
|
html('li', { id: 'annotation::def:4' }, [
|
|
131
131
|
html('span', '4'),
|
|
132
|
-
html('sup', [html('a', { href: '#annotation::ref:5' }, '^5')])
|
|
132
|
+
html('sup', [html('a', { href: '#annotation::ref:5' }, '^5')]),
|
|
133
133
|
]),
|
|
134
134
|
]).outerHTML);
|
|
135
135
|
}
|
|
136
|
-
[...annotation(parse(''),
|
|
136
|
+
[...annotation(parse(''), note)];
|
|
137
137
|
assert.deepStrictEqual(
|
|
138
|
-
|
|
138
|
+
note.outerHTML,
|
|
139
139
|
html('ol').outerHTML);
|
|
140
140
|
});
|
|
141
141
|
|
|
@@ -145,9 +145,9 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
145
145
|
'~~~~example/markdown\n((3))\n~~~~',
|
|
146
146
|
'((4))',
|
|
147
147
|
].join('\n\n')).children);
|
|
148
|
-
const
|
|
148
|
+
const note = html('ol');
|
|
149
149
|
for (let i = 0; i < 3; ++i) {
|
|
150
|
-
[...annotation(target,
|
|
150
|
+
[...annotation(target, note)];
|
|
151
151
|
assert.deepStrictEqual(
|
|
152
152
|
[...target.children].map(el => el.outerHTML),
|
|
153
153
|
[
|
|
@@ -156,92 +156,92 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
156
156
|
'<p><sup class="annotation" id="annotation::ref:1" title="4"><span hidden="">4</span><a href="#annotation::def:4">*1</a></sup></p>',
|
|
157
157
|
]);
|
|
158
158
|
assert.deepStrictEqual(
|
|
159
|
-
|
|
159
|
+
note.outerHTML,
|
|
160
160
|
'<ol><li id="annotation::def:4"><span>4</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>');
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
-
it('id', () => {
|
|
165
|
-
const target = parse('((a b))');
|
|
166
|
-
const footnote = html('ol');
|
|
167
|
-
for (let i = 0; i < 3; ++i) {
|
|
168
|
-
assert.deepStrictEqual([...annotation(target, footnote, { id: '0' })].length, i === 0 ? 2 : 1);
|
|
169
|
-
assert.deepStrictEqual(
|
|
170
|
-
[...target.children].map(el => el.outerHTML),
|
|
171
|
-
[
|
|
172
|
-
html('p', [
|
|
173
|
-
html('sup', { class: "annotation", id: "annotation:0:ref:1", title: "a b" }, [
|
|
174
|
-
html('span', { hidden: '' }, 'a b'),
|
|
175
|
-
html('a', { href: "#annotation:0:def:a_b" }, '*1')
|
|
176
|
-
]),
|
|
177
|
-
]).outerHTML,
|
|
178
|
-
]);
|
|
179
|
-
assert.deepStrictEqual(
|
|
180
|
-
footnote.outerHTML,
|
|
181
|
-
html('ol', [
|
|
182
|
-
html('li', { id: 'annotation:0:def:a_b' }, [
|
|
183
|
-
html('span', 'a b'),
|
|
184
|
-
html('sup', [html('a', { href: '#annotation:0:ref:1' }, '^1')])
|
|
185
|
-
]),
|
|
186
|
-
]).outerHTML);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
164
|
it('split', () => {
|
|
191
165
|
const target = parse('((1))\n\n## a\n\n## b\n\n((2))((3))\n\n## c\n\n((4))');
|
|
192
166
|
for (let i = 0; i < 3; ++i) {
|
|
193
|
-
[...
|
|
167
|
+
[...note(target)];
|
|
194
168
|
assert.deepStrictEqual(
|
|
195
169
|
[...target.children].map(el => el.outerHTML),
|
|
196
170
|
[
|
|
197
171
|
html('p', [
|
|
198
|
-
html('sup', { class:
|
|
172
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: '1' }, [
|
|
199
173
|
html('span', { hidden: '' }, '1'),
|
|
200
|
-
html('a', { href:
|
|
174
|
+
html('a', { href: '#annotation::def:1' }, '*1')
|
|
201
175
|
]),
|
|
202
176
|
]).outerHTML,
|
|
203
177
|
html('ol', { class: 'annotations' }, [
|
|
204
178
|
html('li', { id: 'annotation::def:1', 'data-marker': '*1' }, [
|
|
205
179
|
html('span', '1'),
|
|
206
|
-
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
180
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')]),
|
|
207
181
|
]),
|
|
208
182
|
]).outerHTML,
|
|
209
183
|
html('h2', { id: 'index::a' }, 'a').outerHTML,
|
|
210
184
|
html('h2', { id: 'index::b' }, 'b').outerHTML,
|
|
211
185
|
html('p', [
|
|
212
|
-
html('sup', { class:
|
|
186
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:2', title: '2' }, [
|
|
213
187
|
html('span', { hidden: '' }, '2'),
|
|
214
|
-
html('a', { href:
|
|
188
|
+
html('a', { href: '#annotation::def:2' }, '*2')
|
|
215
189
|
]),
|
|
216
|
-
html('sup', { class:
|
|
190
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:3', title: '3' }, [
|
|
217
191
|
html('span', { hidden: '' }, '3'),
|
|
218
|
-
html('a', { href:
|
|
192
|
+
html('a', { href: '#annotation::def:3' }, '*3')
|
|
219
193
|
]),
|
|
220
194
|
]).outerHTML,
|
|
221
195
|
html('ol', { class: 'annotations' }, [
|
|
222
196
|
html('li', { id: 'annotation::def:2', 'data-marker': '*2' }, [
|
|
223
197
|
html('span', '2'),
|
|
224
|
-
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
|
|
198
|
+
html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')]),
|
|
225
199
|
]),
|
|
226
200
|
html('li', { id: 'annotation::def:3', 'data-marker': '*3' }, [
|
|
227
201
|
html('span', '3'),
|
|
228
|
-
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
|
|
202
|
+
html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')]),
|
|
229
203
|
]),
|
|
230
204
|
]).outerHTML,
|
|
231
205
|
html('h2', { id: 'index::c' }, 'c').outerHTML,
|
|
232
206
|
html('p', [
|
|
233
|
-
html('sup', { class:
|
|
207
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:4', title: '4' }, [
|
|
234
208
|
html('span', { hidden: '' }, '4'),
|
|
235
|
-
html('a', { href:
|
|
209
|
+
html('a', { href: '#annotation::def:4' }, '*4')
|
|
236
210
|
]),
|
|
237
211
|
]).outerHTML,
|
|
238
212
|
html('ol', { class: 'annotations' }, [
|
|
239
213
|
html('li', { id: 'annotation::def:4', 'data-marker': '*4' }, [
|
|
240
214
|
html('span', '4'),
|
|
241
|
-
html('sup', [html('a', { href: '#annotation::ref:4' }, '^4')])
|
|
215
|
+
html('sup', [html('a', { href: '#annotation::ref:4' }, '^4')]),
|
|
216
|
+
]),
|
|
217
|
+
]).outerHTML,
|
|
218
|
+
]);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('id', () => {
|
|
223
|
+
const target = parse('((a b))');
|
|
224
|
+
const note = html('ol');
|
|
225
|
+
for (let i = 0; i < 3; ++i) {
|
|
226
|
+
assert.deepStrictEqual([...annotation(target, note, { id: '0' })].length, i === 0 ? 2 : 1);
|
|
227
|
+
assert.deepStrictEqual(
|
|
228
|
+
[...target.children].map(el => el.outerHTML),
|
|
229
|
+
[
|
|
230
|
+
html('p', [
|
|
231
|
+
html('sup', { class: 'annotation', id: 'annotation:0:ref:1', title: 'a b' }, [
|
|
232
|
+
html('span', { hidden: '' }, 'a b'),
|
|
233
|
+
html('a', { href: '#annotation:0:def:a_b' }, '*1')
|
|
242
234
|
]),
|
|
243
235
|
]).outerHTML,
|
|
244
236
|
]);
|
|
237
|
+
assert.deepStrictEqual(
|
|
238
|
+
note.outerHTML,
|
|
239
|
+
html('ol', [
|
|
240
|
+
html('li', { id: 'annotation:0:def:a_b' }, [
|
|
241
|
+
html('span', 'a b'),
|
|
242
|
+
html('sup', [html('a', { href: '#annotation:0:ref:1' }, '^1')]),
|
|
243
|
+
]),
|
|
244
|
+
]).outerHTML);
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
|
|
@@ -250,55 +250,55 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
250
250
|
describe('reference', () => {
|
|
251
251
|
it('1', () => {
|
|
252
252
|
const target = parse('[[a b]]');
|
|
253
|
-
const
|
|
253
|
+
const note = html('ol');
|
|
254
254
|
for (let i = 0; i < 3; ++i) {
|
|
255
|
-
[...reference(target,
|
|
255
|
+
[...reference(target, note)];
|
|
256
256
|
assert.deepStrictEqual(
|
|
257
257
|
[...target.children].map(el => el.outerHTML),
|
|
258
258
|
[
|
|
259
259
|
html('p', [
|
|
260
|
-
html('sup', { class:
|
|
260
|
+
html('sup', { class: 'reference', id: 'reference::ref:1', title: 'a b' }, [
|
|
261
261
|
html('span', { hidden: '' }, 'a b'),
|
|
262
|
-
html('a', { href:
|
|
262
|
+
html('a', { href: '#reference::def:a_b' }, '[1]')
|
|
263
263
|
]),
|
|
264
264
|
]).outerHTML,
|
|
265
265
|
]);
|
|
266
266
|
assert.deepStrictEqual(
|
|
267
|
-
|
|
267
|
+
note.outerHTML,
|
|
268
268
|
html('ol', [
|
|
269
269
|
html('li', { id: 'reference::def:a_b' }, [
|
|
270
270
|
html('span', 'a b'),
|
|
271
|
-
html('sup', [html('a', { href: '#reference::ref:1' }, '^1')])
|
|
271
|
+
html('sup', [html('a', { href: '#reference::ref:1' }, '^1')]),
|
|
272
272
|
]),
|
|
273
273
|
]).outerHTML);
|
|
274
274
|
}
|
|
275
275
|
});
|
|
276
276
|
|
|
277
277
|
it('abbr', () => {
|
|
278
|
-
const target = parse('[[^a|
|
|
279
|
-
const
|
|
278
|
+
const target = parse('[[^a|b]][[^a]][[^a]]');
|
|
279
|
+
const note = html('ol');
|
|
280
280
|
for (let i = 0; i < 3; ++i) {
|
|
281
|
-
[...reference(target,
|
|
281
|
+
[...reference(target, note)];
|
|
282
282
|
assert.deepStrictEqual(
|
|
283
283
|
[...target.children].map(el => el.outerHTML),
|
|
284
284
|
[
|
|
285
285
|
html('p', [
|
|
286
|
-
html('sup', { class:
|
|
286
|
+
html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:1', title: 'b' }, [
|
|
287
287
|
html('span', { hidden: '' }, 'b'),
|
|
288
|
-
html('a', { href:
|
|
288
|
+
html('a', { href: '#reference::def:a' }, '[a]')
|
|
289
289
|
]),
|
|
290
|
-
html('sup', { class:
|
|
290
|
+
html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:2', title: 'b' }, [
|
|
291
291
|
html('span', { hidden: '' }),
|
|
292
|
-
html('a', { href:
|
|
292
|
+
html('a', { href: '#reference::def:a' }, '[a]')
|
|
293
293
|
]),
|
|
294
|
-
html('sup', { class:
|
|
294
|
+
html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:3', title: 'b' }, [
|
|
295
295
|
html('span', { hidden: '' }),
|
|
296
|
-
html('a', { href:
|
|
296
|
+
html('a', { href: '#reference::def:a' }, '[a]')
|
|
297
297
|
]),
|
|
298
298
|
]).outerHTML,
|
|
299
299
|
]);
|
|
300
300
|
assert.deepStrictEqual(
|
|
301
|
-
|
|
301
|
+
note.outerHTML,
|
|
302
302
|
html('ol', [
|
|
303
303
|
html('li', { id: 'reference::def:a' }, [
|
|
304
304
|
html('span', 'b'),
|
|
@@ -312,6 +312,58 @@ describe('Unit: parser/processor/footnote', () => {
|
|
|
312
312
|
}
|
|
313
313
|
});
|
|
314
314
|
|
|
315
|
+
it('nest', () => {
|
|
316
|
+
const target = parse('((a[[^b]]))[[^b|c]]');
|
|
317
|
+
const note = html('ol');
|
|
318
|
+
for (let i = 0; i < 3; ++i) {
|
|
319
|
+
[...annotation(target)];
|
|
320
|
+
[...reference(target, note)];
|
|
321
|
+
assert.deepStrictEqual(
|
|
322
|
+
[...target.children].map(el => el.outerHTML),
|
|
323
|
+
[
|
|
324
|
+
html('p', [
|
|
325
|
+
html('sup', { class: 'annotation', id: 'annotation::ref:1', title: 'a' }, [
|
|
326
|
+
html('span', { hidden: '' }, [
|
|
327
|
+
'a',
|
|
328
|
+
html('sup', { class: 'reference', 'data-abbr': 'b' }, [
|
|
329
|
+
html('span'),
|
|
330
|
+
]),
|
|
331
|
+
]),
|
|
332
|
+
html('a', { href: '#annotation::def:a' }, '*1')
|
|
333
|
+
]),
|
|
334
|
+
html('sup', { class: 'reference', 'data-abbr': 'b', id: 'reference::ref:1', title: 'c' }, [
|
|
335
|
+
html('span', { hidden: '' }, 'c'),
|
|
336
|
+
html('a', { href: '#reference::def:b' }, '[b]')
|
|
337
|
+
]),
|
|
338
|
+
]).outerHTML,
|
|
339
|
+
html('ol', { class: 'annotations' }, [
|
|
340
|
+
html('li', { id: 'annotation::def:a', 'data-marker': '*1' }, [
|
|
341
|
+
html('span', [
|
|
342
|
+
'a',
|
|
343
|
+
html('sup', { class: 'reference', 'data-abbr': 'b', id: 'reference::ref:2', title: 'c' }, [
|
|
344
|
+
html('span', { hidden: '' }),
|
|
345
|
+
html('a', { href: '#reference::def:b' }, '[b]')
|
|
346
|
+
]),
|
|
347
|
+
]),
|
|
348
|
+
html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
|
|
349
|
+
]),
|
|
350
|
+
]).outerHTML,
|
|
351
|
+
]);
|
|
352
|
+
assert.deepStrictEqual(
|
|
353
|
+
note.outerHTML,
|
|
354
|
+
html('ol', [
|
|
355
|
+
html('li', { id: 'reference::def:b' }, [
|
|
356
|
+
html('span', 'c'),
|
|
357
|
+
html('sup', [
|
|
358
|
+
html('a', { href: '#reference::ref:1', title: 'c' }, '^1'),
|
|
359
|
+
html('a', { href: '#reference::ref:2' }, '^2'),
|
|
360
|
+
]),
|
|
361
|
+
]),
|
|
362
|
+
]).outerHTML);
|
|
363
|
+
target.lastChild?.remove();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
315
367
|
});
|
|
316
368
|
|
|
317
369
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { identity, text } from '../inline/extension/indexee';
|
|
2
2
|
import { frag, html, define } from 'typed-dom/dom';
|
|
3
3
|
|
|
4
|
-
export function*
|
|
4
|
+
export function* note(
|
|
5
5
|
target: ParentNode & Node,
|
|
6
|
-
|
|
6
|
+
notes?: { readonly annotations?: HTMLOListElement; readonly references: HTMLOListElement; },
|
|
7
7
|
opts: { readonly id?: string; } = {},
|
|
8
8
|
bottom: Node | null = null,
|
|
9
9
|
): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
|
|
@@ -12,8 +12,8 @@ export function* footnote(
|
|
|
12
12
|
const el = es[i];
|
|
13
13
|
el.parentNode === target && el.remove();
|
|
14
14
|
}
|
|
15
|
-
yield* annotation(target,
|
|
16
|
-
yield* reference(target,
|
|
15
|
+
yield* annotation(target, notes?.annotations, opts, bottom);
|
|
16
|
+
yield* reference(target, notes?.references, opts, bottom);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -30,7 +30,7 @@ function build(
|
|
|
30
30
|
// 構文ごとに各1回の処理では不可能
|
|
31
31
|
return function* (
|
|
32
32
|
target: ParentNode & Node,
|
|
33
|
-
|
|
33
|
+
note?: HTMLOListElement,
|
|
34
34
|
opts: { readonly id?: string } = {},
|
|
35
35
|
bottom: Node | null = null,
|
|
36
36
|
): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
|
|
@@ -104,7 +104,7 @@ function build(
|
|
|
104
104
|
|| defs.set(identifier, html('li',
|
|
105
105
|
{
|
|
106
106
|
id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${identifier}` : undefined,
|
|
107
|
-
'data-marker': !
|
|
107
|
+
'data-marker': !note ? marker(total + defs.size + 1, abbr) : undefined,
|
|
108
108
|
},
|
|
109
109
|
[define(ref.firstElementChild!.cloneNode(true), { hidden: null }), html('sup')]))
|
|
110
110
|
.get(identifier)!;
|
|
@@ -134,14 +134,14 @@ function build(
|
|
|
134
134
|
},
|
|
135
135
|
`^${refIndex}`));
|
|
136
136
|
}
|
|
137
|
-
if (defs.size > 0 ||
|
|
138
|
-
yield* proc(defs,
|
|
137
|
+
if (defs.size > 0 || note) {
|
|
138
|
+
yield* proc(defs, note ?? target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0] ?? bottom));
|
|
139
139
|
}
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function* proc(defs: Map<string, HTMLLIElement>,
|
|
144
|
-
const { children } =
|
|
143
|
+
function* proc(defs: Map<string, HTMLLIElement>, note: HTMLOListElement): Generator<HTMLLIElement | undefined, undefined, undefined> {
|
|
144
|
+
const { children } = note;
|
|
145
145
|
const size = defs.size;
|
|
146
146
|
let count = 0;
|
|
147
147
|
let length = children.length;
|
|
@@ -152,7 +152,7 @@ function build(
|
|
|
152
152
|
while (length > size) {
|
|
153
153
|
const node = children[count - 1] as HTMLLIElement;
|
|
154
154
|
if (equal(node, def)) continue I;
|
|
155
|
-
yield
|
|
155
|
+
yield note.removeChild(node);
|
|
156
156
|
--length;
|
|
157
157
|
assert(children.length === length);
|
|
158
158
|
}
|
|
@@ -160,13 +160,13 @@ function build(
|
|
|
160
160
|
? children[count - 1]
|
|
161
161
|
: null;
|
|
162
162
|
if (node && equal(node, def)) continue;
|
|
163
|
-
assert(def.parentNode !==
|
|
164
|
-
yield
|
|
163
|
+
assert(def.parentNode !== note);
|
|
164
|
+
yield note.insertBefore(def, node);
|
|
165
165
|
++length;
|
|
166
166
|
assert(children.length === length);
|
|
167
167
|
}
|
|
168
168
|
while (length > size) {
|
|
169
|
-
yield
|
|
169
|
+
yield note.removeChild(children[size] as HTMLLIElement);
|
|
170
170
|
--length;
|
|
171
171
|
assert(children.length === length);
|
|
172
172
|
}
|