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