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