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