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