@pretextbook/remark-pretext 0.0.8 → 0.0.10
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 +454 -411
- 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 +1 -1
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
|
-
const
|
|
95
|
-
for (let
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
for (let
|
|
99
|
-
const
|
|
100
|
-
if (!
|
|
101
|
-
if (
|
|
102
|
-
|
|
94
|
+
const u = [];
|
|
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
|
|
149
|
-
|
|
147
|
+
if (c.type === "containerDirective" && Y.has(c.name)) {
|
|
148
|
+
const u = r(c, o);
|
|
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((
|
|
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
|
-
for (const
|
|
238
|
-
|
|
259
|
+
for (const u of e)
|
|
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
|
-
for (const
|
|
247
|
-
|
|
248
|
-
...
|
|
249
|
-
), s = []), c(),
|
|
250
|
-
return !
|
|
251
|
-
...
|
|
252
|
-
), c(),
|
|
253
|
-
}
|
|
254
|
-
function
|
|
268
|
+
for (const u of e)
|
|
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],
|
|
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
|
-
c.children.push(l),
|
|
263
|
-
...
|
|
264
|
-
),
|
|
284
|
+
c.children.push(l), a && (c.children.push(
|
|
285
|
+
...a
|
|
286
|
+
), i += 1);
|
|
265
287
|
else {
|
|
266
|
-
const
|
|
267
|
-
|
|
288
|
+
const p = [l];
|
|
289
|
+
a && (p.push(...a), i += 1), o.push(h("p", p));
|
|
268
290
|
}
|
|
269
291
|
continue;
|
|
270
292
|
}
|
|
@@ -278,239 +300,247 @@ function w(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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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);
|
|
308
|
+
}
|
|
309
|
+
function be(e) {
|
|
310
|
+
return e.type === "leafDirective" && V(e.name);
|
|
311
|
+
}
|
|
312
|
+
function I(e, t) {
|
|
313
|
+
const n = e.findIndex(
|
|
314
|
+
(l) => l.type === "heading" || be(l)
|
|
315
|
+
);
|
|
316
|
+
if (n <= 0)
|
|
317
|
+
return { introduction: null, rest: e };
|
|
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 };
|
|
320
|
+
}
|
|
321
|
+
function De(e) {
|
|
292
322
|
const t = e.data;
|
|
293
323
|
return t?.id ? { "xml:id": t.id } : void 0;
|
|
294
324
|
}
|
|
295
|
-
function
|
|
296
|
-
const n =
|
|
325
|
+
function Ce(e, t) {
|
|
326
|
+
const n = De(e), o = S(t);
|
|
297
327
|
if (!(!n && !o))
|
|
298
328
|
return { ...o, ...n };
|
|
299
329
|
}
|
|
300
|
-
function
|
|
330
|
+
function S(e) {
|
|
301
331
|
if (e.depth !== 0) return;
|
|
302
332
|
const t = e.topLevelAttributesApplied;
|
|
303
333
|
if (!(!e.topLevelAttributes || !t || t.done))
|
|
304
334
|
return t.done = !0, e.topLevelAttributes;
|
|
305
335
|
}
|
|
306
|
-
const
|
|
307
|
-
paragraph: (e, t) =>
|
|
336
|
+
const Le = {
|
|
337
|
+
paragraph: (e, t) => G(e, t),
|
|
308
338
|
blockquote: (e, t) => xe(e, t),
|
|
309
|
-
list: (e, t) =>
|
|
310
|
-
code: (e, t) =>
|
|
311
|
-
containerDirective: (e, t) =>
|
|
312
|
-
leafDirective: (e, t) =>
|
|
339
|
+
list: (e, t) => we(e, t),
|
|
340
|
+
code: (e, t) => Se(e),
|
|
341
|
+
containerDirective: (e, t) => J(e, t),
|
|
342
|
+
leafDirective: (e, t) => qe(e, t)
|
|
313
343
|
};
|
|
314
|
-
function
|
|
315
|
-
const n =
|
|
344
|
+
function O(e, t) {
|
|
345
|
+
const n = Le[e.type];
|
|
316
346
|
return n ? n(e, t) : (t.messages && t.messages.push({
|
|
317
347
|
type: "warning",
|
|
318
348
|
reason: `Unknown block type: ${e.type}`,
|
|
319
349
|
category: "unknown-block-type"
|
|
320
|
-
}),
|
|
350
|
+
}), P(
|
|
321
351
|
"unknown-block-type",
|
|
322
352
|
`unknown block type "${e.type}"`,
|
|
323
|
-
|
|
353
|
+
R(e, t)
|
|
324
354
|
));
|
|
325
355
|
}
|
|
326
|
-
function
|
|
327
|
-
return h("p",
|
|
356
|
+
function G(e, t) {
|
|
357
|
+
return h("p", x(e.children, t));
|
|
328
358
|
}
|
|
329
359
|
function xe(e, t) {
|
|
330
360
|
const n = e.children.filter((o) => o.type === "paragraph").map((o) => {
|
|
331
|
-
const
|
|
361
|
+
const i = {
|
|
332
362
|
...t,
|
|
333
363
|
ancestors: [...t.ancestors, e],
|
|
334
364
|
depth: t.depth + 1
|
|
335
365
|
};
|
|
336
|
-
return
|
|
366
|
+
return G(o, i);
|
|
337
367
|
});
|
|
338
368
|
return h("blockquote", n);
|
|
339
369
|
}
|
|
340
|
-
function
|
|
370
|
+
function we(e, t) {
|
|
341
371
|
const n = e.children.map((o) => {
|
|
342
|
-
const
|
|
372
|
+
const i = {
|
|
343
373
|
...t,
|
|
344
374
|
ancestors: [...t.ancestors, e],
|
|
345
375
|
depth: t.depth + 1
|
|
346
376
|
};
|
|
347
|
-
return
|
|
377
|
+
return Ie(o, i);
|
|
348
378
|
});
|
|
349
379
|
return h(e.ordered ? "ol" : "ul", n);
|
|
350
380
|
}
|
|
351
|
-
function
|
|
352
|
-
const n =
|
|
381
|
+
function Ie(e, t) {
|
|
382
|
+
const n = L(
|
|
353
383
|
e.children,
|
|
354
384
|
t
|
|
355
385
|
);
|
|
356
386
|
return h("li", n);
|
|
357
387
|
}
|
|
358
|
-
function
|
|
359
|
-
return
|
|
388
|
+
function Se(e, t) {
|
|
389
|
+
return k(
|
|
360
390
|
"program",
|
|
361
391
|
e.value,
|
|
362
392
|
e.lang ? { language: e.lang } : void 0
|
|
363
393
|
);
|
|
364
394
|
}
|
|
365
|
-
function
|
|
395
|
+
function Te(e, t) {
|
|
366
396
|
const n = e.value.split(/\\\\|[\r\n]+/).map((o) => o.trim()).filter((o) => o.length > 0);
|
|
367
397
|
return n.length > 1 ? h(
|
|
368
398
|
"md",
|
|
369
|
-
n.map((o) =>
|
|
370
|
-
) :
|
|
371
|
-
}
|
|
372
|
-
function Se(e, t) {
|
|
373
|
-
return e.meta === "inline" ? g("m", e.value) : Ie(e);
|
|
399
|
+
n.map((o) => k("mrow", o))
|
|
400
|
+
) : k("md", n[0] ?? "");
|
|
374
401
|
}
|
|
375
402
|
function Ee(e, t) {
|
|
376
|
-
|
|
403
|
+
return e.meta === "inline" ? k("m", e.value) : Te(e);
|
|
404
|
+
}
|
|
405
|
+
function qe(e, t) {
|
|
406
|
+
const n = he(e);
|
|
377
407
|
return n || (t.messages && t.messages.push({
|
|
378
408
|
type: "warning",
|
|
379
409
|
reason: "Unnamed leaf directive",
|
|
380
410
|
category: "unknown-directive"
|
|
381
|
-
}),
|
|
411
|
+
}), P(
|
|
382
412
|
"unknown-directive",
|
|
383
413
|
"unnamed leaf directive",
|
|
384
|
-
|
|
414
|
+
R(e, t)
|
|
385
415
|
));
|
|
386
416
|
}
|
|
387
|
-
function
|
|
388
|
-
const n =
|
|
417
|
+
function J(e, t) {
|
|
418
|
+
const n = de(e.name);
|
|
389
419
|
if (!n)
|
|
390
420
|
return t.messages && t.messages.push({
|
|
391
421
|
type: "warning",
|
|
392
422
|
reason: `Unknown directive: ${e.name}`,
|
|
393
423
|
category: "unknown-directive"
|
|
394
|
-
}),
|
|
424
|
+
}), P(
|
|
395
425
|
"unknown-directive",
|
|
396
426
|
`unknown directive "${e.name}"`,
|
|
397
|
-
|
|
427
|
+
R(e, t)
|
|
398
428
|
);
|
|
399
|
-
const o =
|
|
400
|
-
|
|
429
|
+
const o = $e(e), i = e.children, { title: r, body: s } = Ae(
|
|
430
|
+
i,
|
|
401
431
|
t
|
|
402
432
|
), l = {
|
|
403
433
|
...t,
|
|
404
434
|
ancestors: [...t.ancestors, e],
|
|
405
435
|
depth: t.depth + 1
|
|
406
436
|
};
|
|
407
|
-
return
|
|
437
|
+
return ge(
|
|
408
438
|
n,
|
|
409
439
|
o,
|
|
410
|
-
|
|
440
|
+
r,
|
|
411
441
|
s,
|
|
412
442
|
l,
|
|
413
|
-
(c,
|
|
414
|
-
(c,
|
|
443
|
+
(c, u) => O(c, u),
|
|
444
|
+
(c, u) => J(c, u)
|
|
415
445
|
);
|
|
416
446
|
}
|
|
417
|
-
function
|
|
447
|
+
function Ae(e, t) {
|
|
418
448
|
const n = e[0];
|
|
419
449
|
return n?.type === "paragraph" && n.data?.directiveLabel === !0 ? {
|
|
420
450
|
title: h(
|
|
421
451
|
"title",
|
|
422
|
-
|
|
452
|
+
x(n.children, t)
|
|
423
453
|
),
|
|
424
454
|
body: e.slice(1)
|
|
425
455
|
} : { title: null, body: e };
|
|
426
456
|
}
|
|
427
|
-
function
|
|
457
|
+
function $e(e) {
|
|
428
458
|
const t = e.attributes ?? {}, n = {};
|
|
429
|
-
for (const [o,
|
|
430
|
-
|
|
459
|
+
for (const [o, i] of Object.entries(t))
|
|
460
|
+
i != null && (n[o === "id" ? "xml:id" : o] = i);
|
|
431
461
|
return Object.keys(n).length > 0 ? n : void 0;
|
|
432
462
|
}
|
|
433
|
-
function
|
|
463
|
+
function Re(e, t) {
|
|
434
464
|
return !t || e.position?.start?.offset === null || e.position?.start?.offset === void 0 ? "asterisk" : t.charAt(e.position.start.offset) === "_" ? "underscore" : "asterisk";
|
|
435
465
|
}
|
|
436
|
-
const
|
|
437
|
-
text: (e, t) =>
|
|
466
|
+
const Fe = {
|
|
467
|
+
text: (e, t) => E(e.value),
|
|
438
468
|
emphasis: (e, t) => {
|
|
439
|
-
const o =
|
|
440
|
-
return h(o,
|
|
469
|
+
const o = Re(e, t.source) === "underscore" ? "term" : "em";
|
|
470
|
+
return h(o, x(e.children, t));
|
|
441
471
|
},
|
|
442
|
-
strong: (e, t) => h("alert",
|
|
443
|
-
inlineCode: (e, t) =>
|
|
444
|
-
math: (e, t) =>
|
|
472
|
+
strong: (e, t) => h("alert", x(e.children, t)),
|
|
473
|
+
inlineCode: (e, t) => k("c", e.value),
|
|
474
|
+
math: (e, t) => Ee(e)
|
|
445
475
|
};
|
|
446
|
-
function
|
|
476
|
+
function x(e, t) {
|
|
447
477
|
return e.flatMap((n) => Me(n, t)).filter((n) => n !== null);
|
|
448
478
|
}
|
|
449
479
|
function Me(e, t) {
|
|
450
|
-
const n =
|
|
480
|
+
const n = Fe[e.type];
|
|
451
481
|
if (!n)
|
|
452
482
|
return t.messages && t.messages.push({
|
|
453
483
|
type: "warning",
|
|
454
484
|
reason: `Unknown inline type: ${e.type}`,
|
|
455
485
|
category: "unknown-inline-type"
|
|
456
|
-
}),
|
|
486
|
+
}), ye(
|
|
457
487
|
"unknown-inline-type",
|
|
458
488
|
`unknown inline type "${e.type}"`,
|
|
459
|
-
|
|
489
|
+
R(e, t)
|
|
460
490
|
);
|
|
461
491
|
const o = { ...t, ancestors: [...t.ancestors, e] };
|
|
462
492
|
return n(e, o);
|
|
463
493
|
}
|
|
464
|
-
const
|
|
494
|
+
const Oe = [
|
|
465
495
|
// Display math (check these first, before single $)
|
|
466
496
|
{ open: "$$", close: "$$", isDisplay: !0 },
|
|
467
497
|
{ open: "\\[", close: "\\]", isDisplay: !0 },
|
|
468
498
|
// Inline math
|
|
469
499
|
{ open: "$", close: "$", isDisplay: !1 },
|
|
470
500
|
{ open: "\\(", close: "\\)", isDisplay: !1 }
|
|
471
|
-
],
|
|
472
|
-
function
|
|
501
|
+
], ee = "PTX_MATH_TOKEN_", F = new RegExp(`${ee}(\\d+)`, "g");
|
|
502
|
+
function te(e, t) {
|
|
473
503
|
let n = null;
|
|
474
|
-
for (const o of
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
const s = e.substring(
|
|
480
|
-
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 };
|
|
481
511
|
}
|
|
482
512
|
}
|
|
483
513
|
return n;
|
|
484
514
|
}
|
|
485
|
-
function
|
|
515
|
+
function Ne(e, t) {
|
|
486
516
|
let n = t;
|
|
487
517
|
for (; n < e.length; ) {
|
|
488
518
|
const o = e.indexOf("`", n);
|
|
489
519
|
if (o === -1) return null;
|
|
490
|
-
let
|
|
491
|
-
for (;
|
|
492
|
-
|
|
493
|
-
const s = "`".repeat(
|
|
494
|
-
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;
|
|
495
525
|
for (; l < e.length; ) {
|
|
496
526
|
const c = e.indexOf(s, l);
|
|
497
527
|
if (c === -1) break;
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
500
|
-
return { start: o, end:
|
|
528
|
+
const u = c + i;
|
|
529
|
+
if (u >= e.length || e[u] !== "`")
|
|
530
|
+
return { start: o, end: u };
|
|
501
531
|
l = c + 1;
|
|
502
532
|
}
|
|
503
|
-
n = o +
|
|
533
|
+
n = o + i;
|
|
504
534
|
}
|
|
505
535
|
return null;
|
|
506
536
|
}
|
|
507
|
-
function
|
|
537
|
+
function _e(e) {
|
|
508
538
|
const t = /* @__PURE__ */ new Map();
|
|
509
|
-
let n = "", o = 0,
|
|
539
|
+
let n = "", o = 0, i = 0;
|
|
510
540
|
for (; o < e.length; ) {
|
|
511
|
-
const
|
|
512
|
-
if (
|
|
513
|
-
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;
|
|
514
544
|
continue;
|
|
515
545
|
}
|
|
516
546
|
if (!s) {
|
|
@@ -518,20 +548,20 @@ function Ne(e) {
|
|
|
518
548
|
break;
|
|
519
549
|
}
|
|
520
550
|
n += e.substring(o, s.index);
|
|
521
|
-
const l = `${
|
|
551
|
+
const l = `${ee}${i}`;
|
|
522
552
|
n += l, t.set(l, {
|
|
523
553
|
type: "math",
|
|
524
554
|
value: s.content,
|
|
525
555
|
meta: s.pattern.isDisplay ? "display" : "inline"
|
|
526
|
-
}), 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;
|
|
527
557
|
}
|
|
528
558
|
return { markdown: n, tokens: t };
|
|
529
559
|
}
|
|
530
|
-
function
|
|
560
|
+
function Pe(e) {
|
|
531
561
|
const t = [];
|
|
532
562
|
let n = 0;
|
|
533
563
|
for (; n < e.length; ) {
|
|
534
|
-
const o =
|
|
564
|
+
const o = te(e, n);
|
|
535
565
|
if (!o) {
|
|
536
566
|
n < e.length && t.push({ type: "text", value: e.substring(n) });
|
|
537
567
|
break;
|
|
@@ -547,61 +577,61 @@ function Oe(e) {
|
|
|
547
577
|
}
|
|
548
578
|
return t.length === 0 ? [{ type: "text", value: e }] : t;
|
|
549
579
|
}
|
|
550
|
-
function
|
|
580
|
+
function je(e, t) {
|
|
551
581
|
const n = [];
|
|
552
582
|
let o = 0;
|
|
553
|
-
|
|
554
|
-
let
|
|
555
|
-
for (;
|
|
556
|
-
const
|
|
557
|
-
|
|
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) });
|
|
558
588
|
const l = t.get(s);
|
|
559
|
-
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);
|
|
560
590
|
}
|
|
561
591
|
return o < e.length && n.push({ type: "text", value: e.substring(o) }), n.length === 0 ? [{ type: "text", value: e }] : n;
|
|
562
592
|
}
|
|
563
|
-
function
|
|
564
|
-
|
|
593
|
+
function ne(e) {
|
|
594
|
+
K(e, "paragraph", (t) => {
|
|
565
595
|
const n = t.children || [], o = [];
|
|
566
|
-
for (const
|
|
567
|
-
if (
|
|
568
|
-
const
|
|
569
|
-
o.push(...
|
|
596
|
+
for (const i of n)
|
|
597
|
+
if (i.type === "text") {
|
|
598
|
+
const r = Pe(i.value);
|
|
599
|
+
o.push(...r);
|
|
570
600
|
} else
|
|
571
|
-
o.push(
|
|
601
|
+
o.push(i);
|
|
572
602
|
t.children = o;
|
|
573
603
|
});
|
|
574
604
|
}
|
|
575
|
-
function
|
|
576
|
-
|
|
577
|
-
const o = n.children || [],
|
|
578
|
-
for (const
|
|
579
|
-
if (
|
|
580
|
-
const s =
|
|
581
|
-
|
|
605
|
+
function Be(e, t) {
|
|
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);
|
|
582
612
|
} else
|
|
583
|
-
|
|
584
|
-
n.children =
|
|
613
|
+
i.push(r);
|
|
614
|
+
n.children = i;
|
|
585
615
|
});
|
|
586
616
|
}
|
|
587
|
-
const
|
|
588
|
-
|
|
617
|
+
const Pt = () => (e) => {
|
|
618
|
+
ne(e);
|
|
589
619
|
};
|
|
590
|
-
function
|
|
620
|
+
function ze(e) {
|
|
591
621
|
const t = e.trim();
|
|
592
622
|
if (!t.startsWith(":")) return null;
|
|
593
623
|
let n = 0;
|
|
594
|
-
for (let
|
|
624
|
+
for (let r = 0; r < t.length && t[r] === ":"; r++)
|
|
595
625
|
n++;
|
|
596
626
|
if (n < 3) return null;
|
|
597
|
-
const o = t.slice(n).trim(),
|
|
598
|
-
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;
|
|
599
629
|
}
|
|
600
|
-
function
|
|
630
|
+
function We(e) {
|
|
601
631
|
const t = [], n = [];
|
|
602
632
|
for (const o of e)
|
|
603
633
|
if (o.isOpen) {
|
|
604
|
-
const
|
|
634
|
+
const i = {
|
|
605
635
|
colons: o.colons,
|
|
606
636
|
finalColons: o.colons,
|
|
607
637
|
label: o.label,
|
|
@@ -611,76 +641,76 @@ function Be(e) {
|
|
|
611
641
|
parent: null
|
|
612
642
|
};
|
|
613
643
|
if (t.length > 0) {
|
|
614
|
-
const
|
|
615
|
-
|
|
644
|
+
const r = t[t.length - 1];
|
|
645
|
+
i.parent = r, r.children.push(i);
|
|
616
646
|
} else
|
|
617
|
-
n.push(
|
|
618
|
-
t.push(
|
|
647
|
+
n.push(i);
|
|
648
|
+
t.push(i);
|
|
619
649
|
} else {
|
|
620
|
-
const
|
|
621
|
-
|
|
650
|
+
const i = t[t.length - 1];
|
|
651
|
+
i && i.colons === o.colons && (i.closeLineIndex = o.lineIndex, t.pop());
|
|
622
652
|
}
|
|
623
653
|
return n;
|
|
624
654
|
}
|
|
625
|
-
function
|
|
655
|
+
function oe(e) {
|
|
626
656
|
if (e.children.length === 0)
|
|
627
657
|
e.finalColons = e.colons;
|
|
628
658
|
else {
|
|
629
|
-
const t = Math.max(...e.children.map(
|
|
659
|
+
const t = Math.max(...e.children.map(oe));
|
|
630
660
|
e.finalColons = Math.max(e.colons, t + 1);
|
|
631
661
|
}
|
|
632
662
|
return e.finalColons;
|
|
633
663
|
}
|
|
634
|
-
function
|
|
635
|
-
const o = e.slice(),
|
|
636
|
-
for (;
|
|
637
|
-
const s =
|
|
638
|
-
|
|
664
|
+
function Ue(e, t, n) {
|
|
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);
|
|
639
669
|
}
|
|
640
|
-
for (const s of
|
|
670
|
+
for (const s of i) {
|
|
641
671
|
if (s.openLineIndex >= 0) {
|
|
642
|
-
const l = o[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3,
|
|
643
|
-
o[s.openLineIndex] = ":".repeat(s.finalColons) +
|
|
672
|
+
const l = o[s.openLineIndex], c = l.match(/^:+/)?.[0].length || 3, u = l.slice(c);
|
|
673
|
+
o[s.openLineIndex] = ":".repeat(s.finalColons) + u;
|
|
644
674
|
}
|
|
645
675
|
s.closeLineIndex !== null && s.closeLineIndex >= 0 && (o[s.closeLineIndex] = ":".repeat(s.finalColons));
|
|
646
676
|
}
|
|
647
677
|
return o;
|
|
648
678
|
}
|
|
649
|
-
function
|
|
679
|
+
function He(e) {
|
|
650
680
|
const t = e.split(`
|
|
651
681
|
`), n = [];
|
|
652
|
-
let o = !1,
|
|
682
|
+
let o = !1, i = null;
|
|
653
683
|
for (let l = 0; l < t.length; l++) {
|
|
654
|
-
const c = t[l],
|
|
655
|
-
if (
|
|
656
|
-
const
|
|
657
|
-
o ?
|
|
684
|
+
const c = t[l], a = c.trim().match(/^(`{3,}|~{3,})/);
|
|
685
|
+
if (a) {
|
|
686
|
+
const d = a[1];
|
|
687
|
+
o ? i && d[0] === i[0] && d.length >= i.length && (o = !1, i = null) : (o = !0, i = d);
|
|
658
688
|
continue;
|
|
659
689
|
}
|
|
660
690
|
if (o)
|
|
661
691
|
continue;
|
|
662
|
-
const
|
|
663
|
-
|
|
692
|
+
const p = ze(c);
|
|
693
|
+
p && n.push({ ...p, lineIndex: l });
|
|
664
694
|
}
|
|
665
695
|
if (n.length === 0)
|
|
666
696
|
return e;
|
|
667
|
-
const
|
|
668
|
-
for (const l of
|
|
669
|
-
|
|
670
|
-
return
|
|
697
|
+
const r = We(n);
|
|
698
|
+
for (const l of r)
|
|
699
|
+
oe(l);
|
|
700
|
+
return Ue(t, r).join(`
|
|
671
701
|
`);
|
|
672
702
|
}
|
|
673
|
-
function
|
|
703
|
+
function Xe(e) {
|
|
674
704
|
const t = e.trim();
|
|
675
705
|
if (!t.endsWith(":")) return null;
|
|
676
706
|
const n = t.slice(0, -1);
|
|
677
707
|
if (!/^[a-zA-Z]/.test(n)) return null;
|
|
678
708
|
const o = n.match(/^([a-zA-Z][a-zA-Z0-9_-]*)(.*)$/);
|
|
679
709
|
if (!o) return null;
|
|
680
|
-
const [,
|
|
681
|
-
return
|
|
710
|
+
const [, i, r] = o;
|
|
711
|
+
return r && !/^(\[[^\]]*\]|\{[^}]*\})*$/.test(r) || !$[i.toLowerCase()] ? null : n;
|
|
682
712
|
}
|
|
683
|
-
function
|
|
713
|
+
function N(e) {
|
|
684
714
|
let t = 0;
|
|
685
715
|
for (let n = 0; n < e.length; n++)
|
|
686
716
|
if (e[n] === " ")
|
|
@@ -691,17 +721,17 @@ function M(e) {
|
|
|
691
721
|
break;
|
|
692
722
|
return t;
|
|
693
723
|
}
|
|
694
|
-
function
|
|
695
|
-
const n =
|
|
724
|
+
function Ze(e, t) {
|
|
725
|
+
const n = N(e[t]);
|
|
696
726
|
for (let o = t + 1; o < e.length; o++)
|
|
697
|
-
if (!
|
|
698
|
-
return
|
|
727
|
+
if (!ie(e[o]))
|
|
728
|
+
return N(e[o]) > n;
|
|
699
729
|
return !1;
|
|
700
730
|
}
|
|
701
|
-
function
|
|
731
|
+
function ie(e) {
|
|
702
732
|
return e.trim() === "";
|
|
703
733
|
}
|
|
704
|
-
function
|
|
734
|
+
function Ve(e, t) {
|
|
705
735
|
let n = 0, o = 0;
|
|
706
736
|
for (; o < e.length && n < t; )
|
|
707
737
|
if (e[o] === " ")
|
|
@@ -712,7 +742,7 @@ function Xe(e, t) {
|
|
|
712
742
|
break;
|
|
713
743
|
return e.slice(o);
|
|
714
744
|
}
|
|
715
|
-
function
|
|
745
|
+
function Ke(e) {
|
|
716
746
|
const t = e.split(`
|
|
717
747
|
`), n = [], o = {
|
|
718
748
|
level: 0,
|
|
@@ -720,246 +750,259 @@ function Ze(e) {
|
|
|
720
750
|
inCodeFence: !1,
|
|
721
751
|
codeFenceMarker: null
|
|
722
752
|
};
|
|
723
|
-
for (let
|
|
724
|
-
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,})/);
|
|
725
755
|
if (c) {
|
|
726
|
-
const
|
|
727
|
-
o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker =
|
|
756
|
+
const a = c[1];
|
|
757
|
+
o.inCodeFence ? o.codeFenceMarker && s.startsWith(o.codeFenceMarker) && (o.inCodeFence = !1, o.codeFenceMarker = null) : (o.inCodeFence = !0, o.codeFenceMarker = a), n.push(r);
|
|
728
758
|
continue;
|
|
729
759
|
}
|
|
730
760
|
if (o.inCodeFence) {
|
|
731
|
-
n.push(
|
|
761
|
+
n.push(r);
|
|
732
762
|
continue;
|
|
733
763
|
}
|
|
734
|
-
if (
|
|
764
|
+
if (ie(r)) {
|
|
735
765
|
n.push("");
|
|
736
766
|
continue;
|
|
737
767
|
}
|
|
738
|
-
const
|
|
739
|
-
if (
|
|
768
|
+
const u = Xe(s);
|
|
769
|
+
if (u && Ze(t, i)) {
|
|
740
770
|
for (; o.openDirectives.length > 0 && !(o.openDirectives[o.openDirectives.length - 1].indentLevel < l); ) {
|
|
741
771
|
const y = o.openDirectives.pop();
|
|
742
772
|
y && n.push(":".repeat(y.colonCount));
|
|
743
773
|
}
|
|
744
|
-
const
|
|
745
|
-
n.push(":".repeat(
|
|
746
|
-
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,
|
|
747
777
|
indentLevel: l,
|
|
748
|
-
colonCount:
|
|
778
|
+
colonCount: d,
|
|
749
779
|
bodyBaseIndent: -1
|
|
750
780
|
}), o.level = l;
|
|
751
781
|
} else {
|
|
752
782
|
for (; o.openDirectives.length > 0 && l <= o.openDirectives[o.openDirectives.length - 1].indentLevel; ) {
|
|
753
|
-
const
|
|
754
|
-
|
|
783
|
+
const a = o.openDirectives.pop();
|
|
784
|
+
a && n.push(":".repeat(a.colonCount));
|
|
755
785
|
}
|
|
756
786
|
if (o.openDirectives.length > 0) {
|
|
757
|
-
const
|
|
758
|
-
|
|
787
|
+
const a = o.openDirectives[o.openDirectives.length - 1];
|
|
788
|
+
a.bodyBaseIndent < 0 && (a.bodyBaseIndent = l), n.push(Ve(r, a.bodyBaseIndent));
|
|
759
789
|
} else
|
|
760
|
-
n.push(
|
|
790
|
+
n.push(r);
|
|
761
791
|
o.level = l;
|
|
762
792
|
}
|
|
763
793
|
}
|
|
764
794
|
for (; o.openDirectives.length > 0; ) {
|
|
765
|
-
const
|
|
766
|
-
|
|
795
|
+
const i = o.openDirectives.pop();
|
|
796
|
+
i && n.push(":".repeat(i.colonCount));
|
|
767
797
|
}
|
|
768
798
|
return n.join(`
|
|
769
799
|
`);
|
|
770
800
|
}
|
|
771
|
-
const
|
|
772
|
-
function
|
|
773
|
-
|
|
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) {
|
|
811
|
+
const t = e.match(Ye);
|
|
774
812
|
if (!t)
|
|
775
813
|
return { body: e };
|
|
776
|
-
const n = t[1], o = e.slice(t[0].length),
|
|
777
|
-
let
|
|
778
|
-
|
|
779
|
-
const l = {}, c = n.match(
|
|
780
|
-
|
|
781
|
-
|
|
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,
|
|
782
822
|
documentRoot: s,
|
|
783
823
|
attributes: Object.keys(l).length > 0 ? l : void 0,
|
|
824
|
+
title: d,
|
|
784
825
|
body: o
|
|
785
826
|
};
|
|
786
827
|
}
|
|
787
|
-
const
|
|
828
|
+
const st = function(e) {
|
|
788
829
|
return function(n, o) {
|
|
789
830
|
if (typeof o?.value == "string") {
|
|
790
|
-
const
|
|
791
|
-
return
|
|
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, {
|
|
792
833
|
topLevelDivision: s,
|
|
793
|
-
documentRoot:
|
|
794
|
-
topLevelAttributes: l
|
|
834
|
+
documentRoot: r,
|
|
835
|
+
topLevelAttributes: l,
|
|
836
|
+
topLevelTitle: c
|
|
795
837
|
});
|
|
796
838
|
}
|
|
797
|
-
return
|
|
798
|
-
topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ?
|
|
839
|
+
return ne(n), B(n, void 0, {
|
|
840
|
+
topLevelDivision: e?.topLevelDivision ?? (e?.documentRoot ? M(e.documentRoot) : "chapter"),
|
|
799
841
|
documentRoot: e?.documentRoot,
|
|
800
|
-
topLevelAttributes: e?.topLevelAttributes
|
|
842
|
+
topLevelAttributes: e?.topLevelAttributes,
|
|
843
|
+
topLevelTitle: e?.topLevelTitle
|
|
801
844
|
});
|
|
802
845
|
};
|
|
803
|
-
},
|
|
846
|
+
}, lt = /["&'<>`]/g, ct = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ut = (
|
|
804
847
|
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
|
|
805
848
|
/[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
|
|
806
|
-
),
|
|
807
|
-
function
|
|
849
|
+
), at = /[|\\{}()[\]^$+*?.]/g, z = /* @__PURE__ */ new WeakMap();
|
|
850
|
+
function pt(e, t) {
|
|
808
851
|
if (e = e.replace(
|
|
809
|
-
t.subset ?
|
|
852
|
+
t.subset ? ft(t.subset) : lt,
|
|
810
853
|
o
|
|
811
854
|
), t.subset || t.escapeOnly)
|
|
812
855
|
return e;
|
|
813
|
-
return e.replace(
|
|
814
|
-
function n(
|
|
856
|
+
return e.replace(ct, n).replace(ut, o);
|
|
857
|
+
function n(i, r, s) {
|
|
815
858
|
return t.format(
|
|
816
|
-
(
|
|
817
|
-
s.charCodeAt(
|
|
859
|
+
(i.charCodeAt(0) - 55296) * 1024 + i.charCodeAt(1) - 56320 + 65536,
|
|
860
|
+
s.charCodeAt(r + 2),
|
|
818
861
|
t
|
|
819
862
|
);
|
|
820
863
|
}
|
|
821
|
-
function o(
|
|
864
|
+
function o(i, r, s) {
|
|
822
865
|
return t.format(
|
|
823
|
-
|
|
824
|
-
s.charCodeAt(
|
|
866
|
+
i.charCodeAt(0),
|
|
867
|
+
s.charCodeAt(r + 1),
|
|
825
868
|
t
|
|
826
869
|
);
|
|
827
870
|
}
|
|
828
871
|
}
|
|
829
|
-
function
|
|
830
|
-
let t =
|
|
831
|
-
return t || (t =
|
|
872
|
+
function ft(e) {
|
|
873
|
+
let t = z.get(e);
|
|
874
|
+
return t || (t = ht(e), z.set(e, t)), t;
|
|
832
875
|
}
|
|
833
|
-
function
|
|
876
|
+
function ht(e) {
|
|
834
877
|
const t = [];
|
|
835
878
|
let n = -1;
|
|
836
879
|
for (; ++n < e.length; )
|
|
837
|
-
t.push(e[n].replace(
|
|
880
|
+
t.push(e[n].replace(at, "\\$&"));
|
|
838
881
|
return new RegExp("(?:" + t.join("|") + ")", "g");
|
|
839
882
|
}
|
|
840
|
-
function
|
|
883
|
+
function dt(e) {
|
|
841
884
|
return "&#x" + e.toString(16).toUpperCase() + ";";
|
|
842
885
|
}
|
|
843
|
-
function
|
|
844
|
-
return
|
|
886
|
+
function mt(e, t) {
|
|
887
|
+
return pt(e, Object.assign({ format: dt }, t));
|
|
845
888
|
}
|
|
846
|
-
const
|
|
847
|
-
function
|
|
848
|
-
const o =
|
|
849
|
-
return n ? o.replace(n,
|
|
850
|
-
function r
|
|
851
|
-
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 });
|
|
852
895
|
}
|
|
853
896
|
}
|
|
854
|
-
function
|
|
855
|
-
return String(e || "").replace(
|
|
897
|
+
function yt(e) {
|
|
898
|
+
return String(e || "").replace(gt, "");
|
|
856
899
|
}
|
|
857
|
-
const
|
|
858
|
-
function
|
|
859
|
-
return "<![CDATA[" +
|
|
900
|
+
const vt = /]]>/g, kt = [">"];
|
|
901
|
+
function bt(e) {
|
|
902
|
+
return "<![CDATA[" + b(e.value, kt, vt) + "]]>";
|
|
860
903
|
}
|
|
861
|
-
function
|
|
862
|
-
return "<!--" +
|
|
904
|
+
function Dt(e) {
|
|
905
|
+
return "<!--" + b(e.value, ["-"]) + "-->";
|
|
863
906
|
}
|
|
864
|
-
const
|
|
907
|
+
const Ct = [" ", `
|
|
865
908
|
`, " ", '"', "&", "'", "/", "<", "=", ">"];
|
|
866
|
-
function
|
|
867
|
-
return
|
|
909
|
+
function A(e) {
|
|
910
|
+
return b(e, Ct);
|
|
868
911
|
}
|
|
869
|
-
function
|
|
912
|
+
function W(e, t) {
|
|
870
913
|
const n = String(e);
|
|
871
914
|
if (typeof t != "string")
|
|
872
915
|
throw new TypeError("Expected character");
|
|
873
|
-
let o = 0,
|
|
874
|
-
for (;
|
|
875
|
-
o++,
|
|
916
|
+
let o = 0, i = n.indexOf(t);
|
|
917
|
+
for (; i !== -1; )
|
|
918
|
+
o++, i = n.indexOf(t, i + t.length);
|
|
876
919
|
return o;
|
|
877
920
|
}
|
|
878
|
-
function
|
|
921
|
+
function _(e, t) {
|
|
879
922
|
const n = String(e);
|
|
880
923
|
let o = t.options.quote || '"';
|
|
881
924
|
if (t.options.quoteSmart) {
|
|
882
|
-
const
|
|
883
|
-
|
|
925
|
+
const i = o === '"' ? "'" : '"';
|
|
926
|
+
W(n, o) > W(n, i) && (o = i);
|
|
884
927
|
}
|
|
885
|
-
return o +
|
|
928
|
+
return o + b(n, ["<", "&", o]) + o;
|
|
886
929
|
}
|
|
887
|
-
function
|
|
888
|
-
const n =
|
|
889
|
-
let
|
|
890
|
-
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 + ">";
|
|
891
934
|
}
|
|
892
|
-
const
|
|
893
|
-
function
|
|
894
|
-
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 = [];
|
|
895
938
|
let l;
|
|
896
|
-
for (l in
|
|
897
|
-
if (
|
|
898
|
-
const c =
|
|
899
|
-
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));
|
|
900
943
|
}
|
|
901
|
-
return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (
|
|
944
|
+
return "<" + n + (s.length === 0 ? "" : " " + s.join(" ")) + (r ? (t.options.tightClose ? "" : " ") + "/" : "") + ">" + o + (r ? "" : "</" + n + ">");
|
|
902
945
|
}
|
|
903
|
-
const
|
|
904
|
-
function
|
|
905
|
-
const t =
|
|
946
|
+
const It = /\?>/g, St = [">"];
|
|
947
|
+
function Tt(e) {
|
|
948
|
+
const t = A(e.name) || "x", n = b(e.value, St, It);
|
|
906
949
|
return "<?" + t + (n ? " " + n : "") + "?>";
|
|
907
950
|
}
|
|
908
|
-
const
|
|
909
|
-
function
|
|
910
|
-
return
|
|
911
|
-
}
|
|
912
|
-
function
|
|
913
|
-
return t.options.allowDangerousXml ? e.value :
|
|
914
|
-
}
|
|
915
|
-
const
|
|
916
|
-
cdata:
|
|
917
|
-
comment:
|
|
918
|
-
doctype:
|
|
919
|
-
element:
|
|
920
|
-
instruction:
|
|
921
|
-
raw:
|
|
922
|
-
root:
|
|
923
|
-
text:
|
|
951
|
+
const Et = ["&", "<"];
|
|
952
|
+
function re(e) {
|
|
953
|
+
return b(e.value, Et);
|
|
954
|
+
}
|
|
955
|
+
function qt(e, t) {
|
|
956
|
+
return t.options.allowDangerousXml ? e.value : re(e);
|
|
957
|
+
}
|
|
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,
|
|
966
|
+
text: re
|
|
924
967
|
};
|
|
925
|
-
function
|
|
968
|
+
function se(e, t) {
|
|
926
969
|
const n = e && e.type;
|
|
927
970
|
if (!n)
|
|
928
971
|
throw new Error("Expected node, not `" + e + "`");
|
|
929
|
-
if (!
|
|
972
|
+
if (!At.call(U, n))
|
|
930
973
|
throw new Error("Cannot compile unknown node `" + n + "`");
|
|
931
|
-
const o =
|
|
974
|
+
const o = U[n];
|
|
932
975
|
return o(e, t);
|
|
933
976
|
}
|
|
934
|
-
function
|
|
977
|
+
function le(e, t) {
|
|
935
978
|
const n = e && e.children || [];
|
|
936
979
|
let o = -1;
|
|
937
|
-
const
|
|
980
|
+
const i = [];
|
|
938
981
|
for (; ++o < n.length; )
|
|
939
|
-
|
|
940
|
-
return
|
|
982
|
+
i[o] = se(n[o], t);
|
|
983
|
+
return i.join("");
|
|
941
984
|
}
|
|
942
|
-
function
|
|
985
|
+
function $t(e, t) {
|
|
943
986
|
const n = { options: t || {} };
|
|
944
987
|
if (typeof n.options.quote == "string" && n.options.quote !== '"' && n.options.quote !== "'")
|
|
945
988
|
throw new Error(
|
|
946
989
|
"Invalid quote `" + n.options.quote + "`, expected `'` or `\"`"
|
|
947
990
|
);
|
|
948
991
|
const o = Array.isArray(e) ? { type: "root", children: e } : e;
|
|
949
|
-
return
|
|
992
|
+
return se(o, n);
|
|
950
993
|
}
|
|
951
|
-
function
|
|
952
|
-
const n =
|
|
953
|
-
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, {
|
|
954
997
|
closeEmptyElements: !0,
|
|
955
998
|
tightClose: !0
|
|
956
999
|
});
|
|
957
1000
|
}
|
|
958
1001
|
export {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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
|
|
965
1008
|
};
|