@pretextbook/remark-pretext 0.1.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/dist/index.js CHANGED
@@ -1,12 +1,214 @@
1
- import { unified as H } from "unified";
2
- import X from "remark-parse";
3
- import Z from "remark-directive";
4
- import { isTitlelessDivisionType as ce, isTopLevelDivisionType as V, divisionTypeAtRootDepth as ue, divisionTypeAtRelativeDepth as ae, isRootDivisionType as pe, rootChildDivision as M } from "@pretextbook/ptxast";
5
- import { visit as K } from "unist-util-visit";
6
- function fe(e, t = {}) {
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 [o, i] of Object.entries(t))
9
- i != null && (n[o] = i);
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 he(e) {
219
+ function Dt(e) {
18
220
  const t = e.name?.trim();
19
- return t ? fe(t, e.attributes ?? {}) : null;
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;
20
1126
  }
21
- const $ = {
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
+ };
1286
+ }
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
- }, Pt = $;
162
- function de(e) {
163
- return $[e.toLowerCase()];
1575
+ }, vi = H;
1576
+ function Wt(e) {
1577
+ return H[e.toLowerCase()];
164
1578
  }
165
- const Y = new Set(
166
- Object.entries($).filter(
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 L(e, t, n) {
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 w(e) {
1592
+ function P(e) {
179
1593
  return e.type === "containerDirective" && e.name === "task";
180
1594
  }
181
- function me(e) {
182
- return e.type === "containerDirective" && Y.has(e.name);
1595
+ function Vt(e) {
1596
+ return e.type === "containerDirective" && We.has(e.name);
183
1597
  }
184
- function T(e) {
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(L("p", [n])) : t.push(n);
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 ge(e, t, n, o, i, r, s) {
191
- const l = [];
192
- if (n && l.push(n), e.hasNestedTasks) {
193
- const c = o.findIndex(w);
194
- if (c !== -1) {
195
- const u = [];
196
- for (let f = 0; f < o.length; f++)
197
- w(o[f]) && u.push(f);
198
- const a = u[u.length - 1], p = o.slice(0, c), d = o.slice(c).filter(w), g = [], y = [], v = [];
199
- for (let f = c; f < o.length; f++) {
200
- const m = o[f];
201
- if (!w(m)) {
202
- if (f < a) {
203
- g.push(m);
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 (me(m)) {
207
- v.push(m);
1620
+ if (Vt(b)) {
1621
+ L.push(b);
208
1622
  continue;
209
1623
  }
210
- y.push(m);
1624
+ D.push(b);
211
1625
  }
212
1626
  }
213
- if (g.length > 0 && (i.messages ?? (i.messages = [])).push({
1627
+ if (T.length > 0 && (r.messages ?? (r.messages = [])).push({
214
1628
  type: "warning",
215
- reason: `Dropped ${g.length} non-task node(s) between task directives in ${e.type}.`,
1629
+ reason: `Dropped ${T.length} non-task node(s) between task directives in ${e.type}.`,
216
1630
  category: "dropped-content-between-tasks",
217
- position: g[0].position?.start
218
- }), p.length > 0) {
219
- const f = T(
220
- p.map((m) => r(m, i)).filter((m) => m !== null)
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
- f.length > 0 && l.push(L("introduction", f));
1636
+ v.length > 0 && a.push(M("introduction", v));
223
1637
  }
224
- for (const f of d) {
225
- const m = s(f, i);
226
- m && l.push(m);
1638
+ for (const v of x) {
1639
+ const b = c(v, r);
1640
+ b && a.push(b);
227
1641
  }
228
- if (y.length > 0) {
229
- const f = T(
230
- y.map((m) => r(m, i)).filter((m) => m !== null)
1642
+ if (D.length > 0) {
1643
+ const v = Y(
1644
+ D.map((b) => s(b, r)).filter((b) => b !== null)
231
1645
  );
232
- f.length > 0 && l.push(L("conclusion", f));
1646
+ v.length > 0 && a.push(M("conclusion", v));
233
1647
  }
234
- for (const f of v) {
235
- const m = s(f, i);
236
- m && l.push(m);
1648
+ for (const v of L) {
1649
+ const b = c(v, r);
1650
+ b && a.push(b);
237
1651
  }
238
1652
  } else
239
- j(
240
- l,
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
- j(
249
- l,
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 L(e.type, l, t);
1670
+ return M(e.type, a, t);
257
1671
  }
258
- function j(e, t, n, o, i, r) {
1672
+ function Te(e, t, n, i, r, s) {
259
1673
  if (t.requiresStatement) {
260
- const s = [], l = [];
261
- for (const c of n)
262
- if (c.type === "containerDirective" && Y.has(c.name)) {
263
- const u = r(c, o);
264
- u && l.push(u);
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
- s.push(c);
267
- if (s.length > 0) {
268
- const c = T(
269
- s.map((u) => i(u, o)).filter((u) => u !== null)
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
- c.length > 0 && e.push(L("statement", c));
1685
+ h.length > 0 && e.push(M("statement", h));
272
1686
  }
273
- e.push(...l);
1687
+ e.push(...a);
274
1688
  } else {
275
- const s = T(
276
- n.map((l) => i(l, o)).filter((l) => l !== null)
1689
+ const c = Y(
1690
+ n.map((a) => r(a, i)).filter((a) => a !== null)
277
1691
  );
278
- e.push(...s);
1692
+ e.push(...c);
279
1693
  }
280
1694
  }
281
- function E(e) {
1695
+ function Ve(e) {
282
1696
  return { type: "text", value: e };
283
1697
  }
284
- function h(e, t, n) {
1698
+ function k(e, t, n) {
285
1699
  return {
286
1700
  type: "element",
287
1701
  name: e,
@@ -289,554 +1703,476 @@ function h(e, t, n) {
289
1703
  children: t
290
1704
  };
291
1705
  }
292
- function k(e, t, n) {
293
- return h(e, [E(t)], n);
1706
+ function _(e, t, n) {
1707
+ return k(e, [Ve(t)], n);
294
1708
  }
295
- function Q(e) {
1709
+ function He(e) {
296
1710
  return { type: "comment", value: e.replace(/--/g, "- -") };
297
1711
  }
298
- function R(e, t) {
299
- const n = e?.position, o = n?.start?.offset, i = n?.end?.offset;
300
- return t.source && o != null && i != null ? t.source.slice(o, i) : "";
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 P(e, t, n) {
303
- return h("TODO", [Q(`todo: ${t}`), k("pre", n)], {
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 ye(e, t, n) {
308
- return h("TODO", [Q(`todo: ${t}`), k("c", n)], {
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 q(e) {
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(h("p", [n])) : t.push(n);
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 B(e, t, n) {
319
- return ve(e, t, n).tree;
1732
+ function Ie(e, t, n) {
1733
+ return Gt(e, t, n).tree;
320
1734
  }
321
- function ve(e, t, n) {
322
- const o = [], i = {
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: o,
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
- }, r = e.children;
333
- if (i.documentRoot) {
334
- const a = S(i), p = i.topLevelTitle ? h("title", [E(i.topLevelTitle)]) : null, { introduction: d, rest: g } = I(r, i), y = C(g, i), v = [
335
- ...p ? [p] : [],
336
- ...d ? [d] : [],
337
- ...y
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: [h(i.documentRoot, v, a)] },
341
- messages: o
1757
+ tree: { type: "root", children: [k(s.documentRoot, v, g)] },
1758
+ messages: i
342
1759
  };
343
1760
  }
344
- if (ce(i.topLevelDivision)) {
345
- const a = S(i), p = q(
346
- C(r, { ...i, depth: 1 }, !0)
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: [h(i.topLevelDivision, p, a)] },
350
- messages: o
1766
+ tree: { type: "root", children: [k(s.topLevelDivision, x, g)] },
1767
+ messages: i
351
1768
  };
352
1769
  }
353
- if (i.topLevelTitle) {
354
- const a = S(i), p = h("title", [E(i.topLevelTitle)]), d = {
355
- ...i,
356
- depth: i.depth + 1,
357
- headingDepthOffset: (i.headingDepthOffset ?? 0) + 1
358
- }, { introduction: g, rest: y } = I(r, d), v = q(
359
- C(y, d, !0)
360
- ), f = g ? [p, g, ...v] : [p, ...v];
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: [h(i.topLevelDivision, f, a)] },
363
- messages: o
1779
+ tree: { type: "root", children: [k(s.topLevelDivision, b, g)] },
1780
+ messages: i
364
1781
  };
365
1782
  }
366
- const { introduction: s, rest: l } = I(r, i), c = C(l, i);
1783
+ const { introduction: a, rest: h } = X(c, s), p = A(h, s);
367
1784
  return {
368
- tree: { type: "root", children: s ? [s, ...c] : c },
369
- messages: o
1785
+ tree: { type: "root", children: a ? [a, ...p] : p },
1786
+ messages: i
370
1787
  };
371
1788
  }
372
- function C(e, t, n = !1) {
373
- let o = 7;
374
- for (const u of e)
375
- u.type === "heading" && (o = Math.min(o, u.depth));
376
- if (o === 7)
377
- return x(e, t, n);
378
- const i = [];
379
- let r = null, s = [], l = [];
380
- const c = () => {
381
- r && (i.push(ke(r, l, t)), r = null, l = []);
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
+ );
1795
+ }
1796
+ function Kt(e) {
1797
+ return e.some((t) => t.type === "thematicBreak");
1798
+ }
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 = []);
382
1812
  };
383
- for (const u of e)
384
- u.type === "heading" && u.depth === o ? (!r && s.length > 0 && (i.push(
385
- ...x(s, t, n)
386
- ), s = []), c(), r = u, l = []) : r ? l.push(u) : s.push(u);
387
- return !r && s.length > 0 && i.push(
388
- ...x(s, t, n)
389
- ), c(), i;
390
- }
391
- function x(e, t, n = !1) {
392
- const o = [];
393
- for (let i = 0; i < e.length; i += 1) {
394
- const r = e[i], s = O(r, t);
395
- if (s !== null) {
396
- if (s.name === "p" && s.children.length === 1 && s.children[0].name === "md") {
397
- const l = s.children[0], c = o[o.length - 1], u = i + 1 < e.length ? O(e[i + 1], t) : null, a = u?.name === "p" ? u.children : null;
398
- if (c?.name === "p")
399
- c.children.push(l), a && (c.children.push(
400
- ...a
401
- ), i += 1);
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);
402
1832
  else {
403
- const p = [l];
404
- a && (p.push(...a), i += 1), o.push(h("p", p));
1833
+ const g = [a];
1834
+ m && (g.push(...m), r += 1), i.push(k("p", g));
405
1835
  }
406
1836
  continue;
407
1837
  }
408
- if ((s.name === "ul" || s.name === "ol") && o.length > 0) {
409
- const l = o[o.length - 1];
410
- if (l?.name === "p") {
411
- l.children.push(s);
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);
412
1842
  continue;
413
1843
  }
414
1844
  }
415
- o.push(s);
1845
+ i.push(c);
416
1846
  }
417
1847
  }
418
- return n ? q(o) : o;
1848
+ return n ? z(i) : i;
419
1849
  }
420
- function ke(e, t, n) {
421
- const o = e.depth + (n.headingDepthOffset ?? 0), i = n.documentRoot ? ue(n.documentRoot, o) : ae(n.topLevelDivision, o), r = h("title", b(e.children, n)), s = Ce(e, n), l = { ...n, depth: n.depth + 1 }, { introduction: c, rest: u } = I(t, l), a = C(u, l, !0), p = q(a), d = c ? [r, c, ...p] : [r, ...p];
422
- return h(i, d, s);
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);
423
1853
  }
424
- function be(e) {
425
- return e.type === "leafDirective" && V(e.name);
1854
+ function tn(e) {
1855
+ return e.type === "leafDirective" && Oe(e.name);
426
1856
  }
427
- function I(e, t) {
1857
+ function X(e, t) {
428
1858
  const n = e.findIndex(
429
- (l) => l.type === "heading" || be(l)
1859
+ (a) => a.type === "heading" || tn(a)
430
1860
  );
431
1861
  if (n <= 0)
432
1862
  return { introduction: null, rest: e };
433
- const o = e.slice(0, n), i = e.slice(n), r = x(o, t, !0);
434
- return { introduction: r.length > 0 ? h("introduction", r) : null, rest: i };
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 };
435
1865
  }
436
- function De(e) {
1866
+ function nn(e) {
437
1867
  const t = e.data;
438
- return t?.id ? { "xml:id": t.id } : void 0;
1868
+ return t?.id ? { ...t.attributes, "xml:id": t.id } : void 0;
439
1869
  }
440
- function Ce(e, t) {
441
- const n = De(e), o = S(t);
442
- if (!(!n && !o))
443
- return { ...o, ...n };
1870
+ function rn(e, t) {
1871
+ const n = nn(e), i = B(t);
1872
+ if (!(!n && !i))
1873
+ return { ...i, ...n };
444
1874
  }
445
- function S(e) {
1875
+ function B(e) {
446
1876
  if (e.depth !== 0) return;
447
1877
  const t = e.topLevelAttributesApplied;
448
1878
  if (!(!e.topLevelAttributes || !t || t.done))
449
1879
  return t.done = !0, e.topLevelAttributes;
450
1880
  }
451
- const Le = {
452
- paragraph: (e, t) => G(e, t),
453
- blockquote: (e, t) => xe(e, t),
454
- list: (e, t) => we(e, t),
455
- code: (e, t) => Se(e),
456
- containerDirective: (e, t) => J(e, t),
457
- leafDirective: (e, t) => Ae(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
458
1889
  };
459
- function O(e, t) {
460
- const n = Le[e.type];
1890
+ function J(e, t) {
1891
+ const n = sn[e.type];
461
1892
  return n ? n(e, t) : (t.messages && t.messages.push({
462
1893
  type: "warning",
463
1894
  reason: `Unknown block type: ${e.type}`,
464
1895
  category: "unknown-block-type"
465
- }), P(
1896
+ }), ce(
466
1897
  "unknown-block-type",
467
1898
  `unknown block type "${e.type}"`,
468
- R(e, t)
1899
+ q(e, t)
469
1900
  ));
470
1901
  }
471
- function G(e, t) {
472
- return h("p", b(e.children, t));
1902
+ function on(e, t) {
1903
+ return k("p", N(e.children, t));
473
1904
  }
474
- function xe(e, t) {
475
- const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
476
- const i = {
1905
+ function ln(e, t) {
1906
+ const n = e.children.filter((i) => i.type === "paragraph" || i.type === "ptxRaw").map((i) => {
1907
+ const r = {
477
1908
  ...t,
478
1909
  ancestors: [...t.ancestors, e],
479
1910
  depth: t.depth + 1
480
1911
  };
481
- return G(o, i);
1912
+ return J(i, r);
482
1913
  });
483
- return h("blockquote", n);
1914
+ return k("blockquote", n);
484
1915
  }
485
- function we(e, t) {
486
- const n = e.children.map((o) => {
487
- const i = {
1916
+ function cn(e, t) {
1917
+ const n = e.children.map((i) => {
1918
+ const r = {
488
1919
  ...t,
489
1920
  ancestors: [...t.ancestors, e],
490
1921
  depth: t.depth + 1
491
1922
  };
492
- return Ie(o, i);
1923
+ return an(i, r);
493
1924
  });
494
- return h(e.ordered ? "ol" : "ul", n);
1925
+ return k(e.ordered ? "ol" : "ul", n);
495
1926
  }
496
- function Ie(e, t) {
497
- const n = x(
1927
+ function an(e, t) {
1928
+ const n = $(
498
1929
  e.children,
499
1930
  t
500
1931
  );
501
- return h("li", n);
1932
+ return k("li", n);
502
1933
  }
503
- function Se(e, t) {
504
- return k(
1934
+ function un(e, t) {
1935
+ return _(
505
1936
  "program",
506
1937
  e.value,
507
1938
  e.lang ? { language: e.lang } : void 0
508
1939
  );
509
1940
  }
510
- function Te(e, t) {
511
- const n = e.value.split(/\\\\|[\r\n]+/).map((o) => o.trim()).filter((o) => o.length > 0);
512
- return n.length > 1 ? h(
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(
513
1944
  "md",
514
- n.map((o) => k("mrow", o))
515
- ) : k("md", n[0] ?? "");
1945
+ n.map((i) => _("mrow", i))
1946
+ ) : _("md", n[0] ?? "");
516
1947
  }
517
- function Ee(e, t) {
518
- return e.meta === "inline" ? k("m", e.value) : Te(e);
1948
+ function fn(e, t) {
1949
+ return e.meta === "inline" ? _("m", e.value) : hn(e);
519
1950
  }
520
- function qe(e, t) {
521
- return h("url", b(e.children, t), { href: e.url });
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 });
522
1954
  }
523
- function Ae(e, t) {
524
- const n = he(e);
1955
+ function dn(e, t) {
1956
+ const n = Dt(e);
525
1957
  return n || (t.messages && t.messages.push({
526
1958
  type: "warning",
527
1959
  reason: "Unnamed leaf directive",
528
1960
  category: "unknown-directive"
529
- }), P(
1961
+ }), ce(
530
1962
  "unknown-directive",
531
1963
  "unnamed leaf directive",
532
- R(e, t)
1964
+ q(e, t)
533
1965
  ));
534
1966
  }
535
- function J(e, t) {
536
- const n = de(e.name);
1967
+ function Ze(e, t) {
1968
+ const n = Wt(e.name);
537
1969
  if (!n)
538
1970
  return t.messages && t.messages.push({
539
1971
  type: "warning",
540
1972
  reason: `Unknown directive: ${e.name}`,
541
1973
  category: "unknown-directive"
542
- }), P(
1974
+ }), ce(
543
1975
  "unknown-directive",
544
1976
  `unknown directive "${e.name}"`,
545
- R(e, t)
1977
+ q(e, t)
546
1978
  );
547
- const o = Re(e), i = e.children, { title: r, body: s } = $e(
548
- i,
1979
+ const i = gn(e), r = e.children, { title: s, body: c } = mn(
1980
+ r,
549
1981
  t
550
- ), l = {
1982
+ ), a = {
551
1983
  ...t,
552
1984
  ancestors: [...t.ancestors, e],
553
1985
  depth: t.depth + 1
554
1986
  };
555
- return ge(
1987
+ return Ht(
556
1988
  n,
557
- o,
558
- r,
1989
+ i,
559
1990
  s,
560
- l,
561
- (c, u) => O(c, u),
562
- (c, u) => J(c, u)
1991
+ c,
1992
+ a,
1993
+ (h, p) => J(h, p),
1994
+ (h, p) => Ze(h, p)
563
1995
  );
564
1996
  }
565
- function $e(e, t) {
1997
+ function mn(e, t) {
566
1998
  const n = e[0];
567
1999
  return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
568
- title: h(
2000
+ title: k(
569
2001
  "title",
570
- b(n.children, t)
2002
+ N(n.children, t)
571
2003
  ),
572
2004
  body: e.slice(1)
573
2005
  } : { title: null, body: e };
574
2006
  }
575
- function Re(e) {
2007
+ function gn(e) {
576
2008
  const t = e.attributes ?? {}, n = {};
577
- for (const [o, i] of Object.entries(t))
578
- i != null && (n[o === "id" ? "xml:id" : o] = i);
2009
+ for (const [i, r] of Object.entries(t))
2010
+ r != null && (n[i === "id" ? "xml:id" : i] = r);
579
2011
  return Object.keys(n).length > 0 ? n : void 0;
580
2012
  }
581
- function Fe(e, t) {
2013
+ function yn(e, t) {
582
2014
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
583
2015
  }
584
- const Me = {
585
- text: (e, t) => E(e.value),
2016
+ const vn = {
2017
+ text: (e, t) => Ve(e.value),
586
2018
  emphasis: (e, t) => {
587
- const o = Fe(e, t.source) === "underscore" ? "term" : "em";
588
- return h(o, b(e.children, t));
2019
+ const i = yn(e, t.source) === "underscore" ? "term" : "em";
2020
+ return k(i, N(e.children, t));
589
2021
  },
590
- strong: (e, t) => h("alert", b(e.children, t)),
591
- inlineCode: (e, t) => k("c", e.value),
592
- math: (e, t) => Ee(e),
593
- link: (e, t) => qe(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)
594
2026
  };
595
- function b(e, t) {
596
- return e.flatMap((n) => Oe(n, t)).filter((n) => n !== null);
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;
2039
+ }
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 };
597
2059
  }
598
- function Oe(e, t) {
599
- const n = Me[e.type];
2060
+ function wn(e, t) {
2061
+ const n = vn[e.type];
600
2062
  if (!n)
601
2063
  return t.messages && t.messages.push({
602
2064
  type: "warning",
603
2065
  reason: `Unknown inline type: ${e.type}`,
604
2066
  category: "unknown-inline-type"
605
- }), ye(
2067
+ }), Zt(
606
2068
  "unknown-inline-type",
607
2069
  `unknown inline type "${e.type}"`,
608
- R(e, t)
2070
+ q(e, t)
609
2071
  );
610
- const o = { ...t, ancestors: [...t.ancestors, e] };
611
- return n(e, o);
612
- }
613
- const Ne = [
614
- // Display math (check these first, before single $)
615
- { open: "$$", close: "$$", isDisplay: !0 },
616
- { open: "\\[", close: "\\]", isDisplay: !0 },
617
- // Inline math
618
- { open: "$", close: "$", isDisplay: !1 },
619
- { open: "\\(", close: "\\)", isDisplay: !1 }
620
- ], ee = "PTX_MATH_TOKEN_", F = new RegExp(`${ee}(\\d+)`, "g");
621
- function te(e, t) {
622
- let n = null;
623
- for (const o of Ne) {
624
- const i = e.indexOf(o.open, t);
625
- if (i === -1) continue;
626
- const r = e.indexOf(o.close, i + o.open.length);
627
- if (r !== -1 && !(o.open === "$" && (i > 0 && e[i - 1] === "$" || i + 1 < e.length && e[i + 1] === "$")) && (!n || i < n.index)) {
628
- const s = e.substring(i + o.open.length, r);
629
- n = { index: i, pattern: o, content: s };
630
- }
631
- }
632
- return n;
633
- }
634
- function _e(e, t) {
635
- let n = t;
636
- for (; n < e.length; ) {
637
- const o = e.indexOf("`", n);
638
- if (o === -1) return null;
639
- let i = 0, r = o;
640
- for (; r < e.length && e[r] === "`"; )
641
- i++, r++;
642
- const s = "`".repeat(i);
643
- let l = r;
644
- for (; l < e.length; ) {
645
- const c = e.indexOf(s, l);
646
- if (c === -1) break;
647
- const u = c + i;
648
- if (u >= e.length || e[u] !== "`")
649
- return { start: o, end: u };
650
- l = c + 1;
651
- }
652
- n = o + i;
653
- }
654
- return null;
655
- }
656
- function Pe(e) {
657
- const t = /* @__PURE__ */ new Map();
658
- let n = "", o = 0, i = 0;
659
- for (; o < e.length; ) {
660
- const r = _e(e, o), s = te(e, o);
661
- if (r && (!s || r.start < s.index)) {
662
- n += e.substring(o, r.end), o = r.end;
663
- continue;
664
- }
665
- if (!s) {
666
- n += e.substring(o);
667
- break;
668
- }
669
- n += e.substring(o, s.index);
670
- const l = `${ee}${i}`;
671
- n += l, t.set(l, {
672
- type: "math",
673
- value: s.content,
674
- meta: s.pattern.isDisplay ? "display" : "inline"
675
- }), o = s.index + s.pattern.open.length + s.content.length + s.pattern.close.length, i += 1;
676
- }
677
- return { markdown: n, tokens: t };
678
- }
679
- function je(e) {
680
- const t = [];
681
- let n = 0;
682
- for (; n < e.length; ) {
683
- const o = te(e, n);
684
- if (!o) {
685
- n < e.length && t.push({ type: "text", value: e.substring(n) });
686
- break;
687
- }
688
- o.index > n && t.push({
689
- type: "text",
690
- value: e.substring(n, o.index)
691
- }), t.push({
692
- type: "math",
693
- value: o.content,
694
- meta: o.pattern.isDisplay ? "display" : "inline"
695
- }), n = o.index + o.pattern.open.length + o.content.length + o.pattern.close.length;
696
- }
697
- return t.length === 0 ? [{ type: "text", value: e }] : t;
698
- }
699
- function Be(e, t) {
700
- const n = [];
701
- let o = 0;
702
- F.lastIndex = 0;
703
- let i = F.exec(e);
704
- for (; i; ) {
705
- const r = i.index, s = i[0];
706
- r > o && n.push({ type: "text", value: e.substring(o, r) });
707
- const l = t.get(s);
708
- l ? n.push(l) : n.push({ type: "text", value: s }), o = r + s.length, i = F.exec(e);
709
- }
710
- return o < e.length && n.push({ type: "text", value: e.substring(o) }), n.length === 0 ? [{ type: "text", value: e }] : n;
2072
+ const i = { ...t, ancestors: [...t.ancestors, e] };
2073
+ return n(e, i);
711
2074
  }
712
- function ne(e) {
713
- K(e, "paragraph", (t) => {
714
- const n = t.children || [], o = [];
715
- for (const i of n)
716
- if (i.type === "text") {
717
- const r = je(i.value);
718
- o.push(...r);
719
- } else
720
- o.push(i);
721
- t.children = o;
722
- });
723
- }
724
- function ze(e, t) {
725
- K(e, "paragraph", (n) => {
726
- const o = n.children || [], i = [];
727
- for (const r of o)
728
- if (r.type === "text") {
729
- const s = Be(r.value, t);
730
- i.push(...s);
731
- } else
732
- i.push(r);
733
- n.children = i;
734
- });
735
- }
736
- const jt = () => (e) => {
737
- ne(e);
738
- };
739
- function We(e) {
2075
+ function xn(e) {
740
2076
  const t = e.trim();
741
2077
  if (!t.startsWith(":")) return null;
742
2078
  let n = 0;
743
- for (let r = 0; r < t.length && t[r] === ":"; r++)
2079
+ for (let s = 0; s < t.length && t[s] === ":"; s++)
744
2080
  n++;
745
2081
  if (n < 3) return null;
746
- const o = t.slice(n).trim(), i = o.match(
2082
+ const i = t.slice(n).trim(), r = i.match(
747
2083
  /^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/
748
2084
  );
749
- return o === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : i ? {
2085
+ return i === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : r ? {
750
2086
  colons: n,
751
- label: i[0],
2087
+ label: r[0],
752
2088
  lineIndex: -1,
753
2089
  isOpen: !0
754
2090
  } : null;
755
2091
  }
756
- function Ue(e) {
2092
+ function kn(e) {
757
2093
  const t = [], n = [];
758
- for (const o of e)
759
- if (o.isOpen) {
760
- const i = {
761
- colons: o.colons,
762
- finalColons: o.colons,
763
- label: o.label,
764
- openLineIndex: o.lineIndex,
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,
765
2101
  closeLineIndex: null,
766
2102
  children: [],
767
2103
  parent: null
768
2104
  };
769
2105
  if (t.length > 0) {
770
- const r = t[t.length - 1];
771
- i.parent = r, r.children.push(i);
2106
+ const s = t[t.length - 1];
2107
+ r.parent = s, s.children.push(r);
772
2108
  } else
773
- n.push(i);
774
- t.push(i);
2109
+ n.push(r);
2110
+ t.push(r);
775
2111
  } else {
776
- const i = t[t.length - 1];
777
- i && i.colons === o.colons && (i.closeLineIndex = o.lineIndex, t.pop());
2112
+ const r = t[t.length - 1];
2113
+ r && r.colons === i.colons && (r.closeLineIndex = i.lineIndex, t.pop());
778
2114
  }
779
2115
  return n;
780
2116
  }
781
- function oe(e) {
2117
+ function Ge(e) {
782
2118
  if (e.children.length === 0)
783
2119
  e.finalColons = e.colons;
784
2120
  else {
785
- const t = Math.max(...e.children.map(oe));
2121
+ const t = Math.max(...e.children.map(Ge));
786
2122
  e.finalColons = Math.max(e.colons, t + 1);
787
2123
  }
788
2124
  return e.finalColons;
789
2125
  }
790
- function He(e, t, n) {
791
- const o = e.slice(), i = [], r = t.slice();
792
- for (; r.length > 0; ) {
793
- const s = r.shift();
794
- i.push(s), r.push(...s.children);
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);
795
2131
  }
796
- for (const s of i) {
797
- if (s.openLineIndex >= 0) {
798
- const l = o[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, u = l.slice(c);
799
- o[s.openLineIndex] = ":".repeat(s.finalColons) + u;
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;
800
2136
  }
801
- s.closeLineIndex !== null && s.closeLineIndex >= 0 && (o[s.closeLineIndex] = ":".repeat(s.finalColons));
2137
+ c.closeLineIndex !== null && c.closeLineIndex >= 0 && (i[c.closeLineIndex] = ":".repeat(c.finalColons));
802
2138
  }
803
- return o;
2139
+ return i;
804
2140
  }
805
- function Xe(e) {
2141
+ function Dn(e) {
806
2142
  const t = e.split(`
807
2143
  `), n = [];
808
- let o = !1, i = null;
809
- for (let l = 0; l < t.length; l++) {
810
- const c = t[l], a = c.trim().match(/^(`{3,}|~{3,})/);
811
- if (a) {
812
- const d = a[1];
813
- o ? i && d[0] === i[0] && d.length >= i.length && (o = !1, i = null) : (o = !0, i = d);
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);
814
2150
  continue;
815
2151
  }
816
- if (o)
2152
+ if (i)
817
2153
  continue;
818
- const p = We(c);
819
- p && n.push({ ...p, lineIndex: l });
2154
+ const g = xn(h);
2155
+ g && n.push({ ...g, lineIndex: a });
820
2156
  }
821
2157
  if (n.length === 0)
822
2158
  return e;
823
- const r = Ue(n);
824
- for (const l of r)
825
- oe(l);
826
- return He(t, r).join(`
2159
+ const s = kn(n);
2160
+ for (const a of s)
2161
+ Ge(a);
2162
+ return En(t, s).join(`
827
2163
  `);
828
2164
  }
829
- function Ze(e) {
2165
+ function Tn(e) {
830
2166
  const t = e.trim();
831
2167
  if (!t.endsWith(":")) return null;
832
2168
  const n = t.slice(0, -1);
833
2169
  if (!/^[a-zA-Z]/.test(n)) return null;
834
- const o = n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
835
- if (!o) return null;
836
- const [, i, r] = o;
837
- return r && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r) || !$[i.toLowerCase()] ? null : n;
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;
838
2174
  }
839
- function N(e) {
2175
+ function ie(e) {
840
2176
  let t = 0;
841
2177
  for (let n = 0; n < e.length; n++)
842
2178
  if (e[n] === " ")
@@ -847,85 +2183,85 @@ function N(e) {
847
2183
  break;
848
2184
  return t;
849
2185
  }
850
- function Ve(e, t) {
851
- const n = N(e[t]);
852
- for (let o = t + 1; o < e.length; o++)
853
- if (!ie(e[o]))
854
- return N(e[o]) > n;
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;
855
2191
  return !1;
856
2192
  }
857
- function ie(e) {
2193
+ function Ke(e) {
858
2194
  return e.trim() === "";
859
2195
  }
860
- function Ke(e, t) {
861
- let n = 0, o = 0;
862
- for (; o < e.length && n < t; )
863
- if (e[o] === " ")
864
- n++, o++;
865
- else if (e[o] === " ")
866
- n += 4, o++;
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++;
867
2203
  else
868
2204
  break;
869
- return e.slice(o);
2205
+ return e.slice(i);
870
2206
  }
871
- function Ye(e) {
2207
+ function Sn(e) {
872
2208
  const t = e.split(`
873
- `), n = [], o = {
2209
+ `), n = [], i = {
874
2210
  level: 0,
875
2211
  openDirectives: [],
876
2212
  inCodeFence: !1,
877
2213
  codeFenceMarker: null
878
2214
  };
879
- for (let i = 0; i < t.length; i++) {
880
- const r = t[i], s = r.trim(), l = N(r), c = s.match(/^(`{3,}|~{3,})/);
881
- if (c) {
882
- const a = c[1];
883
- o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker = a), n.push(r);
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);
884
2220
  continue;
885
2221
  }
886
- if (o.inCodeFence) {
887
- n.push(r);
2222
+ if (i.inCodeFence) {
2223
+ n.push(s);
888
2224
  continue;
889
2225
  }
890
- if (ie(r)) {
2226
+ if (Ke(s)) {
891
2227
  n.push("");
892
2228
  continue;
893
2229
  }
894
- const u = Ze(s);
895
- if (u && Ve(t, i)) {
896
- for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
897
- const y = o.openDirectives.pop();
898
- y && n.push(":".repeat(y.colonCount));
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));
899
2235
  }
900
- const a = u.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/), p = a ? a[1].toLowerCase() + (a[2] || "") : u, d = o.openDirectives.length * 1 + 3;
901
- n.push(":".repeat(d) + p), o.openDirectives.push({
902
- label: p,
903
- indentLevel: l,
904
- colonCount: d,
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,
905
2241
  bodyBaseIndent: -1
906
- }), o.level = l;
2242
+ }), i.level = a;
907
2243
  } else {
908
- for (; o.openDirectives.length > 0 && l <= o.openDirectives[o.openDirectives.length - 1].indentLevel; ) {
909
- const a = o.openDirectives.pop();
910
- a && n.push(":".repeat(a.colonCount));
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));
911
2247
  }
912
- if (o.openDirectives.length > 0) {
913
- const a = o.openDirectives[o.openDirectives.length - 1];
914
- a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ke(r, a.bodyBaseIndent));
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));
915
2251
  } else
916
- n.push(r);
917
- o.level = l;
2252
+ n.push(s);
2253
+ i.level = a;
918
2254
  }
919
2255
  }
920
- for (; o.openDirectives.length > 0; ) {
921
- const i = o.openDirectives.pop();
922
- i && n.push(":".repeat(i.colonCount));
2256
+ for (; i.openDirectives.length > 0; ) {
2257
+ const r = i.openDirectives.pop();
2258
+ r && n.push(":".repeat(r.colonCount));
923
2259
  }
924
2260
  return n.join(`
925
2261
  `);
926
2262
  }
927
- const Qe = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Ge = /^division:\s*(\S+)\s*$/m, Je = /^id:\s*(\S+)\s*$/m, et = /^xmlid:\s*(\S+)\s*$/m, tt = /^xml:id:\s*(\S+)\s*$/m, nt = /^label:\s*(\S+)\s*$/m, ot = /^component:\s*(\S+)\s*$/m, it = /^title:\s*(.+?)\s*$/m;
928
- function rt(e) {
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) {
929
2265
  if (e.length >= 2) {
930
2266
  const t = e[0], n = e[e.length - 1];
931
2267
  if (t === '"' && n === '"' || t === "'" && n === "'")
@@ -933,206 +2269,205 @@ function rt(e) {
933
2269
  }
934
2270
  return e;
935
2271
  }
936
- function st(e) {
937
- const t = e.match(Qe);
2272
+ function Fn(e) {
2273
+ const t = e.match(Ln);
938
2274
  if (!t)
939
2275
  return { body: e };
940
- const n = t[1], o = e.slice(t[0].length), i = n.match(Ge)?.[1];
941
- let r, s;
942
- i && pe(i) ? (s = i, r = M(i)) : i && V(i) && (r = i);
943
- const l = {}, c = n.match(Je)?.[1] ?? n.match(et)?.[1] ?? n.match(tt)?.[1], u = n.match(nt)?.[1], a = n.match(ot)?.[1];
944
- c && (l["xml:id"] = c), u && (l.label = u), a && (l.component = a);
945
- const p = n.match(it)?.[1], d = p ? rt(p) : void 0;
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;
946
2282
  return {
947
- division: r,
948
- documentRoot: s,
949
- attributes: Object.keys(l).length > 0 ? l : void 0,
950
- title: d,
951
- body: o
2283
+ division: s,
2284
+ documentRoot: c,
2285
+ attributes: Object.keys(a).length > 0 ? a : void 0,
2286
+ title: x,
2287
+ body: i
952
2288
  };
953
2289
  }
954
- const lt = function(e) {
955
- return function(n, o) {
956
- if (typeof o?.value == "string") {
957
- const i = st(o.value), r = e?.documentRoot ?? i.documentRoot, s = e?.topLevelDivision ?? i.division ?? (r ? M(r) : "chapter"), l = e?.topLevelAttributes ?? i.attributes, c = e?.topLevelTitle ?? i.title, u = Ye(
958
- i.body
959
- ), a = Xe(u), p = Pe(a), g = H().data("micromarkExtensions", [
960
- { disable: { null: ["codeIndented"] } }
961
- ]).use(X).use(Z).parse(p.markdown);
962
- return ze(g, p.tokens), B(g, p.markdown, {
963
- topLevelDivision: s,
964
- documentRoot: r,
965
- topLevelAttributes: l,
966
- 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
967
2302
  });
968
2303
  }
969
- return ne(n), B(n, void 0, {
970
- topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? M(e.documentRoot) : "chapter"),
2304
+ return je(n), Ie(n, void 0, {
2305
+ topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? te(e.documentRoot) : "chapter"),
971
2306
  documentRoot: e?.documentRoot,
972
2307
  topLevelAttributes: e?.topLevelAttributes,
973
2308
  topLevelTitle: e?.topLevelTitle
974
2309
  });
975
2310
  };
976
- }, ct = /["&'<>`]/g, ut = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, at = (
2311
+ }, jn = /["&'<>`]/g, Xn = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, Bn = (
977
2312
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
978
2313
  /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
979
- ), pt = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
980
- function ft(e, t) {
2314
+ ), Un = /[|\\{}()[\]^$+*?.]/g, Se = /* @__PURE__ */ new WeakMap();
2315
+ function Yn(e, t) {
981
2316
  if (e = e.replace(
982
- t.subset ? ht(t.subset) : ct,
983
- o
2317
+ t.subset ? zn(t.subset) : jn,
2318
+ i
984
2319
  ), t.subset || t.escapeOnly)
985
2320
  return e;
986
- return e.replace(ut, n).replace(at, o);
987
- function n(i, r, s) {
2321
+ return e.replace(Xn, n).replace(Bn, i);
2322
+ function n(r, s, c) {
988
2323
  return t.format(
989
- (i.charCodeAt(0) - 55296) * 1024 + i.charCodeAt(1) - 56320 + 65536,
990
- s.charCodeAt(r + 2),
2324
+ (r.charCodeAt(0) - 55296) * 1024 + r.charCodeAt(1) - 56320 + 65536,
2325
+ c.charCodeAt(s + 2),
991
2326
  t
992
2327
  );
993
2328
  }
994
- function o(i, r, s) {
2329
+ function i(r, s, c) {
995
2330
  return t.format(
996
- i.charCodeAt(0),
997
- s.charCodeAt(r + 1),
2331
+ r.charCodeAt(0),
2332
+ c.charCodeAt(s + 1),
998
2333
  t
999
2334
  );
1000
2335
  }
1001
2336
  }
1002
- function ht(e) {
1003
- let t = z.get(e);
1004
- return t || (t = dt(e), z.set(e, t)), t;
2337
+ function zn(e) {
2338
+ let t = Se.get(e);
2339
+ return t || (t = Jn(e), Se.set(e, t)), t;
1005
2340
  }
1006
- function dt(e) {
2341
+ function Jn(e) {
1007
2342
  const t = [];
1008
2343
  let n = -1;
1009
2344
  for (; ++n < e.length; )
1010
- t.push(e[n].replace(pt, "\\$&"));
2345
+ t.push(e[n].replace(Un, "\\$&"));
1011
2346
  return new RegExp("(?:" + t.join("|") + ")", "g");
1012
2347
  }
1013
- function mt(e) {
2348
+ function Wn(e) {
1014
2349
  return "&#x" + e.toString(16).toUpperCase() + ";";
1015
2350
  }
1016
- function gt(e, t) {
1017
- return ft(e, Object.assign({ format: mt }, t));
2351
+ function Vn(e, t) {
2352
+ return Yn(e, Object.assign({ format: Wn }, t));
1018
2353
  }
1019
- const yt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
1020
- function D(e, t, n) {
1021
- const o = vt(e);
1022
- return n ? o.replace(n, i) : i(o);
1023
- function i(r) {
1024
- return gt(r, { subset: t });
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 });
1025
2360
  }
1026
2361
  }
1027
- function vt(e) {
1028
- return String(e || "").replace(yt, "");
2362
+ function Zn(e) {
2363
+ return String(e || "").replace(Hn, "");
1029
2364
  }
1030
- const kt = /]]>/g, bt = [">"];
1031
- function Dt(e) {
1032
- return "<![CDATA[" + D(e.value, bt, kt) + "]]>";
2365
+ const Gn = /]]>/g, Kn = [">"];
2366
+ function Qn(e) {
2367
+ return "<![CDATA[" + O(e.value, Kn, Gn) + "]]>";
1033
2368
  }
1034
- function Ct(e) {
1035
- return "<!--" + D(e.value, ["-"]) + "-->";
2369
+ function ei(e) {
2370
+ return "<!--" + O(e.value, ["-"]) + "-->";
1036
2371
  }
1037
- const Lt = [" ", `
2372
+ const ti = [" ", `
1038
2373
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
1039
- function A(e) {
1040
- return D(e, Lt);
2374
+ function W(e) {
2375
+ return O(e, ti);
1041
2376
  }
1042
- function W(e, t) {
2377
+ function Le(e, t) {
1043
2378
  const n = String(e);
1044
2379
  if (typeof t != "string")
1045
2380
  throw new TypeError("Expected character");
1046
- let o = 0, i = n.indexOf(t);
1047
- for (; i !== -1; )
1048
- o++, i = n.indexOf(t, i + t.length);
1049
- return o;
2381
+ let i = 0, r = n.indexOf(t);
2382
+ for (; r !== -1; )
2383
+ i++, r = n.indexOf(t, r + t.length);
2384
+ return i;
1050
2385
  }
1051
- function _(e, t) {
2386
+ function re(e, t) {
1052
2387
  const n = String(e);
1053
- let o = t.options.quote || '"';
2388
+ let i = t.options.quote || '"';
1054
2389
  if (t.options.quoteSmart) {
1055
- const i = o === '"' ? "'" : '"';
1056
- W(n, o) > W(n, i) && (o = i);
2390
+ const r = i === '"' ? "'" : '"';
2391
+ Le(n, i) > Le(n, r) && (i = r);
1057
2392
  }
1058
- return o + D(n, ["<", "&", o]) + o;
1059
- }
1060
- function xt(e, t) {
1061
- const n = A(e.name), o = e.public, i = e.system;
1062
- let r = "<!DOCTYPE";
1063
- return n !== "" && (r += " " + n), o ? r += " PUBLIC " + _(o, t) : i && (r += " SYSTEM"), i && (r += " " + _(i, t)), r + ">";
1064
- }
1065
- const wt = {}.hasOwnProperty;
1066
- function It(e, t) {
1067
- const n = A(e.name), o = le(e, t), i = e.attributes || {}, r = o ? !1 : t.options.closeEmptyElements, s = [];
1068
- let l;
1069
- for (l in i)
1070
- if (wt.call(i, l)) {
1071
- const c = i[l];
1072
- c != null && s.push(A(l) + "=" + _(c, t));
1073
- }
1074
- return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (r ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (r ? "" : "</" + n + ">");
1075
- }
1076
- const St = /\?>/g, Tt = [">"];
1077
- function Et(e) {
1078
- const t = A(e.name) || "x", n = D(e.value, Tt, St);
1079
- return "<?" + t + (n ? " " + n : "") + "?>";
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 + ">");
1080
2410
  }
1081
- const qt = ["&", "<"];
1082
- function re(e) {
1083
- return D(e.value, qt);
2411
+ const si = /\?>/g, oi = [">"];
2412
+ function li(e) {
2413
+ const t = W(e.name) || "x", n = O(e.value, oi, si);
2414
+ return "<?" + t + (n ? " " + n : "") + "?>";
1084
2415
  }
1085
- function At(e, t) {
1086
- return t.options.allowDangerousXml ? e.value : re(e);
1087
- }
1088
- const $t = {}.hasOwnProperty, U = {
1089
- cdata: Dt,
1090
- comment: Ct,
1091
- doctype: xt,
1092
- element: It,
1093
- instruction: Et,
1094
- raw: At,
1095
- root: le,
1096
- text: re
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
1097
2432
  };
1098
- function se(e, t) {
2433
+ function et(e, t) {
1099
2434
  const n = e && e.type;
1100
2435
  if (!n)
1101
2436
  throw new Error("Expected node, not `" + e + "`");
1102
- if (!$t.call(U, n))
2437
+ if (!ui.call(Ne, n))
1103
2438
  throw new Error("Cannot compile unknown node `" + n + "`");
1104
- const o = U[n];
1105
- return o(e, t);
2439
+ const i = Ne[n];
2440
+ return i(e, t);
1106
2441
  }
1107
- function le(e, t) {
2442
+ function tt(e, t) {
1108
2443
  const n = e && e.children || [];
1109
- let o = -1;
1110
- const i = [];
1111
- for (; ++o < n.length; )
1112
- i[o] = se(n[o], t);
1113
- return i.join("");
2444
+ let i = -1;
2445
+ const r = [];
2446
+ for (; ++i < n.length; )
2447
+ r[i] = et(n[i], t);
2448
+ return r.join("");
1114
2449
  }
1115
- function Rt(e, t) {
2450
+ function hi(e, t) {
1116
2451
  const n = { options: t || {} };
1117
2452
  if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
1118
2453
  throw new Error(
1119
2454
  "Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
1120
2455
  );
1121
- const o = Array.isArray(e) ? { type: "root", children: e } : e;
1122
- return se(o, n);
2456
+ const i = Array.isArray(e) ? { type: "root", children: e } : e;
2457
+ return et(i, n);
1123
2458
  }
1124
- function Bt(e, t) {
1125
- const n = H().use(X).use(Z).use(lt, t), o = n.parse(e), i = n.runSync(o, { value: e });
1126
- return Rt(i.children, {
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, {
1127
2462
  closeEmptyElements: !0,
1128
2463
  tightClose: !0
1129
2464
  });
1130
2465
  }
1131
2466
  export {
1132
- Pt as DIRECTIVE_MAP,
1133
- Y as PROOF_SOLUTION_NAMES,
1134
- Bt as markdownToPretext,
1135
- B as mdastToPtxast,
1136
- jt as remarkMath,
1137
- lt as remarkPretext
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
1138
2473
  };