@pretextbook/remark-pretext 0.0.4 → 0.0.6

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