@pretextbook/remark-pretext 0.0.6 → 0.0.8

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,9 +1,24 @@
1
- import { unified as R } from "unified";
2
- import _ from "remark-parse";
3
- import j from "remark-directive";
4
- import { divisionTypeAtRelativeDepth as re, isDivisionType as ie } from "@pretextbook/ptxast";
5
- import { visit as B } from "unist-util-visit";
6
- const I = {
1
+ import { unified as W } from "unified";
2
+ import U from "remark-parse";
3
+ import H from "remark-directive";
4
+ import { isTitlelessDivisionType as se, divisionTypeAtRootDepth as le, divisionTypeAtRelativeDepth as ce, isRootDivisionType as ae, rootChildDivision as q, isTopLevelDivisionType as ue } from "@pretextbook/ptxast";
5
+ import { visit as X } from "unist-util-visit";
6
+ function pe(e, t = {}) {
7
+ const n = {};
8
+ for (const [o, r] of Object.entries(t))
9
+ r != null && (n[o] = r);
10
+ return {
11
+ type: "element",
12
+ name: `plus:${e}`,
13
+ attributes: n,
14
+ children: []
15
+ };
16
+ }
17
+ function fe(e) {
18
+ const t = e.name?.trim();
19
+ return t ? pe(t, e.attributes ?? {}) : null;
20
+ }
21
+ const S = {
7
22
  // theorem-like (requires statement wrapping)
8
23
  theorem: { type: "theorem", category: "theorem-like", requiresStatement: !0 },
9
24
  lemma: { type: "lemma", category: "theorem-like", requiresStatement: !0 },
@@ -44,307 +59,344 @@ const I = {
44
59
  solution: { type: "solution", category: "solution-like", requiresStatement: !1 },
45
60
  hint: { type: "hint", category: "solution-like", requiresStatement: !1 },
46
61
  answer: { type: "answer", category: "solution-like", requiresStatement: !1 }
47
- }, xt = I;
48
- function se(e) {
49
- return I[e.toLowerCase()];
62
+ }, Mt = S;
63
+ function he(e) {
64
+ return S[e.toLowerCase()];
50
65
  }
51
- const z = new Set(
52
- Object.entries(I).filter(([e, t]) => t.category === "proof-like" || t.category === "solution-like").map(([e]) => e)
66
+ const Z = new Set(
67
+ Object.entries(S).filter(([e, t]) => t.category === "proof-like" || t.category === "solution-like").map(([e]) => e)
53
68
  );
54
- function x(e, t, o) {
69
+ function b(e, t, n) {
55
70
  return {
56
71
  type: "element",
57
72
  name: e,
58
- attributes: o ?? {},
73
+ attributes: n ?? {},
59
74
  children: t
60
75
  };
61
76
  }
62
- function C(e) {
77
+ function x(e) {
63
78
  return e.type === "containerDirective" && e.name === "task";
64
79
  }
65
- function le(e) {
66
- return e.type === "containerDirective" && z.has(e.name);
80
+ function de(e) {
81
+ return e.type === "containerDirective" && Z.has(e.name);
67
82
  }
68
- function w(e) {
83
+ function L(e) {
69
84
  const t = [];
70
- for (const o of e)
71
- o.name === "ul" || o.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(o) : t.push(x("p", [o])) : t.push(o);
85
+ for (const n of e)
86
+ n.name === "ul" || n.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(n) : t.push(b("p", [n])) : t.push(n);
72
87
  return t;
73
88
  }
74
- function ce(e, t, o, n, r, i, s) {
89
+ function me(e, t, n, o, r, i, s) {
75
90
  const l = [];
76
- if (o && l.push(o), e.hasNestedTasks) {
77
- const c = n.findIndex(C);
91
+ if (n && l.push(n), e.hasNestedTasks) {
92
+ const c = o.findIndex(x);
78
93
  if (c !== -1) {
79
94
  const a = [];
80
- for (let p = 0; p < n.length; p++)
81
- C(n[p]) && a.push(p);
82
- const u = a[a.length - 1], d = n.slice(0, c), m = n.slice(c).filter(C), v = [], y = [], $ = [];
83
- for (let p = c; p < n.length; p++) {
84
- const f = n[p];
85
- if (!C(f)) {
95
+ for (let p = 0; p < o.length; p++)
96
+ x(o[p]) && a.push(p);
97
+ const u = a[a.length - 1], d = o.slice(0, c), m = o.slice(c).filter(x), k = [], y = [], O = [];
98
+ for (let p = c; p < o.length; p++) {
99
+ const f = o[p];
100
+ if (!x(f)) {
86
101
  if (p < u) {
87
- v.push(f);
102
+ k.push(f);
88
103
  continue;
89
104
  }
90
- if (le(f)) {
91
- $.push(f);
105
+ if (de(f)) {
106
+ O.push(f);
92
107
  continue;
93
108
  }
94
109
  y.push(f);
95
110
  }
96
111
  }
97
- if (v.length > 0 && (r.messages ?? (r.messages = [])).push({
112
+ if (k.length > 0 && (r.messages ?? (r.messages = [])).push({
98
113
  type: "warning",
99
- reason: `Dropped ${v.length} non-task node(s) between task directives in ${e.type}.`,
114
+ reason: `Dropped ${k.length} non-task node(s) between task directives in ${e.type}.`,
100
115
  category: "dropped-content-between-tasks",
101
- position: v[0].position?.start
116
+ position: k[0].position?.start
102
117
  }), d.length > 0) {
103
- const p = w(
118
+ const p = L(
104
119
  d.map((f) => i(f, r)).filter((f) => f !== null)
105
120
  );
106
- p.length > 0 && l.push(x("introduction", p));
121
+ p.length > 0 && l.push(b("introduction", p));
107
122
  }
108
123
  for (const p of m) {
109
124
  const f = s(p, r);
110
125
  f && l.push(f);
111
126
  }
112
127
  if (y.length > 0) {
113
- const p = w(
128
+ const p = L(
114
129
  y.map((f) => i(f, r)).filter((f) => f !== null)
115
130
  );
116
- p.length > 0 && l.push(x("conclusion", p));
131
+ p.length > 0 && l.push(b("conclusion", p));
117
132
  }
118
- for (const p of $) {
133
+ for (const p of O) {
119
134
  const f = s(p, r);
120
135
  f && l.push(f);
121
136
  }
122
137
  } else
123
- F(l, e, n, r, i, s);
138
+ _(l, e, o, r, i, s);
124
139
  } else
125
- F(l, e, n, r, i, s);
126
- return x(e.type, l, t);
140
+ _(l, e, o, r, i, s);
141
+ return b(e.type, l, t);
127
142
  }
128
- function F(e, t, o, n, r, i) {
143
+ function _(e, t, n, o, r, i) {
129
144
  if (t.requiresStatement) {
130
145
  const s = [], l = [];
131
- for (const c of o)
132
- if (c.type === "containerDirective" && z.has(c.name)) {
133
- const a = i(c, n);
146
+ for (const c of n)
147
+ if (c.type === "containerDirective" && Z.has(c.name)) {
148
+ const a = i(c, o);
134
149
  a && l.push(a);
135
150
  } else
136
151
  s.push(c);
137
152
  if (s.length > 0) {
138
- const c = w(
139
- s.map((a) => r(a, n)).filter((a) => a !== null)
153
+ const c = L(
154
+ s.map((a) => r(a, o)).filter((a) => a !== null)
140
155
  );
141
- c.length > 0 && e.push(x("statement", c));
156
+ c.length > 0 && e.push(b("statement", c));
142
157
  }
143
158
  e.push(...l);
144
159
  } else {
145
- const s = w(
146
- o.map((l) => r(l, n)).filter((l) => l !== null)
160
+ const s = L(
161
+ n.map((l) => r(l, o)).filter((l) => l !== null)
147
162
  );
148
163
  e.push(...s);
149
164
  }
150
165
  }
151
- function W(e) {
166
+ function V(e) {
152
167
  return { type: "text", value: e };
153
168
  }
154
- function h(e, t, o) {
169
+ function h(e, t, n) {
155
170
  return {
156
171
  type: "element",
157
172
  name: e,
158
- attributes: o ?? {},
173
+ attributes: n ?? {},
159
174
  children: t
160
175
  };
161
176
  }
162
- function g(e, t, o) {
163
- return h(e, [W(t)], o);
177
+ function g(e, t, n) {
178
+ return h(e, [V(t)], n);
164
179
  }
165
- function H(e) {
180
+ function K(e) {
166
181
  return { type: "comment", value: e.replace(/--/g, "- -") };
167
182
  }
168
- function M(e, t) {
169
- const o = e?.position, n = o?.start?.offset, r = o?.end?.offset;
170
- return t.source && n != null && r != null ? t.source.slice(n, r) : "";
183
+ function E(e, t) {
184
+ const n = e?.position, o = n?.start?.offset, r = n?.end?.offset;
185
+ return t.source && o != null && r != null ? t.source.slice(o, r) : "";
171
186
  }
172
- function U(e, t, o) {
173
- return h("TODO", [H(`todo: ${t}`), g("pre", o)], {
187
+ function F(e, t, n) {
188
+ return h("TODO", [K(`todo: ${t}`), g("pre", n)], {
174
189
  type: e
175
190
  });
176
191
  }
177
- function ae(e, t, o) {
178
- return h("TODO", [H(`todo: ${t}`), g("c", o)], {
192
+ function ge(e, t, n) {
193
+ return h("TODO", [K(`todo: ${t}`), g("c", n)], {
179
194
  type: e
180
195
  });
181
196
  }
182
- function Z(e) {
197
+ function N(e) {
183
198
  const t = [];
184
- for (const o of e)
185
- o.name === "ul" || o.name === "ol" ? t.length > 0 && t[t.length - 1]?.name === "p" ? t[t.length - 1].children.push(o) : t.push(h("p", [o])) : t.push(o);
199
+ for (const n of e)
200
+ 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);
186
201
  return t;
187
202
  }
188
- function N(e, t, o) {
189
- return ue(e, t, o).tree;
203
+ function P(e, t, n) {
204
+ return ye(e, t, n).tree;
190
205
  }
191
- function ue(e, t, o) {
192
- const n = [], r = {
206
+ function ye(e, t, n) {
207
+ const o = [], r = {
193
208
  ancestors: [],
194
209
  depth: 0,
195
- messages: n,
210
+ messages: o,
196
211
  source: t,
197
- topLevelDivision: o?.topLevelDivision ?? "chapter"
212
+ topLevelDivision: n?.topLevelDivision ?? "chapter",
213
+ documentRoot: n?.documentRoot,
214
+ topLevelAttributes: n?.topLevelAttributes,
215
+ topLevelAttributesApplied: n?.topLevelAttributes ? { done: !1 } : void 0
198
216
  }, i = e.children;
217
+ if (r.documentRoot) {
218
+ const l = A(r), c = C(i, r);
219
+ return {
220
+ tree: { type: "root", children: [h(r.documentRoot, c, l)] },
221
+ messages: o
222
+ };
223
+ }
224
+ if (se(r.topLevelDivision)) {
225
+ const l = A(r), c = N(
226
+ C(i, { ...r, depth: 1 }, !0)
227
+ );
228
+ return { tree: { type: "root", children: [h(r.topLevelDivision, c, l)] }, messages: o };
229
+ }
199
230
  return {
200
- tree: { type: "root", children: X(i, r) },
201
- messages: n
231
+ tree: { type: "root", children: C(i, r) },
232
+ messages: o
202
233
  };
203
234
  }
204
- function X(e, t, o = !1) {
205
- let n = 7;
235
+ function C(e, t, n = !1) {
236
+ let o = 7;
206
237
  for (const a of e)
207
- a.type === "heading" && (n = Math.min(n, a.depth));
208
- if (n === 7)
209
- return D(e, t, o);
238
+ a.type === "heading" && (o = Math.min(o, a.depth));
239
+ if (o === 7)
240
+ return w(e, t, n);
210
241
  const r = [];
211
242
  let i = null, s = [], l = [];
212
243
  const c = () => {
213
- i && (r.push(pe(i, l, t)), i = null, l = []);
244
+ i && (r.push(ve(i, l, t)), i = null, l = []);
214
245
  };
215
246
  for (const a of e)
216
- a.type === "heading" && a.depth === n ? (!i && s.length > 0 && (r.push(
217
- ...D(s, t, o)
247
+ a.type === "heading" && a.depth === o ? (!i && s.length > 0 && (r.push(
248
+ ...w(s, t, n)
218
249
  ), s = []), c(), i = a, l = []) : i ? l.push(a) : s.push(a);
219
250
  return !i && s.length > 0 && r.push(
220
- ...D(s, t, o)
251
+ ...w(s, t, n)
221
252
  ), c(), r;
222
253
  }
223
- function D(e, t, o = !1) {
224
- const n = [];
254
+ function w(e, t, n = !1) {
255
+ const o = [];
225
256
  for (let r = 0; r < e.length; r += 1) {
226
- const i = e[r], s = T(i, t);
257
+ const i = e[r], s = $(i, t);
227
258
  if (s !== null) {
228
259
  if (s.name === "p" && s.children.length === 1 && s.children[0].name === "md") {
229
- const l = s.children[0], c = n[n.length - 1], a = r + 1 < e.length ? T(e[r + 1], t) : null, u = a?.name === "p" ? a.children : null;
260
+ const l = s.children[0], c = o[o.length - 1], a = r + 1 < e.length ? $(e[r + 1], t) : null, u = a?.name === "p" ? a.children : null;
230
261
  if (c?.name === "p")
231
262
  c.children.push(l), u && (c.children.push(
232
263
  ...u
233
264
  ), r += 1);
234
265
  else {
235
266
  const d = [l];
236
- u && (d.push(...u), r += 1), n.push(h("p", d));
267
+ u && (d.push(...u), r += 1), o.push(h("p", d));
237
268
  }
238
269
  continue;
239
270
  }
240
- if ((s.name === "ul" || s.name === "ol") && n.length > 0) {
241
- const l = n[n.length - 1];
271
+ if ((s.name === "ul" || s.name === "ol") && o.length > 0) {
272
+ const l = o[o.length - 1];
242
273
  if (l?.name === "p") {
243
274
  l.children.push(s);
244
275
  continue;
245
276
  }
246
277
  }
247
- n.push(s);
278
+ o.push(s);
248
279
  }
249
280
  }
250
- return o ? Z(n) : n;
281
+ return n ? N(o) : o;
251
282
  }
252
- function pe(e, t, o) {
253
- const n = re(
254
- o.topLevelDivision,
255
- e.depth
256
- ), r = h("title", b(e.children, o)), i = fe(e), s = X(
283
+ function ve(e, t, n) {
284
+ const o = n.documentRoot ? le(n.documentRoot, e.depth) : ce(n.topLevelDivision, e.depth), r = h("title", D(e.children, n)), i = be(e, n), s = C(
257
285
  t,
258
- { ...o, depth: o.depth + 1 },
286
+ { ...n, depth: n.depth + 1 },
259
287
  !0
260
- ), l = Z(s);
261
- return h(n, [r, ...l], i);
288
+ ), l = N(s);
289
+ return h(o, [r, ...l], i);
262
290
  }
263
- function fe(e) {
291
+ function ke(e) {
264
292
  const t = e.data;
265
293
  return t?.id ? { "xml:id": t.id } : void 0;
266
294
  }
267
- const he = {
268
- paragraph: (e, t) => K(e, t),
269
- blockquote: (e, t) => de(e, t),
270
- list: (e, t) => me(e, t),
271
- code: (e, t) => ye(e),
272
- containerDirective: (e, t) => V(e, t)
295
+ function be(e, t) {
296
+ const n = ke(e), o = A(t);
297
+ if (!(!n && !o))
298
+ return { ...o, ...n };
299
+ }
300
+ function A(e) {
301
+ if (e.depth !== 0) return;
302
+ const t = e.topLevelAttributesApplied;
303
+ if (!(!e.topLevelAttributes || !t || t.done))
304
+ return t.done = !0, e.topLevelAttributes;
305
+ }
306
+ const De = {
307
+ paragraph: (e, t) => Y(e, t),
308
+ blockquote: (e, t) => xe(e, t),
309
+ list: (e, t) => Ce(e, t),
310
+ code: (e, t) => Le(e),
311
+ containerDirective: (e, t) => G(e, t),
312
+ leafDirective: (e, t) => Ee(e, t)
273
313
  };
274
- function T(e, t) {
275
- const o = he[e.type];
276
- return o ? o(e, t) : (t.messages && t.messages.push({
314
+ function $(e, t) {
315
+ const n = De[e.type];
316
+ return n ? n(e, t) : (t.messages && t.messages.push({
277
317
  type: "warning",
278
318
  reason: `Unknown block type: ${e.type}`,
279
319
  category: "unknown-block-type"
280
- }), U(
320
+ }), F(
281
321
  "unknown-block-type",
282
322
  `unknown block type "${e.type}"`,
283
- M(e, t)
323
+ E(e, t)
284
324
  ));
285
325
  }
286
- function K(e, t) {
287
- return h("p", b(e.children, t));
326
+ function Y(e, t) {
327
+ return h("p", D(e.children, t));
288
328
  }
289
- function de(e, t) {
290
- const o = e.children.filter((n) => n.type === "paragraph").map((n) => {
329
+ function xe(e, t) {
330
+ const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
291
331
  const r = {
292
332
  ...t,
293
333
  ancestors: [...t.ancestors, e],
294
334
  depth: t.depth + 1
295
335
  };
296
- return K(n, r);
336
+ return Y(o, r);
297
337
  });
298
- return h("blockquote", o);
338
+ return h("blockquote", n);
299
339
  }
300
- function me(e, t) {
301
- const o = e.children.map((n) => {
340
+ function Ce(e, t) {
341
+ const n = e.children.map((o) => {
302
342
  const r = {
303
343
  ...t,
304
344
  ancestors: [...t.ancestors, e],
305
345
  depth: t.depth + 1
306
346
  };
307
- return ge(n, r);
347
+ return we(o, r);
308
348
  });
309
- return h(e.ordered ? "ol" : "ul", o);
349
+ return h(e.ordered ? "ol" : "ul", n);
310
350
  }
311
- function ge(e, t) {
312
- const o = D(
351
+ function we(e, t) {
352
+ const n = w(
313
353
  e.children,
314
354
  t
315
355
  );
316
- return h("li", o);
356
+ return h("li", n);
317
357
  }
318
- function ye(e, t) {
358
+ function Le(e, t) {
319
359
  return g(
320
360
  "program",
321
361
  e.value,
322
362
  e.lang ? { language: e.lang } : void 0
323
363
  );
324
364
  }
325
- function ke(e, t) {
326
- const o = e.value.split(/\\\\|[\r\n]+/).map((n) => n.trim()).filter((n) => n.length > 0);
327
- return o.length > 1 ? h(
365
+ function Ie(e, t) {
366
+ const n = e.value.split(/\\\\|[\r\n]+/).map((o) => o.trim()).filter((o) => o.length > 0);
367
+ return n.length > 1 ? h(
328
368
  "md",
329
- o.map((n) => g("mrow", n))
330
- ) : g("md", o[0] ?? "");
369
+ n.map((o) => g("mrow", o))
370
+ ) : g("md", n[0] ?? "");
371
+ }
372
+ function Se(e, t) {
373
+ return e.meta === "inline" ? g("m", e.value) : Ie(e);
331
374
  }
332
- function ve(e, t) {
333
- return e.meta === "inline" ? g("m", e.value) : ke(e);
375
+ function Ee(e, t) {
376
+ const n = fe(e);
377
+ return n || (t.messages && t.messages.push({
378
+ type: "warning",
379
+ reason: "Unnamed leaf directive",
380
+ category: "unknown-directive"
381
+ }), F(
382
+ "unknown-directive",
383
+ "unnamed leaf directive",
384
+ E(e, t)
385
+ ));
334
386
  }
335
- function V(e, t) {
336
- const o = se(e.name);
337
- if (!o)
387
+ function G(e, t) {
388
+ const n = he(e.name);
389
+ if (!n)
338
390
  return t.messages && t.messages.push({
339
391
  type: "warning",
340
392
  reason: `Unknown directive: ${e.name}`,
341
393
  category: "unknown-directive"
342
- }), U(
394
+ }), F(
343
395
  "unknown-directive",
344
396
  `unknown directive "${e.name}"`,
345
- M(e, t)
397
+ E(e, t)
346
398
  );
347
- const n = be(e), r = e.children, { title: i, body: s } = xe(
399
+ const o = qe(e), r = e.children, { title: i, body: s } = Te(
348
400
  r,
349
401
  t
350
402
  ), l = {
@@ -352,90 +404,90 @@ function V(e, t) {
352
404
  ancestors: [...t.ancestors, e],
353
405
  depth: t.depth + 1
354
406
  };
355
- return ce(
356
- o,
407
+ return me(
357
408
  n,
409
+ o,
358
410
  i,
359
411
  s,
360
412
  l,
361
- (c, a) => T(c, a),
362
- (c, a) => V(c, a)
413
+ (c, a) => $(c, a),
414
+ (c, a) => G(c, a)
363
415
  );
364
416
  }
365
- function xe(e, t) {
366
- const o = e[0];
367
- return o?.type === "paragraph" && o.data?.directiveLabel === !0 ? {
417
+ function Te(e, t) {
418
+ const n = e[0];
419
+ return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
368
420
  title: h(
369
421
  "title",
370
- b(o.children, t)
422
+ D(n.children, t)
371
423
  ),
372
424
  body: e.slice(1)
373
425
  } : { title: null, body: e };
374
426
  }
375
- function be(e) {
376
- const t = e.attributes ?? {}, o = {};
377
- for (const [n, r] of Object.entries(t))
378
- r != null && (o[n === "id" ? "xml:id" : n] = r);
379
- return Object.keys(o).length > 0 ? o : void 0;
427
+ function qe(e) {
428
+ const t = e.attributes ?? {}, n = {};
429
+ for (const [o, r] of Object.entries(t))
430
+ r != null && (n[o === "id" ? "xml:id" : o] = r);
431
+ return Object.keys(n).length > 0 ? n : void 0;
380
432
  }
381
- function Ce(e, t) {
433
+ function Ae(e, t) {
382
434
  return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
383
435
  }
384
- const De = {
385
- text: (e, t) => W(e.value),
436
+ const $e = {
437
+ text: (e, t) => V(e.value),
386
438
  emphasis: (e, t) => {
387
- const n = Ce(e, t.source) === "underscore" ? "term" : "em";
388
- return h(n, b(e.children, t));
439
+ const o = Ae(e, t.source) === "underscore" ? "term" : "em";
440
+ return h(o, D(e.children, t));
389
441
  },
390
- strong: (e, t) => h("alert", b(e.children, t)),
442
+ strong: (e, t) => h("alert", D(e.children, t)),
391
443
  inlineCode: (e, t) => g("c", e.value),
392
- math: (e, t) => ve(e)
444
+ math: (e, t) => Se(e)
393
445
  };
394
- function b(e, t) {
395
- return e.flatMap((o) => we(o, t)).filter((o) => o !== null);
446
+ function D(e, t) {
447
+ return e.flatMap((n) => Me(n, t)).filter((n) => n !== null);
396
448
  }
397
- function we(e, t) {
398
- const o = De[e.type];
399
- if (!o)
449
+ function Me(e, t) {
450
+ const n = $e[e.type];
451
+ if (!n)
400
452
  return t.messages && t.messages.push({
401
453
  type: "warning",
402
454
  reason: `Unknown inline type: ${e.type}`,
403
455
  category: "unknown-inline-type"
404
- }), ae(
456
+ }), ge(
405
457
  "unknown-inline-type",
406
458
  `unknown inline type "${e.type}"`,
407
- M(e, t)
459
+ E(e, t)
408
460
  );
409
- const n = { ...t, ancestors: [...t.ancestors, e] };
410
- return o(e, n);
461
+ const o = { ...t, ancestors: [...t.ancestors, e] };
462
+ return n(e, o);
411
463
  }
412
- const Se = [
464
+ const Re = [
413
465
  // Display math (check these first, before single $)
414
466
  { open: "$$", close: "$$", isDisplay: !0 },
415
467
  { open: "\\[", close: "\\]", isDisplay: !0 },
416
468
  // Inline math
417
469
  { open: "$", close: "$", isDisplay: !1 },
418
470
  { open: "\\(", close: "\\)", isDisplay: !1 }
419
- ], Y = "PTX_MATH_TOKEN_", q = new RegExp(`${Y}(\\d+)`, "g");
420
- function G(e, t) {
421
- let o = null;
422
- for (const n of Se) {
423
- const r = e.indexOf(n.open, t);
471
+ ], J = "PTX_MATH_TOKEN_", T = new RegExp(`${J}(\\d+)`, "g");
472
+ function Q(e, t) {
473
+ let n = null;
474
+ for (const o of Re) {
475
+ const r = e.indexOf(o.open, t);
424
476
  if (r === -1) continue;
425
- const i = e.indexOf(n.close, r + n.open.length);
426
- if (i !== -1 && !(n.open === "$" && (r > 0 && e[r - 1] === "$" || r + 1 < e.length && e[r + 1] === "$")) && (!o || r < o.index)) {
427
- const s = e.substring(r + n.open.length, i);
428
- o = { index: r, pattern: n, content: s };
477
+ const i = e.indexOf(o.close, r + o.open.length);
478
+ if (i !== -1 && !(o.open === "$" && (r > 0 && e[r - 1] === "$" || r + 1 < e.length && e[r + 1] === "$")) && (!n || r < n.index)) {
479
+ const s = e.substring(r + o.open.length, i);
480
+ n = { index: r, pattern: o, content: s };
429
481
  }
430
482
  }
431
- return o;
483
+ return n;
432
484
  }
433
- function Ie(e, t) {
434
- let o = t;
435
- for (; o < e.length; ) {
436
- const n = e.indexOf("`", o);
437
- if (n === -1) return null;
438
- let r = 0, i = n;
485
+ function Fe(e, t) {
486
+ let n = t;
487
+ for (; n < e.length; ) {
488
+ const o = e.indexOf("`", n);
489
+ if (o === -1) return null;
490
+ let r = 0, i = o;
439
491
  for (; i < e.length && e[i] === "`"; )
440
492
  r++, i++;
441
493
  const s = "`".repeat(r);
@@ -445,115 +497,115 @@ function Ie(e, t) {
445
497
  if (c === -1) break;
446
498
  const a = c + r;
447
499
  if (a >= e.length || e[a] !== "`")
448
- return { start: n, end: a };
500
+ return { start: o, end: a };
449
501
  l = c + 1;
450
502
  }
451
- o = n + r;
503
+ n = o + r;
452
504
  }
453
505
  return null;
454
506
  }
455
- function qe(e) {
507
+ function Ne(e) {
456
508
  const t = /* @__PURE__ */ new Map();
457
- let o = "", n = 0, r = 0;
458
- for (; n < e.length; ) {
459
- const i = Ie(e, n), s = G(e, n);
509
+ let n = "", o = 0, r = 0;
510
+ for (; o < e.length; ) {
511
+ const i = Fe(e, o), s = Q(e, o);
460
512
  if (i && (!s || i.start < s.index)) {
461
- o += e.substring(n, i.end), n = i.end;
513
+ n += e.substring(o, i.end), o = i.end;
462
514
  continue;
463
515
  }
464
516
  if (!s) {
465
- o += e.substring(n);
517
+ n += e.substring(o);
466
518
  break;
467
519
  }
468
- o += e.substring(n, s.index);
469
- const l = `${Y}${r}`;
470
- o += l, t.set(l, {
520
+ n += e.substring(o, s.index);
521
+ const l = `${J}${r}`;
522
+ n += l, t.set(l, {
471
523
  type: "math",
472
524
  value: s.content,
473
525
  meta: s.pattern.isDisplay ? "display" : "inline"
474
- }), n = s.index + s.pattern.open.length + s.content.length + s.pattern.close.length, r += 1;
526
+ }), o = s.index + s.pattern.open.length + s.content.length + s.pattern.close.length, r += 1;
475
527
  }
476
- return { markdown: o, tokens: t };
528
+ return { markdown: n, tokens: t };
477
529
  }
478
- function Te(e) {
530
+ function Oe(e) {
479
531
  const t = [];
480
- let o = 0;
481
- for (; o < e.length; ) {
482
- const n = G(e, o);
483
- if (!n) {
484
- o < e.length && t.push({ type: "text", value: e.substring(o) });
532
+ let n = 0;
533
+ for (; n < e.length; ) {
534
+ const o = Q(e, n);
535
+ if (!o) {
536
+ n < e.length && t.push({ type: "text", value: e.substring(n) });
485
537
  break;
486
538
  }
487
- n.index > o && t.push({
539
+ o.index > n && t.push({
488
540
  type: "text",
489
- value: e.substring(o, n.index)
541
+ value: e.substring(n, o.index)
490
542
  }), t.push({
491
543
  type: "math",
492
- value: n.content,
493
- meta: n.pattern.isDisplay ? "display" : "inline"
494
- }), o = n.index + n.pattern.open.length + n.content.length + n.pattern.close.length;
544
+ value: o.content,
545
+ meta: o.pattern.isDisplay ? "display" : "inline"
546
+ }), n = o.index + o.pattern.open.length + o.content.length + o.pattern.close.length;
495
547
  }
496
548
  return t.length === 0 ? [{ type: "text", value: e }] : t;
497
549
  }
498
- function Le(e, t) {
499
- const o = [];
500
- let n = 0;
501
- q.lastIndex = 0;
502
- let r = q.exec(e);
550
+ function _e(e, t) {
551
+ const n = [];
552
+ let o = 0;
553
+ T.lastIndex = 0;
554
+ let r = T.exec(e);
503
555
  for (; r; ) {
504
556
  const i = r.index, s = r[0];
505
- i > n && o.push({ type: "text", value: e.substring(n, i) });
557
+ i > o && n.push({ type: "text", value: e.substring(o, i) });
506
558
  const l = t.get(s);
507
- l ? o.push(l) : o.push({ type: "text", value: s }), n = i + s.length, r = q.exec(e);
559
+ l ? n.push(l) : n.push({ type: "text", value: s }), o = i + s.length, r = T.exec(e);
508
560
  }
509
- return n < e.length && o.push({ type: "text", value: e.substring(n) }), o.length === 0 ? [{ type: "text", value: e }] : o;
561
+ return o < e.length && n.push({ type: "text", value: e.substring(o) }), n.length === 0 ? [{ type: "text", value: e }] : n;
510
562
  }
511
- function J(e) {
512
- B(e, "paragraph", (t) => {
513
- const o = t.children || [], n = [];
514
- for (const r of o)
563
+ function ee(e) {
564
+ X(e, "paragraph", (t) => {
565
+ const n = t.children || [], o = [];
566
+ for (const r of n)
515
567
  if (r.type === "text") {
516
- const i = Te(r.value);
517
- n.push(...i);
568
+ const i = Oe(r.value);
569
+ o.push(...i);
518
570
  } else
519
- n.push(r);
520
- t.children = n;
571
+ o.push(r);
572
+ t.children = o;
521
573
  });
522
574
  }
523
- function Ee(e, t) {
524
- B(e, "paragraph", (o) => {
525
- const n = o.children || [], r = [];
526
- for (const i of n)
575
+ function Pe(e, t) {
576
+ X(e, "paragraph", (n) => {
577
+ const o = n.children || [], r = [];
578
+ for (const i of o)
527
579
  if (i.type === "text") {
528
- const s = Le(i.value, t);
580
+ const s = _e(i.value, t);
529
581
  r.push(...s);
530
582
  } else
531
583
  r.push(i);
532
- o.children = r;
584
+ n.children = r;
533
585
  });
534
586
  }
535
- const bt = () => (e) => {
536
- J(e);
587
+ const Rt = () => (e) => {
588
+ ee(e);
537
589
  };
538
- function Me(e) {
590
+ function je(e) {
539
591
  const t = e.trim();
540
592
  if (!t.startsWith(":")) return null;
541
- let o = 0;
593
+ let n = 0;
542
594
  for (let i = 0; i < t.length && t[i] === ":"; i++)
543
- o++;
544
- if (o < 3) return null;
545
- const n = t.slice(o).trim(), r = n.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
546
- return n === "" ? { colons: o, label: null, lineIndex: -1, isOpen: !1 } : r ? { colons: o, label: r[0], lineIndex: -1, isOpen: !0 } : null;
595
+ n++;
596
+ if (n < 3) return null;
597
+ const o = t.slice(n).trim(), r = o.match(/^([a-zA-Z0-9_-]+)(\[[^\]]*\])?(\{[^}]*\})?$/);
598
+ return o === "" ? { colons: n, label: null, lineIndex: -1, isOpen: !1 } : r ? { colons: n, label: r[0], lineIndex: -1, isOpen: !0 } : null;
547
599
  }
548
- function $e(e) {
549
- const t = [], o = [];
550
- for (const n of e)
551
- if (n.isOpen) {
600
+ function Be(e) {
601
+ const t = [], n = [];
602
+ for (const o of e)
603
+ if (o.isOpen) {
552
604
  const r = {
553
- colons: n.colons,
554
- finalColons: n.colons,
555
- label: n.label,
556
- openLineIndex: n.lineIndex,
605
+ colons: o.colons,
606
+ finalColons: o.colons,
607
+ label: o.label,
608
+ openLineIndex: o.lineIndex,
557
609
  closeLineIndex: null,
558
610
  children: [],
559
611
  parent: null
@@ -562,200 +614,211 @@ function $e(e) {
562
614
  const i = t[t.length - 1];
563
615
  r.parent = i, i.children.push(r);
564
616
  } else
565
- o.push(r);
617
+ n.push(r);
566
618
  t.push(r);
567
619
  } else {
568
620
  const r = t[t.length - 1];
569
- r && r.colons === n.colons && (r.closeLineIndex = n.lineIndex, t.pop());
621
+ r && r.colons === o.colons && (r.closeLineIndex = o.lineIndex, t.pop());
570
622
  }
571
- return o;
623
+ return n;
572
624
  }
573
- function Q(e) {
625
+ function te(e) {
574
626
  if (e.children.length === 0)
575
627
  e.finalColons = e.colons;
576
628
  else {
577
- const t = Math.max(...e.children.map(Q));
629
+ const t = Math.max(...e.children.map(te));
578
630
  e.finalColons = Math.max(e.colons, t + 1);
579
631
  }
580
632
  return e.finalColons;
581
633
  }
582
- function Fe(e, t, o) {
583
- const n = e.slice(), r = [], i = t.slice();
634
+ function ze(e, t, n) {
635
+ const o = e.slice(), r = [], i = t.slice();
584
636
  for (; i.length > 0; ) {
585
637
  const s = i.shift();
586
638
  r.push(s), i.push(...s.children);
587
639
  }
588
640
  for (const s of r) {
589
641
  if (s.openLineIndex >= 0) {
590
- const l = n[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, a = l.slice(c);
591
- n[s.openLineIndex] = ":".repeat(s.finalColons) + a;
642
+ const l = o[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, a = l.slice(c);
643
+ o[s.openLineIndex] = ":".repeat(s.finalColons) + a;
592
644
  }
593
- s.closeLineIndex !== null && s.closeLineIndex >= 0 && (n[s.closeLineIndex] = ":".repeat(s.finalColons));
645
+ s.closeLineIndex !== null && s.closeLineIndex >= 0 && (o[s.closeLineIndex] = ":".repeat(s.finalColons));
594
646
  }
595
- return n;
647
+ return o;
596
648
  }
597
- function Ne(e) {
649
+ function We(e) {
598
650
  const t = e.split(`
599
- `), o = [];
600
- let n = !1, r = null;
651
+ `), n = [];
652
+ let o = !1, r = null;
601
653
  for (let l = 0; l < t.length; l++) {
602
654
  const c = t[l], u = c.trim().match(/^(`{3,}|~{3,})/);
603
655
  if (u) {
604
656
  const m = u[1];
605
- n ? r && m[0] === r[0] && m.length >= r.length && (n = !1, r = null) : (n = !0, r = m);
657
+ o ? r && m[0] === r[0] && m.length >= r.length && (o = !1, r = null) : (o = !0, r = m);
606
658
  continue;
607
659
  }
608
- if (n)
660
+ if (o)
609
661
  continue;
610
- const d = Me(c);
611
- d && o.push({ ...d, lineIndex: l });
662
+ const d = je(c);
663
+ d && n.push({ ...d, lineIndex: l });
612
664
  }
613
- if (o.length === 0)
665
+ if (n.length === 0)
614
666
  return e;
615
- const i = $e(o);
667
+ const i = Be(n);
616
668
  for (const l of i)
617
- Q(l);
618
- return Fe(t, i).join(`
669
+ te(l);
670
+ return ze(t, i).join(`
619
671
  `);
620
672
  }
621
- function Oe(e) {
673
+ function Ue(e) {
622
674
  const t = e.trim();
623
675
  if (!t.endsWith(":")) return null;
624
- const o = t.slice(0, -1);
625
- if (!/^[a-zA-Z]/.test(o)) return null;
626
- const n = o.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
627
- if (!n) return null;
628
- const [, r, i] = n;
629
- return i && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(i) || !I[r.toLowerCase()] ? null : o;
630
- }
631
- function L(e) {
676
+ const n = t.slice(0, -1);
677
+ if (!/^[a-zA-Z]/.test(n)) return null;
678
+ const o = n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
679
+ if (!o) return null;
680
+ const [, r, i] = o;
681
+ return i && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(i) || !S[r.toLowerCase()] ? null : n;
682
+ }
683
+ function M(e) {
632
684
  let t = 0;
633
- for (let o = 0; o < e.length; o++)
634
- if (e[o] === " ")
685
+ for (let n = 0; n < e.length; n++)
686
+ if (e[n] === " ")
635
687
  t += 1;
636
- else if (e[o] === " ")
688
+ else if (e[n] === " ")
637
689
  t += 4;
638
690
  else
639
691
  break;
640
692
  return t;
641
693
  }
642
- function Ae(e, t) {
643
- const o = L(e[t]);
644
- for (let n = t + 1; n < e.length; n++)
645
- if (!ee(e[n]))
646
- return L(e[n]) > o;
694
+ function He(e, t) {
695
+ const n = M(e[t]);
696
+ for (let o = t + 1; o < e.length; o++)
697
+ if (!ne(e[o]))
698
+ return M(e[o]) > n;
647
699
  return !1;
648
700
  }
649
- function ee(e) {
701
+ function ne(e) {
650
702
  return e.trim() === "";
651
703
  }
652
- function Pe(e, t) {
653
- let o = 0, n = 0;
654
- for (; n < e.length && o < t; )
655
- if (e[n] === " ")
656
- o++, n++;
657
- else if (e[n] === " ")
658
- o += 4, n++;
704
+ function Xe(e, t) {
705
+ let n = 0, o = 0;
706
+ for (; o < e.length && n < t; )
707
+ if (e[o] === " ")
708
+ n++, o++;
709
+ else if (e[o] === " ")
710
+ n += 4, o++;
659
711
  else
660
712
  break;
661
- return e.slice(n);
713
+ return e.slice(o);
662
714
  }
663
- function Re(e) {
715
+ function Ze(e) {
664
716
  const t = e.split(`
665
- `), o = [], n = {
717
+ `), n = [], o = {
666
718
  level: 0,
667
719
  openDirectives: [],
668
720
  inCodeFence: !1,
669
721
  codeFenceMarker: null
670
722
  };
671
723
  for (let r = 0; r < t.length; r++) {
672
- const i = t[r], s = i.trim(), l = L(i), c = s.match(/^(`{3,}|~{3,})/);
724
+ const i = t[r], s = i.trim(), l = M(i), c = s.match(/^(`{3,}|~{3,})/);
673
725
  if (c) {
674
726
  const u = c[1];
675
- n.inCodeFence ? n.codeFenceMarker && s.startsWith(n.codeFenceMarker) && (n.inCodeFence = !1, n.codeFenceMarker = null) : (n.inCodeFence = !0, n.codeFenceMarker = u), o.push(i);
727
+ o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker = u), n.push(i);
676
728
  continue;
677
729
  }
678
- if (n.inCodeFence) {
679
- o.push(i);
730
+ if (o.inCodeFence) {
731
+ n.push(i);
680
732
  continue;
681
733
  }
682
- if (ee(i)) {
683
- o.push("");
734
+ if (ne(i)) {
735
+ n.push("");
684
736
  continue;
685
737
  }
686
- const a = Oe(s);
687
- if (a && Ae(t, r)) {
688
- for (; n.openDirectives.length > 0 && !(n.openDirectives[n.openDirectives.length - 1].indentLevel < l); ) {
689
- const y = n.openDirectives.pop();
690
- y && o.push(":".repeat(y.colonCount));
738
+ const a = Ue(s);
739
+ if (a && He(t, r)) {
740
+ for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
741
+ const y = o.openDirectives.pop();
742
+ y && n.push(":".repeat(y.colonCount));
691
743
  }
692
- const u = a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/), d = u ? u[1].toLowerCase() + (u[2] || "") : a, m = n.openDirectives.length * 1 + 3;
693
- o.push(":".repeat(m) + d), n.openDirectives.push({
744
+ const u = a.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)/), d = u ? u[1].toLowerCase() + (u[2] || "") : a, m = o.openDirectives.length * 1 + 3;
745
+ n.push(":".repeat(m) + d), o.openDirectives.push({
694
746
  label: d,
695
747
  indentLevel: l,
696
748
  colonCount: m,
697
749
  bodyBaseIndent: -1
698
- }), n.level = l;
750
+ }), o.level = l;
699
751
  } else {
700
- for (; n.openDirectives.length > 0 && l <= n.openDirectives[n.openDirectives.length - 1].indentLevel; ) {
701
- const u = n.openDirectives.pop();
702
- u && o.push(":".repeat(u.colonCount));
752
+ for (; o.openDirectives.length > 0 && l <= o.openDirectives[o.openDirectives.length - 1].indentLevel; ) {
753
+ const u = o.openDirectives.pop();
754
+ u && n.push(":".repeat(u.colonCount));
703
755
  }
704
- if (n.openDirectives.length > 0) {
705
- const u = n.openDirectives[n.openDirectives.length - 1];
706
- u.bodyBaseIndent < 0 && (u.bodyBaseIndent = l), o.push(Pe(i, u.bodyBaseIndent));
756
+ if (o.openDirectives.length > 0) {
757
+ const u = o.openDirectives[o.openDirectives.length - 1];
758
+ u.bodyBaseIndent < 0 && (u.bodyBaseIndent = l), n.push(Xe(i, u.bodyBaseIndent));
707
759
  } else
708
- o.push(i);
709
- n.level = l;
760
+ n.push(i);
761
+ o.level = l;
710
762
  }
711
763
  }
712
- for (; n.openDirectives.length > 0; ) {
713
- const r = n.openDirectives.pop();
714
- r && o.push(":".repeat(r.colonCount));
764
+ for (; o.openDirectives.length > 0; ) {
765
+ const r = o.openDirectives.pop();
766
+ r && n.push(":".repeat(r.colonCount));
715
767
  }
716
- return o.join(`
768
+ return n.join(`
717
769
  `);
718
770
  }
719
- const _e = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, je = /^division:\s*(\S+)\s*$/m;
720
- function Be(e) {
721
- const t = e.match(_e);
771
+ const Ve = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/, Ke = /^division:\s*(\S+)\s*$/m, Ye = /^xmlid:\s*(\S+)\s*$/m, Ge = /^xml:id:\s*(\S+)\s*$/m, Je = /^label:\s*(\S+)\s*$/m, Qe = /^component:\s*(\S+)\s*$/m;
772
+ function et(e) {
773
+ const t = e.match(Ve);
722
774
  if (!t)
723
775
  return { body: e };
724
- const o = t[1], n = e.slice(t[0].length), i = o.match(je)?.[1];
725
- return {
726
- division: i && ie(i) ? i : void 0,
727
- body: n
776
+ const n = t[1], o = e.slice(t[0].length), r = n.match(Ke)?.[1];
777
+ let i, s;
778
+ r && ae(r) ? (s = r, i = q(r)) : r && ue(r) && (i = r);
779
+ const l = {}, c = n.match(Ye)?.[1] ?? n.match(Ge)?.[1], a = n.match(Je)?.[1], u = n.match(Qe)?.[1];
780
+ return c && (l["xml:id"] = c), a && (l.label = a), u && (l.component = u), {
781
+ division: i,
782
+ documentRoot: s,
783
+ attributes: Object.keys(l).length > 0 ? l : void 0,
784
+ body: o
728
785
  };
729
786
  }
730
- const ze = function(e) {
731
- return function(o, n) {
732
- if (typeof n?.value == "string") {
733
- const r = Be(n.value), i = e?.topLevelDivision ?? r.division ?? "chapter", s = Re(r.body), l = Ne(s), c = qe(l), u = R().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(_).use(j).parse(c.markdown);
734
- return Ee(u, c.tokens), N(u, c.markdown, { topLevelDivision: i });
787
+ const tt = function(e) {
788
+ return function(n, o) {
789
+ if (typeof o?.value == "string") {
790
+ const r = et(o.value), i = e?.documentRoot ?? r.documentRoot, s = e?.topLevelDivision ?? r.division ?? (i ? q(i) : "chapter"), l = e?.topLevelAttributes ?? r.attributes, c = Ze(r.body), a = We(c), u = Ne(a), m = W().data("micromarkExtensions", [{ disable: { null: ["codeIndented"] } }]).use(U).use(H).parse(u.markdown);
791
+ return Pe(m, u.tokens), P(m, u.markdown, {
792
+ topLevelDivision: s,
793
+ documentRoot: i,
794
+ topLevelAttributes: l
795
+ });
735
796
  }
736
- return J(o), N(o, void 0, {
737
- topLevelDivision: e?.topLevelDivision ?? "chapter"
797
+ return ee(n), P(n, void 0, {
798
+ topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? q(e.documentRoot) : "chapter"),
799
+ documentRoot: e?.documentRoot,
800
+ topLevelAttributes: e?.topLevelAttributes
738
801
  });
739
802
  };
740
- }, We = /["&'<>`]/g, He = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, Ue = (
803
+ }, nt = /["&'<>`]/g, ot = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, rt = (
741
804
  // eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
742
805
  /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
743
- ), Ze = /[|\\{}()[\]^$+*?.]/g, O = /* @__PURE__ */ new WeakMap();
744
- function Xe(e, t) {
806
+ ), it = /[|\\{}()[\]^$+*?.]/g, j = /* @__PURE__ */ new WeakMap();
807
+ function st(e, t) {
745
808
  if (e = e.replace(
746
- t.subset ? Ke(t.subset) : We,
747
- n
809
+ t.subset ? lt(t.subset) : nt,
810
+ o
748
811
  ), t.subset || t.escapeOnly)
749
812
  return e;
750
- return e.replace(He, o).replace(Ue, n);
751
- function o(r, i, s) {
813
+ return e.replace(ot, n).replace(rt, o);
814
+ function n(r, i, s) {
752
815
  return t.format(
753
816
  (r.charCodeAt(0) - 55296) * 1024 + r.charCodeAt(1) - 56320 + 65536,
754
817
  s.charCodeAt(i + 2),
755
818
  t
756
819
  );
757
820
  }
758
- function n(r, i, s) {
821
+ function o(r, i, s) {
759
822
  return t.format(
760
823
  r.charCodeAt(0),
761
824
  s.charCodeAt(i + 1),
@@ -763,137 +826,140 @@ function Xe(e, t) {
763
826
  );
764
827
  }
765
828
  }
766
- function Ke(e) {
767
- let t = O.get(e);
768
- return t || (t = Ve(e), O.set(e, t)), t;
829
+ function lt(e) {
830
+ let t = j.get(e);
831
+ return t || (t = ct(e), j.set(e, t)), t;
769
832
  }
770
- function Ve(e) {
833
+ function ct(e) {
771
834
  const t = [];
772
- let o = -1;
773
- for (; ++o < e.length; )
774
- t.push(e[o].replace(Ze, "\\$&"));
835
+ let n = -1;
836
+ for (; ++n < e.length; )
837
+ t.push(e[n].replace(it, "\\$&"));
775
838
  return new RegExp("(?:" + t.join("|") + ")", "g");
776
839
  }
777
- function Ye(e) {
840
+ function at(e) {
778
841
  return "&#x" + e.toString(16).toUpperCase() + ";";
779
842
  }
780
- function Ge(e, t) {
781
- return Xe(e, Object.assign({ format: Ye }, t));
843
+ function ut(e, t) {
844
+ return st(e, Object.assign({ format: at }, t));
782
845
  }
783
- const Je = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
784
- function k(e, t, o) {
785
- const n = Qe(e);
786
- return o ? n.replace(o, r) : r(n);
846
+ const pt = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
847
+ function v(e, t, n) {
848
+ const o = ft(e);
849
+ return n ? o.replace(n, r) : r(o);
787
850
  function r(i) {
788
- return Ge(i, { subset: t });
851
+ return ut(i, { subset: t });
789
852
  }
790
853
  }
791
- function Qe(e) {
792
- return String(e || "").replace(Je, "");
854
+ function ft(e) {
855
+ return String(e || "").replace(pt, "");
793
856
  }
794
- const et = /]]>/g, tt = [">"];
795
- function nt(e) {
796
- return "<![CDATA[" + k(e.value, tt, et) + "]]>";
857
+ const ht = /]]>/g, dt = [">"];
858
+ function mt(e) {
859
+ return "<![CDATA[" + v(e.value, dt, ht) + "]]>";
797
860
  }
798
- function ot(e) {
799
- return "<!--" + k(e.value, ["-"]) + "-->";
861
+ function gt(e) {
862
+ return "<!--" + v(e.value, ["-"]) + "-->";
800
863
  }
801
- const rt = [" ", `
864
+ const yt = [" ", `
802
865
  `, " ", '"', "&", "'", "/", "<", "=", ">"];
803
- function S(e) {
804
- return k(e, rt);
866
+ function I(e) {
867
+ return v(e, yt);
805
868
  }
806
- function A(e, t) {
807
- const o = String(e);
869
+ function B(e, t) {
870
+ const n = String(e);
808
871
  if (typeof t != "string")
809
872
  throw new TypeError("Expected character");
810
- let n = 0, r = o.indexOf(t);
873
+ let o = 0, r = n.indexOf(t);
811
874
  for (; r !== -1; )
812
- n++, r = o.indexOf(t, r + t.length);
813
- return n;
875
+ o++, r = n.indexOf(t, r + t.length);
876
+ return o;
814
877
  }
815
- function E(e, t) {
816
- const o = String(e);
817
- let n = t.options.quote || '"';
878
+ function R(e, t) {
879
+ const n = String(e);
880
+ let o = t.options.quote || '"';
818
881
  if (t.options.quoteSmart) {
819
- const r = n === '"' ? "'" : '"';
820
- A(o, n) > A(o, r) && (n = r);
882
+ const r = o === '"' ? "'" : '"';
883
+ B(n, o) > B(n, r) && (o = r);
821
884
  }
822
- return n + k(o, ["<", "&", n]) + n;
885
+ return o + v(n, ["<", "&", o]) + o;
823
886
  }
824
- function it(e, t) {
825
- const o = S(e.name), n = e.public, r = e.system;
887
+ function vt(e, t) {
888
+ const n = I(e.name), o = e.public, r = e.system;
826
889
  let i = "<!DOCTYPE";
827
- return o !== "" && (i += " " + o), n ? i += " PUBLIC " + E(n, t) : r && (i += " SYSTEM"), r && (i += " " + E(r, t)), i + ">";
890
+ return n !== "" && (i += " " + n), o ? i += " PUBLIC " + R(o, t) : r && (i += " SYSTEM"), r && (i += " " + R(r, t)), i + ">";
828
891
  }
829
- const st = {}.hasOwnProperty;
830
- function lt(e, t) {
831
- const o = S(e.name), n = oe(e, t), r = e.attributes || {}, i = n ? !1 : t.options.closeEmptyElements, s = [];
892
+ const kt = {}.hasOwnProperty;
893
+ function bt(e, t) {
894
+ const n = I(e.name), o = ie(e, t), r = e.attributes || {}, i = o ? !1 : t.options.closeEmptyElements, s = [];
832
895
  let l;
833
896
  for (l in r)
834
- if (st.call(r, l)) {
897
+ if (kt.call(r, l)) {
835
898
  const c = r[l];
836
- c != null && s.push(S(l) + "=" + E(c, t));
899
+ c != null && s.push(I(l) + "=" + R(c, t));
837
900
  }
838
- return "<" + o + (s.length === 0 ? "" : " " + s.join(" ")) + (i ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + n + (i ? "" : "</" + o + ">");
839
- }
840
- const ct = /\?>/g, at = [">"];
841
- function ut(e) {
842
- const t = S(e.name) || "x", o = k(e.value, at, ct);
843
- return "<?" + t + (o ? " " + o : "") + "?>";
844
- }
845
- const pt = ["&", "<"];
846
- function te(e) {
847
- return k(e.value, pt);
848
- }
849
- function ft(e, t) {
850
- return t.options.allowDangerousXml ? e.value : te(e);
851
- }
852
- const ht = {}.hasOwnProperty, P = {
853
- cdata: nt,
854
- comment: ot,
855
- doctype: it,
856
- element: lt,
857
- instruction: ut,
858
- raw: ft,
859
- root: oe,
860
- text: te
901
+ return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (i ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (i ? "" : "</" + n + ">");
902
+ }
903
+ const Dt = /\?>/g, xt = [">"];
904
+ function Ct(e) {
905
+ const t = I(e.name) || "x", n = v(e.value, xt, Dt);
906
+ return "<?" + t + (n ? " " + n : "") + "?>";
907
+ }
908
+ const wt = ["&", "<"];
909
+ function oe(e) {
910
+ return v(e.value, wt);
911
+ }
912
+ function Lt(e, t) {
913
+ return t.options.allowDangerousXml ? e.value : oe(e);
914
+ }
915
+ const It = {}.hasOwnProperty, z = {
916
+ cdata: mt,
917
+ comment: gt,
918
+ doctype: vt,
919
+ element: bt,
920
+ instruction: Ct,
921
+ raw: Lt,
922
+ root: ie,
923
+ text: oe
861
924
  };
862
- function ne(e, t) {
863
- const o = e && e.type;
864
- if (!o)
925
+ function re(e, t) {
926
+ const n = e && e.type;
927
+ if (!n)
865
928
  throw new Error("Expected node, not `" + e + "`");
866
- if (!ht.call(P, o))
867
- throw new Error("Cannot compile unknown node `" + o + "`");
868
- const n = P[o];
869
- return n(e, t);
929
+ if (!It.call(z, n))
930
+ throw new Error("Cannot compile unknown node `" + n + "`");
931
+ const o = z[n];
932
+ return o(e, t);
870
933
  }
871
- function oe(e, t) {
872
- const o = e && e.children || [];
873
- let n = -1;
934
+ function ie(e, t) {
935
+ const n = e && e.children || [];
936
+ let o = -1;
874
937
  const r = [];
875
- for (; ++n < o.length; )
876
- r[n] = ne(o[n], t);
938
+ for (; ++o < n.length; )
939
+ r[o] = re(n[o], t);
877
940
  return r.join("");
878
941
  }
879
- function dt(e, t) {
880
- const o = { options: {} };
881
- if (typeof o.options.quote == "string" && o.options.quote !== '"' && o.options.quote !== "'")
942
+ function St(e, t) {
943
+ const n = { options: t || {} };
944
+ if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
882
945
  throw new Error(
883
- "Invalid quote `" + o.options.quote + "`, expected `'` or `\"`"
946
+ "Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
884
947
  );
885
- const n = Array.isArray(e) ? { type: "root", children: e } : e;
886
- return ne(n, o);
887
- }
888
- function Ct(e, t) {
889
- const o = R().use(_).use(j).use(ze, t), n = o.parse(e), r = o.runSync(n, { value: e });
890
- return dt(r.children);
948
+ const o = Array.isArray(e) ? { type: "root", children: e } : e;
949
+ return re(o, n);
950
+ }
951
+ function Ft(e, t) {
952
+ const n = W().use(U).use(H).use(tt, t), o = n.parse(e), r = n.runSync(o, { value: e });
953
+ return St(r.children, {
954
+ closeEmptyElements: !0,
955
+ tightClose: !0
956
+ });
891
957
  }
892
958
  export {
893
- xt as DIRECTIVE_MAP,
894
- z as PROOF_SOLUTION_NAMES,
895
- Ct as markdownToPretext,
896
- N as mdastToPtxast,
897
- bt as remarkMath,
898
- ze as remarkPretext
959
+ Mt as DIRECTIVE_MAP,
960
+ Z as PROOF_SOLUTION_NAMES,
961
+ Ft as markdownToPretext,
962
+ P as mdastToPtxast,
963
+ Rt as remarkMath,
964
+ tt as remarkPretext
899
965
  };