stream-markdown-parser 0.0.1
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 +97 -0
- package/README.zh-CN.md +96 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.js +1726 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1726 @@
|
|
|
1
|
+
import re from "markdown-it";
|
|
2
|
+
import oe from "markdown-it-container";
|
|
3
|
+
function R() {
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
type: "table_open",
|
|
7
|
+
tag: "table",
|
|
8
|
+
attrs: void 0,
|
|
9
|
+
map: void 0,
|
|
10
|
+
children: void 0,
|
|
11
|
+
content: "",
|
|
12
|
+
markup: "",
|
|
13
|
+
info: "",
|
|
14
|
+
level: 0,
|
|
15
|
+
loading: !0,
|
|
16
|
+
meta: void 0
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: "thead_open",
|
|
20
|
+
tag: "thead",
|
|
21
|
+
attrs: void 0,
|
|
22
|
+
block: !0,
|
|
23
|
+
level: 1,
|
|
24
|
+
children: void 0
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "tr_open",
|
|
28
|
+
tag: "tr",
|
|
29
|
+
attrs: void 0,
|
|
30
|
+
block: !0,
|
|
31
|
+
level: 2,
|
|
32
|
+
children: void 0
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
function k() {
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
type: "tr_close",
|
|
40
|
+
tag: "tr",
|
|
41
|
+
attrs: void 0,
|
|
42
|
+
block: !0,
|
|
43
|
+
level: 2,
|
|
44
|
+
children: void 0
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "thead_close",
|
|
48
|
+
tag: "thead",
|
|
49
|
+
attrs: void 0,
|
|
50
|
+
block: !0,
|
|
51
|
+
level: 1,
|
|
52
|
+
children: void 0
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: "table_close",
|
|
56
|
+
tag: "table",
|
|
57
|
+
attrs: void 0,
|
|
58
|
+
map: void 0,
|
|
59
|
+
children: void 0,
|
|
60
|
+
content: "",
|
|
61
|
+
markup: "",
|
|
62
|
+
info: "",
|
|
63
|
+
level: 0,
|
|
64
|
+
meta: void 0
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
function O(e) {
|
|
69
|
+
return [{
|
|
70
|
+
type: "th_open",
|
|
71
|
+
tag: "th",
|
|
72
|
+
attrs: void 0,
|
|
73
|
+
block: !0,
|
|
74
|
+
level: 3,
|
|
75
|
+
children: void 0
|
|
76
|
+
}, {
|
|
77
|
+
type: "inline",
|
|
78
|
+
tag: "",
|
|
79
|
+
children: [
|
|
80
|
+
{
|
|
81
|
+
tag: "",
|
|
82
|
+
type: "text",
|
|
83
|
+
block: !1,
|
|
84
|
+
content: e,
|
|
85
|
+
children: void 0
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
content: e,
|
|
89
|
+
level: 4,
|
|
90
|
+
attrs: void 0,
|
|
91
|
+
block: !0
|
|
92
|
+
}, {
|
|
93
|
+
type: "th_close",
|
|
94
|
+
tag: "th",
|
|
95
|
+
attrs: void 0,
|
|
96
|
+
block: !0,
|
|
97
|
+
level: 3,
|
|
98
|
+
children: void 0
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
function ce(e) {
|
|
102
|
+
const c = [...e];
|
|
103
|
+
if (e.length < 3)
|
|
104
|
+
return c;
|
|
105
|
+
const i = e.length - 2, o = e[i];
|
|
106
|
+
if (o.type === "inline") {
|
|
107
|
+
const n = typeof o.content == "string" ? o.content : "", r = o.children && o.children[0];
|
|
108
|
+
if (/^\|(?:[^|\n]+\|?)+/.test(n)) {
|
|
109
|
+
const t = (r && typeof r.content == "string" ? r.content.slice(1) : "").split("|").map((a) => a.trim()).filter(Boolean).flatMap((a) => O(a)), s = [
|
|
110
|
+
...R(),
|
|
111
|
+
...t,
|
|
112
|
+
...k()
|
|
113
|
+
];
|
|
114
|
+
c.splice(i - 1, 3, ...s);
|
|
115
|
+
} else if (/^\|(?:[^|\n]+\|)+\n\|:?-/.test(n)) {
|
|
116
|
+
const t = (r && typeof r.content == "string" ? r.content.slice(1, -1) : "").split("|").map((a) => a.trim()).flatMap((a) => O(a)), s = [
|
|
117
|
+
...R(),
|
|
118
|
+
...t,
|
|
119
|
+
...k()
|
|
120
|
+
];
|
|
121
|
+
c.splice(i - 1, 3, ...s);
|
|
122
|
+
} else /^\|(?:[^|\n:]+\|)+\n\|:?$/.test(n) && (typeof o.content == "string" && (o.content = o.content.slice(0, -2)), o.children && o.children.splice(2, 1));
|
|
123
|
+
}
|
|
124
|
+
return c;
|
|
125
|
+
}
|
|
126
|
+
function ie(e) {
|
|
127
|
+
return {
|
|
128
|
+
type: "checkbox",
|
|
129
|
+
checked: e.meta?.checked === !0,
|
|
130
|
+
raw: e.meta?.checked ? "[x]" : "[ ]"
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function le(e) {
|
|
134
|
+
return {
|
|
135
|
+
type: "checkbox_input",
|
|
136
|
+
checked: e.attrGet("checked") === "" || e.attrGet("checked") === "true",
|
|
137
|
+
raw: e.attrGet("checked") === "" || e.attrGet("checked") === "true" ? "[x]" : "[ ]"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function se(e) {
|
|
141
|
+
return {
|
|
142
|
+
type: "emoji",
|
|
143
|
+
name: e.content || "",
|
|
144
|
+
markup: e.markup || "",
|
|
145
|
+
raw: `:${e.content || ""}:`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function D(e, c) {
|
|
149
|
+
const i = [];
|
|
150
|
+
let o = "", n = c + 1;
|
|
151
|
+
const r = [];
|
|
152
|
+
for (; n < e.length && e[n].type !== "em_close"; )
|
|
153
|
+
o += e[n].content || "", r.push(e[n]), n++;
|
|
154
|
+
i.push(...b(r));
|
|
155
|
+
const l = {
|
|
156
|
+
type: "emphasis",
|
|
157
|
+
children: i,
|
|
158
|
+
raw: `*${o}*`
|
|
159
|
+
}, t = n < e.length ? n + 1 : e.length;
|
|
160
|
+
return { node: l, nextIndex: t };
|
|
161
|
+
}
|
|
162
|
+
function ae(e) {
|
|
163
|
+
const c = [], i = [];
|
|
164
|
+
for (const o of e.split(/\r?\n/)) {
|
|
165
|
+
const n = o;
|
|
166
|
+
/^(?:diff |index |--- |\+\+\+ |@@ )/.test(n) || (n.startsWith("- ") ? c.push(` ${n.slice(1)}`) : n.startsWith("+ ") ? i.push(` ${n.slice(1)}`) : (c.push(n), i.push(n)));
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
original: c.join(`
|
|
170
|
+
`),
|
|
171
|
+
updated: i.join(`
|
|
172
|
+
`)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function N(e) {
|
|
176
|
+
const c = Array.isArray(e.map) && e.map.length === 2, i = e.meta, o = typeof i?.closed == "boolean" ? i.closed : void 0, n = e.info?.startsWith("diff") || !1, r = n ? e.info?.split(" ")[1] || "" : e.info || "";
|
|
177
|
+
let l = e.content || "";
|
|
178
|
+
const t = /\r?\n[ \t]*`+\s*$/;
|
|
179
|
+
if (t.test(l) && (l = l.replace(t, "")), n) {
|
|
180
|
+
const { original: s, updated: a } = ae(l);
|
|
181
|
+
return {
|
|
182
|
+
type: "code_block",
|
|
183
|
+
language: r,
|
|
184
|
+
code: a || "",
|
|
185
|
+
raw: l,
|
|
186
|
+
diff: n,
|
|
187
|
+
loading: o === !0 ? !1 : o === !1 ? !0 : !c,
|
|
188
|
+
originalCode: s,
|
|
189
|
+
updatedCode: a
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
type: "code_block",
|
|
194
|
+
language: r,
|
|
195
|
+
code: l || "",
|
|
196
|
+
raw: l || "",
|
|
197
|
+
diff: n,
|
|
198
|
+
loading: o === !0 ? !1 : o === !1 ? !0 : !c
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function pe(e) {
|
|
202
|
+
if (e.length < 5)
|
|
203
|
+
return e;
|
|
204
|
+
const c = e[e.length - 5];
|
|
205
|
+
if (c.type !== "text" && !c.content.endsWith("[") || e[e.length - 4].tag !== "em")
|
|
206
|
+
return S(e);
|
|
207
|
+
const o = e[e.length - 1];
|
|
208
|
+
if (!o.content.startsWith("]"))
|
|
209
|
+
return S(e);
|
|
210
|
+
const n = e[e.length - 3], r = o.content.replace(/^\]\(*/, ""), l = !o.content.includes(")");
|
|
211
|
+
return c.content = c.content.replace(/\[$/, ""), e.splice(e.length - 3, 1, {
|
|
212
|
+
type: "link",
|
|
213
|
+
href: r,
|
|
214
|
+
text: n.content,
|
|
215
|
+
children: [
|
|
216
|
+
{
|
|
217
|
+
type: "text",
|
|
218
|
+
content: n.content,
|
|
219
|
+
raw: n.content
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
loading: l
|
|
223
|
+
}), e.splice(e.length - 1, 1), e;
|
|
224
|
+
}
|
|
225
|
+
function S(e) {
|
|
226
|
+
if (e.length < 8)
|
|
227
|
+
return e;
|
|
228
|
+
let c = e.length, i = e[c - 1];
|
|
229
|
+
if (i.type !== "link_close" && (c--, i = e[c - 1], i.type !== "link_close") || e[c - 7].type !== "em_open")
|
|
230
|
+
return e;
|
|
231
|
+
const n = e[c - 6], r = e[c - 8];
|
|
232
|
+
let l = e[c - 2].content, t = 4;
|
|
233
|
+
c !== e.length && (l += i.content || "", t++), e.splice(c - 4, t);
|
|
234
|
+
const s = n.content;
|
|
235
|
+
return c -= 4, r.content = r.content.replace(/\[$/, ""), e.splice(c - 2, 1, {
|
|
236
|
+
type: "link",
|
|
237
|
+
href: l,
|
|
238
|
+
text: s,
|
|
239
|
+
children: [
|
|
240
|
+
{
|
|
241
|
+
type: "text",
|
|
242
|
+
content: s,
|
|
243
|
+
raw: s
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
loading: !0
|
|
247
|
+
}), e;
|
|
248
|
+
}
|
|
249
|
+
function ue(e) {
|
|
250
|
+
const c = e[e.length - 1];
|
|
251
|
+
return /\d+\.\s*$/.test(c.content || "") && e[e.length - 2]?.tag === "br" && e.splice(e.length - 1, 1), e;
|
|
252
|
+
}
|
|
253
|
+
function he(e) {
|
|
254
|
+
const c = [...e];
|
|
255
|
+
if (e.length < 4)
|
|
256
|
+
return c;
|
|
257
|
+
const i = e.length - 4, o = e[i], n = e[i + 1];
|
|
258
|
+
if (o.type === "text" && o.content?.endsWith("*") && n.type === "em_open") {
|
|
259
|
+
const r = e[i + 2], l = r?.type === "text" ? 4 : 3, t = [
|
|
260
|
+
{
|
|
261
|
+
type: "strong_open",
|
|
262
|
+
tag: "strong",
|
|
263
|
+
attrs: null,
|
|
264
|
+
map: null,
|
|
265
|
+
children: null,
|
|
266
|
+
content: "",
|
|
267
|
+
markup: "**",
|
|
268
|
+
info: "",
|
|
269
|
+
meta: null
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
type: "text",
|
|
273
|
+
content: r?.type === "text" ? r.content : ""
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
type: "strong_close",
|
|
277
|
+
tag: "strong",
|
|
278
|
+
attrs: null,
|
|
279
|
+
map: null,
|
|
280
|
+
children: null,
|
|
281
|
+
content: "",
|
|
282
|
+
markup: "**",
|
|
283
|
+
info: "",
|
|
284
|
+
meta: null
|
|
285
|
+
}
|
|
286
|
+
], s = o.content?.slice(0, -1);
|
|
287
|
+
return s && t.unshift({
|
|
288
|
+
type: "text",
|
|
289
|
+
content: s,
|
|
290
|
+
raw: s
|
|
291
|
+
}), c.splice(i, l, ...t), c;
|
|
292
|
+
}
|
|
293
|
+
return c;
|
|
294
|
+
}
|
|
295
|
+
function de(e) {
|
|
296
|
+
return {
|
|
297
|
+
type: "footnote_reference",
|
|
298
|
+
id: e.meta?.label || "",
|
|
299
|
+
raw: `[^${e.meta?.label || ""}]`
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function fe() {
|
|
303
|
+
return {
|
|
304
|
+
type: "hardbreak",
|
|
305
|
+
raw: `\\
|
|
306
|
+
`
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function ge(e, c) {
|
|
310
|
+
const i = [];
|
|
311
|
+
let o = "", n = c + 1;
|
|
312
|
+
const r = [];
|
|
313
|
+
for (; n < e.length && e[n].type !== "mark_close"; )
|
|
314
|
+
o += e[n].content || "", r.push(e[n]), n++;
|
|
315
|
+
i.push(...b(r));
|
|
316
|
+
const l = {
|
|
317
|
+
type: "highlight",
|
|
318
|
+
children: i,
|
|
319
|
+
raw: `==${o}==`
|
|
320
|
+
}, t = n < e.length ? n + 1 : e.length;
|
|
321
|
+
return { node: l, nextIndex: t };
|
|
322
|
+
}
|
|
323
|
+
function P(e, c = !1) {
|
|
324
|
+
return {
|
|
325
|
+
type: "image",
|
|
326
|
+
src: e.attrs?.find((i) => i[0] === "src")?.[1] || "",
|
|
327
|
+
alt: e.attrs?.find((i) => i[0] === "alt")?.[1] || "",
|
|
328
|
+
title: e.attrs?.find((i) => i[0] === "title")?.[1] || null,
|
|
329
|
+
raw: e.content || "",
|
|
330
|
+
loading: c
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function me(e) {
|
|
334
|
+
return {
|
|
335
|
+
type: "inline_code",
|
|
336
|
+
code: e.content || "",
|
|
337
|
+
raw: e.content || ""
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function _e(e, c) {
|
|
341
|
+
const i = [];
|
|
342
|
+
let o = "", n = c + 1;
|
|
343
|
+
const r = [];
|
|
344
|
+
for (; n < e.length && e[n].type !== "ins_close"; )
|
|
345
|
+
o += e[n].content || "", r.push(e[n]), n++;
|
|
346
|
+
i.push(...b(r));
|
|
347
|
+
const l = {
|
|
348
|
+
type: "insert",
|
|
349
|
+
children: i,
|
|
350
|
+
raw: `++${o}++`
|
|
351
|
+
}, t = n < e.length ? n + 1 : e.length;
|
|
352
|
+
return { node: l, nextIndex: t };
|
|
353
|
+
}
|
|
354
|
+
function ye(e, c) {
|
|
355
|
+
const i = e[c], o = i.attrs?.find((u) => u[0] === "href")?.[1] || "", n = i.attrs?.find((u) => u[0] === "title")?.[1] || null;
|
|
356
|
+
let r = c + 1;
|
|
357
|
+
const l = [], t = !0;
|
|
358
|
+
for (; r < e.length && e[r].type !== "link_close"; )
|
|
359
|
+
l.push(e[r]), r++;
|
|
360
|
+
const s = b(l), a = s.map((u) => "content" in u ? u.content : u.raw).join(""), d = {
|
|
361
|
+
type: "link",
|
|
362
|
+
href: o,
|
|
363
|
+
title: n,
|
|
364
|
+
text: a,
|
|
365
|
+
children: s,
|
|
366
|
+
raw: `[${a}](${o}${n ? ` "${n}"` : ""})`,
|
|
367
|
+
loading: t
|
|
368
|
+
}, p = r < e.length ? r + 1 : e.length;
|
|
369
|
+
return { node: d, nextIndex: p };
|
|
370
|
+
}
|
|
371
|
+
function be(e) {
|
|
372
|
+
return {
|
|
373
|
+
type: "math_inline",
|
|
374
|
+
content: e.content || "",
|
|
375
|
+
loading: !!e.loading,
|
|
376
|
+
raw: e.raw
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function we(e) {
|
|
380
|
+
return {
|
|
381
|
+
type: "reference",
|
|
382
|
+
id: e.content || "",
|
|
383
|
+
raw: e.markup || `[${e.content}]`
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function B(e, c) {
|
|
387
|
+
const i = [];
|
|
388
|
+
let o = "", n = c + 1;
|
|
389
|
+
const r = [];
|
|
390
|
+
for (; n < e.length && e[n].type !== "s_close"; )
|
|
391
|
+
o += e[n].content || "", r.push(e[n]), n++;
|
|
392
|
+
i.push(...b(r));
|
|
393
|
+
const l = {
|
|
394
|
+
type: "strikethrough",
|
|
395
|
+
children: i,
|
|
396
|
+
raw: `~~${o}~~`
|
|
397
|
+
}, t = n < e.length ? n + 1 : e.length;
|
|
398
|
+
return { node: l, nextIndex: t };
|
|
399
|
+
}
|
|
400
|
+
function W(e, c, i) {
|
|
401
|
+
const o = [];
|
|
402
|
+
let n = "", r = c + 1;
|
|
403
|
+
const l = [];
|
|
404
|
+
for (; r < e.length && e[r].type !== "strong_close"; )
|
|
405
|
+
n += e[r].content || "", l.push(e[r]), r++;
|
|
406
|
+
o.push(...b(l, i));
|
|
407
|
+
const t = {
|
|
408
|
+
type: "strong",
|
|
409
|
+
children: o,
|
|
410
|
+
raw: `**${n}**`
|
|
411
|
+
}, s = r < e.length ? r + 1 : e.length;
|
|
412
|
+
return { node: t, nextIndex: s };
|
|
413
|
+
}
|
|
414
|
+
function xe(e, c) {
|
|
415
|
+
const i = [];
|
|
416
|
+
let o = "", n = c + 1;
|
|
417
|
+
const r = [];
|
|
418
|
+
for (; n < e.length && e[n].type !== "sub_close"; )
|
|
419
|
+
o += e[n].content || "", r.push(e[n]), n++;
|
|
420
|
+
i.push(...b(r));
|
|
421
|
+
const l = {
|
|
422
|
+
type: "subscript",
|
|
423
|
+
children: i.length > 0 ? i : [
|
|
424
|
+
{
|
|
425
|
+
type: "text",
|
|
426
|
+
// Fallback to the collected inner text (e.g., "2" in H~2~O)
|
|
427
|
+
content: o || e[c].content || "",
|
|
428
|
+
raw: o || e[c].content || ""
|
|
429
|
+
}
|
|
430
|
+
],
|
|
431
|
+
raw: `~${o || e[c].content || ""}~`
|
|
432
|
+
}, t = n < e.length ? n + 1 : e.length;
|
|
433
|
+
return { node: l, nextIndex: t };
|
|
434
|
+
}
|
|
435
|
+
function $e(e, c) {
|
|
436
|
+
const i = [];
|
|
437
|
+
let o = "", n = c + 1;
|
|
438
|
+
const r = [];
|
|
439
|
+
for (; n < e.length && e[n].type !== "sup_close"; )
|
|
440
|
+
o += e[n].content || "", r.push(e[n]), n++;
|
|
441
|
+
i.push(...b(r));
|
|
442
|
+
const l = {
|
|
443
|
+
type: "superscript",
|
|
444
|
+
children: i.length > 0 ? i : [
|
|
445
|
+
{
|
|
446
|
+
type: "text",
|
|
447
|
+
// Fallback to the collected inner text (e.g., "2" in x^2^)
|
|
448
|
+
content: o || e[c].content || "",
|
|
449
|
+
raw: o || e[c].content || ""
|
|
450
|
+
}
|
|
451
|
+
],
|
|
452
|
+
raw: `^${o || e[c].content || ""}^`
|
|
453
|
+
}, t = n < e.length ? n + 1 : e.length;
|
|
454
|
+
return { node: l, nextIndex: t };
|
|
455
|
+
}
|
|
456
|
+
function Te(e) {
|
|
457
|
+
return {
|
|
458
|
+
type: "text",
|
|
459
|
+
content: e.content || "",
|
|
460
|
+
raw: e.content || ""
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function b(e, c, i) {
|
|
464
|
+
if (!e || e.length === 0)
|
|
465
|
+
return [];
|
|
466
|
+
const o = [];
|
|
467
|
+
let n = null, r = 0;
|
|
468
|
+
for (e = he(e), e = ue(e), e = pe(e); r < e.length; ) {
|
|
469
|
+
const l = e[r];
|
|
470
|
+
switch (l.type) {
|
|
471
|
+
case "text": {
|
|
472
|
+
let t = l.content.replace(/\\/g, "") || "";
|
|
473
|
+
if (t === "`" || t === "|" || t === "$" || t === "1" || /^\*+$/.test(t) || /^\d$/.test(t)) {
|
|
474
|
+
r++;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
if (/[^\]]\s*\(\s*$/.test(t) && (t = t.replace(/\(\s*$/, "")), c?.startsWith("[") && i?.type === "list_item_open") {
|
|
478
|
+
const f = t.slice(1).match(/[^\s\]]/);
|
|
479
|
+
if (f === null) {
|
|
480
|
+
r++;
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
if (f && /x/i.test(f[0]) || !f) {
|
|
484
|
+
const h = f ? f[0] === "x" || f[0] === "X" : !1;
|
|
485
|
+
o.push({
|
|
486
|
+
type: "checkbox_input",
|
|
487
|
+
checked: h,
|
|
488
|
+
raw: h ? "[x]" : "[ ]"
|
|
489
|
+
}), r++;
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
if (/`[^`]*/.test(t)) {
|
|
494
|
+
n = null, o.push({
|
|
495
|
+
type: "inline_code",
|
|
496
|
+
code: t.replace(/`/g, ""),
|
|
497
|
+
raw: t || ""
|
|
498
|
+
}), r++;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
if (t === "[") {
|
|
502
|
+
r++;
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
if (/[^~]*~{2,}[^~]+/.test(t)) {
|
|
506
|
+
const u = t.indexOf("~~") || 0, f = t.slice(0, u);
|
|
507
|
+
f && (n ? (n.content += f, n.raw += f) : (n = {
|
|
508
|
+
type: "text",
|
|
509
|
+
content: f || "",
|
|
510
|
+
raw: l.content || ""
|
|
511
|
+
}, o.push(n)));
|
|
512
|
+
const h = t.slice(u);
|
|
513
|
+
n = null;
|
|
514
|
+
const { node: g } = B([
|
|
515
|
+
{
|
|
516
|
+
type: "s_open",
|
|
517
|
+
tag: "s",
|
|
518
|
+
attrs: [],
|
|
519
|
+
map: void 0,
|
|
520
|
+
content: "",
|
|
521
|
+
markup: "*",
|
|
522
|
+
info: "",
|
|
523
|
+
meta: null
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
type: "text",
|
|
527
|
+
tag: "",
|
|
528
|
+
attrs: [],
|
|
529
|
+
map: void 0,
|
|
530
|
+
content: h.replace(/~/g, ""),
|
|
531
|
+
markup: "",
|
|
532
|
+
info: "",
|
|
533
|
+
meta: null
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
type: "s_close",
|
|
537
|
+
tag: "s",
|
|
538
|
+
attrs: [],
|
|
539
|
+
map: void 0,
|
|
540
|
+
content: "",
|
|
541
|
+
markup: "*",
|
|
542
|
+
info: "",
|
|
543
|
+
meta: null
|
|
544
|
+
}
|
|
545
|
+
], 0);
|
|
546
|
+
o.push(g), r++;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
if (/[^*]*\*\*[^*]+/.test(t)) {
|
|
550
|
+
const u = t.indexOf("*") || 0, f = t.slice(0, u);
|
|
551
|
+
f && (n ? (n.content += f, n.raw += f) : (n = {
|
|
552
|
+
type: "text",
|
|
553
|
+
content: f || "",
|
|
554
|
+
raw: l.content || ""
|
|
555
|
+
}, o.push(n)));
|
|
556
|
+
const h = t.slice(u);
|
|
557
|
+
n = null;
|
|
558
|
+
const { node: g } = W([
|
|
559
|
+
{
|
|
560
|
+
type: "strong_open",
|
|
561
|
+
tag: "strong",
|
|
562
|
+
content: "",
|
|
563
|
+
markup: "*",
|
|
564
|
+
info: "",
|
|
565
|
+
meta: null
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
type: "text",
|
|
569
|
+
tag: "",
|
|
570
|
+
content: h.replace(/\*/g, ""),
|
|
571
|
+
markup: "",
|
|
572
|
+
info: "",
|
|
573
|
+
meta: null
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
type: "strong_close",
|
|
577
|
+
tag: "strong",
|
|
578
|
+
content: "",
|
|
579
|
+
markup: "*",
|
|
580
|
+
info: "",
|
|
581
|
+
meta: null
|
|
582
|
+
}
|
|
583
|
+
], 0, c);
|
|
584
|
+
o.push(g), r++;
|
|
585
|
+
break;
|
|
586
|
+
} else if (/[^*]*\*[^*]+/.test(t)) {
|
|
587
|
+
const u = t.indexOf("*") || 0, f = t.slice(0, u);
|
|
588
|
+
f && (n ? (n.content += f, n.raw += f) : (n = {
|
|
589
|
+
type: "text",
|
|
590
|
+
content: f || "",
|
|
591
|
+
raw: l.content || ""
|
|
592
|
+
}, o.push(n)));
|
|
593
|
+
const h = t.slice(u);
|
|
594
|
+
n = null;
|
|
595
|
+
const { node: g } = D([
|
|
596
|
+
{
|
|
597
|
+
type: "em_open",
|
|
598
|
+
tag: "em",
|
|
599
|
+
content: "",
|
|
600
|
+
markup: "*",
|
|
601
|
+
info: "",
|
|
602
|
+
meta: null
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
type: "text",
|
|
606
|
+
tag: "",
|
|
607
|
+
content: h.replace(/\*/g, ""),
|
|
608
|
+
markup: "",
|
|
609
|
+
info: "",
|
|
610
|
+
meta: null
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
type: "em_close",
|
|
614
|
+
tag: "em",
|
|
615
|
+
content: "",
|
|
616
|
+
markup: "*",
|
|
617
|
+
info: "",
|
|
618
|
+
meta: null
|
|
619
|
+
}
|
|
620
|
+
], 0);
|
|
621
|
+
o.push(g), r++;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
const s = t.indexOf(";
|
|
639
|
+
if (f !== -1) {
|
|
640
|
+
o.push({
|
|
641
|
+
type: "text",
|
|
642
|
+
content: u,
|
|
643
|
+
raw: u
|
|
644
|
+
});
|
|
645
|
+
const h = t.slice(a + 1, f);
|
|
646
|
+
o.push({
|
|
647
|
+
type: "link",
|
|
648
|
+
href: "",
|
|
649
|
+
text: h,
|
|
650
|
+
children: [
|
|
651
|
+
{
|
|
652
|
+
type: "text",
|
|
653
|
+
content: h,
|
|
654
|
+
raw: h
|
|
655
|
+
}
|
|
656
|
+
],
|
|
657
|
+
loading: !0
|
|
658
|
+
}), r++;
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const p = e[r - 1];
|
|
663
|
+
if (n)
|
|
664
|
+
n.content += d.content.replace(/(\*+|\(|\\)$/, ""), n.raw += d.raw;
|
|
665
|
+
else {
|
|
666
|
+
const u = p?.tag === "br" && e[r - 2]?.content === "[";
|
|
667
|
+
d.content = d.content.replace(/(\*+|\(|\\)$/, ""), n = d, n.center = u, o.push(n);
|
|
668
|
+
}
|
|
669
|
+
r++;
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
case "softbreak":
|
|
673
|
+
n && (n.content += `
|
|
674
|
+
`, n.raw += `
|
|
675
|
+
`), r++;
|
|
676
|
+
break;
|
|
677
|
+
case "code_inline":
|
|
678
|
+
n = null, o.push(me(l)), r++;
|
|
679
|
+
break;
|
|
680
|
+
case "link_open": {
|
|
681
|
+
n = null;
|
|
682
|
+
const t = l.attrs?.find((d) => d[0] === "href")?.[1];
|
|
683
|
+
if (c && t) {
|
|
684
|
+
const d = new RegExp(`\\(\\s*${t}\\s*\\)`), p = o.length > 0 ? o[o.length - 1] : null, u = !d.test(c);
|
|
685
|
+
if (u && p && new RegExp(`\\[${p.text}\\s*\\]\\(`).test(c)) {
|
|
686
|
+
const h = p?.text || p?.content?.slice(1, -1) || "";
|
|
687
|
+
o.splice(o.length - 1, 1, {
|
|
688
|
+
type: "link",
|
|
689
|
+
href: "",
|
|
690
|
+
text: h,
|
|
691
|
+
loading: u
|
|
692
|
+
}), r += 3, e[r]?.content === "." && r++;
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const { node: s, nextIndex: a } = ye(e, r);
|
|
697
|
+
r = a, s.loading = !1, o.push(s);
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
case "image":
|
|
701
|
+
n = null, o.push(P(l)), r++;
|
|
702
|
+
break;
|
|
703
|
+
case "strong_open": {
|
|
704
|
+
n = null;
|
|
705
|
+
const { node: t, nextIndex: s } = W(e, r, l.content);
|
|
706
|
+
o.push(t), r = s;
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
case "em_open": {
|
|
710
|
+
n = null;
|
|
711
|
+
const { node: t, nextIndex: s } = D(e, r);
|
|
712
|
+
o.push(t), r = s;
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
case "s_open": {
|
|
716
|
+
n = null;
|
|
717
|
+
const { node: t, nextIndex: s } = B(e, r);
|
|
718
|
+
o.push(t), r = s;
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
case "mark_open": {
|
|
722
|
+
n = null;
|
|
723
|
+
const { node: t, nextIndex: s } = ge(e, r);
|
|
724
|
+
o.push(t), r = s;
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
case "ins_open": {
|
|
728
|
+
n = null;
|
|
729
|
+
const { node: t, nextIndex: s } = _e(e, r);
|
|
730
|
+
o.push(t), r = s;
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
case "sub_open": {
|
|
734
|
+
n = null;
|
|
735
|
+
const { node: t, nextIndex: s } = xe(e, r);
|
|
736
|
+
o.push(t), r = s;
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
case "sup_open": {
|
|
740
|
+
n = null;
|
|
741
|
+
const { node: t, nextIndex: s } = $e(e, r);
|
|
742
|
+
o.push(t), r = s;
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
case "sub":
|
|
746
|
+
n = null, o.push({
|
|
747
|
+
type: "subscript",
|
|
748
|
+
children: [
|
|
749
|
+
{
|
|
750
|
+
type: "text",
|
|
751
|
+
content: l.content || "",
|
|
752
|
+
raw: l.content || ""
|
|
753
|
+
}
|
|
754
|
+
],
|
|
755
|
+
raw: `~${l.content || ""}~`
|
|
756
|
+
}), r++;
|
|
757
|
+
break;
|
|
758
|
+
case "sup":
|
|
759
|
+
n = null, o.push({
|
|
760
|
+
type: "superscript",
|
|
761
|
+
children: [
|
|
762
|
+
{
|
|
763
|
+
type: "text",
|
|
764
|
+
content: l.content || "",
|
|
765
|
+
raw: l.content || ""
|
|
766
|
+
}
|
|
767
|
+
],
|
|
768
|
+
raw: `^${l.content || ""}^`
|
|
769
|
+
}), r++;
|
|
770
|
+
break;
|
|
771
|
+
case "emoji": {
|
|
772
|
+
n = null;
|
|
773
|
+
const t = e[r - 1];
|
|
774
|
+
t?.type === "text" && /\|:-+/.test(t.content || "") ? o.push({
|
|
775
|
+
type: "text",
|
|
776
|
+
content: "",
|
|
777
|
+
raw: ""
|
|
778
|
+
}) : o.push(se(l)), r++;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
case "checkbox":
|
|
782
|
+
n = null, o.push(ie(l)), r++;
|
|
783
|
+
break;
|
|
784
|
+
case "checkbox_input":
|
|
785
|
+
n = null, o.push(le(l)), r++;
|
|
786
|
+
break;
|
|
787
|
+
case "footnote_ref":
|
|
788
|
+
n = null, o.push(de(l)), r++;
|
|
789
|
+
break;
|
|
790
|
+
case "hardbreak":
|
|
791
|
+
n = null, o.push(fe()), r++;
|
|
792
|
+
break;
|
|
793
|
+
case "fence": {
|
|
794
|
+
n = null, o.push(N(e[r])), r++;
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
case "math_inline": {
|
|
798
|
+
n = null, o.push(be(l)), r++;
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
case "reference": {
|
|
802
|
+
n = null, o.push(we(l)), r++;
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
default:
|
|
806
|
+
o.push(l), n = null, r++;
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return o;
|
|
811
|
+
}
|
|
812
|
+
function Z(e, c) {
|
|
813
|
+
const i = [];
|
|
814
|
+
let o = c + 1;
|
|
815
|
+
for (; o < e.length && e[o].type !== "blockquote_close"; )
|
|
816
|
+
if (e[o].type === "paragraph_open") {
|
|
817
|
+
const r = e[o + 1];
|
|
818
|
+
i.push({
|
|
819
|
+
type: "paragraph",
|
|
820
|
+
children: b(r.children || []),
|
|
821
|
+
raw: r.content || ""
|
|
822
|
+
}), o += 3;
|
|
823
|
+
} else if (e[o].type === "bullet_list_open" || e[o].type === "ordered_list_open") {
|
|
824
|
+
const [r, l] = E(e, o);
|
|
825
|
+
i.push(r), o = l;
|
|
826
|
+
} else
|
|
827
|
+
o++;
|
|
828
|
+
return [{
|
|
829
|
+
type: "blockquote",
|
|
830
|
+
children: i,
|
|
831
|
+
raw: i.map((r) => r.raw).join(`
|
|
832
|
+
`)
|
|
833
|
+
}, o + 1];
|
|
834
|
+
}
|
|
835
|
+
function A(e) {
|
|
836
|
+
if (e.info?.startsWith("diff"))
|
|
837
|
+
return N(e);
|
|
838
|
+
const c = e.content?.match(/ type="application\/vnd\.ant\.([^"]+)"/);
|
|
839
|
+
c?.[1] && (e.content = e.content.replace(/<antArtifact[^>]*>/g, "").replace(/<\/antArtifact>/g, ""));
|
|
840
|
+
const i = Array.isArray(e.map) && e.map.length === 2;
|
|
841
|
+
return {
|
|
842
|
+
type: "code_block",
|
|
843
|
+
language: c ? c[1] : e.info || "",
|
|
844
|
+
code: e.content || "",
|
|
845
|
+
raw: e.content || "",
|
|
846
|
+
loading: !i
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function U(e, c) {
|
|
850
|
+
const i = [];
|
|
851
|
+
let o = c + 1, n = [], r = [];
|
|
852
|
+
for (; o < e.length && e[o].type !== "dl_close"; )
|
|
853
|
+
if (e[o].type === "dt_open") {
|
|
854
|
+
const t = e[o + 1];
|
|
855
|
+
n = b(t.children || []), o += 3;
|
|
856
|
+
} else if (e[o].type === "dd_open") {
|
|
857
|
+
let t = o + 1;
|
|
858
|
+
for (r = []; t < e.length && e[t].type !== "dd_close"; )
|
|
859
|
+
if (e[t].type === "paragraph_open") {
|
|
860
|
+
const s = e[t + 1];
|
|
861
|
+
r.push({
|
|
862
|
+
type: "paragraph",
|
|
863
|
+
children: b(s.children || [], s.content || ""),
|
|
864
|
+
raw: s.content || ""
|
|
865
|
+
}), t += 3;
|
|
866
|
+
} else
|
|
867
|
+
t++;
|
|
868
|
+
n.length > 0 && (i.push({
|
|
869
|
+
type: "definition_item",
|
|
870
|
+
term: n,
|
|
871
|
+
definition: r,
|
|
872
|
+
raw: `${n.map((s) => s.raw).join("")}: ${r.map((s) => s.raw).join(`
|
|
873
|
+
`)}`
|
|
874
|
+
}), n = []), o = t + 1;
|
|
875
|
+
} else
|
|
876
|
+
o++;
|
|
877
|
+
return [{
|
|
878
|
+
type: "definition_list",
|
|
879
|
+
items: i,
|
|
880
|
+
raw: i.map((t) => t.raw).join(`
|
|
881
|
+
`)
|
|
882
|
+
}, o + 1];
|
|
883
|
+
}
|
|
884
|
+
function G(e, c) {
|
|
885
|
+
const o = e[c].meta?.label ?? 0, n = [];
|
|
886
|
+
let r = c + 1;
|
|
887
|
+
for (; r < e.length && e[r].type !== "footnote_close"; )
|
|
888
|
+
if (e[r].type === "paragraph_open") {
|
|
889
|
+
const t = e[r + 1];
|
|
890
|
+
n.push({
|
|
891
|
+
type: "paragraph",
|
|
892
|
+
children: b(t.children || []),
|
|
893
|
+
raw: t.content || ""
|
|
894
|
+
}), r += 3;
|
|
895
|
+
} else
|
|
896
|
+
r++;
|
|
897
|
+
return [{
|
|
898
|
+
type: "footnote",
|
|
899
|
+
id: o,
|
|
900
|
+
children: n,
|
|
901
|
+
raw: `[^${o}]: ${n.map((t) => t.raw).join(`
|
|
902
|
+
`)}`
|
|
903
|
+
}, r + 1];
|
|
904
|
+
}
|
|
905
|
+
function z(e, c) {
|
|
906
|
+
const i = e[c], o = Number.parseInt(i.tag?.substring(1) || "1"), n = e[c + 1], r = n.content || "";
|
|
907
|
+
return {
|
|
908
|
+
type: "heading",
|
|
909
|
+
level: o,
|
|
910
|
+
text: r,
|
|
911
|
+
children: b(n.children || []),
|
|
912
|
+
raw: r
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
function j(e) {
|
|
916
|
+
return {
|
|
917
|
+
type: "math_block",
|
|
918
|
+
content: e.content || "",
|
|
919
|
+
loading: !!e.loading,
|
|
920
|
+
raw: e.raw || ""
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function K(e, c) {
|
|
924
|
+
let i = c + 1, o = null;
|
|
925
|
+
const n = [];
|
|
926
|
+
let r = !1;
|
|
927
|
+
for (; i < e.length && e[i].type !== "table_close"; )
|
|
928
|
+
if (e[i].type === "thead_open")
|
|
929
|
+
r = !0, i++;
|
|
930
|
+
else if (e[i].type === "thead_close")
|
|
931
|
+
r = !1, i++;
|
|
932
|
+
else if (e[i].type === "tbody_open" || e[i].type === "tbody_close")
|
|
933
|
+
i++;
|
|
934
|
+
else if (e[i].type === "tr_open") {
|
|
935
|
+
const t = [];
|
|
936
|
+
let s = i + 1;
|
|
937
|
+
for (; s < e.length && e[s].type !== "tr_close"; )
|
|
938
|
+
if (e[s].type === "th_open" || e[s].type === "td_open") {
|
|
939
|
+
const d = e[s].type === "th_open", p = e[s + 1], u = p.content || "";
|
|
940
|
+
t.push({
|
|
941
|
+
type: "table_cell",
|
|
942
|
+
header: d || r,
|
|
943
|
+
children: b(p.children || [], u),
|
|
944
|
+
raw: u
|
|
945
|
+
}), s += 3;
|
|
946
|
+
} else
|
|
947
|
+
s++;
|
|
948
|
+
const a = {
|
|
949
|
+
type: "table_row",
|
|
950
|
+
cells: t,
|
|
951
|
+
raw: t.map((d) => d.raw).join("|")
|
|
952
|
+
};
|
|
953
|
+
r ? o = a : n.push(a), i = s + 1;
|
|
954
|
+
} else
|
|
955
|
+
i++;
|
|
956
|
+
return o || (o = {
|
|
957
|
+
type: "table_row",
|
|
958
|
+
cells: [],
|
|
959
|
+
raw: ""
|
|
960
|
+
}), [{
|
|
961
|
+
type: "table",
|
|
962
|
+
header: o,
|
|
963
|
+
rows: n,
|
|
964
|
+
loading: e[c].loading || !1,
|
|
965
|
+
raw: [o, ...n].map((t) => t.raw).join(`
|
|
966
|
+
`)
|
|
967
|
+
}, i + 1];
|
|
968
|
+
}
|
|
969
|
+
function J() {
|
|
970
|
+
return {
|
|
971
|
+
type: "thematic_break",
|
|
972
|
+
raw: "---"
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
function E(e, c) {
|
|
976
|
+
const i = e[c], o = [];
|
|
977
|
+
let n = c + 1;
|
|
978
|
+
for (; n < e.length && e[n].type !== "bullet_list_close" && e[n].type !== "ordered_list_close"; )
|
|
979
|
+
if (e[n].type === "list_item_open") {
|
|
980
|
+
if (e[n].markup === "*") {
|
|
981
|
+
n++;
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const l = [];
|
|
985
|
+
let t = n + 1;
|
|
986
|
+
for (; t < e.length && e[t].type !== "list_item_close"; )
|
|
987
|
+
if (e[t].type === "paragraph_open") {
|
|
988
|
+
const s = e[t + 1], a = e[t - 1], d = s && typeof s.content == "string" ? s.content : "";
|
|
989
|
+
/\n\d+$/.test(d) && (s && (s.content = d.replace(/\n\d+$/, "")), s?.children && s.children.splice(-1, 1)), l.push({
|
|
990
|
+
type: "paragraph",
|
|
991
|
+
children: b(s?.children || [], s?.content || "", a),
|
|
992
|
+
raw: s?.content || ""
|
|
993
|
+
}), t += 3;
|
|
994
|
+
} else if (e[t].type === "blockquote_open") {
|
|
995
|
+
const [s, a] = Z(e, t);
|
|
996
|
+
l.push(s), t = a;
|
|
997
|
+
} else if (e[t].type === "bullet_list_open" || e[t].type === "ordered_list_open") {
|
|
998
|
+
if (e[t].markup === "*") {
|
|
999
|
+
t++;
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
const [s, a] = Q(e, t);
|
|
1003
|
+
l.push(s), t = a;
|
|
1004
|
+
} else if (e[t].type === "code_block")
|
|
1005
|
+
l.push(A(e[t])), t += 1;
|
|
1006
|
+
else if (e[t].type === "fence")
|
|
1007
|
+
l.push(N(e[t])), t += 1;
|
|
1008
|
+
else if (e[t].type === "math_block")
|
|
1009
|
+
l.push(j(e[t])), t += 1;
|
|
1010
|
+
else if (e[t].type === "table_open") {
|
|
1011
|
+
const [s, a] = K(e, t);
|
|
1012
|
+
l.push(s), t = a;
|
|
1013
|
+
} else if (e[t].type === "dl_open") {
|
|
1014
|
+
const [s, a] = U(e, t);
|
|
1015
|
+
l.push(s), t = a;
|
|
1016
|
+
} else if (e[t].type === "footnote_open") {
|
|
1017
|
+
const [s, a] = G(e, t);
|
|
1018
|
+
l.push(s), t = a;
|
|
1019
|
+
} else if (e[t].type === "heading_open") {
|
|
1020
|
+
const s = z(e, t);
|
|
1021
|
+
l.push(s), t += 3;
|
|
1022
|
+
} else if (e[t].type === "hr")
|
|
1023
|
+
l.push(J()), t += 1;
|
|
1024
|
+
else if (e[t].type === "container_open") {
|
|
1025
|
+
const s = /^::: ?(warning|info|note|tip|danger|caution) ?(.*)$/.exec(
|
|
1026
|
+
e[t].info || ""
|
|
1027
|
+
);
|
|
1028
|
+
if (s) {
|
|
1029
|
+
const [a, d] = V(e, t, s);
|
|
1030
|
+
l.push(a), t = d;
|
|
1031
|
+
} else
|
|
1032
|
+
t += 1;
|
|
1033
|
+
} else
|
|
1034
|
+
t += 1;
|
|
1035
|
+
o.push({
|
|
1036
|
+
type: "list_item",
|
|
1037
|
+
children: l,
|
|
1038
|
+
raw: l.map((s) => s.raw).join("")
|
|
1039
|
+
}), n = t + 1;
|
|
1040
|
+
} else
|
|
1041
|
+
n += 1;
|
|
1042
|
+
return [{
|
|
1043
|
+
type: "list",
|
|
1044
|
+
ordered: i.type === "ordered_list_open",
|
|
1045
|
+
// markdown-it may include attrs like [['start','2']] on ordered_list_open
|
|
1046
|
+
start: (() => {
|
|
1047
|
+
if (i.attrs && i.attrs.length) {
|
|
1048
|
+
const l = i.attrs.find((t) => t[0] === "start");
|
|
1049
|
+
if (l)
|
|
1050
|
+
return Number(l[1]) || 1;
|
|
1051
|
+
}
|
|
1052
|
+
})(),
|
|
1053
|
+
items: o,
|
|
1054
|
+
raw: o.map((l) => l.raw).join(`
|
|
1055
|
+
`)
|
|
1056
|
+
}, n + 1];
|
|
1057
|
+
}
|
|
1058
|
+
function Q(e, c) {
|
|
1059
|
+
const i = e[c], o = [];
|
|
1060
|
+
let n = c + 1;
|
|
1061
|
+
for (; n < e.length && e[n].type !== "bullet_list_close" && e[n].type !== "ordered_list_close"; )
|
|
1062
|
+
if (e[n].type === "list_item_open") {
|
|
1063
|
+
if (e[n].markup === "*") {
|
|
1064
|
+
n++;
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1067
|
+
const l = [];
|
|
1068
|
+
let t = n + 1;
|
|
1069
|
+
for (; t < e.length && e[t].type !== "list_item_close"; )
|
|
1070
|
+
if (e[t].type === "paragraph_open") {
|
|
1071
|
+
const s = e[t + 1], a = e[t - 1];
|
|
1072
|
+
l.push({
|
|
1073
|
+
type: "paragraph",
|
|
1074
|
+
children: b(s.children || [], s.content || "", a),
|
|
1075
|
+
raw: s.content || ""
|
|
1076
|
+
}), t += 3;
|
|
1077
|
+
} else if (e[t].type === "bullet_list_open" || e[t].type === "ordered_list_open") {
|
|
1078
|
+
if (e[t].markup === "*") {
|
|
1079
|
+
t++;
|
|
1080
|
+
continue;
|
|
1081
|
+
}
|
|
1082
|
+
const [s, a] = Q(e, t);
|
|
1083
|
+
l.push(s), t = a;
|
|
1084
|
+
} else e[t].type === "code_block" ? (l.push(A(e[t])), t += 1) : e[t].type === "fence" ? (l.push(N(e[t])), t += 1) : (e[t].type === "math_block" && l.push(j(e[t])), t += 1);
|
|
1085
|
+
o.push({
|
|
1086
|
+
type: "list_item",
|
|
1087
|
+
children: l,
|
|
1088
|
+
raw: l.map((s) => s.raw).join("")
|
|
1089
|
+
}), n = t + 1;
|
|
1090
|
+
} else
|
|
1091
|
+
n += 1;
|
|
1092
|
+
return [{
|
|
1093
|
+
type: "list",
|
|
1094
|
+
ordered: i.type === "ordered_list_open",
|
|
1095
|
+
start: (() => {
|
|
1096
|
+
if (i.attrs && i.attrs.length) {
|
|
1097
|
+
const l = i.attrs.find((t) => t[0] === "start");
|
|
1098
|
+
if (l)
|
|
1099
|
+
return Number(l[1]) || 1;
|
|
1100
|
+
}
|
|
1101
|
+
})(),
|
|
1102
|
+
items: o,
|
|
1103
|
+
raw: o.map((l) => l.raw).join(`
|
|
1104
|
+
`)
|
|
1105
|
+
}, n + 1];
|
|
1106
|
+
}
|
|
1107
|
+
function V(e, c, i) {
|
|
1108
|
+
const o = i[1] || "note", n = i[2] || o.charAt(0).toUpperCase() + o.slice(1), r = [];
|
|
1109
|
+
let l = c + 1;
|
|
1110
|
+
for (; l < e.length && e[l].type !== "container_close"; )
|
|
1111
|
+
if (e[l].type === "paragraph_open") {
|
|
1112
|
+
const s = e[l + 1];
|
|
1113
|
+
s && r.push({
|
|
1114
|
+
type: "paragraph",
|
|
1115
|
+
children: b(s.children || []),
|
|
1116
|
+
raw: s.content || ""
|
|
1117
|
+
}), l += 3;
|
|
1118
|
+
} else if (e[l].type === "bullet_list_open" || e[l].type === "ordered_list_open") {
|
|
1119
|
+
const [s, a] = E(e, l);
|
|
1120
|
+
r.push(s), l = a;
|
|
1121
|
+
} else
|
|
1122
|
+
l++;
|
|
1123
|
+
return [{
|
|
1124
|
+
type: "admonition",
|
|
1125
|
+
kind: o,
|
|
1126
|
+
title: n,
|
|
1127
|
+
children: r,
|
|
1128
|
+
raw: `:::${o} ${n}
|
|
1129
|
+
${r.map((s) => s.raw).join(`
|
|
1130
|
+
`)}
|
|
1131
|
+
:::`
|
|
1132
|
+
}, l + 1];
|
|
1133
|
+
}
|
|
1134
|
+
function ve(e, c) {
|
|
1135
|
+
const i = e[c];
|
|
1136
|
+
let o = "note", n = "";
|
|
1137
|
+
const r = i.type.match(/^container_(\w+)_open$/);
|
|
1138
|
+
if (r) {
|
|
1139
|
+
o = r[1];
|
|
1140
|
+
const p = (i.info || "").trim();
|
|
1141
|
+
if (p && !p.startsWith(":::")) {
|
|
1142
|
+
const u = p.replace(new RegExp(`^${o}`), "").trim();
|
|
1143
|
+
u && (n = u);
|
|
1144
|
+
}
|
|
1145
|
+
} else {
|
|
1146
|
+
const p = (i.info || "").trim(), u = /^:{1,3}\s*(warning|info|note|tip|danger|caution)\s*(.*)$/i.exec(p);
|
|
1147
|
+
u && (o = u[1], n = u[2] || "");
|
|
1148
|
+
}
|
|
1149
|
+
n || (n = o.charAt(0).toUpperCase() + o.slice(1));
|
|
1150
|
+
const l = [];
|
|
1151
|
+
let t = c + 1;
|
|
1152
|
+
const s = new RegExp(`^container_${o}_close$`);
|
|
1153
|
+
for (; t < e.length && e[t].type !== "container_close" && !s.test(e[t].type); )
|
|
1154
|
+
if (e[t].type === "paragraph_open") {
|
|
1155
|
+
const p = e[t + 1];
|
|
1156
|
+
if (p) {
|
|
1157
|
+
let u = -1;
|
|
1158
|
+
if (p.children)
|
|
1159
|
+
for (let h = p.children.length - 1; h >= 0; h--) {
|
|
1160
|
+
const g = p.children[h];
|
|
1161
|
+
if (g && g.type === "text" && /:+/.test(g.content || "")) {
|
|
1162
|
+
u = h;
|
|
1163
|
+
break;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
const f = u !== -1 && p.children ? p.children.slice(0, u) : p.children;
|
|
1167
|
+
l.push({
|
|
1168
|
+
type: "paragraph",
|
|
1169
|
+
children: b(f || []),
|
|
1170
|
+
raw: p && typeof p.content == "string" ? p.content.replace(/\n:+$/, "").replace(/\n\s*:::\s*$/, "") : ""
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
t += 3;
|
|
1174
|
+
} else if (e[t].type === "bullet_list_open" || e[t].type === "ordered_list_open") {
|
|
1175
|
+
const [p, u] = E(e, t);
|
|
1176
|
+
l.push(p), t = u;
|
|
1177
|
+
} else
|
|
1178
|
+
t++;
|
|
1179
|
+
return [{
|
|
1180
|
+
type: "admonition",
|
|
1181
|
+
kind: o,
|
|
1182
|
+
title: n,
|
|
1183
|
+
children: l,
|
|
1184
|
+
raw: `:::${o} ${n}
|
|
1185
|
+
${l.map((p) => p.raw).join(`
|
|
1186
|
+
`)}
|
|
1187
|
+
:::`
|
|
1188
|
+
}, t + 1];
|
|
1189
|
+
}
|
|
1190
|
+
function Ce() {
|
|
1191
|
+
return {
|
|
1192
|
+
type: "hardbreak",
|
|
1193
|
+
raw: `\\
|
|
1194
|
+
`
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
function Ne(e, c) {
|
|
1198
|
+
const i = e[c + 1], o = i.content || "";
|
|
1199
|
+
return {
|
|
1200
|
+
type: "paragraph",
|
|
1201
|
+
children: b(i.children || [], o),
|
|
1202
|
+
raw: o
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
function Fe(e, c, i = {}) {
|
|
1206
|
+
let o = (e ?? "").toString().replace(/([^\\])\right/g, "$1\\right");
|
|
1207
|
+
o.endsWith("- *") && (o = o.replace(/- \*$/, "- \\*")), /\n\s*-\s*$/.test(o) ? o = o.replace(/\n\s*-\s*$/, `
|
|
1208
|
+
`) : /\n[[(]\n*$/.test(o) && (o = o.replace(/(\n\[|\n\()+\n*$/g, `
|
|
1209
|
+
`));
|
|
1210
|
+
const n = c.parse(o, {});
|
|
1211
|
+
if (!n || !Array.isArray(n))
|
|
1212
|
+
return [];
|
|
1213
|
+
const r = i.preTransformTokens, l = i.postTransformTokens;
|
|
1214
|
+
let t = n;
|
|
1215
|
+
r && typeof r == "function" && (t = r(n) || n);
|
|
1216
|
+
let s = Ie(t);
|
|
1217
|
+
return l && typeof l == "function" && (s = l(t) || t), s;
|
|
1218
|
+
}
|
|
1219
|
+
function Ie(e) {
|
|
1220
|
+
if (!e || !Array.isArray(e))
|
|
1221
|
+
return [];
|
|
1222
|
+
const c = [];
|
|
1223
|
+
let i = 0;
|
|
1224
|
+
for (e = ce(e); i < e.length; ) {
|
|
1225
|
+
const o = e[i];
|
|
1226
|
+
switch (o.type) {
|
|
1227
|
+
case "container_warning_open":
|
|
1228
|
+
case "container_info_open":
|
|
1229
|
+
case "container_note_open":
|
|
1230
|
+
case "container_tip_open":
|
|
1231
|
+
case "container_danger_open":
|
|
1232
|
+
case "container_caution_open":
|
|
1233
|
+
case "container_error_open": {
|
|
1234
|
+
const [n, r] = ve(e, i);
|
|
1235
|
+
c.push(n), i = r;
|
|
1236
|
+
break;
|
|
1237
|
+
}
|
|
1238
|
+
case "heading_open":
|
|
1239
|
+
c.push(z(e, i)), i += 3;
|
|
1240
|
+
break;
|
|
1241
|
+
case "paragraph_open":
|
|
1242
|
+
c.push(Ne(e, i)), i += 3;
|
|
1243
|
+
break;
|
|
1244
|
+
case "html_block":
|
|
1245
|
+
case "code_block":
|
|
1246
|
+
c.push(A(e[i])), i += 1;
|
|
1247
|
+
break;
|
|
1248
|
+
case "fence":
|
|
1249
|
+
c.push(N(e[i])), i += 1;
|
|
1250
|
+
break;
|
|
1251
|
+
case "bullet_list_open":
|
|
1252
|
+
case "ordered_list_open": {
|
|
1253
|
+
const [n, r] = E(e, i);
|
|
1254
|
+
c.push(n), i = r;
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
case "hr":
|
|
1258
|
+
c.push(J()), i += 1;
|
|
1259
|
+
break;
|
|
1260
|
+
case "blockquote_open": {
|
|
1261
|
+
const [n, r] = Z(e, i);
|
|
1262
|
+
c.push(n), i = r;
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1265
|
+
case "table_open": {
|
|
1266
|
+
const [n, r] = K(e, i);
|
|
1267
|
+
c.push(n), i = r;
|
|
1268
|
+
break;
|
|
1269
|
+
}
|
|
1270
|
+
case "dl_open": {
|
|
1271
|
+
const [n, r] = U(e, i);
|
|
1272
|
+
c.push(n), i = r;
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
case "footnote_open": {
|
|
1276
|
+
const [n, r] = G(e, i);
|
|
1277
|
+
c.push(n), i = r;
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
case "container_open": {
|
|
1281
|
+
const n = /^::: ?(warning|info|note|tip|danger|caution|error) ?(.*)$/.exec(
|
|
1282
|
+
o.info || ""
|
|
1283
|
+
);
|
|
1284
|
+
if (n) {
|
|
1285
|
+
const [r, l] = V(e, i, n);
|
|
1286
|
+
c.push(r), i = l;
|
|
1287
|
+
} else
|
|
1288
|
+
i += 1;
|
|
1289
|
+
break;
|
|
1290
|
+
}
|
|
1291
|
+
case "hardbreak":
|
|
1292
|
+
c.push(Ce()), i++;
|
|
1293
|
+
break;
|
|
1294
|
+
case "math_block":
|
|
1295
|
+
c.push(j(e[i])), i += 1;
|
|
1296
|
+
break;
|
|
1297
|
+
default:
|
|
1298
|
+
i += 1;
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
return c;
|
|
1303
|
+
}
|
|
1304
|
+
let Y;
|
|
1305
|
+
function Ze(e) {
|
|
1306
|
+
Y = e;
|
|
1307
|
+
}
|
|
1308
|
+
function Me() {
|
|
1309
|
+
return Y;
|
|
1310
|
+
}
|
|
1311
|
+
function Ee(e, c, i, o) {
|
|
1312
|
+
const n = e.length;
|
|
1313
|
+
if (i === "$$" && o === "$$") {
|
|
1314
|
+
let a = c;
|
|
1315
|
+
for (; a < n - 1; ) {
|
|
1316
|
+
if (e[a] === "$" && e[a + 1] === "$") {
|
|
1317
|
+
let d = a - 1, p = 0;
|
|
1318
|
+
for (; d >= 0 && e[d] === "\\"; )
|
|
1319
|
+
p++, d--;
|
|
1320
|
+
if (p % 2 === 0)
|
|
1321
|
+
return a;
|
|
1322
|
+
}
|
|
1323
|
+
a++;
|
|
1324
|
+
}
|
|
1325
|
+
return -1;
|
|
1326
|
+
}
|
|
1327
|
+
const r = i[i.length - 1], l = o;
|
|
1328
|
+
let t = 0, s = c;
|
|
1329
|
+
for (; s < n; ) {
|
|
1330
|
+
if (e.slice(s, s + l.length) === l) {
|
|
1331
|
+
let d = s - 1, p = 0;
|
|
1332
|
+
for (; d >= 0 && e[d] === "\\"; )
|
|
1333
|
+
p++, d--;
|
|
1334
|
+
if (p % 2 === 0) {
|
|
1335
|
+
if (t === 0)
|
|
1336
|
+
return s;
|
|
1337
|
+
t--, s += l.length;
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
const a = e[s];
|
|
1342
|
+
if (a === "\\") {
|
|
1343
|
+
s += 2;
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
a === r ? t++ : a === l[l.length - 1] && t > 0 && t--, s++;
|
|
1347
|
+
}
|
|
1348
|
+
return -1;
|
|
1349
|
+
}
|
|
1350
|
+
function Se(e) {
|
|
1351
|
+
[
|
|
1352
|
+
"admonition",
|
|
1353
|
+
"info",
|
|
1354
|
+
"warning",
|
|
1355
|
+
"error",
|
|
1356
|
+
"tip",
|
|
1357
|
+
"danger",
|
|
1358
|
+
"note",
|
|
1359
|
+
"caution"
|
|
1360
|
+
].forEach((c) => {
|
|
1361
|
+
e.use(oe, c, {
|
|
1362
|
+
render(i, o) {
|
|
1363
|
+
return i[o].nesting === 1 ? `<div class="vmr-container vmr-container-${c}">` : `</div>
|
|
1364
|
+
`;
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
}), e.block.ruler.before(
|
|
1368
|
+
"fence",
|
|
1369
|
+
"vmr_container_fallback",
|
|
1370
|
+
(c, i, o, n) => {
|
|
1371
|
+
const r = c.bMarks[i] + c.tShift[i], l = c.eMarks[i], t = c.src.slice(r, l).match(/^:::\s*(\w+)/);
|
|
1372
|
+
if (!t)
|
|
1373
|
+
return !1;
|
|
1374
|
+
if (n)
|
|
1375
|
+
return !0;
|
|
1376
|
+
const s = t[1];
|
|
1377
|
+
let a = i + 1, d = !1;
|
|
1378
|
+
for (; a <= o; ) {
|
|
1379
|
+
const h = c.bMarks[a] + c.tShift[a], g = c.eMarks[a];
|
|
1380
|
+
if (c.src.slice(h, g).trim() === ":::") {
|
|
1381
|
+
d = !0;
|
|
1382
|
+
break;
|
|
1383
|
+
}
|
|
1384
|
+
a++;
|
|
1385
|
+
}
|
|
1386
|
+
if (!d)
|
|
1387
|
+
return !1;
|
|
1388
|
+
c.push("vmr_container_open", "div", 1).attrSet("class", `vmr-container vmr-container-${s}`);
|
|
1389
|
+
const u = [];
|
|
1390
|
+
for (let h = i + 1; h < a; h++) {
|
|
1391
|
+
const g = c.bMarks[h] + c.tShift[h], x = c.eMarks[h];
|
|
1392
|
+
u.push(c.src.slice(g, x));
|
|
1393
|
+
}
|
|
1394
|
+
c.push("paragraph_open", "p", 1);
|
|
1395
|
+
const f = c.push("inline", "", 0);
|
|
1396
|
+
return f.content = u.join(`
|
|
1397
|
+
`), f.map = [i + 1, a], f.children = [], c.md.inline.parse(f.content, c.md, c.env, f.children), c.push("paragraph_close", "p", -1), c.push("vmr_container_close", "div", -1), c.line = a + 1, !0;
|
|
1398
|
+
}
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
const Ae = [
|
|
1402
|
+
"mathbf",
|
|
1403
|
+
"boldsymbol",
|
|
1404
|
+
"mathbb",
|
|
1405
|
+
"mathcal",
|
|
1406
|
+
"mathfrak",
|
|
1407
|
+
"mathrm",
|
|
1408
|
+
"mathit",
|
|
1409
|
+
"mathsf",
|
|
1410
|
+
"vec",
|
|
1411
|
+
"hat",
|
|
1412
|
+
"bar",
|
|
1413
|
+
"tilde",
|
|
1414
|
+
"overline",
|
|
1415
|
+
"underline",
|
|
1416
|
+
"mathscr",
|
|
1417
|
+
"mathnormal",
|
|
1418
|
+
"operatorname",
|
|
1419
|
+
"mathbf*"
|
|
1420
|
+
], M = Ae.map((e) => e.replace(/[.*+?^${}()|[\\]"\]/g, "\\$&")).join("|"), je = /\\[a-z]+/i, ee = "(?:\\\\|\\u0008)", Re = new RegExp(`${ee}(?:${M})\\s*\\{[^}]+\\}`, "i"), ke = new RegExp(`(?:${ee})?(?:${M})s*{`, "i"), Oe = /\\(?:text|frac|left|right|times)/, De = new RegExp("(?<!\\+)\\+(?!\\+)|[=\\-*/^<>]|\\\\times|\\\\pm|\\\\cdot|\\\\le|\\\\ge|\\\\neq"), Pe = /[A-Z]+\s*\([^)]+\)/i, Be = /\b(?:sin|cos|tan|log|ln|exp|sqrt|frac|sum|lim|int|prod)\b/, We = /\b\d{4}\/\d{1,2}\/\d{1,2}(?:[ T]\d{1,2}:\d{2}(?::\d{2})?)?\b/;
|
|
1421
|
+
function q(e) {
|
|
1422
|
+
if (!e)
|
|
1423
|
+
return !1;
|
|
1424
|
+
const c = e.replace(/\u0008/g, "\\b"), i = c.trim();
|
|
1425
|
+
if (We.test(i))
|
|
1426
|
+
return !1;
|
|
1427
|
+
if (i.length > 2e3)
|
|
1428
|
+
return !0;
|
|
1429
|
+
if (/[./]\s*\D|\D\s*[./]/.test(e))
|
|
1430
|
+
return !1;
|
|
1431
|
+
const o = je.test(c), n = Re.test(c), r = ke.test(c), l = Oe.test(c), t = /(?:^|[^\w\\])(?:[A-Z]|\\[A-Z]+)_(?:\{[^}]+\}|[A-Z0-9\\])/i, s = /(?:^|[^\w\\])(?:[A-Z]|\\[A-Z]+)\^(?:\{[^}]+\}|[A-Z0-9\\])/i, a = t.test(c) || s.test(c), d = De.test(c), p = Pe.test(c), u = Be.test(c);
|
|
1432
|
+
return o || n || r || l || a || d || p || u;
|
|
1433
|
+
}
|
|
1434
|
+
const ne = [
|
|
1435
|
+
"ldots",
|
|
1436
|
+
"cdots",
|
|
1437
|
+
"quad",
|
|
1438
|
+
"in",
|
|
1439
|
+
"infty",
|
|
1440
|
+
"perp",
|
|
1441
|
+
"mid",
|
|
1442
|
+
"operatorname",
|
|
1443
|
+
"to",
|
|
1444
|
+
"rightarrow",
|
|
1445
|
+
"leftarrow",
|
|
1446
|
+
"math",
|
|
1447
|
+
"mathrm",
|
|
1448
|
+
"mathbf",
|
|
1449
|
+
"mathit",
|
|
1450
|
+
"mathbb",
|
|
1451
|
+
"mathcal",
|
|
1452
|
+
"mathfrak",
|
|
1453
|
+
"alpha",
|
|
1454
|
+
"beta",
|
|
1455
|
+
"gamma",
|
|
1456
|
+
"delta",
|
|
1457
|
+
"epsilon",
|
|
1458
|
+
"lambda",
|
|
1459
|
+
"sum",
|
|
1460
|
+
"prod",
|
|
1461
|
+
"int",
|
|
1462
|
+
"sqrt",
|
|
1463
|
+
"fbox",
|
|
1464
|
+
"boxed",
|
|
1465
|
+
"color",
|
|
1466
|
+
"rule",
|
|
1467
|
+
"edef",
|
|
1468
|
+
"fcolorbox",
|
|
1469
|
+
"hline",
|
|
1470
|
+
"hdashline",
|
|
1471
|
+
"cdot",
|
|
1472
|
+
"times",
|
|
1473
|
+
"pm",
|
|
1474
|
+
"le",
|
|
1475
|
+
"ge",
|
|
1476
|
+
"neq",
|
|
1477
|
+
"sin",
|
|
1478
|
+
"cos",
|
|
1479
|
+
"tan",
|
|
1480
|
+
"log",
|
|
1481
|
+
"ln",
|
|
1482
|
+
"exp",
|
|
1483
|
+
"lim",
|
|
1484
|
+
"frac",
|
|
1485
|
+
"text",
|
|
1486
|
+
"left",
|
|
1487
|
+
"right",
|
|
1488
|
+
"times"
|
|
1489
|
+
], L = ne.slice().sort((e, c) => c.length - e.length).map((e) => e.replace(/[.*+?^${}()|[\\]\\\]/g, "\\$&")).join("|"), H = "[ \r\b\f\v]", X = {
|
|
1490
|
+
" ": "t",
|
|
1491
|
+
"\r": "r",
|
|
1492
|
+
"\b": "b",
|
|
1493
|
+
"\f": "f",
|
|
1494
|
+
"\v": "v"
|
|
1495
|
+
};
|
|
1496
|
+
function F(e) {
|
|
1497
|
+
const c = /(^|[^\\])(__|\*\*)/g;
|
|
1498
|
+
let i = 0;
|
|
1499
|
+
for (; c.exec(e) !== null; )
|
|
1500
|
+
i++;
|
|
1501
|
+
return i;
|
|
1502
|
+
}
|
|
1503
|
+
function C(e, c) {
|
|
1504
|
+
const i = c?.commands ?? ne, o = c?.escapeExclamation ?? !0, n = c?.commands == null;
|
|
1505
|
+
let r;
|
|
1506
|
+
if (n)
|
|
1507
|
+
r = new RegExp(`${H}|(?<!\\\\|\\w)(${L})\\b`, "g");
|
|
1508
|
+
else {
|
|
1509
|
+
const a = `(?:${i.slice().sort((d, p) => p.length - d.length).map((d) => d.replace(/[.*+?^${}()|[\\]\\"\]/g, "\\$&")).join("|")})`;
|
|
1510
|
+
r = new RegExp(`${H}|(?<!\\\\|\\w)(${a})\\b`, "g");
|
|
1511
|
+
}
|
|
1512
|
+
let l = e.replace(r, (a, d) => X[a] !== void 0 ? `\\${X[a]}` : d && i.includes(d) ? `\\${d}` : a);
|
|
1513
|
+
o && (l = l.replace(/(^|[^\\])!/g, "$1\\!"));
|
|
1514
|
+
const t = n ? [M, L].filter(Boolean).join("|") : [i.map((a) => a.replace(/[.*+?^${}()|[\\]\\\]/g, "\\$&")).join("|"), M].filter(Boolean).join("|");
|
|
1515
|
+
let s = l;
|
|
1516
|
+
if (t) {
|
|
1517
|
+
const a = new RegExp(`(^|[^\\\\])(${t})\\s*\\{`, "g");
|
|
1518
|
+
s = s.replace(a, (d, p, u) => `${p}\\${u}{`);
|
|
1519
|
+
}
|
|
1520
|
+
return s = s.replace(/span\{([^}]+)\}/, "span\\{$1\\}").replace(/\\operatorname\{span\}\{((?:[^{}]|\{[^}]*\})+)\}/, "\\operatorname{span}\\{$1\\}"), s;
|
|
1521
|
+
}
|
|
1522
|
+
function qe(e, c) {
|
|
1523
|
+
const i = (n, r) => {
|
|
1524
|
+
if (/^\*[^*]+/.test(n.src))
|
|
1525
|
+
return !1;
|
|
1526
|
+
const l = [
|
|
1527
|
+
["$$", "$$"],
|
|
1528
|
+
["\\(", "\\)"],
|
|
1529
|
+
["(", ")"]
|
|
1530
|
+
];
|
|
1531
|
+
let t = 0, s = 0;
|
|
1532
|
+
for (const [a, d] of l) {
|
|
1533
|
+
const p = n.src;
|
|
1534
|
+
let u = !1;
|
|
1535
|
+
const f = (h) => {
|
|
1536
|
+
if ((h === "undefined" || h == null) && (h = ""), h === "\\") {
|
|
1537
|
+
n.pos = n.pos + h.length, t = n.pos;
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
if (h === "\\)" || h === "\\(") {
|
|
1541
|
+
const x = n.push("text_special", "", 0);
|
|
1542
|
+
x.content = h === "\\)" ? ")" : "(", x.markup = h, n.pos = n.pos + h.length, t = n.pos;
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
if (!h)
|
|
1546
|
+
return;
|
|
1547
|
+
const g = n.push("text", "", 0);
|
|
1548
|
+
g.content = h, n.pos = n.pos + h.length, t = n.pos;
|
|
1549
|
+
};
|
|
1550
|
+
for (; !(t >= p.length); ) {
|
|
1551
|
+
const h = p.indexOf(a, t);
|
|
1552
|
+
if (h === -1)
|
|
1553
|
+
break;
|
|
1554
|
+
if (h > 0) {
|
|
1555
|
+
let _ = h - 1;
|
|
1556
|
+
for (; _ >= 0 && p[_] === " "; )
|
|
1557
|
+
_--;
|
|
1558
|
+
if (_ >= 0 && p[_] === "]")
|
|
1559
|
+
return !1;
|
|
1560
|
+
}
|
|
1561
|
+
const g = Ee(p, h + a.length, a, d);
|
|
1562
|
+
if (g === -1) {
|
|
1563
|
+
const _ = p.slice(h + a.length);
|
|
1564
|
+
if (q(_)) {
|
|
1565
|
+
if (t = h + a.length, u = !0, !r) {
|
|
1566
|
+
n.pending = "";
|
|
1567
|
+
const T = s ? p.slice(s, t) : p.slice(0, t), y = F(T) % 2 === 1;
|
|
1568
|
+
if (f(s ? p.slice(s, t) : p.slice(0, t)), y) {
|
|
1569
|
+
const w = n.push("strong_open", "", 0);
|
|
1570
|
+
w.markup = p.slice(0, h + 2);
|
|
1571
|
+
const m = n.push("math_inline", "math", 0);
|
|
1572
|
+
m.content = C(_, c), m.markup = a === "$$" ? "$$" : a === "\\(" ? "\\(\\)" : a === "$" ? "$" : "()", m.raw = `${a}${_}${d}`, m.loading = !0, w.content = _, n.push("strong_close", "", 0);
|
|
1573
|
+
} else {
|
|
1574
|
+
const w = n.push("math_inline", "math", 0);
|
|
1575
|
+
w.content = C(_, c), w.markup = a === "$$" ? "$$" : a === "\\(" ? "\\(\\)" : a === "$" ? "$" : "()", w.raw = `${a}${_}${d}`, w.loading = !0;
|
|
1576
|
+
}
|
|
1577
|
+
n.pos = p.length;
|
|
1578
|
+
}
|
|
1579
|
+
t = p.length, s = t;
|
|
1580
|
+
}
|
|
1581
|
+
break;
|
|
1582
|
+
}
|
|
1583
|
+
const x = p.slice(h + a.length, g);
|
|
1584
|
+
if (!q(x)) {
|
|
1585
|
+
t = g + d.length;
|
|
1586
|
+
const _ = p.slice(n.pos, t);
|
|
1587
|
+
n.pending || f(_);
|
|
1588
|
+
continue;
|
|
1589
|
+
}
|
|
1590
|
+
if (u = !0, !r) {
|
|
1591
|
+
const _ = p.slice(0, h);
|
|
1592
|
+
let y = p.slice(0, t) ? p.slice(s, h) : _;
|
|
1593
|
+
const w = F(y) % 2 === 1;
|
|
1594
|
+
if (h !== n.pos && w && (y = n.pending + p.slice(n.pos, h)), n.pending !== y)
|
|
1595
|
+
if (n.pending = "", w) {
|
|
1596
|
+
const m = y.match(/(\*+)/), $ = y.slice(m.index + m[0].length);
|
|
1597
|
+
f(y.slice(0, m.index));
|
|
1598
|
+
const v = n.push("strong_open", "", 0);
|
|
1599
|
+
v.markup = m[0];
|
|
1600
|
+
const I = n.push("text", "", 0);
|
|
1601
|
+
I.content = $, n.push("strong_close", "", 0);
|
|
1602
|
+
} else
|
|
1603
|
+
f(y);
|
|
1604
|
+
if (w) {
|
|
1605
|
+
const m = n.push("strong_open", "", 0);
|
|
1606
|
+
m.markup = "**";
|
|
1607
|
+
const $ = n.push("math_inline", "math", 0);
|
|
1608
|
+
$.content = C(x, c), $.markup = a === "$$" ? "$$" : a === "\\(" ? "\\(\\)" : a === "$" ? "$" : "()", $.raw = `${a}${x}${d}`, $.loading = !1;
|
|
1609
|
+
const v = p.slice(g + d.length), I = v.startsWith("*");
|
|
1610
|
+
if (I && n.push("strong_close", "", 0), v) {
|
|
1611
|
+
const te = n.push("text", "", 0);
|
|
1612
|
+
te.content = (v == null ? "" : String(v)).replace(/^\*+/, "");
|
|
1613
|
+
}
|
|
1614
|
+
I || n.push("strong_close", "", 0), n.pos = p.length, t = p.length, s = t;
|
|
1615
|
+
continue;
|
|
1616
|
+
} else {
|
|
1617
|
+
const m = n.push("math_inline", "math", 0);
|
|
1618
|
+
m.content = C(x, c), m.markup = a === "$$" ? "$$" : a === "\\(" ? "\\(\\)" : a === "$" ? "$" : "()", m.raw = `${a}${x}${d}`, m.loading = !1;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
t = g + d.length, s = t, n.pos = t;
|
|
1622
|
+
}
|
|
1623
|
+
if (u)
|
|
1624
|
+
return r ? n.pos = t : (t < p.length && f(p.slice(t)), n.pos = p.length), !0;
|
|
1625
|
+
}
|
|
1626
|
+
return !1;
|
|
1627
|
+
}, o = (n, r, l, t) => {
|
|
1628
|
+
const s = [
|
|
1629
|
+
["\\[", "\\]"],
|
|
1630
|
+
["[", "]"],
|
|
1631
|
+
["$$", "$$"]
|
|
1632
|
+
], a = n.bMarks[r] + n.tShift[r], d = n.src.slice(a, n.eMarks[r]).trim();
|
|
1633
|
+
let p = !1, u = "", f = "";
|
|
1634
|
+
for (const [y, w] of s)
|
|
1635
|
+
if (d === y || d.startsWith(y))
|
|
1636
|
+
if (y.includes("[")) {
|
|
1637
|
+
if (d.replace("\\", "") === "[") {
|
|
1638
|
+
if (r + 1 < l) {
|
|
1639
|
+
p = !0, u = y, f = w;
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
continue;
|
|
1643
|
+
}
|
|
1644
|
+
} else {
|
|
1645
|
+
p = !0, u = y, f = w;
|
|
1646
|
+
break;
|
|
1647
|
+
}
|
|
1648
|
+
if (!p)
|
|
1649
|
+
return !1;
|
|
1650
|
+
if (t)
|
|
1651
|
+
return !0;
|
|
1652
|
+
if (d.includes(f) && d.indexOf(f) > u.length) {
|
|
1653
|
+
const y = d.indexOf(u), w = d.indexOf(
|
|
1654
|
+
f,
|
|
1655
|
+
y + u.length
|
|
1656
|
+
), m = d.slice(
|
|
1657
|
+
y + u.length,
|
|
1658
|
+
w
|
|
1659
|
+
), $ = n.push("math_block", "math", 0);
|
|
1660
|
+
return $.content = C(m), $.markup = u === "$$" ? "$$" : u === "[" ? "[]" : "\\[\\]", $.map = [r, r + 1], $.raw = `${u}${m}${f}`, $.block = !0, $.loading = !1, n.line = r + 1, !0;
|
|
1661
|
+
}
|
|
1662
|
+
let h = r, g = "", x = !1;
|
|
1663
|
+
const _ = d === u ? "" : d.slice(u.length);
|
|
1664
|
+
if (_.includes(f)) {
|
|
1665
|
+
const y = _.indexOf(f);
|
|
1666
|
+
g = _.slice(0, y), x = !0, h = r;
|
|
1667
|
+
} else
|
|
1668
|
+
for (_ && (g = _), h = r + 1; h < l; h++) {
|
|
1669
|
+
const y = n.bMarks[h] + n.tShift[h], w = n.eMarks[h], m = n.src.slice(y - 1, w);
|
|
1670
|
+
if (m.trim() === f) {
|
|
1671
|
+
x = !0;
|
|
1672
|
+
break;
|
|
1673
|
+
} else if (m.includes(f)) {
|
|
1674
|
+
x = !0;
|
|
1675
|
+
const $ = m.indexOf(f);
|
|
1676
|
+
g += (g ? `
|
|
1677
|
+
` : "") + m.slice(0, $);
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
g += (g ? `
|
|
1681
|
+
` : "") + m;
|
|
1682
|
+
}
|
|
1683
|
+
const T = n.push("math_block", "math", 0);
|
|
1684
|
+
return T.content = C(g), T.markup = u === "$$" ? "$$" : u === "[" ? "[]" : "\\[\\]", T.raw = `${u}${g}${g.startsWith(`
|
|
1685
|
+
`) ? `
|
|
1686
|
+
` : ""}${f}`, T.map = [r, h + 1], T.block = !0, T.loading = !x, n.line = h + 1, !0;
|
|
1687
|
+
};
|
|
1688
|
+
e.inline.ruler.before("escape", "math", i), e.block.ruler.before("paragraph", "math_block", o, {
|
|
1689
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
function Le(e) {
|
|
1693
|
+
const c = e.renderer.rules.image || function(i, o, n, r, l) {
|
|
1694
|
+
return l.renderToken(i, o, n);
|
|
1695
|
+
};
|
|
1696
|
+
e.renderer.rules.image = (i, o, n, r, l) => (i[o].attrSet?.("loading", "lazy"), c(i, o, n, r, l)), e.renderer.rules.fence = e.renderer.rules.fence || ((i, o) => {
|
|
1697
|
+
const n = i[o], r = n.info ? n.info.trim() : "", l = r ? `language-${e.utils.escapeHtml(r.split(/\s+/g)[0])}` : "", t = e.utils.escapeHtml(n.content);
|
|
1698
|
+
return `<pre class="${l}"><code>${t}</code></pre>`;
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
function Ue(e = {}) {
|
|
1702
|
+
const c = new re({
|
|
1703
|
+
html: !0,
|
|
1704
|
+
linkify: !0,
|
|
1705
|
+
typographer: !0,
|
|
1706
|
+
...e.markdownItOptions ?? {}
|
|
1707
|
+
});
|
|
1708
|
+
if (e.enableMath ?? !0) {
|
|
1709
|
+
const i = { ...Me() ?? {}, ...e.mathOptions ?? {} };
|
|
1710
|
+
qe(c, i);
|
|
1711
|
+
}
|
|
1712
|
+
return (e.enableContainers ?? !0) && Se(c), Le(c), c;
|
|
1713
|
+
}
|
|
1714
|
+
export {
|
|
1715
|
+
ne as KATEX_COMMANDS,
|
|
1716
|
+
Se as applyContainers,
|
|
1717
|
+
qe as applyMath,
|
|
1718
|
+
Ee as findMatchingClose,
|
|
1719
|
+
Me as getDefaultMathOptions,
|
|
1720
|
+
Ue as getMarkdown,
|
|
1721
|
+
C as normalizeStandaloneBackslashT,
|
|
1722
|
+
b as parseInlineTokens,
|
|
1723
|
+
Fe as parseMarkdownToStructure,
|
|
1724
|
+
Ie as processTokens,
|
|
1725
|
+
Ze as setDefaultMathOptions
|
|
1726
|
+
};
|