@pretextbook/remark-pretext 0.2.0 → 0.4.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/README.md +73 -1
- package/dist/index.cjs +15 -6
- package/dist/index.js +1987 -618
- package/dist/lib/context.d.ts +2 -0
- package/dist/lib/directive-map.d.ts +1 -1
- package/dist/lib/heading-attributes.d.ts +8 -0
- package/dist/lib/math-parser.d.ts +8 -2
- package/dist/lib/mdast-to-ptxast.d.ts +6 -3
- package/dist/lib/parse-markdown.d.ts +16 -0
- package/dist/lib/raw-pretext.d.ts +28 -0
- package/dist/lib/remark-pretext.d.ts +4 -4
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,219 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { visit as V } from "unist-util-visit";
|
|
2
|
+
import { unified as se } from "unified";
|
|
3
|
+
import oe from "remark-parse";
|
|
4
|
+
import Ae from "remark-directive";
|
|
5
|
+
import { gfmTable as ot } from "micromark-extension-gfm-table";
|
|
6
|
+
import { gfmTableFromMarkdown as lt } from "mdast-util-gfm-table";
|
|
7
|
+
import { getPtxSchemaChildElementNames as Oe, isPtxSchemaElementName as ct, isTitlelessDivisionType as at, isTopLevelDivisionType as Me, divisionTypeAtRootDepth as ut, divisionTypeAtRelativeDepth as ht, isRootDivisionType as ft, rootChildDivision as te } from "@pretextbook/ptxast";
|
|
8
|
+
const Re = /([\w:.-]+)=(?:"([^"]*)"|'([^']*)'|([^\s"'{}]+))/g, pt = new RegExp(
|
|
9
|
+
String.raw`\s*\{#([\w:.-]+)((?:\s+${Re.source})*)\s*\}$`
|
|
10
|
+
);
|
|
11
|
+
function dt(e, t) {
|
|
12
|
+
const { start: n, end: i } = e.position ?? {}, r = t?.slice(n?.offset, i?.offset) ?? "";
|
|
13
|
+
return r[r.lastIndexOf("{") - 1] === "\\";
|
|
14
|
+
}
|
|
15
|
+
function mt(e, t) {
|
|
16
|
+
V(e, "heading", (n) => {
|
|
17
|
+
const i = n.children[n.children.length - 1];
|
|
18
|
+
if (i?.type !== "text") return;
|
|
19
|
+
const r = pt.exec(i.value);
|
|
20
|
+
if (!r || dt(n, t)) return;
|
|
21
|
+
const s = {};
|
|
22
|
+
for (const [, c, ...a] of r[2].matchAll(Re))
|
|
23
|
+
s[c] = a.find((h) => h !== void 0) ?? "";
|
|
24
|
+
n.data = {
|
|
25
|
+
...n.data,
|
|
26
|
+
id: r[1],
|
|
27
|
+
attributes: s
|
|
28
|
+
}, i.value = i.value.slice(0, r.index), i.value || n.children.pop();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const gt = [
|
|
32
|
+
// Display math (check these first, before single $)
|
|
33
|
+
{ open: "$$", close: "$$", isDisplay: !0 },
|
|
34
|
+
{ open: "\\[", close: "\\]", isDisplay: !0 },
|
|
35
|
+
// Inline math
|
|
36
|
+
{ open: "$", close: "$", isDisplay: !1 },
|
|
37
|
+
{ open: "\\(", close: "\\)", isDisplay: !1 }
|
|
38
|
+
], $e = "", qe = "", j = new RegExp(`${$e}\\d+${qe}`, "g"), be = /[\p{L}\p{N}]/u;
|
|
39
|
+
function we(e, t) {
|
|
40
|
+
let n = 0;
|
|
41
|
+
for (let i = t - 1; i >= 0 && e[i] === "\\"; i--) n++;
|
|
42
|
+
return n % 2 === 1;
|
|
43
|
+
}
|
|
44
|
+
function yt(e, t) {
|
|
45
|
+
const n = e[t - 1] ?? "", i = e[t + 1] ?? "";
|
|
46
|
+
if (we(e, t) || n === "$" || i === "$" || be.test(n) || i === "" || /\s/.test(i)) return -1;
|
|
47
|
+
let r = e.indexOf("$", t + 1);
|
|
48
|
+
for (; r !== -1 && we(e, r); )
|
|
49
|
+
r = e.indexOf("$", r + 1);
|
|
50
|
+
if (r === -1) return -1;
|
|
51
|
+
const s = e.slice(t + 1, r);
|
|
52
|
+
return s.includes(`
|
|
53
|
+
`) || s.includes("`") || /\s$/.test(s) || be.test(e[r + 1] ?? "") ? -1 : r;
|
|
54
|
+
}
|
|
55
|
+
function Fe(e, t) {
|
|
56
|
+
let n = null;
|
|
57
|
+
for (const i of gt) {
|
|
58
|
+
let r = e.indexOf(i.open, t), s = -1;
|
|
59
|
+
for (; r !== -1 && (s = i.open === "$" ? yt(e, r) : e.indexOf(i.close, r + i.open.length), !(s !== -1 || i.open !== "$")); )
|
|
60
|
+
r = e.indexOf(i.open, r + 1);
|
|
61
|
+
if (!(r === -1 || s === -1) && (!n || r < n.index)) {
|
|
62
|
+
const c = e.substring(r + i.open.length, s);
|
|
63
|
+
n = { index: r, pattern: i, content: c };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return n;
|
|
67
|
+
}
|
|
68
|
+
function vt(e, t) {
|
|
69
|
+
let n = t;
|
|
70
|
+
for (; n < e.length; ) {
|
|
71
|
+
const i = e.indexOf("`", n);
|
|
72
|
+
if (i === -1) return null;
|
|
73
|
+
let r = 0, s = i;
|
|
74
|
+
for (; s < e.length && e[s] === "`"; )
|
|
75
|
+
r++, s++;
|
|
76
|
+
const c = "`".repeat(r);
|
|
77
|
+
let a = s;
|
|
78
|
+
for (; a < e.length; ) {
|
|
79
|
+
const h = e.indexOf(c, a);
|
|
80
|
+
if (h === -1) break;
|
|
81
|
+
const f = h + r;
|
|
82
|
+
if (f >= e.length || e[f] !== "`")
|
|
83
|
+
return { start: i, end: f };
|
|
84
|
+
a = h + 1;
|
|
85
|
+
}
|
|
86
|
+
n = i + r;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function Pe(e) {
|
|
91
|
+
const t = /* @__PURE__ */ new Map();
|
|
92
|
+
let n = "", i = 0, r = 0;
|
|
93
|
+
for (; i < e.length; ) {
|
|
94
|
+
const s = vt(e, i), c = Fe(e, i);
|
|
95
|
+
if (s && (!c || s.start < c.index)) {
|
|
96
|
+
n += e.substring(i, s.end), i = s.end;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!c) {
|
|
100
|
+
n += e.substring(i);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
n += e.substring(i, c.index);
|
|
104
|
+
const a = `${$e}${r}${qe}`;
|
|
105
|
+
n += a;
|
|
106
|
+
const h = c.index + c.pattern.open.length + c.content.length + c.pattern.close.length;
|
|
107
|
+
t.set(a, {
|
|
108
|
+
type: "math",
|
|
109
|
+
value: c.content,
|
|
110
|
+
meta: c.pattern.isDisplay ? "display" : "inline",
|
|
111
|
+
source: e.substring(c.index, h)
|
|
112
|
+
}), i = h, r += 1;
|
|
113
|
+
}
|
|
114
|
+
return { markdown: n, tokens: t };
|
|
115
|
+
}
|
|
116
|
+
function bt(e) {
|
|
117
|
+
const t = [];
|
|
118
|
+
let n = 0;
|
|
119
|
+
for (; n < e.length; ) {
|
|
120
|
+
const i = Fe(e, n);
|
|
121
|
+
if (!i) {
|
|
122
|
+
n < e.length && t.push({ type: "text", value: e.substring(n) });
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
i.index > n && t.push({
|
|
126
|
+
type: "text",
|
|
127
|
+
value: e.substring(n, i.index)
|
|
128
|
+
}), t.push({
|
|
129
|
+
type: "math",
|
|
130
|
+
value: i.content,
|
|
131
|
+
meta: i.pattern.isDisplay ? "display" : "inline"
|
|
132
|
+
}), n = i.index + i.pattern.open.length + i.content.length + i.pattern.close.length;
|
|
133
|
+
}
|
|
134
|
+
return t.length === 0 ? [{ type: "text", value: e }] : t;
|
|
135
|
+
}
|
|
136
|
+
function wt(e, t) {
|
|
137
|
+
const n = [];
|
|
138
|
+
let i = 0;
|
|
139
|
+
j.lastIndex = 0;
|
|
140
|
+
let r = j.exec(e);
|
|
141
|
+
for (; r; ) {
|
|
142
|
+
const s = r.index, c = r[0];
|
|
143
|
+
s > i && n.push({ type: "text", value: e.substring(i, s) });
|
|
144
|
+
const a = t.get(c);
|
|
145
|
+
a ? n.push(a) : n.push({ type: "text", value: c }), i = s + c.length, r = j.exec(e);
|
|
146
|
+
}
|
|
147
|
+
return i < e.length && n.push({ type: "text", value: e.substring(i) }), n.length === 0 ? [{ type: "text", value: e }] : n;
|
|
148
|
+
}
|
|
149
|
+
function je(e, t) {
|
|
150
|
+
V(e, "text", (n, i, r) => {
|
|
151
|
+
if (!r || i === void 0) return;
|
|
152
|
+
const s = r.type === "paragraph" && !r.data?.directiveLabel, c = t(n.value).map(
|
|
153
|
+
(a) => a.type === "math" && !s ? { ...a, meta: "inline" } : a
|
|
154
|
+
);
|
|
155
|
+
return r.children.splice(i, 1, ...c), i + c.length;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function Xe(e) {
|
|
159
|
+
je(e, bt);
|
|
160
|
+
}
|
|
161
|
+
const xt = ["value", "url", "title", "alt"];
|
|
162
|
+
function U(e, t) {
|
|
163
|
+
return e.replace(j, (n) => t.get(n)?.source ?? n);
|
|
164
|
+
}
|
|
165
|
+
function Be(e, t) {
|
|
166
|
+
je(e, (n) => wt(n, t)), V(e, (n) => {
|
|
167
|
+
for (const i of xt)
|
|
168
|
+
typeof n[i] == "string" && (n[i] = U(n[i], t));
|
|
169
|
+
for (const [i, r] of Object.entries(n.attributes ?? {}))
|
|
170
|
+
typeof r == "string" && (n.attributes[i] = U(r, t));
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const Ti = () => (e) => {
|
|
174
|
+
Xe(e);
|
|
175
|
+
}, kt = [
|
|
176
|
+
"blockQuote",
|
|
177
|
+
"codeFenced",
|
|
178
|
+
"codeIndented",
|
|
179
|
+
"definition",
|
|
180
|
+
"headingAtx",
|
|
181
|
+
"htmlFlow",
|
|
182
|
+
"list",
|
|
183
|
+
"setextUnderline",
|
|
184
|
+
"thematicBreak"
|
|
185
|
+
];
|
|
186
|
+
function Et() {
|
|
187
|
+
const e = this.data();
|
|
188
|
+
e.micromarkExtensions = e.micromarkExtensions?.map(
|
|
189
|
+
({ text: t, ...n }) => n
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
function Tt(e) {
|
|
193
|
+
const { markdown: t, tokens: n } = Pe(e), r = se().data("micromarkExtensions", [
|
|
194
|
+
{ disable: { null: ["codeIndented"] } },
|
|
195
|
+
ot()
|
|
196
|
+
]).data("fromMarkdownExtensions", [lt()]).use(oe).use(Ae).use(Et).parse(t);
|
|
197
|
+
return Be(r, n), {
|
|
198
|
+
tree: r,
|
|
199
|
+
source: t,
|
|
200
|
+
restoreSource: (s) => U(s, n)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function Dt(e) {
|
|
204
|
+
const { markdown: t, tokens: n } = Pe(e);
|
|
205
|
+
for (const s of n.values()) s.meta = "inline";
|
|
206
|
+
const r = se().data("micromarkExtensions", [{ disable: { null: kt } }]).use(oe).parse(t);
|
|
207
|
+
return Be(r, n), {
|
|
208
|
+
tree: r.children.flatMap((s) => s.children),
|
|
209
|
+
source: t,
|
|
210
|
+
restoreSource: (s) => U(s, n)
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function It(e, t = {}) {
|
|
7
214
|
const n = {};
|
|
8
|
-
for (const [
|
|
9
|
-
|
|
215
|
+
for (const [i, r] of Object.entries(t))
|
|
216
|
+
r != null && (n[i] = r);
|
|
10
217
|
return {
|
|
11
218
|
type: "element",
|
|
12
219
|
name: `plus:${e}`,
|
|
@@ -14,11 +221,1223 @@ function fe(e, t = {}) {
|
|
|
14
221
|
children: []
|
|
15
222
|
};
|
|
16
223
|
}
|
|
17
|
-
function
|
|
224
|
+
function Ct(e) {
|
|
18
225
|
const t = e.name?.trim();
|
|
19
|
-
return t ?
|
|
226
|
+
return t ? It(t, e.attributes ?? {}) : null;
|
|
227
|
+
}
|
|
228
|
+
var ee, xe;
|
|
229
|
+
function St() {
|
|
230
|
+
if (xe) return ee;
|
|
231
|
+
xe = 1;
|
|
232
|
+
var e = Object.defineProperty, t = Object.getOwnPropertyDescriptor, n = Object.getOwnPropertyNames, i = Object.prototype.hasOwnProperty, r = (l, o) => {
|
|
233
|
+
for (var u in o)
|
|
234
|
+
e(l, u, { get: o[u], enumerable: !0 });
|
|
235
|
+
}, s = (l, o, u, p) => {
|
|
236
|
+
if (o && typeof o == "object" || typeof o == "function")
|
|
237
|
+
for (let d of n(o))
|
|
238
|
+
!i.call(l, d) && d !== u && e(l, d, { get: () => o[d], enumerable: !(p = t(o, d)) || p.enumerable });
|
|
239
|
+
return l;
|
|
240
|
+
}, c = (l) => s(e({}, "__esModule", { value: !0 }), l), a = {};
|
|
241
|
+
r(a, {
|
|
242
|
+
XmlCdata: () => he,
|
|
243
|
+
XmlComment: () => fe,
|
|
244
|
+
XmlDeclaration: () => pe,
|
|
245
|
+
XmlDocument: () => de,
|
|
246
|
+
XmlDocumentType: () => me,
|
|
247
|
+
XmlElement: () => G,
|
|
248
|
+
XmlError: () => ge,
|
|
249
|
+
XmlNode: () => x,
|
|
250
|
+
XmlProcessingInstruction: () => K,
|
|
251
|
+
XmlText: () => Z,
|
|
252
|
+
parseXml: () => st
|
|
253
|
+
}), ee = c(a);
|
|
254
|
+
var h = "", f = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, m = class {
|
|
255
|
+
constructor(l) {
|
|
256
|
+
if (this.k = this.u(l, !0), this.d = 0, this.length = l.length, this.l = this.k !== this.length, this.h = l, this.l) {
|
|
257
|
+
let o = [];
|
|
258
|
+
for (let u = 0, p = 0; p < this.k; ++p)
|
|
259
|
+
o[p] = u, u += l.codePointAt(u) > 65535 ? 2 : 1;
|
|
260
|
+
this.A = o;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Whether the current character index is at the end of the input string.
|
|
265
|
+
*/
|
|
266
|
+
get B() {
|
|
267
|
+
return this.d >= this.k;
|
|
268
|
+
}
|
|
269
|
+
// -- Protected Methods ------------------------------------------------------
|
|
270
|
+
/**
|
|
271
|
+
* Returns the number of characters in the given string, which may differ from
|
|
272
|
+
* the byte length if the string contains multibyte characters.
|
|
273
|
+
*/
|
|
274
|
+
u(l, o = this.l) {
|
|
275
|
+
return o ? l.replace(f, "_").length : l.length;
|
|
276
|
+
}
|
|
277
|
+
// -- Public Methods ---------------------------------------------------------
|
|
278
|
+
/**
|
|
279
|
+
* Advances the scanner by the given number of characters, stopping if the end
|
|
280
|
+
* of the string is reached.
|
|
281
|
+
*/
|
|
282
|
+
p(l = 1) {
|
|
283
|
+
this.d = Math.min(this.k, this.d + l);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Returns the byte index of the given character index in the string. The two
|
|
287
|
+
* may differ in strings that contain multibyte characters.
|
|
288
|
+
*/
|
|
289
|
+
f(l = this.d) {
|
|
290
|
+
var o;
|
|
291
|
+
return this.l ? (o = this.A[l]) != null ? o : 1 / 0 : l;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Consumes and returns the given number of characters if possible, advancing
|
|
295
|
+
* the scanner and stopping if the end of the string is reached.
|
|
296
|
+
*
|
|
297
|
+
* If no characters could be consumed, an empty string will be returned.
|
|
298
|
+
*/
|
|
299
|
+
G(l = 1) {
|
|
300
|
+
let o = this.m(l);
|
|
301
|
+
return this.p(l), o;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Consumes and returns the given number of bytes if possible, advancing the
|
|
305
|
+
* scanner and stopping if the end of the string is reached.
|
|
306
|
+
*
|
|
307
|
+
* It's up to the caller to ensure that the given byte count doesn't split a
|
|
308
|
+
* multibyte character.
|
|
309
|
+
*
|
|
310
|
+
* If no bytes could be consumed, an empty string will be returned.
|
|
311
|
+
*/
|
|
312
|
+
v(l) {
|
|
313
|
+
let o = this.f(), u = this.h.slice(o, o + l);
|
|
314
|
+
return this.p(this.u(u)), u;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Consumes and returns all characters for which the given function returns
|
|
318
|
+
* `true`, stopping when `false` is returned or the end of the input is
|
|
319
|
+
* reached.
|
|
320
|
+
*/
|
|
321
|
+
w(l) {
|
|
322
|
+
let { length: o, l: u, h: p } = this, d = this.f(), y = d;
|
|
323
|
+
if (u)
|
|
324
|
+
for (; y < o; ) {
|
|
325
|
+
let E = p[y], C = E >= "\uD800" && E <= "\uDBFF";
|
|
326
|
+
if (C && (E += p[y + 1]), !l(E))
|
|
327
|
+
break;
|
|
328
|
+
y += C ? 2 : 1;
|
|
329
|
+
}
|
|
330
|
+
else
|
|
331
|
+
for (; y < o && l(p[y]); )
|
|
332
|
+
++y;
|
|
333
|
+
return this.v(y - d);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Consumes the given string if it exists at the current character index, and
|
|
337
|
+
* advances the scanner.
|
|
338
|
+
*
|
|
339
|
+
* If the given string doesn't exist at the current character index, an empty
|
|
340
|
+
* string will be returned and the scanner will not be advanced.
|
|
341
|
+
*/
|
|
342
|
+
b(l) {
|
|
343
|
+
let { length: o } = l, u = this.f();
|
|
344
|
+
return l === this.h.slice(u, u + o) ? (this.p(o === 1 ? 1 : this.u(l)), l) : h;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Consumes characters until the given global regex is matched, advancing the
|
|
348
|
+
* scanner up to (but not beyond) the beginning of the match. If the regex
|
|
349
|
+
* doesn't match, nothing will be consumed.
|
|
350
|
+
*
|
|
351
|
+
* Returns the consumed string, or an empty string if nothing was consumed.
|
|
352
|
+
*/
|
|
353
|
+
x(l) {
|
|
354
|
+
let o = this.h.slice(this.f()).search(l);
|
|
355
|
+
return o > 0 ? this.v(o) : h;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Consumes characters until the given string is found, advancing the scanner
|
|
359
|
+
* up to (but not beyond) that point. If the string is never found, nothing
|
|
360
|
+
* will be consumed.
|
|
361
|
+
*
|
|
362
|
+
* Returns the consumed string, or an empty string if nothing was consumed.
|
|
363
|
+
*/
|
|
364
|
+
s(l) {
|
|
365
|
+
let o = this.f(), u = this.h.indexOf(l, o);
|
|
366
|
+
return u > 0 ? this.v(u - o) : h;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Returns the given number of characters starting at the current character
|
|
370
|
+
* index, without advancing the scanner and without exceeding the end of the
|
|
371
|
+
* input string.
|
|
372
|
+
*/
|
|
373
|
+
m(l = 1) {
|
|
374
|
+
let { d: o, h: u } = this;
|
|
375
|
+
return this.l ? u.slice(this.f(o), this.f(o + l)) : u.slice(o, o + l);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Resets the scanner position to the given character _index_, or to the start
|
|
379
|
+
* of the input string if no index is given.
|
|
380
|
+
*
|
|
381
|
+
* If _index_ is negative, the scanner position will be moved backward by that
|
|
382
|
+
* many characters, stopping if the beginning of the string is reached.
|
|
383
|
+
*/
|
|
384
|
+
n(l = 0) {
|
|
385
|
+
this.d = l >= 0 ? Math.min(this.k, l) : Math.max(0, this.d + l);
|
|
386
|
+
}
|
|
387
|
+
}, g = /["&<]/, k = /['&<]/, D = /\r\n|[\n\r\t]/g, T = /<|&|]]>/, N = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
388
|
+
amp: "&",
|
|
389
|
+
apos: "'",
|
|
390
|
+
gt: ">",
|
|
391
|
+
lt: "<",
|
|
392
|
+
quot: '"'
|
|
393
|
+
}));
|
|
394
|
+
function b(l) {
|
|
395
|
+
let o = l.codePointAt(0);
|
|
396
|
+
return o >= 97 && o <= 122 || o >= 65 && o <= 90 || o >= 48 && o <= 57 || o === 45 || o === 46 || o === 183 || o >= 768 && o <= 879 || o === 8255 || o === 8256 || w(l, o);
|
|
397
|
+
}
|
|
398
|
+
function w(l, o = l.codePointAt(0)) {
|
|
399
|
+
return o >= 97 && o <= 122 || o >= 65 && o <= 90 || o === 58 || o === 95 || o >= 192 && o <= 214 || o >= 216 && o <= 246 || o >= 248 && o <= 767 || o >= 880 && o <= 893 || o >= 895 && o <= 8191 || o === 8204 || o === 8205 || o >= 8304 && o <= 8591 || o >= 11264 && o <= 12271 || o >= 12289 && o <= 55295 || o >= 63744 && o <= 64975 || o >= 65008 && o <= 65533 || o >= 65536 && o <= 983039;
|
|
400
|
+
}
|
|
401
|
+
function ae(l) {
|
|
402
|
+
return l === "#" || b(l);
|
|
403
|
+
}
|
|
404
|
+
function it(l) {
|
|
405
|
+
let o = l.codePointAt(0);
|
|
406
|
+
return o === 32 || o === 9 || o === 10 || o === 13;
|
|
407
|
+
}
|
|
408
|
+
function ue(l) {
|
|
409
|
+
return l >= 32 && l <= 55295 || l === 10 || l === 9 || l === 13 || l >= 57344 && l <= 65533 || l >= 65536 && l <= 1114111;
|
|
410
|
+
}
|
|
411
|
+
var S = class Ue {
|
|
412
|
+
constructor() {
|
|
413
|
+
this.parent = null, this.start = -1, this.end = -1;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Document that contains this node, or `null` if this node is not associated
|
|
417
|
+
* with a document.
|
|
418
|
+
*/
|
|
419
|
+
get document() {
|
|
420
|
+
var o, u;
|
|
421
|
+
return (u = (o = this.parent) == null ? void 0 : o.document) != null ? u : null;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Whether this node is the root node of the document (also known as the
|
|
425
|
+
* document element).
|
|
426
|
+
*/
|
|
427
|
+
get isRootNode() {
|
|
428
|
+
return this.parent !== null && this.parent === this.document && this.type === Ue.TYPE_ELEMENT;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Whether whitespace should be preserved in the content of this element and
|
|
432
|
+
* its children.
|
|
433
|
+
*
|
|
434
|
+
* This is influenced by the value of the special `xml:space` attribute, and
|
|
435
|
+
* will be `true` for any node whose `xml:space` attribute is set to
|
|
436
|
+
* "preserve". If a node has no such attribute, it will inherit the value of
|
|
437
|
+
* the nearest ancestor that does (if any).
|
|
438
|
+
*
|
|
439
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space
|
|
440
|
+
*/
|
|
441
|
+
get preserveWhitespace() {
|
|
442
|
+
var o;
|
|
443
|
+
return !!((o = this.parent) != null && o.preserveWhitespace);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Type of this node.
|
|
447
|
+
*
|
|
448
|
+
* The value of this property is a string that matches one of the static
|
|
449
|
+
* `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,
|
|
450
|
+
* `TYPE_TEXT`, etc.).
|
|
451
|
+
*
|
|
452
|
+
* The `XmlNode` class itself is a base class and doesn't have its own type
|
|
453
|
+
* name.
|
|
454
|
+
*/
|
|
455
|
+
get type() {
|
|
456
|
+
return "";
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Returns a JSON-serializable object representing this node, minus properties
|
|
460
|
+
* that could result in circular references.
|
|
461
|
+
*/
|
|
462
|
+
toJSON() {
|
|
463
|
+
let o = {
|
|
464
|
+
type: this.type
|
|
465
|
+
};
|
|
466
|
+
return this.isRootNode && (o.isRootNode = !0), this.preserveWhitespace && (o.preserveWhitespace = !0), this.start !== -1 && (o.start = this.start, o.end = this.end), o;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
S.TYPE_CDATA = "cdata", S.TYPE_COMMENT = "comment", S.TYPE_DOCUMENT = "document", S.TYPE_DOCUMENT_TYPE = "doctype", S.TYPE_ELEMENT = "element", S.TYPE_PROCESSING_INSTRUCTION = "pi", S.TYPE_TEXT = "text", S.TYPE_XML_DECLARATION = "xmldecl";
|
|
470
|
+
var x = S, Z = class extends x {
|
|
471
|
+
constructor(l = "") {
|
|
472
|
+
super(), this.text = l;
|
|
473
|
+
}
|
|
474
|
+
get type() {
|
|
475
|
+
return x.TYPE_TEXT;
|
|
476
|
+
}
|
|
477
|
+
toJSON() {
|
|
478
|
+
return Object.assign(x.prototype.toJSON.call(this), {
|
|
479
|
+
text: this.text
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}, he = class extends Z {
|
|
483
|
+
get type() {
|
|
484
|
+
return x.TYPE_CDATA;
|
|
485
|
+
}
|
|
486
|
+
}, fe = class extends x {
|
|
487
|
+
constructor(l = "") {
|
|
488
|
+
super(), this.content = l;
|
|
489
|
+
}
|
|
490
|
+
get type() {
|
|
491
|
+
return x.TYPE_COMMENT;
|
|
492
|
+
}
|
|
493
|
+
toJSON() {
|
|
494
|
+
return Object.assign(x.prototype.toJSON.call(this), {
|
|
495
|
+
content: this.content
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}, pe = class extends x {
|
|
499
|
+
constructor(l, o, u) {
|
|
500
|
+
super(), this.version = l, this.encoding = o ?? null, this.standalone = u ?? null;
|
|
501
|
+
}
|
|
502
|
+
get type() {
|
|
503
|
+
return x.TYPE_XML_DECLARATION;
|
|
504
|
+
}
|
|
505
|
+
toJSON() {
|
|
506
|
+
let l = x.prototype.toJSON.call(this);
|
|
507
|
+
l.version = this.version;
|
|
508
|
+
for (let o of ["encoding", "standalone"])
|
|
509
|
+
this[o] !== null && (l[o] = this[o]);
|
|
510
|
+
return l;
|
|
511
|
+
}
|
|
512
|
+
}, G = class Ye extends x {
|
|
513
|
+
constructor(o, u = /* @__PURE__ */ Object.create(null), p = []) {
|
|
514
|
+
super(), this.name = o, this.attributes = u, this.children = p;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Whether this element is empty (meaning it has no children).
|
|
518
|
+
*/
|
|
519
|
+
get isEmpty() {
|
|
520
|
+
return this.children.length === 0;
|
|
521
|
+
}
|
|
522
|
+
get preserveWhitespace() {
|
|
523
|
+
let o = this;
|
|
524
|
+
for (; o instanceof Ye; ) {
|
|
525
|
+
if ("xml:space" in o.attributes)
|
|
526
|
+
return o.attributes["xml:space"] === "preserve";
|
|
527
|
+
o = o.parent;
|
|
528
|
+
}
|
|
529
|
+
return !1;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Text content of this element and all its descendants.
|
|
533
|
+
*/
|
|
534
|
+
get text() {
|
|
535
|
+
return this.children.map((o) => "text" in o ? o.text : "").join("");
|
|
536
|
+
}
|
|
537
|
+
get type() {
|
|
538
|
+
return x.TYPE_ELEMENT;
|
|
539
|
+
}
|
|
540
|
+
toJSON() {
|
|
541
|
+
return Object.assign(x.prototype.toJSON.call(this), {
|
|
542
|
+
name: this.name,
|
|
543
|
+
attributes: this.attributes,
|
|
544
|
+
children: this.children.map((o) => o.toJSON())
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}, de = class extends x {
|
|
548
|
+
constructor(l = []) {
|
|
549
|
+
super(), this.children = l;
|
|
550
|
+
}
|
|
551
|
+
get document() {
|
|
552
|
+
return this;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Root element of this document, or `null` if this document is empty.
|
|
556
|
+
*/
|
|
557
|
+
get root() {
|
|
558
|
+
for (let l of this.children)
|
|
559
|
+
if (l instanceof G)
|
|
560
|
+
return l;
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Text content of this document and all its descendants.
|
|
565
|
+
*/
|
|
566
|
+
get text() {
|
|
567
|
+
return this.children.map((l) => "text" in l ? l.text : "").join("");
|
|
568
|
+
}
|
|
569
|
+
get type() {
|
|
570
|
+
return x.TYPE_DOCUMENT;
|
|
571
|
+
}
|
|
572
|
+
toJSON() {
|
|
573
|
+
return Object.assign(x.prototype.toJSON.call(this), {
|
|
574
|
+
children: this.children.map((l) => l.toJSON())
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}, me = class extends x {
|
|
578
|
+
constructor(l, o, u, p) {
|
|
579
|
+
super(), this.name = l, this.publicId = o ?? null, this.systemId = u ?? null, this.internalSubset = p ?? null;
|
|
580
|
+
}
|
|
581
|
+
get type() {
|
|
582
|
+
return x.TYPE_DOCUMENT_TYPE;
|
|
583
|
+
}
|
|
584
|
+
toJSON() {
|
|
585
|
+
let l = x.prototype.toJSON.call(this);
|
|
586
|
+
l.name = this.name;
|
|
587
|
+
for (let o of ["publicId", "systemId", "internalSubset"])
|
|
588
|
+
this[o] !== null && (l[o] = this[o]);
|
|
589
|
+
return l;
|
|
590
|
+
}
|
|
591
|
+
}, ge = class extends Error {
|
|
592
|
+
constructor(l, o, u) {
|
|
593
|
+
let p = 1, d = "", y = 1;
|
|
594
|
+
for (let Q = 0; Q < o; ++Q) {
|
|
595
|
+
let ve = u[Q];
|
|
596
|
+
ve === `
|
|
597
|
+
` ? (p = 1, d = "", y += 1) : (p += 1, d += ve);
|
|
598
|
+
}
|
|
599
|
+
let E = u.indexOf(`
|
|
600
|
+
`, o);
|
|
601
|
+
d += E === -1 ? u.slice(o) : u.slice(o, E);
|
|
602
|
+
let C = 0;
|
|
603
|
+
d.length > 50 && (p < 40 ? d = d.slice(0, 50) : (C = p - 20, d = d.slice(C, p + 30))), super(
|
|
604
|
+
`${l} (line ${y}, column ${p})
|
|
605
|
+
${d}
|
|
606
|
+
` + " ".repeat(p - C + 1) + `^
|
|
607
|
+
`
|
|
608
|
+
), this.column = p, this.excerpt = d, this.line = y, this.name = "XmlError", this.pos = o;
|
|
609
|
+
}
|
|
610
|
+
}, K = class extends x {
|
|
611
|
+
constructor(l, o = "") {
|
|
612
|
+
super(), this.name = l, this.content = o;
|
|
613
|
+
}
|
|
614
|
+
get type() {
|
|
615
|
+
return x.TYPE_PROCESSING_INSTRUCTION;
|
|
616
|
+
}
|
|
617
|
+
toJSON() {
|
|
618
|
+
return Object.assign(x.prototype.toJSON.call(this), {
|
|
619
|
+
name: this.name,
|
|
620
|
+
content: this.content
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
}, ye = "", rt = class {
|
|
624
|
+
/**
|
|
625
|
+
* @param xml XML string to parse.
|
|
626
|
+
* @param options Parser options.
|
|
627
|
+
*/
|
|
628
|
+
constructor(l, o = {}) {
|
|
629
|
+
let u = this.document = new de();
|
|
630
|
+
this.j = u, this.g = o, this.c = new m(l), this.g.includeOffsets && (u.start = 0, u.end = l.length), this.parse();
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Adds the given `XmlNode` as a child of `this.currentNode`.
|
|
634
|
+
*/
|
|
635
|
+
i(l, o) {
|
|
636
|
+
return l.parent = this.j, this.g.includeOffsets && (l.start = this.c.f(o), l.end = this.c.f()), this.j.children.push(l), !0;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Adds the given _text_ to the document, either by appending it to a
|
|
640
|
+
* preceding `XmlText` node (if possible) or by creating a new `XmlText` node.
|
|
641
|
+
*
|
|
642
|
+
* When _normalize_ is `true` (the default), line breaks in _text_ are
|
|
643
|
+
* normalized per section 2.11 of the XML spec. This must be `false` for text
|
|
644
|
+
* that comes from a character or entity reference, since references aren't
|
|
645
|
+
* subject to line break normalization.
|
|
646
|
+
*/
|
|
647
|
+
y(l, o, u = !0) {
|
|
648
|
+
let { children: p } = this.j, { length: d } = p;
|
|
649
|
+
if (u && (l = F(l)), d > 0) {
|
|
650
|
+
let y = p[d - 1];
|
|
651
|
+
if (y?.type === x.TYPE_TEXT) {
|
|
652
|
+
let E = y;
|
|
653
|
+
return E.text += l, this.g.includeOffsets && (E.end = this.c.f()), !0;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return this.i(new Z(l), o);
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Consumes element attributes.
|
|
660
|
+
*
|
|
661
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags
|
|
662
|
+
*/
|
|
663
|
+
H() {
|
|
664
|
+
let l = /* @__PURE__ */ Object.create(null);
|
|
665
|
+
for (; this.e(); ) {
|
|
666
|
+
let o = this.q();
|
|
667
|
+
if (!o)
|
|
668
|
+
break;
|
|
669
|
+
let u = this.t() && this.I();
|
|
670
|
+
if (u === !1)
|
|
671
|
+
throw this.a("Attribute value expected");
|
|
672
|
+
if (o in l)
|
|
673
|
+
throw this.a(`Duplicate attribute: ${o}`);
|
|
674
|
+
if (o === "xml:space" && u !== "default" && u !== "preserve")
|
|
675
|
+
throw this.a('Value of the `xml:space` attribute must be "default" or "preserve"');
|
|
676
|
+
l[o] = u;
|
|
677
|
+
}
|
|
678
|
+
if (this.g.sortAttributes) {
|
|
679
|
+
let o = Object.keys(l).sort(), u = /* @__PURE__ */ Object.create(null);
|
|
680
|
+
for (let p = 0; p < o.length; ++p) {
|
|
681
|
+
let d = o[p];
|
|
682
|
+
u[d] = l[d];
|
|
683
|
+
}
|
|
684
|
+
l = u;
|
|
685
|
+
}
|
|
686
|
+
return l;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Consumes an `AttValue` (attribute value) if possible.
|
|
690
|
+
*
|
|
691
|
+
* @returns
|
|
692
|
+
* Contents of the `AttValue` minus quotes, or `false` if nothing was
|
|
693
|
+
* consumed. An empty string indicates that an `AttValue` was consumed but
|
|
694
|
+
* was empty.
|
|
695
|
+
*
|
|
696
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
|
|
697
|
+
*/
|
|
698
|
+
I() {
|
|
699
|
+
let { c: l } = this, o = l.m();
|
|
700
|
+
if (o !== '"' && o !== "'")
|
|
701
|
+
return !1;
|
|
702
|
+
l.p();
|
|
703
|
+
let u, p = !1, d = ye, y = o === '"' ? g : k;
|
|
704
|
+
e: for (; !l.B; )
|
|
705
|
+
switch (u = l.x(y), u && (this.o(u), d += u.replace(D, " ")), l.m()) {
|
|
706
|
+
case o:
|
|
707
|
+
p = !0;
|
|
708
|
+
break e;
|
|
709
|
+
case "&":
|
|
710
|
+
d += this.C();
|
|
711
|
+
continue;
|
|
712
|
+
case "<":
|
|
713
|
+
throw this.a("Unescaped `<` is not allowed in an attribute value");
|
|
714
|
+
default:
|
|
715
|
+
break e;
|
|
716
|
+
}
|
|
717
|
+
if (!p)
|
|
718
|
+
throw this.a("Unclosed attribute");
|
|
719
|
+
return l.p(), d;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Consumes a CDATA section if possible.
|
|
723
|
+
*
|
|
724
|
+
* @returns Whether a CDATA section was consumed.
|
|
725
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect
|
|
726
|
+
*/
|
|
727
|
+
J() {
|
|
728
|
+
let { c: l } = this, o = l.d;
|
|
729
|
+
if (!l.b("<![CDATA["))
|
|
730
|
+
return !1;
|
|
731
|
+
let u = l.s("]]>");
|
|
732
|
+
if (this.o(u), !l.b("]]>"))
|
|
733
|
+
throw this.a("Unclosed CDATA section");
|
|
734
|
+
return this.g.preserveCdata ? this.i(new he(F(u)), o) : this.y(u, o);
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Consumes character data if possible.
|
|
738
|
+
*
|
|
739
|
+
* @returns Whether character data was consumed.
|
|
740
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata
|
|
741
|
+
*/
|
|
742
|
+
K() {
|
|
743
|
+
let { c: l } = this, o = l.d, u = l.x(T);
|
|
744
|
+
if (!u)
|
|
745
|
+
return !1;
|
|
746
|
+
if (this.o(u), l.m(3) === "]]>")
|
|
747
|
+
throw this.a("Element content may not contain the CDATA section close delimiter `]]>`");
|
|
748
|
+
return this.y(u, o);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Consumes a comment if possible.
|
|
752
|
+
*
|
|
753
|
+
* @returns Whether a comment was consumed.
|
|
754
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment
|
|
755
|
+
*/
|
|
756
|
+
D() {
|
|
757
|
+
let { c: l } = this, o = l.d;
|
|
758
|
+
if (!l.b("<!--"))
|
|
759
|
+
return !1;
|
|
760
|
+
let u = l.s("--");
|
|
761
|
+
if (this.o(u), !l.b("-->"))
|
|
762
|
+
throw l.m(2) === "--" ? this.a("The string `--` isn't allowed inside a comment") : this.a("Unclosed comment");
|
|
763
|
+
return this.g.preserveComments ? this.i(new fe(F(u)), o) : !0;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Consumes a reference in a content context if possible.
|
|
767
|
+
*
|
|
768
|
+
* This differs from `consumeReference()` in that a consumed reference will be
|
|
769
|
+
* added to the document as a text node instead of returned.
|
|
770
|
+
*
|
|
771
|
+
* @returns Whether a reference was consumed.
|
|
772
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc
|
|
773
|
+
*/
|
|
774
|
+
L() {
|
|
775
|
+
let l = this.c.d, o = this.C();
|
|
776
|
+
return o ? this.y(o, l, !1) : !1;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Consumes a doctype declaration if possible.
|
|
780
|
+
*
|
|
781
|
+
* This is a loose implementation since doctype declarations are currently
|
|
782
|
+
* discarded without further parsing.
|
|
783
|
+
*
|
|
784
|
+
* @returns Whether a doctype declaration was consumed.
|
|
785
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd
|
|
786
|
+
*/
|
|
787
|
+
M() {
|
|
788
|
+
let { c: l } = this, o = l.d;
|
|
789
|
+
if (!l.b("<!DOCTYPE"))
|
|
790
|
+
return !1;
|
|
791
|
+
let u = this.e() && this.q();
|
|
792
|
+
if (!u)
|
|
793
|
+
throw this.a("Expected a name");
|
|
794
|
+
let p, d;
|
|
795
|
+
if (this.e()) {
|
|
796
|
+
if (l.b("PUBLIC")) {
|
|
797
|
+
if (p = this.e() && this.N(), p === !1)
|
|
798
|
+
throw this.a("Expected a public identifier");
|
|
799
|
+
this.e();
|
|
800
|
+
}
|
|
801
|
+
if (p !== void 0 || l.b("SYSTEM")) {
|
|
802
|
+
if (this.e(), d = this.r(), d === !1)
|
|
803
|
+
throw this.a("Expected a system identifier");
|
|
804
|
+
this.e();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
let y;
|
|
808
|
+
if (l.b("[")) {
|
|
809
|
+
if (y = l.x(/\][\x20\t\r\n]*>/), !l.b("]"))
|
|
810
|
+
throw this.a("Unclosed internal subset");
|
|
811
|
+
this.e();
|
|
812
|
+
}
|
|
813
|
+
if (!l.b(">"))
|
|
814
|
+
throw this.a("Unclosed doctype declaration");
|
|
815
|
+
return this.g.preserveDocumentType ? this.i(new me(u, p, d, y), o) : !0;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Consumes an element if possible.
|
|
819
|
+
*
|
|
820
|
+
* @returns Whether an element was consumed.
|
|
821
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element
|
|
822
|
+
*/
|
|
823
|
+
E() {
|
|
824
|
+
let { c: l } = this, o = l.d;
|
|
825
|
+
if (!l.b("<"))
|
|
826
|
+
return !1;
|
|
827
|
+
let u = this.q();
|
|
828
|
+
if (!u)
|
|
829
|
+
return l.n(o), !1;
|
|
830
|
+
let p = this.H(), d = !!l.b("/>"), y = new G(u, p);
|
|
831
|
+
if (y.parent = this.j, !d) {
|
|
832
|
+
if (!l.b(">"))
|
|
833
|
+
throw this.a(`Unclosed start tag for element \`${u}\``);
|
|
834
|
+
this.j = y;
|
|
835
|
+
do
|
|
836
|
+
this.K();
|
|
837
|
+
while (this.E() || this.L() || this.J() || this.F() || this.D());
|
|
838
|
+
let E = l.d, C;
|
|
839
|
+
if (!l.b("</") || !(C = this.q()) || C !== u)
|
|
840
|
+
throw l.n(E), this.a(`Missing end tag for element ${u}`);
|
|
841
|
+
if (this.e(), !l.b(">"))
|
|
842
|
+
throw this.a(`Unclosed end tag for element ${u}`);
|
|
843
|
+
this.j = y.parent;
|
|
844
|
+
}
|
|
845
|
+
return this.i(y, o);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Consumes an `Eq` production if possible.
|
|
849
|
+
*
|
|
850
|
+
* @returns Whether an `Eq` production was consumed.
|
|
851
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq
|
|
852
|
+
*/
|
|
853
|
+
t() {
|
|
854
|
+
return this.e(), this.c.b("=") ? (this.e(), !0) : !1;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Consumes `Misc` content if possible.
|
|
858
|
+
*
|
|
859
|
+
* @returns Whether anything was consumed.
|
|
860
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc
|
|
861
|
+
*/
|
|
862
|
+
z() {
|
|
863
|
+
return this.D() || this.F() || this.e();
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Consumes one or more `Name` characters if possible.
|
|
867
|
+
*
|
|
868
|
+
* @returns `Name` characters, or an empty string if none were consumed.
|
|
869
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name
|
|
870
|
+
*/
|
|
871
|
+
q() {
|
|
872
|
+
return w(this.c.m()) ? this.c.w(b) : ye;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Consumes a processing instruction if possible.
|
|
876
|
+
*
|
|
877
|
+
* @returns Whether a processing instruction was consumed.
|
|
878
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi
|
|
879
|
+
*/
|
|
880
|
+
F() {
|
|
881
|
+
let { c: l } = this, o = l.d;
|
|
882
|
+
if (!l.b("<?"))
|
|
883
|
+
return !1;
|
|
884
|
+
let u = this.q();
|
|
885
|
+
if (u) {
|
|
886
|
+
if (u.toLowerCase() === "xml")
|
|
887
|
+
throw l.n(o), this.a("XML declaration isn't allowed here");
|
|
888
|
+
} else
|
|
889
|
+
throw this.a("Invalid processing instruction");
|
|
890
|
+
if (!this.e()) {
|
|
891
|
+
if (l.b("?>"))
|
|
892
|
+
return this.i(new K(u), o);
|
|
893
|
+
throw this.a("Whitespace is required after a processing instruction name");
|
|
894
|
+
}
|
|
895
|
+
let p = l.s("?>");
|
|
896
|
+
if (this.o(p), !l.b("?>"))
|
|
897
|
+
throw this.a("Unterminated processing instruction");
|
|
898
|
+
return this.i(new K(u, F(p)), o);
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Consumes a prolog if possible.
|
|
902
|
+
*
|
|
903
|
+
* @returns Whether a prolog was consumed.
|
|
904
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd
|
|
905
|
+
*/
|
|
906
|
+
O() {
|
|
907
|
+
let { c: l } = this, o = l.d;
|
|
908
|
+
for (this.P(); this.z(); )
|
|
909
|
+
;
|
|
910
|
+
if (this.M())
|
|
911
|
+
for (; this.z(); )
|
|
912
|
+
;
|
|
913
|
+
return o < l.d;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Consumes a public identifier literal if possible.
|
|
917
|
+
*
|
|
918
|
+
* @returns
|
|
919
|
+
* Value of the public identifier literal minus quotes, or `false` if
|
|
920
|
+
* nothing was consumed. An empty string indicates that a public id literal
|
|
921
|
+
* was consumed but was empty.
|
|
922
|
+
*
|
|
923
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-PubidLiteral
|
|
924
|
+
*/
|
|
925
|
+
N() {
|
|
926
|
+
let l = this.c.d, o = this.r();
|
|
927
|
+
if (o !== !1 && !/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(o))
|
|
928
|
+
throw this.c.n(l), this.a("Invalid character in public identifier");
|
|
929
|
+
return o;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Consumes a reference if possible.
|
|
933
|
+
*
|
|
934
|
+
* This differs from `consumeContentReference()` in that a consumed reference
|
|
935
|
+
* will be returned rather than added to the document.
|
|
936
|
+
*
|
|
937
|
+
* @returns
|
|
938
|
+
* Parsed reference value, or `false` if nothing was consumed (to
|
|
939
|
+
* distinguish from a reference that resolves to an empty string).
|
|
940
|
+
*
|
|
941
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference
|
|
942
|
+
*/
|
|
943
|
+
C() {
|
|
944
|
+
let { c: l } = this;
|
|
945
|
+
if (!l.b("&"))
|
|
946
|
+
return !1;
|
|
947
|
+
let o = l.w(ae);
|
|
948
|
+
if (l.G() !== ";")
|
|
949
|
+
throw this.a("Unterminated reference (a reference must end with `;`)");
|
|
950
|
+
let u;
|
|
951
|
+
if (o[0] === "#") {
|
|
952
|
+
let p = o[1] === "x" ? parseInt(o.slice(2), 16) : parseInt(o.slice(1), 10);
|
|
953
|
+
if (isNaN(p) || !/^#(?:x[0-9A-Fa-f]+|[0-9]+)$/.test(o))
|
|
954
|
+
throw this.a("Invalid character reference");
|
|
955
|
+
if (!ue(p))
|
|
956
|
+
throw this.a("Character reference resolves to an invalid character");
|
|
957
|
+
u = String.fromCodePoint(p);
|
|
958
|
+
} else if (u = N[o], u === void 0) {
|
|
959
|
+
let {
|
|
960
|
+
ignoreUndefinedEntities: p,
|
|
961
|
+
resolveUndefinedEntity: d
|
|
962
|
+
} = this.g, y = `&${o};`;
|
|
963
|
+
if (d) {
|
|
964
|
+
let E = d(y);
|
|
965
|
+
if (E != null) {
|
|
966
|
+
let C = typeof E;
|
|
967
|
+
if (C !== "string")
|
|
968
|
+
throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${C}`);
|
|
969
|
+
return E;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (p)
|
|
973
|
+
return y;
|
|
974
|
+
throw l.n(-y.length), this.a(`Named entity isn't defined: ${y}`);
|
|
975
|
+
}
|
|
976
|
+
return u;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Consumes a `SystemLiteral` if possible.
|
|
980
|
+
*
|
|
981
|
+
* A `SystemLiteral` is similar to an attribute value, but allows the
|
|
982
|
+
* characters `<` and `&` and doesn't replace references.
|
|
983
|
+
*
|
|
984
|
+
* @returns
|
|
985
|
+
* Value of the `SystemLiteral` minus quotes, or `false` if nothing was
|
|
986
|
+
* consumed. An empty string indicates that a `SystemLiteral` was consumed
|
|
987
|
+
* but was empty.
|
|
988
|
+
*
|
|
989
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral
|
|
990
|
+
*/
|
|
991
|
+
r() {
|
|
992
|
+
let { c: l } = this, o = l.b('"') || l.b("'");
|
|
993
|
+
if (!o)
|
|
994
|
+
return !1;
|
|
995
|
+
let u = l.s(o);
|
|
996
|
+
if (this.o(u), !l.b(o))
|
|
997
|
+
throw this.a("Missing end quote");
|
|
998
|
+
return u;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Consumes one or more whitespace characters if possible.
|
|
1002
|
+
*
|
|
1003
|
+
* @returns Whether any whitespace characters were consumed.
|
|
1004
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
|
|
1005
|
+
*/
|
|
1006
|
+
e() {
|
|
1007
|
+
return !!this.c.w(it);
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Consumes an XML declaration if possible.
|
|
1011
|
+
*
|
|
1012
|
+
* @returns Whether an XML declaration was consumed.
|
|
1013
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl
|
|
1014
|
+
*/
|
|
1015
|
+
P() {
|
|
1016
|
+
let { c: l } = this, o = l.d;
|
|
1017
|
+
if (!l.b("<?xml"))
|
|
1018
|
+
return !1;
|
|
1019
|
+
if (!this.e())
|
|
1020
|
+
throw this.a("Invalid XML declaration");
|
|
1021
|
+
let u = !!l.b("version") && this.t() && this.r();
|
|
1022
|
+
if (u === !1)
|
|
1023
|
+
throw this.a("XML version is missing or invalid");
|
|
1024
|
+
if (!/^1\.[0-9]+$/.test(u))
|
|
1025
|
+
throw this.a("Invalid character in version number");
|
|
1026
|
+
let p, d;
|
|
1027
|
+
if (this.e()) {
|
|
1028
|
+
if (p = !!l.b("encoding") && this.t() && this.r(), p) {
|
|
1029
|
+
if (!/^[A-Za-z][\w.-]*$/.test(p))
|
|
1030
|
+
throw this.a("Invalid character in encoding name");
|
|
1031
|
+
this.e();
|
|
1032
|
+
}
|
|
1033
|
+
if (d = !!l.b("standalone") && this.t() && this.r(), d) {
|
|
1034
|
+
if (d !== "yes" && d !== "no")
|
|
1035
|
+
throw this.a('Only "yes" and "no" are permitted as values of `standalone`');
|
|
1036
|
+
this.e();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (!l.b("?>"))
|
|
1040
|
+
throw this.a("Invalid or unclosed XML declaration");
|
|
1041
|
+
return this.g.preserveXmlDeclaration ? this.i(new pe(
|
|
1042
|
+
u,
|
|
1043
|
+
p || void 0,
|
|
1044
|
+
d || void 0
|
|
1045
|
+
), o) : !0;
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Returns an `XmlError` for the current scanner position.
|
|
1049
|
+
*/
|
|
1050
|
+
a(l) {
|
|
1051
|
+
let { c: o } = this;
|
|
1052
|
+
return new ge(l, o.d, o.h);
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Parses the XML input.
|
|
1056
|
+
*/
|
|
1057
|
+
parse() {
|
|
1058
|
+
if (this.c.b("\uFEFF"), this.O(), !this.E())
|
|
1059
|
+
throw this.a("Root element is missing or invalid");
|
|
1060
|
+
for (; this.z(); )
|
|
1061
|
+
;
|
|
1062
|
+
if (!this.c.B)
|
|
1063
|
+
throw this.a("Extra content at the end of the document");
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Throws an invalid character error if any character in the given _string_
|
|
1067
|
+
* isn't a valid XML character.
|
|
1068
|
+
*/
|
|
1069
|
+
o(l) {
|
|
1070
|
+
let { length: o } = l;
|
|
1071
|
+
for (let u = 0; u < o; ++u) {
|
|
1072
|
+
let p = l.codePointAt(u);
|
|
1073
|
+
if (!ue(p))
|
|
1074
|
+
throw this.c.n(-([...l].length - u)), this.a("Invalid character");
|
|
1075
|
+
p > 65535 && (u += 1);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
function F(l) {
|
|
1080
|
+
let o = 0;
|
|
1081
|
+
for (; (o = l.indexOf("\r", o)) !== -1; )
|
|
1082
|
+
l = l[o + 1] === `
|
|
1083
|
+
` ? l.slice(0, o) + l.slice(o + 1) : l.slice(0, o) + `
|
|
1084
|
+
` + l.slice(o + 1);
|
|
1085
|
+
return l;
|
|
1086
|
+
}
|
|
1087
|
+
function st(l, o) {
|
|
1088
|
+
return new rt(l, o).document;
|
|
1089
|
+
}
|
|
1090
|
+
return ee;
|
|
1091
|
+
}
|
|
1092
|
+
var Lt = St();
|
|
1093
|
+
function Nt(e) {
|
|
1094
|
+
const t = String(e), n = [];
|
|
1095
|
+
return { toOffset: r, toPoint: i };
|
|
1096
|
+
function i(s) {
|
|
1097
|
+
if (typeof s == "number" && s > -1 && s <= t.length) {
|
|
1098
|
+
let c = 0;
|
|
1099
|
+
for (; ; ) {
|
|
1100
|
+
let a = n[c];
|
|
1101
|
+
if (a === void 0) {
|
|
1102
|
+
const h = ke(t, n[c - 1]);
|
|
1103
|
+
a = h === -1 ? t.length + 1 : h + 1, n[c] = a;
|
|
1104
|
+
}
|
|
1105
|
+
if (a > s)
|
|
1106
|
+
return {
|
|
1107
|
+
line: c + 1,
|
|
1108
|
+
column: s - (c > 0 ? n[c - 1] : 0) + 1,
|
|
1109
|
+
offset: s
|
|
1110
|
+
};
|
|
1111
|
+
c++;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
function r(s) {
|
|
1116
|
+
if (s && typeof s.line == "number" && typeof s.column == "number" && !Number.isNaN(s.line) && !Number.isNaN(s.column)) {
|
|
1117
|
+
for (; n.length < s.line; ) {
|
|
1118
|
+
const a = n[n.length - 1], h = ke(t, a), f = h === -1 ? t.length + 1 : h + 1;
|
|
1119
|
+
if (a === f) break;
|
|
1120
|
+
n.push(f);
|
|
1121
|
+
}
|
|
1122
|
+
const c = (s.line > 1 ? n[s.line - 2] : 0) + s.column - 1;
|
|
1123
|
+
if (c < n[s.line - 1]) return c;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
function ke(e, t) {
|
|
1128
|
+
const n = e.indexOf("\r", t), i = e.indexOf(`
|
|
1129
|
+
`, t);
|
|
1130
|
+
return i === -1 ? n : n === -1 || n + 1 === i ? i : n < i ? n : i;
|
|
1131
|
+
}
|
|
1132
|
+
function _t(e) {
|
|
1133
|
+
return !e || typeof e != "object" ? "" : "position" in e || "type" in e ? Ee(e.position) : "start" in e || "end" in e ? Ee(e) : "line" in e || "column" in e ? ne(e) : "";
|
|
1134
|
+
}
|
|
1135
|
+
function ne(e) {
|
|
1136
|
+
return Te(e && e.line) + ":" + Te(e && e.column);
|
|
1137
|
+
}
|
|
1138
|
+
function Ee(e) {
|
|
1139
|
+
return ne(e && e.start) + "-" + ne(e && e.end);
|
|
1140
|
+
}
|
|
1141
|
+
function Te(e) {
|
|
1142
|
+
return e && typeof e == "number" ? e : 1;
|
|
1143
|
+
}
|
|
1144
|
+
class I extends Error {
|
|
1145
|
+
/**
|
|
1146
|
+
* Create a message for `reason`.
|
|
1147
|
+
*
|
|
1148
|
+
* > 🪦 **Note**: also has obsolete signatures.
|
|
1149
|
+
*
|
|
1150
|
+
* @overload
|
|
1151
|
+
* @param {string} reason
|
|
1152
|
+
* @param {Options | null | undefined} [options]
|
|
1153
|
+
* @returns
|
|
1154
|
+
*
|
|
1155
|
+
* @overload
|
|
1156
|
+
* @param {string} reason
|
|
1157
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
1158
|
+
* @param {string | null | undefined} [origin]
|
|
1159
|
+
* @returns
|
|
1160
|
+
*
|
|
1161
|
+
* @overload
|
|
1162
|
+
* @param {string} reason
|
|
1163
|
+
* @param {Point | Position | null | undefined} place
|
|
1164
|
+
* @param {string | null | undefined} [origin]
|
|
1165
|
+
* @returns
|
|
1166
|
+
*
|
|
1167
|
+
* @overload
|
|
1168
|
+
* @param {string} reason
|
|
1169
|
+
* @param {string | null | undefined} [origin]
|
|
1170
|
+
* @returns
|
|
1171
|
+
*
|
|
1172
|
+
* @overload
|
|
1173
|
+
* @param {Error | VFileMessage} cause
|
|
1174
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
1175
|
+
* @param {string | null | undefined} [origin]
|
|
1176
|
+
* @returns
|
|
1177
|
+
*
|
|
1178
|
+
* @overload
|
|
1179
|
+
* @param {Error | VFileMessage} cause
|
|
1180
|
+
* @param {Point | Position | null | undefined} place
|
|
1181
|
+
* @param {string | null | undefined} [origin]
|
|
1182
|
+
* @returns
|
|
1183
|
+
*
|
|
1184
|
+
* @overload
|
|
1185
|
+
* @param {Error | VFileMessage} cause
|
|
1186
|
+
* @param {string | null | undefined} [origin]
|
|
1187
|
+
* @returns
|
|
1188
|
+
*
|
|
1189
|
+
* @param {Error | VFileMessage | string} causeOrReason
|
|
1190
|
+
* Reason for message, should use markdown.
|
|
1191
|
+
* @param {Node | NodeLike | Options | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
|
|
1192
|
+
* Configuration (optional).
|
|
1193
|
+
* @param {string | null | undefined} [origin]
|
|
1194
|
+
* Place in code where the message originates (example:
|
|
1195
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
1196
|
+
* @returns
|
|
1197
|
+
* Instance of `VFileMessage`.
|
|
1198
|
+
*/
|
|
1199
|
+
// eslint-disable-next-line complexity
|
|
1200
|
+
constructor(t, n, i) {
|
|
1201
|
+
super(), typeof n == "string" && (i = n, n = void 0);
|
|
1202
|
+
let r = "", s = {}, c = !1;
|
|
1203
|
+
if (n && ("line" in n && "column" in n ? s = { place: n } : "start" in n && "end" in n ? s = { place: n } : "type" in n ? s = {
|
|
1204
|
+
ancestors: [n],
|
|
1205
|
+
place: n.position
|
|
1206
|
+
} : s = { ...n }), typeof t == "string" ? r = t : !s.cause && t && (c = !0, r = t.message, s.cause = t), !s.ruleId && !s.source && typeof i == "string") {
|
|
1207
|
+
const h = i.indexOf(":");
|
|
1208
|
+
h === -1 ? s.ruleId = i : (s.source = i.slice(0, h), s.ruleId = i.slice(h + 1));
|
|
1209
|
+
}
|
|
1210
|
+
if (!s.place && s.ancestors && s.ancestors) {
|
|
1211
|
+
const h = s.ancestors[s.ancestors.length - 1];
|
|
1212
|
+
h && (s.place = h.position);
|
|
1213
|
+
}
|
|
1214
|
+
const a = s.place && "start" in s.place ? s.place.start : s.place;
|
|
1215
|
+
this.ancestors = s.ancestors || void 0, this.cause = s.cause || void 0, this.column = a ? a.column : void 0, this.fatal = void 0, this.file = "", this.message = r, this.line = a ? a.line : void 0, this.name = _t(s.place) || "1:1", this.place = s.place || void 0, this.reason = this.message, this.ruleId = s.ruleId || void 0, this.source = s.source || void 0, this.stack = c && s.cause && typeof s.cause.stack == "string" ? s.cause.stack : "", this.actual = void 0, this.expected = void 0, this.note = void 0, this.url = void 0;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
I.prototype.file = "";
|
|
1219
|
+
I.prototype.name = "";
|
|
1220
|
+
I.prototype.reason = "";
|
|
1221
|
+
I.prototype.message = "";
|
|
1222
|
+
I.prototype.stack = "";
|
|
1223
|
+
I.prototype.column = void 0;
|
|
1224
|
+
I.prototype.line = void 0;
|
|
1225
|
+
I.prototype.ancestors = void 0;
|
|
1226
|
+
I.prototype.cause = void 0;
|
|
1227
|
+
I.prototype.fatal = void 0;
|
|
1228
|
+
I.prototype.place = void 0;
|
|
1229
|
+
I.prototype.ruleId = void 0;
|
|
1230
|
+
I.prototype.source = void 0;
|
|
1231
|
+
function At(e) {
|
|
1232
|
+
const t = Nt(e);
|
|
1233
|
+
let n;
|
|
1234
|
+
try {
|
|
1235
|
+
n = Lt.parseXml(String(e), {
|
|
1236
|
+
// Positional offsets.
|
|
1237
|
+
includeOffsets: !0,
|
|
1238
|
+
// `<![CDATA[>&<]]>`
|
|
1239
|
+
preserveCdata: !0,
|
|
1240
|
+
// `<!--a-->`
|
|
1241
|
+
preserveComments: !0,
|
|
1242
|
+
// `<!DOCTYPE b>` (a specific declaration)
|
|
1243
|
+
preserveDocumentType: !0,
|
|
1244
|
+
// `<?xml?>` (a specific instruction)
|
|
1245
|
+
preserveXmlDeclaration: !0
|
|
1246
|
+
});
|
|
1247
|
+
} catch (s) {
|
|
1248
|
+
const c = (
|
|
1249
|
+
/** @type {XmlError} */
|
|
1250
|
+
s
|
|
1251
|
+
), a = t.toPoint(c.pos), h = new I(
|
|
1252
|
+
"Could not parse XML with `@rgrove/parse-xml`",
|
|
1253
|
+
{
|
|
1254
|
+
cause: c,
|
|
1255
|
+
place: a,
|
|
1256
|
+
ruleId: "error",
|
|
1257
|
+
source: "xast-util-from-xml"
|
|
1258
|
+
}
|
|
1259
|
+
);
|
|
1260
|
+
throw h.fatal = !0, h.url = "https://github.com/syntax-tree/xast-util-from-xml#throws", h;
|
|
1261
|
+
}
|
|
1262
|
+
const i = { location: t }, r = Rt(n, i);
|
|
1263
|
+
return Je(n, r, i), r;
|
|
1264
|
+
}
|
|
1265
|
+
function Ot(e) {
|
|
1266
|
+
return { type: "cdata", value: e.text };
|
|
1267
|
+
}
|
|
1268
|
+
function Mt(e) {
|
|
1269
|
+
return { type: "comment", value: e.content };
|
|
1270
|
+
}
|
|
1271
|
+
function Rt(e, t) {
|
|
1272
|
+
return { type: "root", children: ze(e.children, t) };
|
|
1273
|
+
}
|
|
1274
|
+
function $t(e) {
|
|
1275
|
+
return {
|
|
1276
|
+
type: "doctype",
|
|
1277
|
+
name: e.name,
|
|
1278
|
+
public: e.publicId || void 0,
|
|
1279
|
+
system: e.systemId || void 0
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
function qt(e, t) {
|
|
1283
|
+
const n = ze(e.children, t);
|
|
1284
|
+
return {
|
|
1285
|
+
type: "element",
|
|
1286
|
+
name: e.name,
|
|
1287
|
+
attributes: { ...e.attributes },
|
|
1288
|
+
// @ts-expect-error: assume content matches.
|
|
1289
|
+
children: n
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
function Ft(e) {
|
|
1293
|
+
return { type: "instruction", name: e.name, value: e.content };
|
|
1294
|
+
}
|
|
1295
|
+
function Pt(e) {
|
|
1296
|
+
return { type: "text", value: e.text };
|
|
20
1297
|
}
|
|
21
|
-
|
|
1298
|
+
function jt(e) {
|
|
1299
|
+
const t = [];
|
|
1300
|
+
return e.version && t.push('version="' + e.version + '"'), e.encoding && t.push('encoding="' + e.encoding + '"'), e.standalone && t.push('standalone="' + e.standalone + '"'), { type: "instruction", name: "xml", value: t.join(" ") };
|
|
1301
|
+
}
|
|
1302
|
+
function ze(e, t) {
|
|
1303
|
+
const n = [];
|
|
1304
|
+
let i = -1;
|
|
1305
|
+
for (; ++i < e.length; ) {
|
|
1306
|
+
const r = e[i];
|
|
1307
|
+
let s;
|
|
1308
|
+
r.type === "cdata" ? s = Ot(
|
|
1309
|
+
/** @type {XmlCdata} */
|
|
1310
|
+
r
|
|
1311
|
+
) : r.type === "comment" ? s = Mt(
|
|
1312
|
+
/** @type {XmlComment} */
|
|
1313
|
+
r
|
|
1314
|
+
) : r.type === "doctype" ? s = $t(
|
|
1315
|
+
/** @type {XmlDocumentType} */
|
|
1316
|
+
r
|
|
1317
|
+
) : r.type === "element" ? s = qt(
|
|
1318
|
+
/** @type {XmlElement} */
|
|
1319
|
+
r,
|
|
1320
|
+
t
|
|
1321
|
+
) : r.type === "pi" ? s = Ft(
|
|
1322
|
+
/** @type {XmlProcessingInstruction} */
|
|
1323
|
+
r
|
|
1324
|
+
) : r.type === "text" ? s = Pt(
|
|
1325
|
+
/** @type {XmlText} */
|
|
1326
|
+
r
|
|
1327
|
+
) : r.type === "xmldecl" && (s = jt(
|
|
1328
|
+
/** @type {XmlDeclaration} */
|
|
1329
|
+
r
|
|
1330
|
+
)), s && (Je(r, s, t), n.push(s));
|
|
1331
|
+
}
|
|
1332
|
+
return n;
|
|
1333
|
+
}
|
|
1334
|
+
function Je(e, t, n) {
|
|
1335
|
+
const i = (
|
|
1336
|
+
// Doesn’t practically happen as far as I found, but `-1` is used in the
|
|
1337
|
+
// code, so let’s keep it in.
|
|
1338
|
+
/* c8 ignore next */
|
|
1339
|
+
e.start === -1 ? void 0 : n.location.toPoint(e.start)
|
|
1340
|
+
), r = (
|
|
1341
|
+
// Same as above
|
|
1342
|
+
/* c8 ignore next */
|
|
1343
|
+
e.end === -1 ? void 0 : n.location.toPoint(e.end)
|
|
1344
|
+
);
|
|
1345
|
+
i && r && (t.position = { start: i, end: r });
|
|
1346
|
+
}
|
|
1347
|
+
const Xt = /<!--[\s\S]*?-->/g, le = /* @__PURE__ */ new Set(["me", "men", "mdn"]), Bt = /* @__PURE__ */ new Set([
|
|
1348
|
+
...le,
|
|
1349
|
+
"c",
|
|
1350
|
+
"cd",
|
|
1351
|
+
"cline",
|
|
1352
|
+
"m",
|
|
1353
|
+
"md",
|
|
1354
|
+
"mrow",
|
|
1355
|
+
"pre"
|
|
1356
|
+
]), Ut = /* @__PURE__ */ new Set([
|
|
1357
|
+
"blockquote",
|
|
1358
|
+
"containerDirective",
|
|
1359
|
+
"listItem",
|
|
1360
|
+
"root"
|
|
1361
|
+
]), We = /* @__PURE__ */ new Set([
|
|
1362
|
+
...le,
|
|
1363
|
+
...Oe("p")
|
|
1364
|
+
]);
|
|
1365
|
+
for (const e of Oe("section"))
|
|
1366
|
+
We.delete(e);
|
|
1367
|
+
function Yt(e) {
|
|
1368
|
+
return ct(e) || le.has(e);
|
|
1369
|
+
}
|
|
1370
|
+
function $(e) {
|
|
1371
|
+
let t;
|
|
1372
|
+
try {
|
|
1373
|
+
t = At(`<raw>${e.replace(Xt, "")}</raw>`);
|
|
1374
|
+
} catch {
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1377
|
+
const i = t.children.find((s) => s.type === "element").children;
|
|
1378
|
+
return i.every(
|
|
1379
|
+
(s) => s.type === "element" ? Yt(s.name) : s.type !== "instruction"
|
|
1380
|
+
) ? i : null;
|
|
1381
|
+
}
|
|
1382
|
+
function zt(e) {
|
|
1383
|
+
const t = $(e);
|
|
1384
|
+
if (t) return { children: t };
|
|
1385
|
+
const [n] = $(e.replace(/>$/, "/>")) ?? [];
|
|
1386
|
+
return n?.type === "element" ? { children: [], opens: n } : null;
|
|
1387
|
+
}
|
|
1388
|
+
function Jt(e, t, n) {
|
|
1389
|
+
const i = new RegExp(`^<${n}(\\s[^]*)?(?<!/)>$`), r = new RegExp(`^</${n}\\s*>$`);
|
|
1390
|
+
let s = 1;
|
|
1391
|
+
for (let c = t + 1; c < e.length; c += 1) {
|
|
1392
|
+
if (e[c].type !== "html") continue;
|
|
1393
|
+
const { value: a } = e[c];
|
|
1394
|
+
if (i.test(a) && (s += 1), r.test(a) && (s -= 1), s === 0) return c;
|
|
1395
|
+
}
|
|
1396
|
+
return -1;
|
|
1397
|
+
}
|
|
1398
|
+
function Wt(e) {
|
|
1399
|
+
const t = [];
|
|
1400
|
+
let n = null;
|
|
1401
|
+
for (const i of e) {
|
|
1402
|
+
if (i.type === "element" && !We.has(i.name)) {
|
|
1403
|
+
t.push(i), n = null;
|
|
1404
|
+
continue;
|
|
1405
|
+
}
|
|
1406
|
+
!n && i.type === "text" && !i.value.trim() || (n || (n = { type: "element", name: "p", attributes: {}, children: [] }, t.push(n)), n.children.push(i));
|
|
1407
|
+
}
|
|
1408
|
+
return t;
|
|
1409
|
+
}
|
|
1410
|
+
function Vt(e, t, n, i) {
|
|
1411
|
+
const r = $(e[t].value);
|
|
1412
|
+
if (r) return { nodes: r, end: t };
|
|
1413
|
+
const s = e[t].position?.start.offset;
|
|
1414
|
+
if (n === void 0 || s === void 0) return null;
|
|
1415
|
+
let c = e[t].position?.end.offset;
|
|
1416
|
+
for (let a = t + 1; a < e.length; a += 1) {
|
|
1417
|
+
const h = e[a].position?.end.offset;
|
|
1418
|
+
if (!n.slice(c, h).includes("</")) continue;
|
|
1419
|
+
c = h;
|
|
1420
|
+
const f = $(i(n.slice(s, h)));
|
|
1421
|
+
if (f) return { nodes: f, end: a };
|
|
1422
|
+
}
|
|
1423
|
+
return null;
|
|
1424
|
+
}
|
|
1425
|
+
function Ht(e, t, n) {
|
|
1426
|
+
V(e, (i) => {
|
|
1427
|
+
if (!Ut.has(i.type)) return;
|
|
1428
|
+
const r = i.children;
|
|
1429
|
+
for (let s = 0; s < r.length; s += 1) {
|
|
1430
|
+
if (r[s].type !== "html") continue;
|
|
1431
|
+
const c = Vt(r, s, t, n);
|
|
1432
|
+
if (!c) continue;
|
|
1433
|
+
const a = Wt(c.nodes).map(
|
|
1434
|
+
(h) => ({ type: "ptxRaw", element: h })
|
|
1435
|
+
);
|
|
1436
|
+
r.splice(s, c.end - s + 1, ...a), s += a.length - 1;
|
|
1437
|
+
}
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
const H = {
|
|
22
1441
|
// theorem-like (requires statement wrapping)
|
|
23
1442
|
theorem: {
|
|
24
1443
|
type: "theorem",
|
|
@@ -157,17 +1576,20 @@ const $ = {
|
|
|
157
1576
|
type: "answer",
|
|
158
1577
|
category: "solution-like",
|
|
159
1578
|
requiresStatement: !1
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
1579
|
+
},
|
|
1580
|
+
// figure-like (a titled wrapper around one piece of content, which for
|
|
1581
|
+
// `table` is a pipe table → <tabular>: `:::table[Caption]{#id}`)
|
|
1582
|
+
table: { type: "table", category: "figure-like", requiresStatement: !1 }
|
|
1583
|
+
}, Di = H;
|
|
1584
|
+
function Zt(e) {
|
|
1585
|
+
return H[e.toLowerCase()];
|
|
1586
|
+
}
|
|
1587
|
+
const Ve = new Set(
|
|
1588
|
+
Object.entries(H).filter(
|
|
167
1589
|
([e, t]) => t.category === "proof-like" || t.category === "solution-like"
|
|
168
1590
|
).map(([e]) => e)
|
|
169
1591
|
);
|
|
170
|
-
function
|
|
1592
|
+
function M(e, t, n) {
|
|
171
1593
|
return {
|
|
172
1594
|
type: "element",
|
|
173
1595
|
name: e,
|
|
@@ -175,113 +1597,113 @@ function L(e, t, n) {
|
|
|
175
1597
|
children: t
|
|
176
1598
|
};
|
|
177
1599
|
}
|
|
178
|
-
function
|
|
1600
|
+
function P(e) {
|
|
179
1601
|
return e.type === "containerDirective" && e.name === "task";
|
|
180
1602
|
}
|
|
181
|
-
function
|
|
182
|
-
return e.type === "containerDirective" &&
|
|
1603
|
+
function Gt(e) {
|
|
1604
|
+
return e.type === "containerDirective" && Ve.has(e.name);
|
|
183
1605
|
}
|
|
184
|
-
function
|
|
1606
|
+
function Y(e) {
|
|
185
1607
|
const t = [];
|
|
186
1608
|
for (const n of e)
|
|
187
|
-
n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(
|
|
1609
|
+
n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(M("p", [n])) : t.push(n);
|
|
188
1610
|
return t;
|
|
189
1611
|
}
|
|
190
|
-
function
|
|
191
|
-
const
|
|
192
|
-
if (n &&
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
for (let
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
for (let
|
|
200
|
-
const
|
|
201
|
-
if (!w
|
|
202
|
-
if (
|
|
203
|
-
|
|
1612
|
+
function Kt(e, t, n, i, r, s, c) {
|
|
1613
|
+
const a = [];
|
|
1614
|
+
if (n && a.push(n), e.hasNestedTasks) {
|
|
1615
|
+
const h = i.findIndex(P);
|
|
1616
|
+
if (h !== -1) {
|
|
1617
|
+
const f = [];
|
|
1618
|
+
for (let b = 0; b < i.length; b++)
|
|
1619
|
+
P(i[b]) && f.push(b);
|
|
1620
|
+
const m = f[f.length - 1], g = i.slice(0, h), k = i.slice(h).filter(P), D = [], T = [], N = [];
|
|
1621
|
+
for (let b = h; b < i.length; b++) {
|
|
1622
|
+
const w = i[b];
|
|
1623
|
+
if (!P(w)) {
|
|
1624
|
+
if (b < m) {
|
|
1625
|
+
D.push(w);
|
|
204
1626
|
continue;
|
|
205
1627
|
}
|
|
206
|
-
if (
|
|
207
|
-
|
|
1628
|
+
if (Gt(w)) {
|
|
1629
|
+
N.push(w);
|
|
208
1630
|
continue;
|
|
209
1631
|
}
|
|
210
|
-
|
|
1632
|
+
T.push(w);
|
|
211
1633
|
}
|
|
212
1634
|
}
|
|
213
|
-
if (
|
|
1635
|
+
if (D.length > 0 && (r.messages ?? (r.messages = [])).push({
|
|
214
1636
|
type: "warning",
|
|
215
|
-
reason: `Dropped ${
|
|
1637
|
+
reason: `Dropped ${D.length} non-task node(s) between task directives in ${e.type}.`,
|
|
216
1638
|
category: "dropped-content-between-tasks",
|
|
217
|
-
position:
|
|
218
|
-
}),
|
|
219
|
-
const
|
|
220
|
-
|
|
1639
|
+
position: D[0].position?.start
|
|
1640
|
+
}), g.length > 0) {
|
|
1641
|
+
const b = Y(
|
|
1642
|
+
g.map((w) => s(w, r)).filter((w) => w !== null)
|
|
221
1643
|
);
|
|
222
|
-
|
|
1644
|
+
b.length > 0 && a.push(M("introduction", b));
|
|
223
1645
|
}
|
|
224
|
-
for (const
|
|
225
|
-
const
|
|
226
|
-
|
|
1646
|
+
for (const b of k) {
|
|
1647
|
+
const w = c(b, r);
|
|
1648
|
+
w && a.push(w);
|
|
227
1649
|
}
|
|
228
|
-
if (
|
|
229
|
-
const
|
|
230
|
-
|
|
1650
|
+
if (T.length > 0) {
|
|
1651
|
+
const b = Y(
|
|
1652
|
+
T.map((w) => s(w, r)).filter((w) => w !== null)
|
|
231
1653
|
);
|
|
232
|
-
|
|
1654
|
+
b.length > 0 && a.push(M("conclusion", b));
|
|
233
1655
|
}
|
|
234
|
-
for (const
|
|
235
|
-
const
|
|
236
|
-
|
|
1656
|
+
for (const b of N) {
|
|
1657
|
+
const w = c(b, r);
|
|
1658
|
+
w && a.push(w);
|
|
237
1659
|
}
|
|
238
1660
|
} else
|
|
239
|
-
|
|
240
|
-
|
|
1661
|
+
De(
|
|
1662
|
+
a,
|
|
241
1663
|
e,
|
|
242
|
-
o,
|
|
243
1664
|
i,
|
|
244
1665
|
r,
|
|
245
|
-
s
|
|
1666
|
+
s,
|
|
1667
|
+
c
|
|
246
1668
|
);
|
|
247
1669
|
} else
|
|
248
|
-
|
|
249
|
-
|
|
1670
|
+
De(
|
|
1671
|
+
a,
|
|
250
1672
|
e,
|
|
251
|
-
o,
|
|
252
1673
|
i,
|
|
253
1674
|
r,
|
|
254
|
-
s
|
|
1675
|
+
s,
|
|
1676
|
+
c
|
|
255
1677
|
);
|
|
256
|
-
return
|
|
1678
|
+
return M(e.type, a, t);
|
|
257
1679
|
}
|
|
258
|
-
function
|
|
1680
|
+
function De(e, t, n, i, r, s) {
|
|
259
1681
|
if (t.requiresStatement) {
|
|
260
|
-
const
|
|
261
|
-
for (const
|
|
262
|
-
if (
|
|
263
|
-
const
|
|
264
|
-
|
|
1682
|
+
const c = [], a = [];
|
|
1683
|
+
for (const h of n)
|
|
1684
|
+
if (h.type === "containerDirective" && Ve.has(h.name)) {
|
|
1685
|
+
const f = s(h, i);
|
|
1686
|
+
f && a.push(f);
|
|
265
1687
|
} else
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
const
|
|
269
|
-
|
|
1688
|
+
c.push(h);
|
|
1689
|
+
if (c.length > 0) {
|
|
1690
|
+
const h = Y(
|
|
1691
|
+
c.map((f) => r(f, i)).filter((f) => f !== null)
|
|
270
1692
|
);
|
|
271
|
-
|
|
1693
|
+
h.length > 0 && e.push(M("statement", h));
|
|
272
1694
|
}
|
|
273
|
-
e.push(...
|
|
1695
|
+
e.push(...a);
|
|
274
1696
|
} else {
|
|
275
|
-
const
|
|
276
|
-
n.map((
|
|
1697
|
+
const c = Y(
|
|
1698
|
+
n.map((a) => r(a, i)).filter((a) => a !== null)
|
|
277
1699
|
);
|
|
278
|
-
e.push(...
|
|
1700
|
+
e.push(...c);
|
|
279
1701
|
}
|
|
280
1702
|
}
|
|
281
|
-
function
|
|
1703
|
+
function He(e) {
|
|
282
1704
|
return { type: "text", value: e };
|
|
283
1705
|
}
|
|
284
|
-
function
|
|
1706
|
+
function v(e, t, n) {
|
|
285
1707
|
return {
|
|
286
1708
|
type: "element",
|
|
287
1709
|
name: e,
|
|
@@ -289,560 +1711,508 @@ function h(e, t, n) {
|
|
|
289
1711
|
children: t
|
|
290
1712
|
};
|
|
291
1713
|
}
|
|
292
|
-
function
|
|
293
|
-
return
|
|
1714
|
+
function _(e, t, n) {
|
|
1715
|
+
return v(e, [He(t)], n);
|
|
294
1716
|
}
|
|
295
|
-
function
|
|
1717
|
+
function Ze(e) {
|
|
296
1718
|
return { type: "comment", value: e.replace(/--/g, "- -") };
|
|
297
1719
|
}
|
|
298
|
-
function
|
|
299
|
-
const n = e?.position,
|
|
300
|
-
return t.source &&
|
|
1720
|
+
function q(e, t) {
|
|
1721
|
+
const n = e?.position, i = n?.start?.offset, r = n?.end?.offset;
|
|
1722
|
+
return t.source && i != null && r != null ? t.restoreSource(t.source.slice(i, r)) : "";
|
|
301
1723
|
}
|
|
302
|
-
function
|
|
303
|
-
return
|
|
1724
|
+
function ce(e, t, n) {
|
|
1725
|
+
return v("TODO", [Ze(`todo: ${t}`), _("pre", n)], {
|
|
304
1726
|
type: e
|
|
305
1727
|
});
|
|
306
1728
|
}
|
|
307
|
-
function
|
|
308
|
-
return
|
|
1729
|
+
function Qt(e, t, n) {
|
|
1730
|
+
return v("TODO", [Ze(`todo: ${t}`), _("c", n)], {
|
|
309
1731
|
type: e
|
|
310
1732
|
});
|
|
311
1733
|
}
|
|
312
|
-
function
|
|
1734
|
+
function z(e) {
|
|
313
1735
|
const t = [];
|
|
314
1736
|
for (const n of e)
|
|
315
|
-
n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(
|
|
1737
|
+
n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(v("p", [n])) : t.push(n);
|
|
316
1738
|
return t;
|
|
317
1739
|
}
|
|
318
|
-
function
|
|
319
|
-
return
|
|
1740
|
+
function Ie(e, t, n) {
|
|
1741
|
+
return en(e, t, n).tree;
|
|
320
1742
|
}
|
|
321
|
-
function
|
|
322
|
-
const
|
|
1743
|
+
function en(e, t, n) {
|
|
1744
|
+
const i = [], r = n?.restoreSource ?? ((g) => g);
|
|
1745
|
+
Ht(e, t, r), mt(e, t);
|
|
1746
|
+
const s = {
|
|
323
1747
|
ancestors: [],
|
|
324
1748
|
depth: 0,
|
|
325
|
-
messages:
|
|
1749
|
+
messages: i,
|
|
326
1750
|
source: t,
|
|
1751
|
+
restoreSource: r,
|
|
327
1752
|
topLevelDivision: n?.topLevelDivision ?? "chapter",
|
|
328
1753
|
documentRoot: n?.documentRoot,
|
|
329
1754
|
topLevelAttributes: n?.topLevelAttributes,
|
|
330
1755
|
topLevelAttributesApplied: n?.topLevelAttributes ? { done: !1 } : void 0,
|
|
331
1756
|
topLevelTitle: n?.topLevelTitle
|
|
332
|
-
},
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
335
|
-
...
|
|
336
|
-
...
|
|
337
|
-
...
|
|
1757
|
+
}, c = e.children;
|
|
1758
|
+
if (s.documentRoot) {
|
|
1759
|
+
const g = B(s), k = s.topLevelTitle ? Ce(s.topLevelTitle, s) : null, { introduction: D, rest: T } = X(c, s), N = s.documentRoot === "slideshow" && tn(T) ? nn(T, s) : A(T, s), b = [
|
|
1760
|
+
...k ? [k] : [],
|
|
1761
|
+
...D ? [D] : [],
|
|
1762
|
+
...N
|
|
338
1763
|
];
|
|
339
1764
|
return {
|
|
340
|
-
tree: { type: "root", children: [
|
|
341
|
-
messages:
|
|
1765
|
+
tree: { type: "root", children: [v(s.documentRoot, b, g)] },
|
|
1766
|
+
messages: i
|
|
342
1767
|
};
|
|
343
1768
|
}
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
|
|
1769
|
+
if (at(s.topLevelDivision)) {
|
|
1770
|
+
const g = B(s), k = z(
|
|
1771
|
+
A(c, { ...s, depth: 1 }, !0)
|
|
347
1772
|
);
|
|
348
1773
|
return {
|
|
349
|
-
tree: { type: "root", children: [
|
|
350
|
-
messages:
|
|
1774
|
+
tree: { type: "root", children: [v(s.topLevelDivision, k, g)] },
|
|
1775
|
+
messages: i
|
|
351
1776
|
};
|
|
352
1777
|
}
|
|
353
|
-
if (
|
|
354
|
-
const
|
|
355
|
-
...
|
|
356
|
-
depth:
|
|
357
|
-
headingDepthOffset: (
|
|
358
|
-
}, { introduction:
|
|
359
|
-
|
|
360
|
-
),
|
|
1778
|
+
if (s.topLevelTitle) {
|
|
1779
|
+
const g = B(s), k = Ce(s.topLevelTitle, s), D = {
|
|
1780
|
+
...s,
|
|
1781
|
+
depth: s.depth + 1,
|
|
1782
|
+
headingDepthOffset: (s.headingDepthOffset ?? 0) + 1
|
|
1783
|
+
}, { introduction: T, rest: N } = X(c, D), b = z(
|
|
1784
|
+
A(N, D, !0)
|
|
1785
|
+
), w = T ? [k, T, ...b] : [k, ...b];
|
|
361
1786
|
return {
|
|
362
|
-
tree: { type: "root", children: [
|
|
363
|
-
messages:
|
|
1787
|
+
tree: { type: "root", children: [v(s.topLevelDivision, w, g)] },
|
|
1788
|
+
messages: i
|
|
364
1789
|
};
|
|
365
1790
|
}
|
|
366
|
-
const { introduction:
|
|
1791
|
+
const { introduction: a, rest: h } = X(c, s), f = A(h, s);
|
|
367
1792
|
return {
|
|
368
|
-
tree: { type: "root", children:
|
|
369
|
-
messages:
|
|
1793
|
+
tree: { type: "root", children: a ? [a, ...f] : f },
|
|
1794
|
+
messages: i
|
|
370
1795
|
};
|
|
371
1796
|
}
|
|
372
|
-
function
|
|
373
|
-
|
|
1797
|
+
function Ce(e, t) {
|
|
1798
|
+
const { tree: n, source: i, restoreSource: r } = Dt(e);
|
|
1799
|
+
return v(
|
|
1800
|
+
"title",
|
|
1801
|
+
L(n, { ...t, source: i, restoreSource: r })
|
|
1802
|
+
);
|
|
374
1803
|
}
|
|
375
|
-
function
|
|
376
|
-
return
|
|
1804
|
+
function tn(e) {
|
|
1805
|
+
return e.some((t) => t.type === "thematicBreak");
|
|
377
1806
|
}
|
|
378
|
-
function
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
1807
|
+
function nn(e, t) {
|
|
1808
|
+
return A(e, t);
|
|
1809
|
+
}
|
|
1810
|
+
function A(e, t, n = !1) {
|
|
1811
|
+
let i = 7;
|
|
1812
|
+
for (const f of e)
|
|
1813
|
+
f.type === "heading" && (i = Math.min(i, f.depth));
|
|
1814
|
+
if (i === 7)
|
|
1815
|
+
return R(e, t, n);
|
|
1816
|
+
const r = [];
|
|
1817
|
+
let s = null, c = [], a = [];
|
|
1818
|
+
const h = () => {
|
|
1819
|
+
s && (r.push(rn(s, a, t)), s = null, a = []);
|
|
388
1820
|
};
|
|
389
|
-
for (const
|
|
390
|
-
|
|
391
|
-
...
|
|
392
|
-
),
|
|
393
|
-
return !
|
|
394
|
-
...
|
|
395
|
-
),
|
|
396
|
-
}
|
|
397
|
-
function
|
|
398
|
-
const
|
|
399
|
-
for (let
|
|
400
|
-
const
|
|
401
|
-
if (
|
|
402
|
-
if (
|
|
403
|
-
const
|
|
404
|
-
if (
|
|
405
|
-
|
|
406
|
-
...
|
|
407
|
-
),
|
|
1821
|
+
for (const f of e)
|
|
1822
|
+
f.type === "heading" && f.depth === i ? (!s && c.length > 0 && (r.push(
|
|
1823
|
+
...R(c, t, n)
|
|
1824
|
+
), c = []), h(), s = f, a = []) : s ? a.push(f) : c.push(f);
|
|
1825
|
+
return !s && c.length > 0 && r.push(
|
|
1826
|
+
...R(c, t, n)
|
|
1827
|
+
), h(), r;
|
|
1828
|
+
}
|
|
1829
|
+
function R(e, t, n = !1) {
|
|
1830
|
+
const i = [];
|
|
1831
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
1832
|
+
const s = e[r], c = J(s, t);
|
|
1833
|
+
if (c !== null) {
|
|
1834
|
+
if (c.name === "p" && c.children.length === 1 && c.children[0].name === "md") {
|
|
1835
|
+
const a = c.children[0], h = i[i.length - 1], f = r + 1 < e.length ? J(e[r + 1], t) : null, m = f?.name === "p" ? f.children : null;
|
|
1836
|
+
if (h?.name === "p")
|
|
1837
|
+
h.children.push(a), m && (h.children.push(
|
|
1838
|
+
...m
|
|
1839
|
+
), r += 1);
|
|
408
1840
|
else {
|
|
409
|
-
const
|
|
410
|
-
|
|
1841
|
+
const g = [a];
|
|
1842
|
+
m && (g.push(...m), r += 1), i.push(v("p", g));
|
|
411
1843
|
}
|
|
412
1844
|
continue;
|
|
413
1845
|
}
|
|
414
|
-
if ((
|
|
415
|
-
const
|
|
416
|
-
if (
|
|
417
|
-
|
|
1846
|
+
if ((c.name === "ul" || c.name === "ol") && i.length > 0) {
|
|
1847
|
+
const a = i[i.length - 1];
|
|
1848
|
+
if (a?.name === "p") {
|
|
1849
|
+
a.children.push(c);
|
|
418
1850
|
continue;
|
|
419
1851
|
}
|
|
420
1852
|
}
|
|
421
|
-
|
|
1853
|
+
i.push(c);
|
|
422
1854
|
}
|
|
423
1855
|
}
|
|
424
|
-
return n ?
|
|
1856
|
+
return n ? z(i) : i;
|
|
425
1857
|
}
|
|
426
|
-
function
|
|
427
|
-
const
|
|
428
|
-
return
|
|
1858
|
+
function rn(e, t, n) {
|
|
1859
|
+
const i = e.depth + (n.headingDepthOffset ?? 0), r = n.documentRoot ? ut(n.documentRoot, i) : ht(n.topLevelDivision, i), s = v("title", L(e.children, n)), c = ln(e, n), a = { ...n, depth: n.depth + 1 }, { introduction: h, rest: f } = X(t, a), m = A(f, a, !0), g = z(m), k = h ? [s, h, ...g] : [s, ...g];
|
|
1860
|
+
return v(r, k, c);
|
|
429
1861
|
}
|
|
430
|
-
function
|
|
431
|
-
return e.type === "leafDirective" &&
|
|
1862
|
+
function sn(e) {
|
|
1863
|
+
return e.type === "leafDirective" && Me(e.name);
|
|
432
1864
|
}
|
|
433
|
-
function
|
|
1865
|
+
function X(e, t) {
|
|
434
1866
|
const n = e.findIndex(
|
|
435
|
-
(
|
|
1867
|
+
(a) => a.type === "heading" || sn(a)
|
|
436
1868
|
);
|
|
437
1869
|
if (n <= 0)
|
|
438
1870
|
return { introduction: null, rest: e };
|
|
439
|
-
const
|
|
440
|
-
return { introduction:
|
|
1871
|
+
const i = e.slice(0, n), r = e.slice(n), s = R(i, t, !0);
|
|
1872
|
+
return { introduction: s.length > 0 ? v("introduction", s) : null, rest: r };
|
|
441
1873
|
}
|
|
442
|
-
function
|
|
1874
|
+
function on(e) {
|
|
443
1875
|
const t = e.data;
|
|
444
|
-
return t?.id ? { "xml:id": t.id } : void 0;
|
|
1876
|
+
return t?.id ? { ...t.attributes, "xml:id": t.id } : void 0;
|
|
445
1877
|
}
|
|
446
|
-
function
|
|
447
|
-
const n =
|
|
448
|
-
if (!(!n && !
|
|
449
|
-
return { ...
|
|
1878
|
+
function ln(e, t) {
|
|
1879
|
+
const n = on(e), i = B(t);
|
|
1880
|
+
if (!(!n && !i))
|
|
1881
|
+
return { ...i, ...n };
|
|
450
1882
|
}
|
|
451
|
-
function
|
|
1883
|
+
function B(e) {
|
|
452
1884
|
if (e.depth !== 0) return;
|
|
453
1885
|
const t = e.topLevelAttributesApplied;
|
|
454
1886
|
if (!(!e.topLevelAttributes || !t || t.done))
|
|
455
1887
|
return t.done = !0, e.topLevelAttributes;
|
|
456
1888
|
}
|
|
457
|
-
const
|
|
458
|
-
paragraph: (e, t) =>
|
|
459
|
-
blockquote: (e, t) =>
|
|
460
|
-
list: (e, t) =>
|
|
461
|
-
code: (e, t) =>
|
|
462
|
-
|
|
463
|
-
|
|
1889
|
+
const cn = {
|
|
1890
|
+
paragraph: (e, t) => an(e, t),
|
|
1891
|
+
blockquote: (e, t) => un(e, t),
|
|
1892
|
+
list: (e, t) => hn(e, t),
|
|
1893
|
+
code: (e, t) => pn(e),
|
|
1894
|
+
table: (e, t) => dn(e, t),
|
|
1895
|
+
containerDirective: (e, t) => Ge(e, t),
|
|
1896
|
+
leafDirective: (e, t) => bn(e, t),
|
|
1897
|
+
ptxRaw: (e) => e.element
|
|
464
1898
|
};
|
|
465
|
-
function
|
|
466
|
-
const n =
|
|
1899
|
+
function J(e, t) {
|
|
1900
|
+
const n = cn[e.type];
|
|
467
1901
|
return n ? n(e, t) : (t.messages && t.messages.push({
|
|
468
1902
|
type: "warning",
|
|
469
1903
|
reason: `Unknown block type: ${e.type}`,
|
|
470
1904
|
category: "unknown-block-type"
|
|
471
|
-
}),
|
|
1905
|
+
}), ce(
|
|
472
1906
|
"unknown-block-type",
|
|
473
1907
|
`unknown block type "${e.type}"`,
|
|
474
|
-
|
|
1908
|
+
q(e, t)
|
|
475
1909
|
));
|
|
476
1910
|
}
|
|
477
|
-
function
|
|
478
|
-
return
|
|
1911
|
+
function an(e, t) {
|
|
1912
|
+
return v("p", L(e.children, t));
|
|
479
1913
|
}
|
|
480
|
-
function
|
|
481
|
-
const n = e.children.filter((
|
|
482
|
-
const
|
|
1914
|
+
function un(e, t) {
|
|
1915
|
+
const n = e.children.filter((i) => i.type === "paragraph" || i.type === "ptxRaw").map((i) => {
|
|
1916
|
+
const r = {
|
|
483
1917
|
...t,
|
|
484
1918
|
ancestors: [...t.ancestors, e],
|
|
485
1919
|
depth: t.depth + 1
|
|
486
1920
|
};
|
|
487
|
-
return
|
|
1921
|
+
return J(i, r);
|
|
488
1922
|
});
|
|
489
|
-
return
|
|
1923
|
+
return v("blockquote", n);
|
|
490
1924
|
}
|
|
491
|
-
function
|
|
492
|
-
const n = e.children.map((
|
|
493
|
-
const
|
|
1925
|
+
function hn(e, t) {
|
|
1926
|
+
const n = e.children.map((i) => {
|
|
1927
|
+
const r = {
|
|
494
1928
|
...t,
|
|
495
1929
|
ancestors: [...t.ancestors, e],
|
|
496
1930
|
depth: t.depth + 1
|
|
497
1931
|
};
|
|
498
|
-
return
|
|
1932
|
+
return fn(i, r);
|
|
499
1933
|
});
|
|
500
|
-
return
|
|
1934
|
+
return v(e.ordered ? "ol" : "ul", n);
|
|
501
1935
|
}
|
|
502
|
-
function
|
|
503
|
-
const n =
|
|
1936
|
+
function fn(e, t) {
|
|
1937
|
+
const n = R(
|
|
504
1938
|
e.children,
|
|
505
1939
|
t
|
|
506
1940
|
);
|
|
507
|
-
return
|
|
1941
|
+
return v("li", n);
|
|
508
1942
|
}
|
|
509
|
-
function
|
|
510
|
-
return
|
|
1943
|
+
function pn(e, t) {
|
|
1944
|
+
return _(
|
|
511
1945
|
"program",
|
|
512
1946
|
e.value,
|
|
513
1947
|
e.lang ? { language: e.lang } : void 0
|
|
514
1948
|
);
|
|
515
1949
|
}
|
|
516
|
-
function
|
|
517
|
-
const n = e.
|
|
518
|
-
|
|
1950
|
+
function dn(e, t) {
|
|
1951
|
+
const [n, ...i] = e.children, r = n?.children.length ?? 0, s = Array.from(
|
|
1952
|
+
{ length: r },
|
|
1953
|
+
(m, g) => e.align?.[g] ?? null
|
|
1954
|
+
), c = {
|
|
1955
|
+
...t,
|
|
1956
|
+
ancestors: [...t.ancestors, e],
|
|
1957
|
+
depth: t.depth + 1
|
|
1958
|
+
}, a = [];
|
|
1959
|
+
n && !mn(n) && a.push(Se(n, r, c, { header: "yes" }));
|
|
1960
|
+
for (const m of i) a.push(Se(m, r, c));
|
|
1961
|
+
const h = s.every((m) => m === s[0]) ? s[0] : void 0;
|
|
1962
|
+
if (h) return v("tabular", a, { halign: h });
|
|
1963
|
+
if (h === null) return v("tabular", a);
|
|
1964
|
+
const f = s.map((m) => v("col", [], m ? { halign: m } : void 0));
|
|
1965
|
+
return v("tabular", [...f, ...a]);
|
|
1966
|
+
}
|
|
1967
|
+
function mn(e) {
|
|
1968
|
+
return e.children.every(
|
|
1969
|
+
(t) => t.children.every(
|
|
1970
|
+
(n) => n.type === "text" && n.value.trim() === ""
|
|
1971
|
+
)
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
function Se(e, t, n, i) {
|
|
1975
|
+
const r = e.children.map(
|
|
1976
|
+
(s) => v("cell", L(s.children, n))
|
|
1977
|
+
);
|
|
1978
|
+
for (; r.length < t; ) r.push(v("cell", []));
|
|
1979
|
+
return v("row", r, i);
|
|
1980
|
+
}
|
|
1981
|
+
function gn(e, t) {
|
|
1982
|
+
const n = e.value.split(/\\\\|[\r\n]+/).map((i) => i.trim()).filter((i) => i.length > 0);
|
|
1983
|
+
return n.length > 1 ? v(
|
|
519
1984
|
"md",
|
|
520
|
-
n.map((
|
|
521
|
-
) :
|
|
1985
|
+
n.map((i) => _("mrow", i))
|
|
1986
|
+
) : _("md", n[0] ?? "");
|
|
522
1987
|
}
|
|
523
|
-
function
|
|
524
|
-
return e.meta === "inline" ?
|
|
1988
|
+
function yn(e, t) {
|
|
1989
|
+
return e.meta === "inline" ? _("m", e.value) : gn(e);
|
|
525
1990
|
}
|
|
526
|
-
function
|
|
527
|
-
|
|
1991
|
+
function vn(e, t) {
|
|
1992
|
+
const n = L(e.children, t);
|
|
1993
|
+
return /^#./.test(e.url) ? v("xref", n, { ref: e.url.slice(1) }) : v("url", n, { href: e.url });
|
|
528
1994
|
}
|
|
529
|
-
function
|
|
530
|
-
const n =
|
|
1995
|
+
function bn(e, t) {
|
|
1996
|
+
const n = Ct(e);
|
|
531
1997
|
return n || (t.messages && t.messages.push({
|
|
532
1998
|
type: "warning",
|
|
533
1999
|
reason: "Unnamed leaf directive",
|
|
534
2000
|
category: "unknown-directive"
|
|
535
|
-
}),
|
|
2001
|
+
}), ce(
|
|
536
2002
|
"unknown-directive",
|
|
537
2003
|
"unnamed leaf directive",
|
|
538
|
-
|
|
2004
|
+
q(e, t)
|
|
539
2005
|
));
|
|
540
2006
|
}
|
|
541
|
-
function
|
|
542
|
-
const n =
|
|
2007
|
+
function Ge(e, t) {
|
|
2008
|
+
const n = Zt(e.name);
|
|
543
2009
|
if (!n)
|
|
544
2010
|
return t.messages && t.messages.push({
|
|
545
2011
|
type: "warning",
|
|
546
2012
|
reason: `Unknown directive: ${e.name}`,
|
|
547
2013
|
category: "unknown-directive"
|
|
548
|
-
}),
|
|
2014
|
+
}), ce(
|
|
549
2015
|
"unknown-directive",
|
|
550
2016
|
`unknown directive "${e.name}"`,
|
|
551
|
-
|
|
2017
|
+
q(e, t)
|
|
552
2018
|
);
|
|
553
|
-
const
|
|
554
|
-
|
|
2019
|
+
const i = xn(e), r = e.children, { title: s, body: c } = wn(
|
|
2020
|
+
r,
|
|
555
2021
|
t
|
|
556
|
-
),
|
|
2022
|
+
), a = {
|
|
557
2023
|
...t,
|
|
558
2024
|
ancestors: [...t.ancestors, e],
|
|
559
2025
|
depth: t.depth + 1
|
|
560
2026
|
};
|
|
561
|
-
return
|
|
2027
|
+
return Kt(
|
|
562
2028
|
n,
|
|
563
|
-
|
|
564
|
-
r,
|
|
2029
|
+
i,
|
|
565
2030
|
s,
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
(
|
|
2031
|
+
c,
|
|
2032
|
+
a,
|
|
2033
|
+
(h, f) => J(h, f),
|
|
2034
|
+
(h, f) => Ge(h, f)
|
|
569
2035
|
);
|
|
570
2036
|
}
|
|
571
|
-
function
|
|
2037
|
+
function wn(e, t) {
|
|
572
2038
|
const n = e[0];
|
|
573
2039
|
return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
|
|
574
|
-
title:
|
|
2040
|
+
title: v(
|
|
575
2041
|
"title",
|
|
576
|
-
|
|
2042
|
+
L(n.children, t)
|
|
577
2043
|
),
|
|
578
2044
|
body: e.slice(1)
|
|
579
2045
|
} : { title: null, body: e };
|
|
580
2046
|
}
|
|
581
|
-
function
|
|
2047
|
+
function xn(e) {
|
|
582
2048
|
const t = e.attributes ?? {}, n = {};
|
|
583
|
-
for (const [
|
|
584
|
-
|
|
2049
|
+
for (const [i, r] of Object.entries(t))
|
|
2050
|
+
r != null && (n[i === "id" ? "xml:id" : i] = r);
|
|
585
2051
|
return Object.keys(n).length > 0 ? n : void 0;
|
|
586
2052
|
}
|
|
587
|
-
function
|
|
2053
|
+
function kn(e, t) {
|
|
588
2054
|
return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
|
|
589
2055
|
}
|
|
590
|
-
const
|
|
591
|
-
text: (e, t) =>
|
|
2056
|
+
const En = {
|
|
2057
|
+
text: (e, t) => He(e.value),
|
|
592
2058
|
emphasis: (e, t) => {
|
|
593
|
-
const
|
|
594
|
-
return
|
|
2059
|
+
const i = kn(e, t.source) === "underscore" ? "term" : "em";
|
|
2060
|
+
return v(i, L(e.children, t));
|
|
595
2061
|
},
|
|
596
|
-
strong: (e, t) =>
|
|
597
|
-
inlineCode: (e, t) =>
|
|
598
|
-
math: (e, t) =>
|
|
599
|
-
link: (e, t) =>
|
|
2062
|
+
strong: (e, t) => v("alert", L(e.children, t)),
|
|
2063
|
+
inlineCode: (e, t) => _("c", e.value),
|
|
2064
|
+
math: (e, t) => yn(e),
|
|
2065
|
+
link: (e, t) => vn(e, t)
|
|
600
2066
|
};
|
|
601
|
-
function
|
|
602
|
-
|
|
2067
|
+
function L(e, t) {
|
|
2068
|
+
const n = [];
|
|
2069
|
+
for (let i = 0; i < e.length; i += 1) {
|
|
2070
|
+
const r = Tn(e, i, t);
|
|
2071
|
+
if (r) {
|
|
2072
|
+
n.push(...r.children), i = r.end;
|
|
2073
|
+
continue;
|
|
2074
|
+
}
|
|
2075
|
+
const s = Dn(e[i], t);
|
|
2076
|
+
s !== null && n.push(s);
|
|
2077
|
+
}
|
|
2078
|
+
return n;
|
|
2079
|
+
}
|
|
2080
|
+
function Tn(e, t, n) {
|
|
2081
|
+
const i = e[t];
|
|
2082
|
+
if (i.type !== "html") return null;
|
|
2083
|
+
const r = zt(i.value);
|
|
2084
|
+
if (!r) return null;
|
|
2085
|
+
const { opens: s } = r;
|
|
2086
|
+
if (!s)
|
|
2087
|
+
return { children: r.children, end: t };
|
|
2088
|
+
const c = Jt(e, t, s.name);
|
|
2089
|
+
if (c === -1) return null;
|
|
2090
|
+
if (Bt.has(s.name)) {
|
|
2091
|
+
const f = {
|
|
2092
|
+
start: i.position?.start,
|
|
2093
|
+
end: e[c].position?.end
|
|
2094
|
+
}, m = $(q({ position: f }, n));
|
|
2095
|
+
return m && { children: m, end: c };
|
|
2096
|
+
}
|
|
2097
|
+
const a = L(e.slice(t + 1, c), n);
|
|
2098
|
+
return { children: [{ ...s, children: a }], end: c };
|
|
603
2099
|
}
|
|
604
|
-
function
|
|
605
|
-
const n =
|
|
2100
|
+
function Dn(e, t) {
|
|
2101
|
+
const n = En[e.type];
|
|
606
2102
|
if (!n)
|
|
607
2103
|
return t.messages && t.messages.push({
|
|
608
2104
|
type: "warning",
|
|
609
2105
|
reason: `Unknown inline type: ${e.type}`,
|
|
610
2106
|
category: "unknown-inline-type"
|
|
611
|
-
}),
|
|
2107
|
+
}), Qt(
|
|
612
2108
|
"unknown-inline-type",
|
|
613
2109
|
`unknown inline type "${e.type}"`,
|
|
614
|
-
|
|
2110
|
+
q(e, t)
|
|
615
2111
|
);
|
|
616
|
-
const
|
|
617
|
-
return n(e,
|
|
618
|
-
}
|
|
619
|
-
const Pe = [
|
|
620
|
-
// Display math (check these first, before single $)
|
|
621
|
-
{ open: "$$", close: "$$", isDisplay: !0 },
|
|
622
|
-
{ open: "\\[", close: "\\]", isDisplay: !0 },
|
|
623
|
-
// Inline math
|
|
624
|
-
{ open: "$", close: "$", isDisplay: !1 },
|
|
625
|
-
{ open: "\\(", close: "\\)", isDisplay: !1 }
|
|
626
|
-
], ee = "PTX_MATH_TOKEN_", F = new RegExp(`${ee}(\\d+)`, "g");
|
|
627
|
-
function te(e, t) {
|
|
628
|
-
let n = null;
|
|
629
|
-
for (const o of Pe) {
|
|
630
|
-
const i = e.indexOf(o.open, t);
|
|
631
|
-
if (i === -1) continue;
|
|
632
|
-
const r = e.indexOf(o.close, i + o.open.length);
|
|
633
|
-
if (r !== -1 && !(o.open === "$" && (i > 0 && e[i - 1] === "$" || i + 1 < e.length && e[i + 1] === "$")) && (!n || i < n.index)) {
|
|
634
|
-
const s = e.substring(i + o.open.length, r);
|
|
635
|
-
n = { index: i, pattern: o, content: s };
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
return n;
|
|
639
|
-
}
|
|
640
|
-
function Be(e, t) {
|
|
641
|
-
let n = t;
|
|
642
|
-
for (; n < e.length; ) {
|
|
643
|
-
const o = e.indexOf("`", n);
|
|
644
|
-
if (o === -1) return null;
|
|
645
|
-
let i = 0, r = o;
|
|
646
|
-
for (; r < e.length && e[r] === "`"; )
|
|
647
|
-
i++, r++;
|
|
648
|
-
const s = "`".repeat(i);
|
|
649
|
-
let l = r;
|
|
650
|
-
for (; l < e.length; ) {
|
|
651
|
-
const c = e.indexOf(s, l);
|
|
652
|
-
if (c === -1) break;
|
|
653
|
-
const u = c + i;
|
|
654
|
-
if (u >= e.length || e[u] !== "`")
|
|
655
|
-
return { start: o, end: u };
|
|
656
|
-
l = c + 1;
|
|
657
|
-
}
|
|
658
|
-
n = o + i;
|
|
659
|
-
}
|
|
660
|
-
return null;
|
|
661
|
-
}
|
|
662
|
-
function je(e) {
|
|
663
|
-
const t = /* @__PURE__ */ new Map();
|
|
664
|
-
let n = "", o = 0, i = 0;
|
|
665
|
-
for (; o < e.length; ) {
|
|
666
|
-
const r = Be(e, o), s = te(e, o);
|
|
667
|
-
if (r && (!s || r.start < s.index)) {
|
|
668
|
-
n += e.substring(o, r.end), o = r.end;
|
|
669
|
-
continue;
|
|
670
|
-
}
|
|
671
|
-
if (!s) {
|
|
672
|
-
n += e.substring(o);
|
|
673
|
-
break;
|
|
674
|
-
}
|
|
675
|
-
n += e.substring(o, s.index);
|
|
676
|
-
const l = `${ee}${i}`;
|
|
677
|
-
n += l, t.set(l, {
|
|
678
|
-
type: "math",
|
|
679
|
-
value: s.content,
|
|
680
|
-
meta: s.pattern.isDisplay ? "display" : "inline"
|
|
681
|
-
}), o = s.index + s.pattern.open.length + s.content.length + s.pattern.close.length, i += 1;
|
|
682
|
-
}
|
|
683
|
-
return { markdown: n, tokens: t };
|
|
684
|
-
}
|
|
685
|
-
function ze(e) {
|
|
686
|
-
const t = [];
|
|
687
|
-
let n = 0;
|
|
688
|
-
for (; n < e.length; ) {
|
|
689
|
-
const o = te(e, n);
|
|
690
|
-
if (!o) {
|
|
691
|
-
n < e.length && t.push({ type: "text", value: e.substring(n) });
|
|
692
|
-
break;
|
|
693
|
-
}
|
|
694
|
-
o.index > n && t.push({
|
|
695
|
-
type: "text",
|
|
696
|
-
value: e.substring(n, o.index)
|
|
697
|
-
}), t.push({
|
|
698
|
-
type: "math",
|
|
699
|
-
value: o.content,
|
|
700
|
-
meta: o.pattern.isDisplay ? "display" : "inline"
|
|
701
|
-
}), n = o.index + o.pattern.open.length + o.content.length + o.pattern.close.length;
|
|
702
|
-
}
|
|
703
|
-
return t.length === 0 ? [{ type: "text", value: e }] : t;
|
|
704
|
-
}
|
|
705
|
-
function We(e, t) {
|
|
706
|
-
const n = [];
|
|
707
|
-
let o = 0;
|
|
708
|
-
F.lastIndex = 0;
|
|
709
|
-
let i = F.exec(e);
|
|
710
|
-
for (; i; ) {
|
|
711
|
-
const r = i.index, s = i[0];
|
|
712
|
-
r > o && n.push({ type: "text", value: e.substring(o, r) });
|
|
713
|
-
const l = t.get(s);
|
|
714
|
-
l ? n.push(l) : n.push({ type: "text", value: s }), o = r + s.length, i = F.exec(e);
|
|
715
|
-
}
|
|
716
|
-
return o < e.length && n.push({ type: "text", value: e.substring(o) }), n.length === 0 ? [{ type: "text", value: e }] : n;
|
|
717
|
-
}
|
|
718
|
-
function ne(e) {
|
|
719
|
-
K(e, "paragraph", (t) => {
|
|
720
|
-
const n = t.children || [], o = [];
|
|
721
|
-
for (const i of n)
|
|
722
|
-
if (i.type === "text") {
|
|
723
|
-
const r = ze(i.value);
|
|
724
|
-
o.push(...r);
|
|
725
|
-
} else
|
|
726
|
-
o.push(i);
|
|
727
|
-
t.children = o;
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
function Ue(e, t) {
|
|
731
|
-
K(e, "paragraph", (n) => {
|
|
732
|
-
const o = n.children || [], i = [];
|
|
733
|
-
for (const r of o)
|
|
734
|
-
if (r.type === "text") {
|
|
735
|
-
const s = We(r.value, t);
|
|
736
|
-
i.push(...s);
|
|
737
|
-
} else
|
|
738
|
-
i.push(r);
|
|
739
|
-
n.children = i;
|
|
740
|
-
});
|
|
2112
|
+
const i = { ...t, ancestors: [...t.ancestors, e] };
|
|
2113
|
+
return n(e, i);
|
|
741
2114
|
}
|
|
742
|
-
|
|
743
|
-
ne(e);
|
|
744
|
-
};
|
|
745
|
-
function He(e) {
|
|
2115
|
+
function In(e) {
|
|
746
2116
|
const t = e.trim();
|
|
747
2117
|
if (!t.startsWith(":")) return null;
|
|
748
2118
|
let n = 0;
|
|
749
|
-
for (let
|
|
2119
|
+
for (let s = 0; s < t.length && t[s] === ":"; s++)
|
|
750
2120
|
n++;
|
|
751
2121
|
if (n < 3) return null;
|
|
752
|
-
const
|
|
2122
|
+
const i = t.slice(n).trim(), r = i.match(
|
|
753
2123
|
/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/
|
|
754
2124
|
);
|
|
755
|
-
return
|
|
2125
|
+
return i === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : r ? {
|
|
756
2126
|
colons: n,
|
|
757
|
-
label:
|
|
2127
|
+
label: r[0],
|
|
758
2128
|
lineIndex: -1,
|
|
759
2129
|
isOpen: !0
|
|
760
2130
|
} : null;
|
|
761
2131
|
}
|
|
762
|
-
function
|
|
2132
|
+
function Cn(e) {
|
|
763
2133
|
const t = [], n = [];
|
|
764
|
-
for (const
|
|
765
|
-
if (
|
|
766
|
-
const
|
|
767
|
-
colons:
|
|
768
|
-
finalColons:
|
|
769
|
-
label:
|
|
770
|
-
openLineIndex:
|
|
2134
|
+
for (const i of e)
|
|
2135
|
+
if (i.isOpen) {
|
|
2136
|
+
const r = {
|
|
2137
|
+
colons: i.colons,
|
|
2138
|
+
finalColons: i.colons,
|
|
2139
|
+
label: i.label,
|
|
2140
|
+
openLineIndex: i.lineIndex,
|
|
771
2141
|
closeLineIndex: null,
|
|
772
2142
|
children: [],
|
|
773
2143
|
parent: null
|
|
774
2144
|
};
|
|
775
2145
|
if (t.length > 0) {
|
|
776
|
-
const
|
|
777
|
-
|
|
2146
|
+
const s = t[t.length - 1];
|
|
2147
|
+
r.parent = s, s.children.push(r);
|
|
778
2148
|
} else
|
|
779
|
-
n.push(
|
|
780
|
-
t.push(
|
|
2149
|
+
n.push(r);
|
|
2150
|
+
t.push(r);
|
|
781
2151
|
} else {
|
|
782
|
-
const
|
|
783
|
-
|
|
2152
|
+
const r = t[t.length - 1];
|
|
2153
|
+
r && r.colons === i.colons && (r.closeLineIndex = i.lineIndex, t.pop());
|
|
784
2154
|
}
|
|
785
2155
|
return n;
|
|
786
2156
|
}
|
|
787
|
-
function
|
|
2157
|
+
function Ke(e) {
|
|
788
2158
|
if (e.children.length === 0)
|
|
789
2159
|
e.finalColons = e.colons;
|
|
790
2160
|
else {
|
|
791
|
-
const t = Math.max(...e.children.map(
|
|
2161
|
+
const t = Math.max(...e.children.map(Ke));
|
|
792
2162
|
e.finalColons = Math.max(e.colons, t + 1);
|
|
793
2163
|
}
|
|
794
2164
|
return e.finalColons;
|
|
795
2165
|
}
|
|
796
|
-
function
|
|
797
|
-
const
|
|
798
|
-
for (;
|
|
799
|
-
const
|
|
800
|
-
|
|
2166
|
+
function Sn(e, t, n) {
|
|
2167
|
+
const i = e.slice(), r = [], s = t.slice();
|
|
2168
|
+
for (; s.length > 0; ) {
|
|
2169
|
+
const c = s.shift();
|
|
2170
|
+
r.push(c), s.push(...c.children);
|
|
801
2171
|
}
|
|
802
|
-
for (const
|
|
803
|
-
if (
|
|
804
|
-
const
|
|
805
|
-
|
|
2172
|
+
for (const c of r) {
|
|
2173
|
+
if (c.openLineIndex >= 0) {
|
|
2174
|
+
const a = i[c.openLineIndex], h = a.match(/^:+/)?.[0].length || 3, f = a.slice(h);
|
|
2175
|
+
i[c.openLineIndex] = ":".repeat(c.finalColons) + f;
|
|
806
2176
|
}
|
|
807
|
-
|
|
2177
|
+
c.closeLineIndex !== null && c.closeLineIndex >= 0 && (i[c.closeLineIndex] = ":".repeat(c.finalColons));
|
|
808
2178
|
}
|
|
809
|
-
return
|
|
2179
|
+
return i;
|
|
810
2180
|
}
|
|
811
|
-
function
|
|
2181
|
+
function Ln(e) {
|
|
812
2182
|
const t = e.split(`
|
|
813
2183
|
`), n = [];
|
|
814
|
-
let
|
|
815
|
-
for (let
|
|
816
|
-
const
|
|
817
|
-
if (
|
|
818
|
-
const
|
|
819
|
-
|
|
2184
|
+
let i = !1, r = null;
|
|
2185
|
+
for (let a = 0; a < t.length; a++) {
|
|
2186
|
+
const h = t[a], m = h.trim().match(/^(`{3,}|~{3,})/);
|
|
2187
|
+
if (m) {
|
|
2188
|
+
const k = m[1];
|
|
2189
|
+
i ? r && k[0] === r[0] && k.length >= r.length && (i = !1, r = null) : (i = !0, r = k);
|
|
820
2190
|
continue;
|
|
821
2191
|
}
|
|
822
|
-
if (
|
|
2192
|
+
if (i)
|
|
823
2193
|
continue;
|
|
824
|
-
const
|
|
825
|
-
|
|
2194
|
+
const g = In(h);
|
|
2195
|
+
g && n.push({ ...g, lineIndex: a });
|
|
826
2196
|
}
|
|
827
2197
|
if (n.length === 0)
|
|
828
2198
|
return e;
|
|
829
|
-
const
|
|
830
|
-
for (const
|
|
831
|
-
|
|
832
|
-
return
|
|
2199
|
+
const s = Cn(n);
|
|
2200
|
+
for (const a of s)
|
|
2201
|
+
Ke(a);
|
|
2202
|
+
return Sn(t, s).join(`
|
|
833
2203
|
`);
|
|
834
2204
|
}
|
|
835
|
-
function
|
|
2205
|
+
function Nn(e) {
|
|
836
2206
|
const t = e.trim();
|
|
837
2207
|
if (!t.endsWith(":")) return null;
|
|
838
2208
|
const n = t.slice(0, -1);
|
|
839
2209
|
if (!/^[a-zA-Z]/.test(n)) return null;
|
|
840
|
-
const
|
|
841
|
-
if (!
|
|
842
|
-
const [,
|
|
843
|
-
return
|
|
2210
|
+
const i = n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
|
|
2211
|
+
if (!i) return null;
|
|
2212
|
+
const [, r, s] = i;
|
|
2213
|
+
return s && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(s) || !H[r.toLowerCase()] ? null : n;
|
|
844
2214
|
}
|
|
845
|
-
function
|
|
2215
|
+
function ie(e) {
|
|
846
2216
|
let t = 0;
|
|
847
2217
|
for (let n = 0; n < e.length; n++)
|
|
848
2218
|
if (e[n] === " ")
|
|
@@ -853,85 +2223,85 @@ function N(e) {
|
|
|
853
2223
|
break;
|
|
854
2224
|
return t;
|
|
855
2225
|
}
|
|
856
|
-
function
|
|
857
|
-
const n =
|
|
858
|
-
for (let
|
|
859
|
-
if (!
|
|
860
|
-
return
|
|
2226
|
+
function _n(e, t) {
|
|
2227
|
+
const n = ie(e[t]);
|
|
2228
|
+
for (let i = t + 1; i < e.length; i++)
|
|
2229
|
+
if (!Qe(e[i]))
|
|
2230
|
+
return ie(e[i]) > n;
|
|
861
2231
|
return !1;
|
|
862
2232
|
}
|
|
863
|
-
function
|
|
2233
|
+
function Qe(e) {
|
|
864
2234
|
return e.trim() === "";
|
|
865
2235
|
}
|
|
866
|
-
function
|
|
867
|
-
let n = 0,
|
|
868
|
-
for (;
|
|
869
|
-
if (e[
|
|
870
|
-
n++,
|
|
871
|
-
else if (e[
|
|
872
|
-
n += 4,
|
|
2236
|
+
function An(e, t) {
|
|
2237
|
+
let n = 0, i = 0;
|
|
2238
|
+
for (; i < e.length && n < t; )
|
|
2239
|
+
if (e[i] === " ")
|
|
2240
|
+
n++, i++;
|
|
2241
|
+
else if (e[i] === " ")
|
|
2242
|
+
n += 4, i++;
|
|
873
2243
|
else
|
|
874
2244
|
break;
|
|
875
|
-
return e.slice(
|
|
2245
|
+
return e.slice(i);
|
|
876
2246
|
}
|
|
877
|
-
function
|
|
2247
|
+
function On(e) {
|
|
878
2248
|
const t = e.split(`
|
|
879
|
-
`), n = [],
|
|
2249
|
+
`), n = [], i = {
|
|
880
2250
|
level: 0,
|
|
881
2251
|
openDirectives: [],
|
|
882
2252
|
inCodeFence: !1,
|
|
883
2253
|
codeFenceMarker: null
|
|
884
2254
|
};
|
|
885
|
-
for (let
|
|
886
|
-
const
|
|
887
|
-
if (
|
|
888
|
-
const
|
|
889
|
-
|
|
2255
|
+
for (let r = 0; r < t.length; r++) {
|
|
2256
|
+
const s = t[r], c = s.trim(), a = ie(s), h = c.match(/^(`{3,}|~{3,})/);
|
|
2257
|
+
if (h) {
|
|
2258
|
+
const m = h[1];
|
|
2259
|
+
i.inCodeFence ? i.codeFenceMarker && c.startsWith(i.codeFenceMarker) && (i.inCodeFence = !1, i.codeFenceMarker = null) : (i.inCodeFence = !0, i.codeFenceMarker = m), n.push(s);
|
|
890
2260
|
continue;
|
|
891
2261
|
}
|
|
892
|
-
if (
|
|
893
|
-
n.push(
|
|
2262
|
+
if (i.inCodeFence) {
|
|
2263
|
+
n.push(s);
|
|
894
2264
|
continue;
|
|
895
2265
|
}
|
|
896
|
-
if (
|
|
2266
|
+
if (Qe(s)) {
|
|
897
2267
|
n.push("");
|
|
898
2268
|
continue;
|
|
899
2269
|
}
|
|
900
|
-
const
|
|
901
|
-
if (
|
|
902
|
-
for (;
|
|
903
|
-
const
|
|
904
|
-
|
|
2270
|
+
const f = Nn(c);
|
|
2271
|
+
if (f && _n(t, r)) {
|
|
2272
|
+
for (; i.openDirectives.length > 0 && !(i.openDirectives[i.openDirectives.length - 1].indentLevel < a); ) {
|
|
2273
|
+
const T = i.openDirectives.pop();
|
|
2274
|
+
T && n.push(":".repeat(T.colonCount));
|
|
905
2275
|
}
|
|
906
|
-
const
|
|
907
|
-
n.push(":".repeat(
|
|
908
|
-
label:
|
|
909
|
-
indentLevel:
|
|
910
|
-
colonCount:
|
|
2276
|
+
const m = f.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/), g = m ? m[1].toLowerCase() + (m[2] || "") : f, k = i.openDirectives.length * 1 + 3;
|
|
2277
|
+
n.push(":".repeat(k) + g), i.openDirectives.push({
|
|
2278
|
+
label: g,
|
|
2279
|
+
indentLevel: a,
|
|
2280
|
+
colonCount: k,
|
|
911
2281
|
bodyBaseIndent: -1
|
|
912
|
-
}),
|
|
2282
|
+
}), i.level = a;
|
|
913
2283
|
} else {
|
|
914
|
-
for (;
|
|
915
|
-
const
|
|
916
|
-
|
|
2284
|
+
for (; i.openDirectives.length > 0 && a <= i.openDirectives[i.openDirectives.length - 1].indentLevel; ) {
|
|
2285
|
+
const m = i.openDirectives.pop();
|
|
2286
|
+
m && n.push(":".repeat(m.colonCount));
|
|
917
2287
|
}
|
|
918
|
-
if (
|
|
919
|
-
const
|
|
920
|
-
|
|
2288
|
+
if (i.openDirectives.length > 0) {
|
|
2289
|
+
const m = i.openDirectives[i.openDirectives.length - 1];
|
|
2290
|
+
m.bodyBaseIndent < 0 && (m.bodyBaseIndent = a), n.push(An(s, m.bodyBaseIndent));
|
|
921
2291
|
} else
|
|
922
|
-
n.push(
|
|
923
|
-
|
|
2292
|
+
n.push(s);
|
|
2293
|
+
i.level = a;
|
|
924
2294
|
}
|
|
925
2295
|
}
|
|
926
|
-
for (;
|
|
927
|
-
const
|
|
928
|
-
|
|
2296
|
+
for (; i.openDirectives.length > 0; ) {
|
|
2297
|
+
const r = i.openDirectives.pop();
|
|
2298
|
+
r && n.push(":".repeat(r.colonCount));
|
|
929
2299
|
}
|
|
930
2300
|
return n.join(`
|
|
931
2301
|
`);
|
|
932
2302
|
}
|
|
933
|
-
const
|
|
934
|
-
function
|
|
2303
|
+
const Mn = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Rn = /^division:\s*(\S+)\s*$/m, $n = /^id:\s*(\S+)\s*$/m, qn = /^xmlid:\s*(\S+)\s*$/m, Fn = /^xml:id:\s*(\S+)\s*$/m, Pn = /^label:\s*(\S+)\s*$/m, jn = /^component:\s*(\S+)\s*$/m, Xn = /^title:\s*(.+?)\s*$/m;
|
|
2304
|
+
function Bn(e) {
|
|
935
2305
|
if (e.length >= 2) {
|
|
936
2306
|
const t = e[0], n = e[e.length - 1];
|
|
937
2307
|
if (t === '"' && n === '"' || t === "'" && n === "'")
|
|
@@ -939,206 +2309,205 @@ function lt(e) {
|
|
|
939
2309
|
}
|
|
940
2310
|
return e;
|
|
941
2311
|
}
|
|
942
|
-
function
|
|
943
|
-
const t = e.match(
|
|
2312
|
+
function Un(e) {
|
|
2313
|
+
const t = e.match(Mn);
|
|
944
2314
|
if (!t)
|
|
945
2315
|
return { body: e };
|
|
946
|
-
const n = t[1],
|
|
947
|
-
let
|
|
948
|
-
|
|
949
|
-
const
|
|
950
|
-
|
|
951
|
-
const
|
|
2316
|
+
const n = t[1], i = e.slice(t[0].length), r = n.match(Rn)?.[1];
|
|
2317
|
+
let s, c;
|
|
2318
|
+
r && ft(r) ? (c = r, s = te(r)) : r && Me(r) && (s = r);
|
|
2319
|
+
const a = {}, h = n.match($n)?.[1] ?? n.match(qn)?.[1] ?? n.match(Fn)?.[1], f = n.match(Pn)?.[1], m = n.match(jn)?.[1];
|
|
2320
|
+
h && (a["xml:id"] = h), f && (a.label = f), m && (a.component = m);
|
|
2321
|
+
const g = n.match(Xn)?.[1], k = g ? Bn(g) : void 0;
|
|
952
2322
|
return {
|
|
953
|
-
division:
|
|
954
|
-
documentRoot:
|
|
955
|
-
attributes: Object.keys(
|
|
956
|
-
title:
|
|
957
|
-
body:
|
|
2323
|
+
division: s,
|
|
2324
|
+
documentRoot: c,
|
|
2325
|
+
attributes: Object.keys(a).length > 0 ? a : void 0,
|
|
2326
|
+
title: k,
|
|
2327
|
+
body: i
|
|
958
2328
|
};
|
|
959
2329
|
}
|
|
960
|
-
const
|
|
961
|
-
return function(n,
|
|
962
|
-
if (typeof
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
),
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
topLevelTitle: c
|
|
2330
|
+
const Yn = function(e) {
|
|
2331
|
+
return function(n, i) {
|
|
2332
|
+
if (typeof i?.value == "string") {
|
|
2333
|
+
const r = Un(i.value), s = e?.documentRoot ?? r.documentRoot, c = e?.topLevelDivision ?? r.division ?? (s ? te(s) : "chapter"), a = e?.topLevelAttributes ?? r.attributes, h = e?.topLevelTitle ?? r.title, f = On(
|
|
2334
|
+
r.body
|
|
2335
|
+
), m = Ln(f), g = Tt(m);
|
|
2336
|
+
return Ie(g.tree, g.source, {
|
|
2337
|
+
topLevelDivision: c,
|
|
2338
|
+
documentRoot: s,
|
|
2339
|
+
topLevelAttributes: a,
|
|
2340
|
+
topLevelTitle: h,
|
|
2341
|
+
restoreSource: g.restoreSource
|
|
973
2342
|
});
|
|
974
2343
|
}
|
|
975
|
-
return
|
|
976
|
-
topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ?
|
|
2344
|
+
return Xe(n), Ie(n, void 0, {
|
|
2345
|
+
topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? te(e.documentRoot) : "chapter"),
|
|
977
2346
|
documentRoot: e?.documentRoot,
|
|
978
2347
|
topLevelAttributes: e?.topLevelAttributes,
|
|
979
2348
|
topLevelTitle: e?.topLevelTitle
|
|
980
2349
|
});
|
|
981
2350
|
};
|
|
982
|
-
},
|
|
2351
|
+
}, zn = /["&'<>`]/g, Jn = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, Wn = (
|
|
983
2352
|
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
|
|
984
2353
|
/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
|
|
985
|
-
),
|
|
986
|
-
function
|
|
2354
|
+
), Vn = /[|\\{}()[\]^$+*?.]/g, Le = /* @__PURE__ */ new WeakMap();
|
|
2355
|
+
function Hn(e, t) {
|
|
987
2356
|
if (e = e.replace(
|
|
988
|
-
t.subset ?
|
|
989
|
-
|
|
2357
|
+
t.subset ? Zn(t.subset) : zn,
|
|
2358
|
+
i
|
|
990
2359
|
), t.subset || t.escapeOnly)
|
|
991
2360
|
return e;
|
|
992
|
-
return e.replace(
|
|
993
|
-
function n(
|
|
2361
|
+
return e.replace(Jn, n).replace(Wn, i);
|
|
2362
|
+
function n(r, s, c) {
|
|
994
2363
|
return t.format(
|
|
995
|
-
(
|
|
996
|
-
|
|
2364
|
+
(r.charCodeAt(0) - 55296) * 1024 + r.charCodeAt(1) - 56320 + 65536,
|
|
2365
|
+
c.charCodeAt(s + 2),
|
|
997
2366
|
t
|
|
998
2367
|
);
|
|
999
2368
|
}
|
|
1000
|
-
function
|
|
2369
|
+
function i(r, s, c) {
|
|
1001
2370
|
return t.format(
|
|
1002
|
-
|
|
1003
|
-
|
|
2371
|
+
r.charCodeAt(0),
|
|
2372
|
+
c.charCodeAt(s + 1),
|
|
1004
2373
|
t
|
|
1005
2374
|
);
|
|
1006
2375
|
}
|
|
1007
2376
|
}
|
|
1008
|
-
function
|
|
1009
|
-
let t =
|
|
1010
|
-
return t || (t =
|
|
2377
|
+
function Zn(e) {
|
|
2378
|
+
let t = Le.get(e);
|
|
2379
|
+
return t || (t = Gn(e), Le.set(e, t)), t;
|
|
1011
2380
|
}
|
|
1012
|
-
function
|
|
2381
|
+
function Gn(e) {
|
|
1013
2382
|
const t = [];
|
|
1014
2383
|
let n = -1;
|
|
1015
2384
|
for (; ++n < e.length; )
|
|
1016
|
-
t.push(e[n].replace(
|
|
2385
|
+
t.push(e[n].replace(Vn, "\\$&"));
|
|
1017
2386
|
return new RegExp("(?:" + t.join("|") + ")", "g");
|
|
1018
2387
|
}
|
|
1019
|
-
function
|
|
2388
|
+
function Kn(e) {
|
|
1020
2389
|
return "&#x" + e.toString(16).toUpperCase() + ";";
|
|
1021
2390
|
}
|
|
1022
|
-
function
|
|
1023
|
-
return
|
|
1024
|
-
}
|
|
1025
|
-
const
|
|
1026
|
-
function
|
|
1027
|
-
const
|
|
1028
|
-
return n ?
|
|
1029
|
-
function
|
|
1030
|
-
return
|
|
2391
|
+
function Qn(e, t) {
|
|
2392
|
+
return Hn(e, Object.assign({ format: Kn }, t));
|
|
2393
|
+
}
|
|
2394
|
+
const ei = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
|
|
2395
|
+
function O(e, t, n) {
|
|
2396
|
+
const i = ti(e);
|
|
2397
|
+
return n ? i.replace(n, r) : r(i);
|
|
2398
|
+
function r(s) {
|
|
2399
|
+
return Qn(s, { subset: t });
|
|
1031
2400
|
}
|
|
1032
2401
|
}
|
|
1033
|
-
function
|
|
1034
|
-
return String(e || "").replace(
|
|
2402
|
+
function ti(e) {
|
|
2403
|
+
return String(e || "").replace(ei, "");
|
|
1035
2404
|
}
|
|
1036
|
-
const
|
|
1037
|
-
function
|
|
1038
|
-
return "<![CDATA[" +
|
|
2405
|
+
const ni = /]]>/g, ii = [">"];
|
|
2406
|
+
function ri(e) {
|
|
2407
|
+
return "<![CDATA[" + O(e.value, ii, ni) + "]]>";
|
|
1039
2408
|
}
|
|
1040
|
-
function
|
|
1041
|
-
return "<!--" +
|
|
2409
|
+
function si(e) {
|
|
2410
|
+
return "<!--" + O(e.value, ["-"]) + "-->";
|
|
1042
2411
|
}
|
|
1043
|
-
const
|
|
2412
|
+
const oi = [" ", `
|
|
1044
2413
|
`, " ", '"', "&", "'", "/", "<", "=", ">"];
|
|
1045
|
-
function
|
|
1046
|
-
return
|
|
2414
|
+
function W(e) {
|
|
2415
|
+
return O(e, oi);
|
|
1047
2416
|
}
|
|
1048
|
-
function
|
|
2417
|
+
function Ne(e, t) {
|
|
1049
2418
|
const n = String(e);
|
|
1050
2419
|
if (typeof t != "string")
|
|
1051
2420
|
throw new TypeError("Expected character");
|
|
1052
|
-
let
|
|
1053
|
-
for (;
|
|
1054
|
-
|
|
1055
|
-
return
|
|
2421
|
+
let i = 0, r = n.indexOf(t);
|
|
2422
|
+
for (; r !== -1; )
|
|
2423
|
+
i++, r = n.indexOf(t, r + t.length);
|
|
2424
|
+
return i;
|
|
1056
2425
|
}
|
|
1057
|
-
function
|
|
2426
|
+
function re(e, t) {
|
|
1058
2427
|
const n = String(e);
|
|
1059
|
-
let
|
|
2428
|
+
let i = t.options.quote || '"';
|
|
1060
2429
|
if (t.options.quoteSmart) {
|
|
1061
|
-
const
|
|
1062
|
-
|
|
2430
|
+
const r = i === '"' ? "'" : '"';
|
|
2431
|
+
Ne(n, i) > Ne(n, r) && (i = r);
|
|
1063
2432
|
}
|
|
1064
|
-
return
|
|
1065
|
-
}
|
|
1066
|
-
function
|
|
1067
|
-
const n =
|
|
1068
|
-
let
|
|
1069
|
-
return n !== "" && (
|
|
1070
|
-
}
|
|
1071
|
-
const
|
|
1072
|
-
function
|
|
1073
|
-
const n =
|
|
1074
|
-
let
|
|
1075
|
-
for (
|
|
1076
|
-
if (
|
|
1077
|
-
const
|
|
1078
|
-
|
|
2433
|
+
return i + O(n, ["<", "&", i]) + i;
|
|
2434
|
+
}
|
|
2435
|
+
function li(e, t) {
|
|
2436
|
+
const n = W(e.name), i = e.public, r = e.system;
|
|
2437
|
+
let s = "<!DOCTYPE";
|
|
2438
|
+
return n !== "" && (s += " " + n), i ? s += " PUBLIC " + re(i, t) : r && (s += " SYSTEM"), r && (s += " " + re(r, t)), s + ">";
|
|
2439
|
+
}
|
|
2440
|
+
const ci = {}.hasOwnProperty;
|
|
2441
|
+
function ai(e, t) {
|
|
2442
|
+
const n = W(e.name), i = nt(e, t), r = e.attributes || {}, s = i ? !1 : t.options.closeEmptyElements, c = [];
|
|
2443
|
+
let a;
|
|
2444
|
+
for (a in r)
|
|
2445
|
+
if (ci.call(r, a)) {
|
|
2446
|
+
const h = r[a];
|
|
2447
|
+
h != null && c.push(W(a) + "=" + re(h, t));
|
|
1079
2448
|
}
|
|
1080
|
-
return "<" + n + (
|
|
2449
|
+
return "<" + n + (c.length === 0 ? "" : " " + c.join(" ")) + (s ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + i + (s ? "" : "</" + n + ">");
|
|
1081
2450
|
}
|
|
1082
|
-
const
|
|
1083
|
-
function
|
|
1084
|
-
const t =
|
|
2451
|
+
const ui = /\?>/g, hi = [">"];
|
|
2452
|
+
function fi(e) {
|
|
2453
|
+
const t = W(e.name) || "x", n = O(e.value, hi, ui);
|
|
1085
2454
|
return "<?" + t + (n ? " " + n : "") + "?>";
|
|
1086
2455
|
}
|
|
1087
|
-
const
|
|
1088
|
-
function
|
|
1089
|
-
return
|
|
1090
|
-
}
|
|
1091
|
-
function
|
|
1092
|
-
return t.options.allowDangerousXml ? e.value :
|
|
1093
|
-
}
|
|
1094
|
-
const
|
|
1095
|
-
cdata:
|
|
1096
|
-
comment:
|
|
1097
|
-
doctype:
|
|
1098
|
-
element:
|
|
1099
|
-
instruction:
|
|
1100
|
-
raw:
|
|
1101
|
-
root:
|
|
1102
|
-
text:
|
|
2456
|
+
const pi = ["&", "<"];
|
|
2457
|
+
function et(e) {
|
|
2458
|
+
return O(e.value, pi);
|
|
2459
|
+
}
|
|
2460
|
+
function di(e, t) {
|
|
2461
|
+
return t.options.allowDangerousXml ? e.value : et(e);
|
|
2462
|
+
}
|
|
2463
|
+
const mi = {}.hasOwnProperty, _e = {
|
|
2464
|
+
cdata: ri,
|
|
2465
|
+
comment: si,
|
|
2466
|
+
doctype: li,
|
|
2467
|
+
element: ai,
|
|
2468
|
+
instruction: fi,
|
|
2469
|
+
raw: di,
|
|
2470
|
+
root: nt,
|
|
2471
|
+
text: et
|
|
1103
2472
|
};
|
|
1104
|
-
function
|
|
2473
|
+
function tt(e, t) {
|
|
1105
2474
|
const n = e && e.type;
|
|
1106
2475
|
if (!n)
|
|
1107
2476
|
throw new Error("Expected node, not `" + e + "`");
|
|
1108
|
-
if (!
|
|
2477
|
+
if (!mi.call(_e, n))
|
|
1109
2478
|
throw new Error("Cannot compile unknown node `" + n + "`");
|
|
1110
|
-
const
|
|
1111
|
-
return
|
|
2479
|
+
const i = _e[n];
|
|
2480
|
+
return i(e, t);
|
|
1112
2481
|
}
|
|
1113
|
-
function
|
|
2482
|
+
function nt(e, t) {
|
|
1114
2483
|
const n = e && e.children || [];
|
|
1115
|
-
let
|
|
1116
|
-
const
|
|
1117
|
-
for (; ++
|
|
1118
|
-
i
|
|
1119
|
-
return
|
|
2484
|
+
let i = -1;
|
|
2485
|
+
const r = [];
|
|
2486
|
+
for (; ++i < n.length; )
|
|
2487
|
+
r[i] = tt(n[i], t);
|
|
2488
|
+
return r.join("");
|
|
1120
2489
|
}
|
|
1121
|
-
function
|
|
2490
|
+
function gi(e, t) {
|
|
1122
2491
|
const n = { options: t || {} };
|
|
1123
2492
|
if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
|
|
1124
2493
|
throw new Error(
|
|
1125
2494
|
"Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
|
|
1126
2495
|
);
|
|
1127
|
-
const
|
|
1128
|
-
return
|
|
2496
|
+
const i = Array.isArray(e) ? { type: "root", children: e } : e;
|
|
2497
|
+
return tt(i, n);
|
|
1129
2498
|
}
|
|
1130
|
-
function
|
|
1131
|
-
const n =
|
|
1132
|
-
return
|
|
2499
|
+
function Ii(e, t) {
|
|
2500
|
+
const n = se().use(oe).use(Ae).use(Yn, t), i = n.parse(e), r = n.runSync(i, { value: e });
|
|
2501
|
+
return gi(r.children, {
|
|
1133
2502
|
closeEmptyElements: !0,
|
|
1134
2503
|
tightClose: !0
|
|
1135
2504
|
});
|
|
1136
2505
|
}
|
|
1137
2506
|
export {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
2507
|
+
Di as DIRECTIVE_MAP,
|
|
2508
|
+
Ve as PROOF_SOLUTION_NAMES,
|
|
2509
|
+
Ii as markdownToPretext,
|
|
2510
|
+
Ie as mdastToPtxast,
|
|
2511
|
+
Ti as remarkMath,
|
|
2512
|
+
Yn as remarkPretext
|
|
1144
2513
|
};
|