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