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