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