@wsxjs/wsx-press 0.0.18
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/LICENSE +21 -0
- package/dist/client.cjs +1 -0
- package/dist/client.js +1256 -0
- package/dist/index-ChO3PMD5.js +461 -0
- package/dist/index-uNJnOC7n.cjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +8 -0
- package/dist/node.cjs +47 -0
- package/dist/node.js +1708 -0
- package/package.json +90 -0
- package/src/client/components/DocLayout.css +49 -0
- package/src/client/components/DocLayout.wsx +92 -0
- package/src/client/components/DocPage.css +56 -0
- package/src/client/components/DocPage.wsx +480 -0
- package/src/client/components/DocSearch.css +113 -0
- package/src/client/components/DocSearch.wsx +328 -0
- package/src/client/components/DocSidebar.css +97 -0
- package/src/client/components/DocSidebar.wsx +173 -0
- package/src/client/components/DocTOC.css +105 -0
- package/src/client/components/DocTOC.wsx +262 -0
- package/src/client/index.ts +32 -0
- package/src/client/styles/code.css +242 -0
- package/src/client/styles/index.css +12 -0
- package/src/client/styles/reset.css +116 -0
- package/src/client/styles/theme.css +171 -0
- package/src/client/styles/typography.css +239 -0
- package/src/index.ts +26 -0
- package/src/node/index.ts +16 -0
- package/src/node/metadata.ts +113 -0
- package/src/node/plugin.ts +223 -0
- package/src/node/search.ts +53 -0
- package/src/node/toc.ts +148 -0
- package/src/node/typedoc.ts +96 -0
- package/src/types/wsx.d.ts +11 -0
- package/src/types.test.ts +118 -0
- package/src/types.ts +150 -0
package/dist/node.js
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
1
|
+
var Te = Object.defineProperty;
|
|
2
|
+
var ne = (a) => {
|
|
3
|
+
throw TypeError(a);
|
|
4
|
+
};
|
|
5
|
+
var ze = (a, t, e) => t in a ? Te(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
6
|
+
var k = (a, t, e) => ze(a, typeof t != "symbol" ? t + "" : t, e), Re = (a, t, e) => t.has(a) || ne("Cannot " + e);
|
|
7
|
+
var se = (a, t, e) => t.has(a) ? ne("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(a) : t.set(a, e);
|
|
8
|
+
var v = (a, t, e) => (Re(a, t, "access private method"), e);
|
|
9
|
+
import { glob as Se } from "glob";
|
|
10
|
+
import x from "path";
|
|
11
|
+
import m from "fs-extra";
|
|
12
|
+
import { Application as _e, TSConfigReader as Ie, TypeDocReader as Ae } from "typedoc";
|
|
13
|
+
import { L as Ce } from "./index-ChO3PMD5.js";
|
|
14
|
+
async function O(a) {
|
|
15
|
+
const t = await Se("**/*.md", { cwd: a, absolute: !0 }), e = {};
|
|
16
|
+
for (const n of t) {
|
|
17
|
+
const i = x.relative(a, n), r = await m.readFile(n, "utf-8"), s = je(r), l = i.replace(/\.md$/, ""), o = x.dirname(i);
|
|
18
|
+
e[l] = {
|
|
19
|
+
title: s.title || x.basename(n, ".md"),
|
|
20
|
+
category: o === "." ? "." : o,
|
|
21
|
+
route: `/docs/${l}`,
|
|
22
|
+
...s
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return Ee(e);
|
|
26
|
+
}
|
|
27
|
+
function je(a) {
|
|
28
|
+
const t = a.match(/^---\n([\s\S]*?)\n---/);
|
|
29
|
+
if (!t)
|
|
30
|
+
return {};
|
|
31
|
+
const e = t[1], n = {};
|
|
32
|
+
return e.split(`
|
|
33
|
+
`).forEach((i) => {
|
|
34
|
+
const r = i.indexOf(":");
|
|
35
|
+
if (r === -1)
|
|
36
|
+
return;
|
|
37
|
+
const s = i.substring(0, r).trim(), l = i.substring(r + 1).trim();
|
|
38
|
+
s && l && (s === "title" || s === "description" || s === "category" ? n[s] = l : s === "tags" ? n.tags = l.replace(/[[\]]/g, "").split(",").map((o) => o.trim()) : n[s] = l);
|
|
39
|
+
}), n;
|
|
40
|
+
}
|
|
41
|
+
function Ee(a) {
|
|
42
|
+
const t = /* @__PURE__ */ new Map();
|
|
43
|
+
for (const [e, n] of Object.entries(a)) {
|
|
44
|
+
const i = n.category;
|
|
45
|
+
t.has(i) || t.set(i, []), t.get(i).push(e);
|
|
46
|
+
}
|
|
47
|
+
for (const [e, n] of t) {
|
|
48
|
+
n.sort();
|
|
49
|
+
for (let i = 0; i < n.length; i++) {
|
|
50
|
+
const r = n[i];
|
|
51
|
+
a[r].prev = i > 0 ? `/docs/${n[i - 1]}` : null, a[r].next = i < n.length - 1 ? `/docs/${n[i + 1]}` : null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return a;
|
|
55
|
+
}
|
|
56
|
+
async function ie(a, t) {
|
|
57
|
+
const e = [];
|
|
58
|
+
for (const [n, i] of Object.entries(a)) {
|
|
59
|
+
const r = x.join(t, `${n}.md`), l = (await m.readFile(r, "utf-8")).replace(/^---[\s\S]*?---/, "").replace(/```[\s\S]*?```/g, "").replace(/[#*`_[\]()]/g, "").trim();
|
|
60
|
+
e.push({
|
|
61
|
+
id: n,
|
|
62
|
+
title: i.title,
|
|
63
|
+
category: i.category,
|
|
64
|
+
route: i.route,
|
|
65
|
+
content: l.substring(0, 500)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
documents: e,
|
|
70
|
+
options: {
|
|
71
|
+
keys: [
|
|
72
|
+
{ name: "title", weight: 0.7 },
|
|
73
|
+
{ name: "content", weight: 0.3 }
|
|
74
|
+
],
|
|
75
|
+
threshold: 0.3,
|
|
76
|
+
includeScore: !0,
|
|
77
|
+
includeMatches: !0
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async function Pe(a) {
|
|
82
|
+
const {
|
|
83
|
+
entryPoints: t,
|
|
84
|
+
tsconfig: e,
|
|
85
|
+
outputDir: n,
|
|
86
|
+
excludePrivate: i = !0,
|
|
87
|
+
excludeProtected: r = !1,
|
|
88
|
+
excludeInternal: s = !0,
|
|
89
|
+
publicPath: l = "/api/"
|
|
90
|
+
} = a;
|
|
91
|
+
for (const o of t)
|
|
92
|
+
if (!await m.pathExists(o))
|
|
93
|
+
throw new Error(`Entry point not found: ${o}`);
|
|
94
|
+
if (!await m.pathExists(e))
|
|
95
|
+
throw new Error(`TypeScript config not found: ${e}`);
|
|
96
|
+
await m.ensureDir(n);
|
|
97
|
+
try {
|
|
98
|
+
const o = await _e.bootstrapWithPlugins({
|
|
99
|
+
entryPoints: t,
|
|
100
|
+
tsconfig: e,
|
|
101
|
+
plugin: ["typedoc-plugin-markdown"],
|
|
102
|
+
theme: "markdown",
|
|
103
|
+
// 输出配置
|
|
104
|
+
readme: "none",
|
|
105
|
+
excludePrivate: i,
|
|
106
|
+
excludeProtected: r,
|
|
107
|
+
excludeInternal: s,
|
|
108
|
+
publicPath: l
|
|
109
|
+
});
|
|
110
|
+
o.options.addReader(new Ie()), o.options.addReader(new Ae());
|
|
111
|
+
const p = await o.convert();
|
|
112
|
+
if (!p)
|
|
113
|
+
throw new Error("Failed to convert TypeScript project");
|
|
114
|
+
await o.generateDocs(p, n);
|
|
115
|
+
} catch (o) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Failed to generate API documentation: ${o instanceof Error ? o.message : String(o)}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function J() {
|
|
122
|
+
return {
|
|
123
|
+
async: !1,
|
|
124
|
+
breaks: !1,
|
|
125
|
+
extensions: null,
|
|
126
|
+
gfm: !0,
|
|
127
|
+
hooks: null,
|
|
128
|
+
pedantic: !1,
|
|
129
|
+
renderer: null,
|
|
130
|
+
silent: !1,
|
|
131
|
+
tokenizer: null,
|
|
132
|
+
walkTokens: null
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
let I = J();
|
|
136
|
+
function pe(a) {
|
|
137
|
+
I = a;
|
|
138
|
+
}
|
|
139
|
+
const ue = /[&<>"']/, ve = new RegExp(ue.source, "g"), fe = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, Oe = new RegExp(fe.source, "g"), Le = {
|
|
140
|
+
"&": "&",
|
|
141
|
+
"<": "<",
|
|
142
|
+
">": ">",
|
|
143
|
+
'"': """,
|
|
144
|
+
"'": "'"
|
|
145
|
+
}, re = (a) => Le[a];
|
|
146
|
+
function b(a, t) {
|
|
147
|
+
if (t) {
|
|
148
|
+
if (ue.test(a))
|
|
149
|
+
return a.replace(ve, re);
|
|
150
|
+
} else if (fe.test(a))
|
|
151
|
+
return a.replace(Oe, re);
|
|
152
|
+
return a;
|
|
153
|
+
}
|
|
154
|
+
const De = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
155
|
+
function Ze(a) {
|
|
156
|
+
return a.replace(De, (t, e) => (e = e.toLowerCase(), e === "colon" ? ":" : e.charAt(0) === "#" ? e.charAt(1) === "x" ? String.fromCharCode(parseInt(e.substring(2), 16)) : String.fromCharCode(+e.substring(1)) : ""));
|
|
157
|
+
}
|
|
158
|
+
const qe = /(^|[^\[])\^/g;
|
|
159
|
+
function d(a, t) {
|
|
160
|
+
let e = typeof a == "string" ? a : a.source;
|
|
161
|
+
t = t || "";
|
|
162
|
+
const n = {
|
|
163
|
+
replace: (i, r) => {
|
|
164
|
+
let s = typeof r == "string" ? r : r.source;
|
|
165
|
+
return s = s.replace(qe, "$1"), e = e.replace(i, s), n;
|
|
166
|
+
},
|
|
167
|
+
getRegex: () => new RegExp(e, t)
|
|
168
|
+
};
|
|
169
|
+
return n;
|
|
170
|
+
}
|
|
171
|
+
function oe(a) {
|
|
172
|
+
try {
|
|
173
|
+
a = encodeURI(a).replace(/%25/g, "%");
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return a;
|
|
178
|
+
}
|
|
179
|
+
const C = { exec: () => null };
|
|
180
|
+
function le(a, t) {
|
|
181
|
+
const e = a.replace(/\|/g, (r, s, l) => {
|
|
182
|
+
let o = !1, p = s;
|
|
183
|
+
for (; --p >= 0 && l[p] === "\\"; )
|
|
184
|
+
o = !o;
|
|
185
|
+
return o ? "|" : " |";
|
|
186
|
+
}), n = e.split(/ \|/);
|
|
187
|
+
let i = 0;
|
|
188
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n[n.length - 1].trim() && n.pop(), t)
|
|
189
|
+
if (n.length > t)
|
|
190
|
+
n.splice(t);
|
|
191
|
+
else
|
|
192
|
+
for (; n.length < t; )
|
|
193
|
+
n.push("");
|
|
194
|
+
for (; i < n.length; i++)
|
|
195
|
+
n[i] = n[i].trim().replace(/\\\|/g, "|");
|
|
196
|
+
return n;
|
|
197
|
+
}
|
|
198
|
+
function L(a, t, e) {
|
|
199
|
+
const n = a.length;
|
|
200
|
+
if (n === 0)
|
|
201
|
+
return "";
|
|
202
|
+
let i = 0;
|
|
203
|
+
for (; i < n && a.charAt(n - i - 1) === t; )
|
|
204
|
+
i++;
|
|
205
|
+
return a.slice(0, n - i);
|
|
206
|
+
}
|
|
207
|
+
function Be(a, t) {
|
|
208
|
+
if (a.indexOf(t[1]) === -1)
|
|
209
|
+
return -1;
|
|
210
|
+
let e = 0;
|
|
211
|
+
for (let n = 0; n < a.length; n++)
|
|
212
|
+
if (a[n] === "\\")
|
|
213
|
+
n++;
|
|
214
|
+
else if (a[n] === t[0])
|
|
215
|
+
e++;
|
|
216
|
+
else if (a[n] === t[1] && (e--, e < 0))
|
|
217
|
+
return n;
|
|
218
|
+
return -1;
|
|
219
|
+
}
|
|
220
|
+
function ae(a, t, e, n) {
|
|
221
|
+
const i = t.href, r = t.title ? b(t.title) : null, s = a[1].replace(/\\([\[\]])/g, "$1");
|
|
222
|
+
if (a[0].charAt(0) !== "!") {
|
|
223
|
+
n.state.inLink = !0;
|
|
224
|
+
const l = {
|
|
225
|
+
type: "link",
|
|
226
|
+
raw: e,
|
|
227
|
+
href: i,
|
|
228
|
+
title: r,
|
|
229
|
+
text: s,
|
|
230
|
+
tokens: n.inlineTokens(s)
|
|
231
|
+
};
|
|
232
|
+
return n.state.inLink = !1, l;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
type: "image",
|
|
236
|
+
raw: e,
|
|
237
|
+
href: i,
|
|
238
|
+
title: r,
|
|
239
|
+
text: b(s)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function Me(a, t) {
|
|
243
|
+
const e = a.match(/^(\s+)(?:```)/);
|
|
244
|
+
if (e === null)
|
|
245
|
+
return t;
|
|
246
|
+
const n = e[1];
|
|
247
|
+
return t.split(`
|
|
248
|
+
`).map((i) => {
|
|
249
|
+
const r = i.match(/^\s+/);
|
|
250
|
+
if (r === null)
|
|
251
|
+
return i;
|
|
252
|
+
const [s] = r;
|
|
253
|
+
return s.length >= n.length ? i.slice(n.length) : i;
|
|
254
|
+
}).join(`
|
|
255
|
+
`);
|
|
256
|
+
}
|
|
257
|
+
class Z {
|
|
258
|
+
// set by the lexer
|
|
259
|
+
constructor(t) {
|
|
260
|
+
k(this, "options");
|
|
261
|
+
k(this, "rules");
|
|
262
|
+
// set by the lexer
|
|
263
|
+
k(this, "lexer");
|
|
264
|
+
this.options = t || I;
|
|
265
|
+
}
|
|
266
|
+
space(t) {
|
|
267
|
+
const e = this.rules.block.newline.exec(t);
|
|
268
|
+
if (e && e[0].length > 0)
|
|
269
|
+
return {
|
|
270
|
+
type: "space",
|
|
271
|
+
raw: e[0]
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
code(t) {
|
|
275
|
+
const e = this.rules.block.code.exec(t);
|
|
276
|
+
if (e) {
|
|
277
|
+
const n = e[0].replace(/^ {1,4}/gm, "");
|
|
278
|
+
return {
|
|
279
|
+
type: "code",
|
|
280
|
+
raw: e[0],
|
|
281
|
+
codeBlockStyle: "indented",
|
|
282
|
+
text: this.options.pedantic ? n : L(n, `
|
|
283
|
+
`)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
fences(t) {
|
|
288
|
+
const e = this.rules.block.fences.exec(t);
|
|
289
|
+
if (e) {
|
|
290
|
+
const n = e[0], i = Me(n, e[3] || "");
|
|
291
|
+
return {
|
|
292
|
+
type: "code",
|
|
293
|
+
raw: n,
|
|
294
|
+
lang: e[2] ? e[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : e[2],
|
|
295
|
+
text: i
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
heading(t) {
|
|
300
|
+
const e = this.rules.block.heading.exec(t);
|
|
301
|
+
if (e) {
|
|
302
|
+
let n = e[2].trim();
|
|
303
|
+
if (/#$/.test(n)) {
|
|
304
|
+
const i = L(n, "#");
|
|
305
|
+
(this.options.pedantic || !i || / $/.test(i)) && (n = i.trim());
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
type: "heading",
|
|
309
|
+
raw: e[0],
|
|
310
|
+
depth: e[1].length,
|
|
311
|
+
text: n,
|
|
312
|
+
tokens: this.lexer.inline(n)
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
hr(t) {
|
|
317
|
+
const e = this.rules.block.hr.exec(t);
|
|
318
|
+
if (e)
|
|
319
|
+
return {
|
|
320
|
+
type: "hr",
|
|
321
|
+
raw: e[0]
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
blockquote(t) {
|
|
325
|
+
const e = this.rules.block.blockquote.exec(t);
|
|
326
|
+
if (e) {
|
|
327
|
+
let n = e[0].replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g, `
|
|
328
|
+
$1`);
|
|
329
|
+
n = L(n.replace(/^ *>[ \t]?/gm, ""), `
|
|
330
|
+
`);
|
|
331
|
+
const i = this.lexer.state.top;
|
|
332
|
+
this.lexer.state.top = !0;
|
|
333
|
+
const r = this.lexer.blockTokens(n);
|
|
334
|
+
return this.lexer.state.top = i, {
|
|
335
|
+
type: "blockquote",
|
|
336
|
+
raw: e[0],
|
|
337
|
+
tokens: r,
|
|
338
|
+
text: n
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
list(t) {
|
|
343
|
+
let e = this.rules.block.list.exec(t);
|
|
344
|
+
if (e) {
|
|
345
|
+
let n = e[1].trim();
|
|
346
|
+
const i = n.length > 1, r = {
|
|
347
|
+
type: "list",
|
|
348
|
+
raw: "",
|
|
349
|
+
ordered: i,
|
|
350
|
+
start: i ? +n.slice(0, -1) : "",
|
|
351
|
+
loose: !1,
|
|
352
|
+
items: []
|
|
353
|
+
};
|
|
354
|
+
n = i ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = i ? n : "[*+-]");
|
|
355
|
+
const s = new RegExp(`^( {0,3}${n})((?:[ ][^\\n]*)?(?:\\n|$))`);
|
|
356
|
+
let l = "", o = "", p = !1;
|
|
357
|
+
for (; t; ) {
|
|
358
|
+
let c = !1;
|
|
359
|
+
if (!(e = s.exec(t)) || this.rules.block.hr.test(t))
|
|
360
|
+
break;
|
|
361
|
+
l = e[0], t = t.substring(l.length);
|
|
362
|
+
let u = e[2].split(`
|
|
363
|
+
`, 1)[0].replace(/^\t+/, (N) => " ".repeat(3 * N.length)), h = t.split(`
|
|
364
|
+
`, 1)[0], f = 0;
|
|
365
|
+
this.options.pedantic ? (f = 2, o = u.trimStart()) : (f = e[2].search(/[^ ]/), f = f > 4 ? 1 : f, o = u.slice(f), f += e[1].length);
|
|
366
|
+
let w = !1;
|
|
367
|
+
if (!u && /^ *$/.test(h) && (l += h + `
|
|
368
|
+
`, t = t.substring(h.length + 1), c = !0), !c) {
|
|
369
|
+
const N = new RegExp(`^ {0,${Math.min(3, f - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), Y = new RegExp(`^ {0,${Math.min(3, f - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), ee = new RegExp(`^ {0,${Math.min(3, f - 1)}}(?:\`\`\`|~~~)`), te = new RegExp(`^ {0,${Math.min(3, f - 1)}}#`);
|
|
370
|
+
for (; t; ) {
|
|
371
|
+
const F = t.split(`
|
|
372
|
+
`, 1)[0];
|
|
373
|
+
if (h = F, this.options.pedantic && (h = h.replace(/^ {1,4}(?=( {4})*[^ ])/g, " ")), ee.test(h) || te.test(h) || N.test(h) || Y.test(t))
|
|
374
|
+
break;
|
|
375
|
+
if (h.search(/[^ ]/) >= f || !h.trim())
|
|
376
|
+
o += `
|
|
377
|
+
` + h.slice(f);
|
|
378
|
+
else {
|
|
379
|
+
if (w || u.search(/[^ ]/) >= 4 || ee.test(u) || te.test(u) || Y.test(u))
|
|
380
|
+
break;
|
|
381
|
+
o += `
|
|
382
|
+
` + h;
|
|
383
|
+
}
|
|
384
|
+
!w && !h.trim() && (w = !0), l += F + `
|
|
385
|
+
`, t = t.substring(F.length + 1), u = h.slice(f);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
r.loose || (p ? r.loose = !0 : /\n *\n *$/.test(l) && (p = !0));
|
|
389
|
+
let y = null, R;
|
|
390
|
+
this.options.gfm && (y = /^\[[ xX]\] /.exec(o), y && (R = y[0] !== "[ ] ", o = o.replace(/^\[[ xX]\] +/, ""))), r.items.push({
|
|
391
|
+
type: "list_item",
|
|
392
|
+
raw: l,
|
|
393
|
+
task: !!y,
|
|
394
|
+
checked: R,
|
|
395
|
+
loose: !1,
|
|
396
|
+
text: o,
|
|
397
|
+
tokens: []
|
|
398
|
+
}), r.raw += l;
|
|
399
|
+
}
|
|
400
|
+
r.items[r.items.length - 1].raw = l.trimEnd(), r.items[r.items.length - 1].text = o.trimEnd(), r.raw = r.raw.trimEnd();
|
|
401
|
+
for (let c = 0; c < r.items.length; c++)
|
|
402
|
+
if (this.lexer.state.top = !1, r.items[c].tokens = this.lexer.blockTokens(r.items[c].text, []), !r.loose) {
|
|
403
|
+
const u = r.items[c].tokens.filter((f) => f.type === "space"), h = u.length > 0 && u.some((f) => /\n.*\n/.test(f.raw));
|
|
404
|
+
r.loose = h;
|
|
405
|
+
}
|
|
406
|
+
if (r.loose)
|
|
407
|
+
for (let c = 0; c < r.items.length; c++)
|
|
408
|
+
r.items[c].loose = !0;
|
|
409
|
+
return r;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
html(t) {
|
|
413
|
+
const e = this.rules.block.html.exec(t);
|
|
414
|
+
if (e)
|
|
415
|
+
return {
|
|
416
|
+
type: "html",
|
|
417
|
+
block: !0,
|
|
418
|
+
raw: e[0],
|
|
419
|
+
pre: e[1] === "pre" || e[1] === "script" || e[1] === "style",
|
|
420
|
+
text: e[0]
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
def(t) {
|
|
424
|
+
const e = this.rules.block.def.exec(t);
|
|
425
|
+
if (e) {
|
|
426
|
+
const n = e[1].toLowerCase().replace(/\s+/g, " "), i = e[2] ? e[2].replace(/^<(.*)>$/, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = e[3] ? e[3].substring(1, e[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : e[3];
|
|
427
|
+
return {
|
|
428
|
+
type: "def",
|
|
429
|
+
tag: n,
|
|
430
|
+
raw: e[0],
|
|
431
|
+
href: i,
|
|
432
|
+
title: r
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
table(t) {
|
|
437
|
+
const e = this.rules.block.table.exec(t);
|
|
438
|
+
if (!e || !/[:|]/.test(e[2]))
|
|
439
|
+
return;
|
|
440
|
+
const n = le(e[1]), i = e[2].replace(/^\||\| *$/g, "").split("|"), r = e[3] && e[3].trim() ? e[3].replace(/\n[ \t]*$/, "").split(`
|
|
441
|
+
`) : [], s = {
|
|
442
|
+
type: "table",
|
|
443
|
+
raw: e[0],
|
|
444
|
+
header: [],
|
|
445
|
+
align: [],
|
|
446
|
+
rows: []
|
|
447
|
+
};
|
|
448
|
+
if (n.length === i.length) {
|
|
449
|
+
for (const l of i)
|
|
450
|
+
/^ *-+: *$/.test(l) ? s.align.push("right") : /^ *:-+: *$/.test(l) ? s.align.push("center") : /^ *:-+ *$/.test(l) ? s.align.push("left") : s.align.push(null);
|
|
451
|
+
for (const l of n)
|
|
452
|
+
s.header.push({
|
|
453
|
+
text: l,
|
|
454
|
+
tokens: this.lexer.inline(l)
|
|
455
|
+
});
|
|
456
|
+
for (const l of r)
|
|
457
|
+
s.rows.push(le(l, s.header.length).map((o) => ({
|
|
458
|
+
text: o,
|
|
459
|
+
tokens: this.lexer.inline(o)
|
|
460
|
+
})));
|
|
461
|
+
return s;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
lheading(t) {
|
|
465
|
+
const e = this.rules.block.lheading.exec(t);
|
|
466
|
+
if (e)
|
|
467
|
+
return {
|
|
468
|
+
type: "heading",
|
|
469
|
+
raw: e[0],
|
|
470
|
+
depth: e[2].charAt(0) === "=" ? 1 : 2,
|
|
471
|
+
text: e[1],
|
|
472
|
+
tokens: this.lexer.inline(e[1])
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
paragraph(t) {
|
|
476
|
+
const e = this.rules.block.paragraph.exec(t);
|
|
477
|
+
if (e) {
|
|
478
|
+
const n = e[1].charAt(e[1].length - 1) === `
|
|
479
|
+
` ? e[1].slice(0, -1) : e[1];
|
|
480
|
+
return {
|
|
481
|
+
type: "paragraph",
|
|
482
|
+
raw: e[0],
|
|
483
|
+
text: n,
|
|
484
|
+
tokens: this.lexer.inline(n)
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
text(t) {
|
|
489
|
+
const e = this.rules.block.text.exec(t);
|
|
490
|
+
if (e)
|
|
491
|
+
return {
|
|
492
|
+
type: "text",
|
|
493
|
+
raw: e[0],
|
|
494
|
+
text: e[0],
|
|
495
|
+
tokens: this.lexer.inline(e[0])
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
escape(t) {
|
|
499
|
+
const e = this.rules.inline.escape.exec(t);
|
|
500
|
+
if (e)
|
|
501
|
+
return {
|
|
502
|
+
type: "escape",
|
|
503
|
+
raw: e[0],
|
|
504
|
+
text: b(e[1])
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
tag(t) {
|
|
508
|
+
const e = this.rules.inline.tag.exec(t);
|
|
509
|
+
if (e)
|
|
510
|
+
return !this.lexer.state.inLink && /^<a /i.test(e[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && /^<\/a>/i.test(e[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(e[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(e[0]) && (this.lexer.state.inRawBlock = !1), {
|
|
511
|
+
type: "html",
|
|
512
|
+
raw: e[0],
|
|
513
|
+
inLink: this.lexer.state.inLink,
|
|
514
|
+
inRawBlock: this.lexer.state.inRawBlock,
|
|
515
|
+
block: !1,
|
|
516
|
+
text: e[0]
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
link(t) {
|
|
520
|
+
const e = this.rules.inline.link.exec(t);
|
|
521
|
+
if (e) {
|
|
522
|
+
const n = e[2].trim();
|
|
523
|
+
if (!this.options.pedantic && /^</.test(n)) {
|
|
524
|
+
if (!/>$/.test(n))
|
|
525
|
+
return;
|
|
526
|
+
const s = L(n.slice(0, -1), "\\");
|
|
527
|
+
if ((n.length - s.length) % 2 === 0)
|
|
528
|
+
return;
|
|
529
|
+
} else {
|
|
530
|
+
const s = Be(e[2], "()");
|
|
531
|
+
if (s > -1) {
|
|
532
|
+
const o = (e[0].indexOf("!") === 0 ? 5 : 4) + e[1].length + s;
|
|
533
|
+
e[2] = e[2].substring(0, s), e[0] = e[0].substring(0, o).trim(), e[3] = "";
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
let i = e[2], r = "";
|
|
537
|
+
if (this.options.pedantic) {
|
|
538
|
+
const s = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);
|
|
539
|
+
s && (i = s[1], r = s[3]);
|
|
540
|
+
} else
|
|
541
|
+
r = e[3] ? e[3].slice(1, -1) : "";
|
|
542
|
+
return i = i.trim(), /^</.test(i) && (this.options.pedantic && !/>$/.test(n) ? i = i.slice(1) : i = i.slice(1, -1)), ae(e, {
|
|
543
|
+
href: i && i.replace(this.rules.inline.anyPunctuation, "$1"),
|
|
544
|
+
title: r && r.replace(this.rules.inline.anyPunctuation, "$1")
|
|
545
|
+
}, e[0], this.lexer);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
reflink(t, e) {
|
|
549
|
+
let n;
|
|
550
|
+
if ((n = this.rules.inline.reflink.exec(t)) || (n = this.rules.inline.nolink.exec(t))) {
|
|
551
|
+
const i = (n[2] || n[1]).replace(/\s+/g, " "), r = e[i.toLowerCase()];
|
|
552
|
+
if (!r) {
|
|
553
|
+
const s = n[0].charAt(0);
|
|
554
|
+
return {
|
|
555
|
+
type: "text",
|
|
556
|
+
raw: s,
|
|
557
|
+
text: s
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
return ae(n, r, n[0], this.lexer);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
emStrong(t, e, n = "") {
|
|
564
|
+
let i = this.rules.inline.emStrongLDelim.exec(t);
|
|
565
|
+
if (!i || i[3] && n.match(/[\p{L}\p{N}]/u))
|
|
566
|
+
return;
|
|
567
|
+
if (!(i[1] || i[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
568
|
+
const s = [...i[0]].length - 1;
|
|
569
|
+
let l, o, p = s, c = 0;
|
|
570
|
+
const u = i[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
571
|
+
for (u.lastIndex = 0, e = e.slice(-1 * t.length + s); (i = u.exec(e)) != null; ) {
|
|
572
|
+
if (l = i[1] || i[2] || i[3] || i[4] || i[5] || i[6], !l)
|
|
573
|
+
continue;
|
|
574
|
+
if (o = [...l].length, i[3] || i[4]) {
|
|
575
|
+
p += o;
|
|
576
|
+
continue;
|
|
577
|
+
} else if ((i[5] || i[6]) && s % 3 && !((s + o) % 3)) {
|
|
578
|
+
c += o;
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if (p -= o, p > 0)
|
|
582
|
+
continue;
|
|
583
|
+
o = Math.min(o, o + p + c);
|
|
584
|
+
const h = [...i[0]][0].length, f = t.slice(0, s + i.index + h + o);
|
|
585
|
+
if (Math.min(s, o) % 2) {
|
|
586
|
+
const y = f.slice(1, -1);
|
|
587
|
+
return {
|
|
588
|
+
type: "em",
|
|
589
|
+
raw: f,
|
|
590
|
+
text: y,
|
|
591
|
+
tokens: this.lexer.inlineTokens(y)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
const w = f.slice(2, -2);
|
|
595
|
+
return {
|
|
596
|
+
type: "strong",
|
|
597
|
+
raw: f,
|
|
598
|
+
text: w,
|
|
599
|
+
tokens: this.lexer.inlineTokens(w)
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
codespan(t) {
|
|
605
|
+
const e = this.rules.inline.code.exec(t);
|
|
606
|
+
if (e) {
|
|
607
|
+
let n = e[2].replace(/\n/g, " ");
|
|
608
|
+
const i = /[^ ]/.test(n), r = /^ /.test(n) && / $/.test(n);
|
|
609
|
+
return i && r && (n = n.substring(1, n.length - 1)), n = b(n, !0), {
|
|
610
|
+
type: "codespan",
|
|
611
|
+
raw: e[0],
|
|
612
|
+
text: n
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
br(t) {
|
|
617
|
+
const e = this.rules.inline.br.exec(t);
|
|
618
|
+
if (e)
|
|
619
|
+
return {
|
|
620
|
+
type: "br",
|
|
621
|
+
raw: e[0]
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
del(t) {
|
|
625
|
+
const e = this.rules.inline.del.exec(t);
|
|
626
|
+
if (e)
|
|
627
|
+
return {
|
|
628
|
+
type: "del",
|
|
629
|
+
raw: e[0],
|
|
630
|
+
text: e[2],
|
|
631
|
+
tokens: this.lexer.inlineTokens(e[2])
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
autolink(t) {
|
|
635
|
+
const e = this.rules.inline.autolink.exec(t);
|
|
636
|
+
if (e) {
|
|
637
|
+
let n, i;
|
|
638
|
+
return e[2] === "@" ? (n = b(e[1]), i = "mailto:" + n) : (n = b(e[1]), i = n), {
|
|
639
|
+
type: "link",
|
|
640
|
+
raw: e[0],
|
|
641
|
+
text: n,
|
|
642
|
+
href: i,
|
|
643
|
+
tokens: [
|
|
644
|
+
{
|
|
645
|
+
type: "text",
|
|
646
|
+
raw: n,
|
|
647
|
+
text: n
|
|
648
|
+
}
|
|
649
|
+
]
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
url(t) {
|
|
654
|
+
var n;
|
|
655
|
+
let e;
|
|
656
|
+
if (e = this.rules.inline.url.exec(t)) {
|
|
657
|
+
let i, r;
|
|
658
|
+
if (e[2] === "@")
|
|
659
|
+
i = b(e[0]), r = "mailto:" + i;
|
|
660
|
+
else {
|
|
661
|
+
let s;
|
|
662
|
+
do
|
|
663
|
+
s = e[0], e[0] = ((n = this.rules.inline._backpedal.exec(e[0])) == null ? void 0 : n[0]) ?? "";
|
|
664
|
+
while (s !== e[0]);
|
|
665
|
+
i = b(e[0]), e[1] === "www." ? r = "http://" + e[0] : r = e[0];
|
|
666
|
+
}
|
|
667
|
+
return {
|
|
668
|
+
type: "link",
|
|
669
|
+
raw: e[0],
|
|
670
|
+
text: i,
|
|
671
|
+
href: r,
|
|
672
|
+
tokens: [
|
|
673
|
+
{
|
|
674
|
+
type: "text",
|
|
675
|
+
raw: i,
|
|
676
|
+
text: i
|
|
677
|
+
}
|
|
678
|
+
]
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
inlineText(t) {
|
|
683
|
+
const e = this.rules.inline.text.exec(t);
|
|
684
|
+
if (e) {
|
|
685
|
+
let n;
|
|
686
|
+
return this.lexer.state.inRawBlock ? n = e[0] : n = b(e[0]), {
|
|
687
|
+
type: "text",
|
|
688
|
+
raw: e[0],
|
|
689
|
+
text: n
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
const Ne = /^(?: *(?:\n|$))+/, Fe = /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/, Qe = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, E = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, He = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, ge = /(?:[*+-]|\d{1,9}[.)])/, de = d(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g, ge).replace(/blockCode/g, / {4}/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).getRegex(), W = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, Je = /^[^\n]+/, G = /(?!\s*\])(?:\\.|[^\[\]\\])+/, We = d(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label", G).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), Ge = d(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, ge).getRegex(), M = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", U = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, Ue = d("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))", "i").replace("comment", U).replace("tag", M).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), ke = d(W).replace("hr", E).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", M).getRegex(), Xe = d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ke).getRegex(), X = {
|
|
695
|
+
blockquote: Xe,
|
|
696
|
+
code: Fe,
|
|
697
|
+
def: We,
|
|
698
|
+
fences: Qe,
|
|
699
|
+
heading: He,
|
|
700
|
+
hr: E,
|
|
701
|
+
html: Ue,
|
|
702
|
+
lheading: de,
|
|
703
|
+
list: Ge,
|
|
704
|
+
newline: Ne,
|
|
705
|
+
paragraph: ke,
|
|
706
|
+
table: C,
|
|
707
|
+
text: Je
|
|
708
|
+
}, ce = d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", E).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", " {4}[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", M).getRegex(), Ke = {
|
|
709
|
+
...X,
|
|
710
|
+
table: ce,
|
|
711
|
+
paragraph: d(W).replace("hr", E).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", ce).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", M).getRegex()
|
|
712
|
+
}, Ve = {
|
|
713
|
+
...X,
|
|
714
|
+
html: d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", U).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
|
|
715
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
716
|
+
heading: /^(#{1,6})(.*)(?:\n+|$)/,
|
|
717
|
+
fences: C,
|
|
718
|
+
// fences not supported
|
|
719
|
+
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
720
|
+
paragraph: d(W).replace("hr", E).replace("heading", ` *#{1,6} *[^
|
|
721
|
+
]`).replace("lheading", de).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
|
|
722
|
+
}, xe = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, Ye = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, me = /^( {2,}|\\)\n(?!\s*$)/, et = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, P = "\\p{P}\\p{S}", tt = d(/^((?![*_])[\spunctuation])/, "u").replace(/punctuation/g, P).getRegex(), nt = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g, st = d(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/, "u").replace(/punct/g, P).getRegex(), it = d("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])", "gu").replace(/punct/g, P).getRegex(), rt = d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])", "gu").replace(/punct/g, P).getRegex(), ot = d(/\\([punct])/, "gu").replace(/punct/g, P).getRegex(), lt = d(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(), at = d(U).replace("(?:-->|$)", "-->").getRegex(), ct = d("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", at).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), q = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/, ht = d(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), we = d(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", G).getRegex(), be = d(/^!?\[(ref)\](?:\[\])?/).replace("ref", G).getRegex(), pt = d("reflink|nolink(?!\\()", "g").replace("reflink", we).replace("nolink", be).getRegex(), K = {
|
|
723
|
+
_backpedal: C,
|
|
724
|
+
// only used for GFM url
|
|
725
|
+
anyPunctuation: ot,
|
|
726
|
+
autolink: lt,
|
|
727
|
+
blockSkip: nt,
|
|
728
|
+
br: me,
|
|
729
|
+
code: Ye,
|
|
730
|
+
del: C,
|
|
731
|
+
emStrongLDelim: st,
|
|
732
|
+
emStrongRDelimAst: it,
|
|
733
|
+
emStrongRDelimUnd: rt,
|
|
734
|
+
escape: xe,
|
|
735
|
+
link: ht,
|
|
736
|
+
nolink: be,
|
|
737
|
+
punctuation: tt,
|
|
738
|
+
reflink: we,
|
|
739
|
+
reflinkSearch: pt,
|
|
740
|
+
tag: ct,
|
|
741
|
+
text: et,
|
|
742
|
+
url: C
|
|
743
|
+
}, ut = {
|
|
744
|
+
...K,
|
|
745
|
+
link: d(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(),
|
|
746
|
+
reflink: d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex()
|
|
747
|
+
}, Q = {
|
|
748
|
+
...K,
|
|
749
|
+
escape: d(xe).replace("])", "~|])").getRegex(),
|
|
750
|
+
url: d(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i").replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
|
|
751
|
+
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
752
|
+
del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
|
|
753
|
+
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
|
|
754
|
+
}, ft = {
|
|
755
|
+
...Q,
|
|
756
|
+
br: d(me).replace("{2,}", "*").getRegex(),
|
|
757
|
+
text: d(Q.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
|
|
758
|
+
}, D = {
|
|
759
|
+
normal: X,
|
|
760
|
+
gfm: Ke,
|
|
761
|
+
pedantic: Ve
|
|
762
|
+
}, A = {
|
|
763
|
+
normal: K,
|
|
764
|
+
gfm: Q,
|
|
765
|
+
breaks: ft,
|
|
766
|
+
pedantic: ut
|
|
767
|
+
};
|
|
768
|
+
class T {
|
|
769
|
+
constructor(t) {
|
|
770
|
+
k(this, "tokens");
|
|
771
|
+
k(this, "options");
|
|
772
|
+
k(this, "state");
|
|
773
|
+
k(this, "tokenizer");
|
|
774
|
+
k(this, "inlineQueue");
|
|
775
|
+
this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = t || I, this.options.tokenizer = this.options.tokenizer || new Z(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
|
|
776
|
+
inLink: !1,
|
|
777
|
+
inRawBlock: !1,
|
|
778
|
+
top: !0
|
|
779
|
+
};
|
|
780
|
+
const e = {
|
|
781
|
+
block: D.normal,
|
|
782
|
+
inline: A.normal
|
|
783
|
+
};
|
|
784
|
+
this.options.pedantic ? (e.block = D.pedantic, e.inline = A.pedantic) : this.options.gfm && (e.block = D.gfm, this.options.breaks ? e.inline = A.breaks : e.inline = A.gfm), this.tokenizer.rules = e;
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Expose Rules
|
|
788
|
+
*/
|
|
789
|
+
static get rules() {
|
|
790
|
+
return {
|
|
791
|
+
block: D,
|
|
792
|
+
inline: A
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Static Lex Method
|
|
797
|
+
*/
|
|
798
|
+
static lex(t, e) {
|
|
799
|
+
return new T(e).lex(t);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Static Lex Inline Method
|
|
803
|
+
*/
|
|
804
|
+
static lexInline(t, e) {
|
|
805
|
+
return new T(e).inlineTokens(t);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Preprocessing
|
|
809
|
+
*/
|
|
810
|
+
lex(t) {
|
|
811
|
+
t = t.replace(/\r\n|\r/g, `
|
|
812
|
+
`), this.blockTokens(t, this.tokens);
|
|
813
|
+
for (let e = 0; e < this.inlineQueue.length; e++) {
|
|
814
|
+
const n = this.inlineQueue[e];
|
|
815
|
+
this.inlineTokens(n.src, n.tokens);
|
|
816
|
+
}
|
|
817
|
+
return this.inlineQueue = [], this.tokens;
|
|
818
|
+
}
|
|
819
|
+
blockTokens(t, e = []) {
|
|
820
|
+
this.options.pedantic ? t = t.replace(/\t/g, " ").replace(/^ +$/gm, "") : t = t.replace(/^( *)(\t+)/gm, (l, o, p) => o + " ".repeat(p.length));
|
|
821
|
+
let n, i, r, s;
|
|
822
|
+
for (; t; )
|
|
823
|
+
if (!(this.options.extensions && this.options.extensions.block && this.options.extensions.block.some((l) => (n = l.call({ lexer: this }, t, e)) ? (t = t.substring(n.raw.length), e.push(n), !0) : !1))) {
|
|
824
|
+
if (n = this.tokenizer.space(t)) {
|
|
825
|
+
t = t.substring(n.raw.length), n.raw.length === 1 && e.length > 0 ? e[e.length - 1].raw += `
|
|
826
|
+
` : e.push(n);
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
if (n = this.tokenizer.code(t)) {
|
|
830
|
+
t = t.substring(n.raw.length), i = e[e.length - 1], i && (i.type === "paragraph" || i.type === "text") ? (i.raw += `
|
|
831
|
+
` + n.raw, i.text += `
|
|
832
|
+
` + n.text, this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : e.push(n);
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (n = this.tokenizer.fences(t)) {
|
|
836
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
if (n = this.tokenizer.heading(t)) {
|
|
840
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
if (n = this.tokenizer.hr(t)) {
|
|
844
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
if (n = this.tokenizer.blockquote(t)) {
|
|
848
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
if (n = this.tokenizer.list(t)) {
|
|
852
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (n = this.tokenizer.html(t)) {
|
|
856
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
if (n = this.tokenizer.def(t)) {
|
|
860
|
+
t = t.substring(n.raw.length), i = e[e.length - 1], i && (i.type === "paragraph" || i.type === "text") ? (i.raw += `
|
|
861
|
+
` + n.raw, i.text += `
|
|
862
|
+
` + n.raw, this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : this.tokens.links[n.tag] || (this.tokens.links[n.tag] = {
|
|
863
|
+
href: n.href,
|
|
864
|
+
title: n.title
|
|
865
|
+
});
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
if (n = this.tokenizer.table(t)) {
|
|
869
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (n = this.tokenizer.lheading(t)) {
|
|
873
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (r = t, this.options.extensions && this.options.extensions.startBlock) {
|
|
877
|
+
let l = 1 / 0;
|
|
878
|
+
const o = t.slice(1);
|
|
879
|
+
let p;
|
|
880
|
+
this.options.extensions.startBlock.forEach((c) => {
|
|
881
|
+
p = c.call({ lexer: this }, o), typeof p == "number" && p >= 0 && (l = Math.min(l, p));
|
|
882
|
+
}), l < 1 / 0 && l >= 0 && (r = t.substring(0, l + 1));
|
|
883
|
+
}
|
|
884
|
+
if (this.state.top && (n = this.tokenizer.paragraph(r))) {
|
|
885
|
+
i = e[e.length - 1], s && i.type === "paragraph" ? (i.raw += `
|
|
886
|
+
` + n.raw, i.text += `
|
|
887
|
+
` + n.text, this.inlineQueue.pop(), this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : e.push(n), s = r.length !== t.length, t = t.substring(n.raw.length);
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (n = this.tokenizer.text(t)) {
|
|
891
|
+
t = t.substring(n.raw.length), i = e[e.length - 1], i && i.type === "text" ? (i.raw += `
|
|
892
|
+
` + n.raw, i.text += `
|
|
893
|
+
` + n.text, this.inlineQueue.pop(), this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : e.push(n);
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
if (t) {
|
|
897
|
+
const l = "Infinite loop on byte: " + t.charCodeAt(0);
|
|
898
|
+
if (this.options.silent) {
|
|
899
|
+
console.error(l);
|
|
900
|
+
break;
|
|
901
|
+
} else
|
|
902
|
+
throw new Error(l);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return this.state.top = !0, e;
|
|
906
|
+
}
|
|
907
|
+
inline(t, e = []) {
|
|
908
|
+
return this.inlineQueue.push({ src: t, tokens: e }), e;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Lexing/Compiling
|
|
912
|
+
*/
|
|
913
|
+
inlineTokens(t, e = []) {
|
|
914
|
+
let n, i, r, s = t, l, o, p;
|
|
915
|
+
if (this.tokens.links) {
|
|
916
|
+
const c = Object.keys(this.tokens.links);
|
|
917
|
+
if (c.length > 0)
|
|
918
|
+
for (; (l = this.tokenizer.rules.inline.reflinkSearch.exec(s)) != null; )
|
|
919
|
+
c.includes(l[0].slice(l[0].lastIndexOf("[") + 1, -1)) && (s = s.slice(0, l.index) + "[" + "a".repeat(l[0].length - 2) + "]" + s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
|
|
920
|
+
}
|
|
921
|
+
for (; (l = this.tokenizer.rules.inline.blockSkip.exec(s)) != null; )
|
|
922
|
+
s = s.slice(0, l.index) + "[" + "a".repeat(l[0].length - 2) + "]" + s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
923
|
+
for (; (l = this.tokenizer.rules.inline.anyPunctuation.exec(s)) != null; )
|
|
924
|
+
s = s.slice(0, l.index) + "++" + s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
925
|
+
for (; t; )
|
|
926
|
+
if (o || (p = ""), o = !1, !(this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some((c) => (n = c.call({ lexer: this }, t, e)) ? (t = t.substring(n.raw.length), e.push(n), !0) : !1))) {
|
|
927
|
+
if (n = this.tokenizer.escape(t)) {
|
|
928
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
if (n = this.tokenizer.tag(t)) {
|
|
932
|
+
t = t.substring(n.raw.length), i = e[e.length - 1], i && n.type === "text" && i.type === "text" ? (i.raw += n.raw, i.text += n.text) : e.push(n);
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (n = this.tokenizer.link(t)) {
|
|
936
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
937
|
+
continue;
|
|
938
|
+
}
|
|
939
|
+
if (n = this.tokenizer.reflink(t, this.tokens.links)) {
|
|
940
|
+
t = t.substring(n.raw.length), i = e[e.length - 1], i && n.type === "text" && i.type === "text" ? (i.raw += n.raw, i.text += n.text) : e.push(n);
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
if (n = this.tokenizer.emStrong(t, s, p)) {
|
|
944
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
if (n = this.tokenizer.codespan(t)) {
|
|
948
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
if (n = this.tokenizer.br(t)) {
|
|
952
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
if (n = this.tokenizer.del(t)) {
|
|
956
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (n = this.tokenizer.autolink(t)) {
|
|
960
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
if (!this.state.inLink && (n = this.tokenizer.url(t))) {
|
|
964
|
+
t = t.substring(n.raw.length), e.push(n);
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
if (r = t, this.options.extensions && this.options.extensions.startInline) {
|
|
968
|
+
let c = 1 / 0;
|
|
969
|
+
const u = t.slice(1);
|
|
970
|
+
let h;
|
|
971
|
+
this.options.extensions.startInline.forEach((f) => {
|
|
972
|
+
h = f.call({ lexer: this }, u), typeof h == "number" && h >= 0 && (c = Math.min(c, h));
|
|
973
|
+
}), c < 1 / 0 && c >= 0 && (r = t.substring(0, c + 1));
|
|
974
|
+
}
|
|
975
|
+
if (n = this.tokenizer.inlineText(r)) {
|
|
976
|
+
t = t.substring(n.raw.length), n.raw.slice(-1) !== "_" && (p = n.raw.slice(-1)), o = !0, i = e[e.length - 1], i && i.type === "text" ? (i.raw += n.raw, i.text += n.text) : e.push(n);
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
if (t) {
|
|
980
|
+
const c = "Infinite loop on byte: " + t.charCodeAt(0);
|
|
981
|
+
if (this.options.silent) {
|
|
982
|
+
console.error(c);
|
|
983
|
+
break;
|
|
984
|
+
} else
|
|
985
|
+
throw new Error(c);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return e;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
class B {
|
|
992
|
+
constructor(t) {
|
|
993
|
+
k(this, "options");
|
|
994
|
+
this.options = t || I;
|
|
995
|
+
}
|
|
996
|
+
code(t, e, n) {
|
|
997
|
+
var r;
|
|
998
|
+
const i = (r = (e || "").match(/^\S*/)) == null ? void 0 : r[0];
|
|
999
|
+
return t = t.replace(/\n$/, "") + `
|
|
1000
|
+
`, i ? '<pre><code class="language-' + b(i) + '">' + (n ? t : b(t, !0)) + `</code></pre>
|
|
1001
|
+
` : "<pre><code>" + (n ? t : b(t, !0)) + `</code></pre>
|
|
1002
|
+
`;
|
|
1003
|
+
}
|
|
1004
|
+
blockquote(t) {
|
|
1005
|
+
return `<blockquote>
|
|
1006
|
+
${t}</blockquote>
|
|
1007
|
+
`;
|
|
1008
|
+
}
|
|
1009
|
+
html(t, e) {
|
|
1010
|
+
return t;
|
|
1011
|
+
}
|
|
1012
|
+
heading(t, e, n) {
|
|
1013
|
+
return `<h${e}>${t}</h${e}>
|
|
1014
|
+
`;
|
|
1015
|
+
}
|
|
1016
|
+
hr() {
|
|
1017
|
+
return `<hr>
|
|
1018
|
+
`;
|
|
1019
|
+
}
|
|
1020
|
+
list(t, e, n) {
|
|
1021
|
+
const i = e ? "ol" : "ul", r = e && n !== 1 ? ' start="' + n + '"' : "";
|
|
1022
|
+
return "<" + i + r + `>
|
|
1023
|
+
` + t + "</" + i + `>
|
|
1024
|
+
`;
|
|
1025
|
+
}
|
|
1026
|
+
listitem(t, e, n) {
|
|
1027
|
+
return `<li>${t}</li>
|
|
1028
|
+
`;
|
|
1029
|
+
}
|
|
1030
|
+
checkbox(t) {
|
|
1031
|
+
return "<input " + (t ? 'checked="" ' : "") + 'disabled="" type="checkbox">';
|
|
1032
|
+
}
|
|
1033
|
+
paragraph(t) {
|
|
1034
|
+
return `<p>${t}</p>
|
|
1035
|
+
`;
|
|
1036
|
+
}
|
|
1037
|
+
table(t, e) {
|
|
1038
|
+
return e && (e = `<tbody>${e}</tbody>`), `<table>
|
|
1039
|
+
<thead>
|
|
1040
|
+
` + t + `</thead>
|
|
1041
|
+
` + e + `</table>
|
|
1042
|
+
`;
|
|
1043
|
+
}
|
|
1044
|
+
tablerow(t) {
|
|
1045
|
+
return `<tr>
|
|
1046
|
+
${t}</tr>
|
|
1047
|
+
`;
|
|
1048
|
+
}
|
|
1049
|
+
tablecell(t, e) {
|
|
1050
|
+
const n = e.header ? "th" : "td";
|
|
1051
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
1052
|
+
`;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* span level renderer
|
|
1056
|
+
*/
|
|
1057
|
+
strong(t) {
|
|
1058
|
+
return `<strong>${t}</strong>`;
|
|
1059
|
+
}
|
|
1060
|
+
em(t) {
|
|
1061
|
+
return `<em>${t}</em>`;
|
|
1062
|
+
}
|
|
1063
|
+
codespan(t) {
|
|
1064
|
+
return `<code>${t}</code>`;
|
|
1065
|
+
}
|
|
1066
|
+
br() {
|
|
1067
|
+
return "<br>";
|
|
1068
|
+
}
|
|
1069
|
+
del(t) {
|
|
1070
|
+
return `<del>${t}</del>`;
|
|
1071
|
+
}
|
|
1072
|
+
link(t, e, n) {
|
|
1073
|
+
const i = oe(t);
|
|
1074
|
+
if (i === null)
|
|
1075
|
+
return n;
|
|
1076
|
+
t = i;
|
|
1077
|
+
let r = '<a href="' + t + '"';
|
|
1078
|
+
return e && (r += ' title="' + e + '"'), r += ">" + n + "</a>", r;
|
|
1079
|
+
}
|
|
1080
|
+
image(t, e, n) {
|
|
1081
|
+
const i = oe(t);
|
|
1082
|
+
if (i === null)
|
|
1083
|
+
return n;
|
|
1084
|
+
t = i;
|
|
1085
|
+
let r = `<img src="${t}" alt="${n}"`;
|
|
1086
|
+
return e && (r += ` title="${e}"`), r += ">", r;
|
|
1087
|
+
}
|
|
1088
|
+
text(t) {
|
|
1089
|
+
return t;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
class V {
|
|
1093
|
+
// no need for block level renderers
|
|
1094
|
+
strong(t) {
|
|
1095
|
+
return t;
|
|
1096
|
+
}
|
|
1097
|
+
em(t) {
|
|
1098
|
+
return t;
|
|
1099
|
+
}
|
|
1100
|
+
codespan(t) {
|
|
1101
|
+
return t;
|
|
1102
|
+
}
|
|
1103
|
+
del(t) {
|
|
1104
|
+
return t;
|
|
1105
|
+
}
|
|
1106
|
+
html(t) {
|
|
1107
|
+
return t;
|
|
1108
|
+
}
|
|
1109
|
+
text(t) {
|
|
1110
|
+
return t;
|
|
1111
|
+
}
|
|
1112
|
+
link(t, e, n) {
|
|
1113
|
+
return "" + n;
|
|
1114
|
+
}
|
|
1115
|
+
image(t, e, n) {
|
|
1116
|
+
return "" + n;
|
|
1117
|
+
}
|
|
1118
|
+
br() {
|
|
1119
|
+
return "";
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
class z {
|
|
1123
|
+
constructor(t) {
|
|
1124
|
+
k(this, "options");
|
|
1125
|
+
k(this, "renderer");
|
|
1126
|
+
k(this, "textRenderer");
|
|
1127
|
+
this.options = t || I, this.options.renderer = this.options.renderer || new B(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.textRenderer = new V();
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Static Parse Method
|
|
1131
|
+
*/
|
|
1132
|
+
static parse(t, e) {
|
|
1133
|
+
return new z(e).parse(t);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Static Parse Inline Method
|
|
1137
|
+
*/
|
|
1138
|
+
static parseInline(t, e) {
|
|
1139
|
+
return new z(e).parseInline(t);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Parse Loop
|
|
1143
|
+
*/
|
|
1144
|
+
parse(t, e = !0) {
|
|
1145
|
+
let n = "";
|
|
1146
|
+
for (let i = 0; i < t.length; i++) {
|
|
1147
|
+
const r = t[i];
|
|
1148
|
+
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[r.type]) {
|
|
1149
|
+
const s = r, l = this.options.extensions.renderers[s.type].call({ parser: this }, s);
|
|
1150
|
+
if (l !== !1 || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(s.type)) {
|
|
1151
|
+
n += l || "";
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
switch (r.type) {
|
|
1156
|
+
case "space":
|
|
1157
|
+
continue;
|
|
1158
|
+
case "hr": {
|
|
1159
|
+
n += this.renderer.hr();
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
case "heading": {
|
|
1163
|
+
const s = r;
|
|
1164
|
+
n += this.renderer.heading(this.parseInline(s.tokens), s.depth, Ze(this.parseInline(s.tokens, this.textRenderer)));
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
case "code": {
|
|
1168
|
+
const s = r;
|
|
1169
|
+
n += this.renderer.code(s.text, s.lang, !!s.escaped);
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
case "table": {
|
|
1173
|
+
const s = r;
|
|
1174
|
+
let l = "", o = "";
|
|
1175
|
+
for (let c = 0; c < s.header.length; c++)
|
|
1176
|
+
o += this.renderer.tablecell(this.parseInline(s.header[c].tokens), { header: !0, align: s.align[c] });
|
|
1177
|
+
l += this.renderer.tablerow(o);
|
|
1178
|
+
let p = "";
|
|
1179
|
+
for (let c = 0; c < s.rows.length; c++) {
|
|
1180
|
+
const u = s.rows[c];
|
|
1181
|
+
o = "";
|
|
1182
|
+
for (let h = 0; h < u.length; h++)
|
|
1183
|
+
o += this.renderer.tablecell(this.parseInline(u[h].tokens), { header: !1, align: s.align[h] });
|
|
1184
|
+
p += this.renderer.tablerow(o);
|
|
1185
|
+
}
|
|
1186
|
+
n += this.renderer.table(l, p);
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
case "blockquote": {
|
|
1190
|
+
const s = r, l = this.parse(s.tokens);
|
|
1191
|
+
n += this.renderer.blockquote(l);
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
case "list": {
|
|
1195
|
+
const s = r, l = s.ordered, o = s.start, p = s.loose;
|
|
1196
|
+
let c = "";
|
|
1197
|
+
for (let u = 0; u < s.items.length; u++) {
|
|
1198
|
+
const h = s.items[u], f = h.checked, w = h.task;
|
|
1199
|
+
let y = "";
|
|
1200
|
+
if (h.task) {
|
|
1201
|
+
const R = this.renderer.checkbox(!!f);
|
|
1202
|
+
p ? h.tokens.length > 0 && h.tokens[0].type === "paragraph" ? (h.tokens[0].text = R + " " + h.tokens[0].text, h.tokens[0].tokens && h.tokens[0].tokens.length > 0 && h.tokens[0].tokens[0].type === "text" && (h.tokens[0].tokens[0].text = R + " " + h.tokens[0].tokens[0].text)) : h.tokens.unshift({
|
|
1203
|
+
type: "text",
|
|
1204
|
+
text: R + " "
|
|
1205
|
+
}) : y += R + " ";
|
|
1206
|
+
}
|
|
1207
|
+
y += this.parse(h.tokens, p), c += this.renderer.listitem(y, w, !!f);
|
|
1208
|
+
}
|
|
1209
|
+
n += this.renderer.list(c, l, o);
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
case "html": {
|
|
1213
|
+
const s = r;
|
|
1214
|
+
n += this.renderer.html(s.text, s.block);
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
case "paragraph": {
|
|
1218
|
+
const s = r;
|
|
1219
|
+
n += this.renderer.paragraph(this.parseInline(s.tokens));
|
|
1220
|
+
continue;
|
|
1221
|
+
}
|
|
1222
|
+
case "text": {
|
|
1223
|
+
let s = r, l = s.tokens ? this.parseInline(s.tokens) : s.text;
|
|
1224
|
+
for (; i + 1 < t.length && t[i + 1].type === "text"; )
|
|
1225
|
+
s = t[++i], l += `
|
|
1226
|
+
` + (s.tokens ? this.parseInline(s.tokens) : s.text);
|
|
1227
|
+
n += e ? this.renderer.paragraph(l) : l;
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
default: {
|
|
1231
|
+
const s = 'Token with "' + r.type + '" type was not found.';
|
|
1232
|
+
if (this.options.silent)
|
|
1233
|
+
return console.error(s), "";
|
|
1234
|
+
throw new Error(s);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
return n;
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Parse Inline Tokens
|
|
1242
|
+
*/
|
|
1243
|
+
parseInline(t, e) {
|
|
1244
|
+
e = e || this.renderer;
|
|
1245
|
+
let n = "";
|
|
1246
|
+
for (let i = 0; i < t.length; i++) {
|
|
1247
|
+
const r = t[i];
|
|
1248
|
+
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[r.type]) {
|
|
1249
|
+
const s = this.options.extensions.renderers[r.type].call({ parser: this }, r);
|
|
1250
|
+
if (s !== !1 || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(r.type)) {
|
|
1251
|
+
n += s || "";
|
|
1252
|
+
continue;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
switch (r.type) {
|
|
1256
|
+
case "escape": {
|
|
1257
|
+
const s = r;
|
|
1258
|
+
n += e.text(s.text);
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1261
|
+
case "html": {
|
|
1262
|
+
const s = r;
|
|
1263
|
+
n += e.html(s.text);
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
case "link": {
|
|
1267
|
+
const s = r;
|
|
1268
|
+
n += e.link(s.href, s.title, this.parseInline(s.tokens, e));
|
|
1269
|
+
break;
|
|
1270
|
+
}
|
|
1271
|
+
case "image": {
|
|
1272
|
+
const s = r;
|
|
1273
|
+
n += e.image(s.href, s.title, s.text);
|
|
1274
|
+
break;
|
|
1275
|
+
}
|
|
1276
|
+
case "strong": {
|
|
1277
|
+
const s = r;
|
|
1278
|
+
n += e.strong(this.parseInline(s.tokens, e));
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
case "em": {
|
|
1282
|
+
const s = r;
|
|
1283
|
+
n += e.em(this.parseInline(s.tokens, e));
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
case "codespan": {
|
|
1287
|
+
const s = r;
|
|
1288
|
+
n += e.codespan(s.text);
|
|
1289
|
+
break;
|
|
1290
|
+
}
|
|
1291
|
+
case "br": {
|
|
1292
|
+
n += e.br();
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
case "del": {
|
|
1296
|
+
const s = r;
|
|
1297
|
+
n += e.del(this.parseInline(s.tokens, e));
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
case "text": {
|
|
1301
|
+
const s = r;
|
|
1302
|
+
n += e.text(s.text);
|
|
1303
|
+
break;
|
|
1304
|
+
}
|
|
1305
|
+
default: {
|
|
1306
|
+
const s = 'Token with "' + r.type + '" type was not found.';
|
|
1307
|
+
if (this.options.silent)
|
|
1308
|
+
return console.error(s), "";
|
|
1309
|
+
throw new Error(s);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
return n;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
class j {
|
|
1317
|
+
constructor(t) {
|
|
1318
|
+
k(this, "options");
|
|
1319
|
+
this.options = t || I;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Process markdown before marked
|
|
1323
|
+
*/
|
|
1324
|
+
preprocess(t) {
|
|
1325
|
+
return t;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Process HTML after marked is finished
|
|
1329
|
+
*/
|
|
1330
|
+
postprocess(t) {
|
|
1331
|
+
return t;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Process all tokens before walk tokens
|
|
1335
|
+
*/
|
|
1336
|
+
processAllTokens(t) {
|
|
1337
|
+
return t;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
k(j, "passThroughHooks", /* @__PURE__ */ new Set([
|
|
1341
|
+
"preprocess",
|
|
1342
|
+
"postprocess",
|
|
1343
|
+
"processAllTokens"
|
|
1344
|
+
]));
|
|
1345
|
+
var _, H, ye;
|
|
1346
|
+
class gt {
|
|
1347
|
+
constructor(...t) {
|
|
1348
|
+
se(this, _);
|
|
1349
|
+
k(this, "defaults", J());
|
|
1350
|
+
k(this, "options", this.setOptions);
|
|
1351
|
+
k(this, "parse", v(this, _, H).call(this, T.lex, z.parse));
|
|
1352
|
+
k(this, "parseInline", v(this, _, H).call(this, T.lexInline, z.parseInline));
|
|
1353
|
+
k(this, "Parser", z);
|
|
1354
|
+
k(this, "Renderer", B);
|
|
1355
|
+
k(this, "TextRenderer", V);
|
|
1356
|
+
k(this, "Lexer", T);
|
|
1357
|
+
k(this, "Tokenizer", Z);
|
|
1358
|
+
k(this, "Hooks", j);
|
|
1359
|
+
this.use(...t);
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Run callback for every token
|
|
1363
|
+
*/
|
|
1364
|
+
walkTokens(t, e) {
|
|
1365
|
+
var i, r;
|
|
1366
|
+
let n = [];
|
|
1367
|
+
for (const s of t)
|
|
1368
|
+
switch (n = n.concat(e.call(this, s)), s.type) {
|
|
1369
|
+
case "table": {
|
|
1370
|
+
const l = s;
|
|
1371
|
+
for (const o of l.header)
|
|
1372
|
+
n = n.concat(this.walkTokens(o.tokens, e));
|
|
1373
|
+
for (const o of l.rows)
|
|
1374
|
+
for (const p of o)
|
|
1375
|
+
n = n.concat(this.walkTokens(p.tokens, e));
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
case "list": {
|
|
1379
|
+
const l = s;
|
|
1380
|
+
n = n.concat(this.walkTokens(l.items, e));
|
|
1381
|
+
break;
|
|
1382
|
+
}
|
|
1383
|
+
default: {
|
|
1384
|
+
const l = s;
|
|
1385
|
+
(r = (i = this.defaults.extensions) == null ? void 0 : i.childTokens) != null && r[l.type] ? this.defaults.extensions.childTokens[l.type].forEach((o) => {
|
|
1386
|
+
const p = l[o].flat(1 / 0);
|
|
1387
|
+
n = n.concat(this.walkTokens(p, e));
|
|
1388
|
+
}) : l.tokens && (n = n.concat(this.walkTokens(l.tokens, e)));
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
return n;
|
|
1392
|
+
}
|
|
1393
|
+
use(...t) {
|
|
1394
|
+
const e = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
1395
|
+
return t.forEach((n) => {
|
|
1396
|
+
const i = { ...n };
|
|
1397
|
+
if (i.async = this.defaults.async || i.async || !1, n.extensions && (n.extensions.forEach((r) => {
|
|
1398
|
+
if (!r.name)
|
|
1399
|
+
throw new Error("extension name required");
|
|
1400
|
+
if ("renderer" in r) {
|
|
1401
|
+
const s = e.renderers[r.name];
|
|
1402
|
+
s ? e.renderers[r.name] = function(...l) {
|
|
1403
|
+
let o = r.renderer.apply(this, l);
|
|
1404
|
+
return o === !1 && (o = s.apply(this, l)), o;
|
|
1405
|
+
} : e.renderers[r.name] = r.renderer;
|
|
1406
|
+
}
|
|
1407
|
+
if ("tokenizer" in r) {
|
|
1408
|
+
if (!r.level || r.level !== "block" && r.level !== "inline")
|
|
1409
|
+
throw new Error("extension level must be 'block' or 'inline'");
|
|
1410
|
+
const s = e[r.level];
|
|
1411
|
+
s ? s.unshift(r.tokenizer) : e[r.level] = [r.tokenizer], r.start && (r.level === "block" ? e.startBlock ? e.startBlock.push(r.start) : e.startBlock = [r.start] : r.level === "inline" && (e.startInline ? e.startInline.push(r.start) : e.startInline = [r.start]));
|
|
1412
|
+
}
|
|
1413
|
+
"childTokens" in r && r.childTokens && (e.childTokens[r.name] = r.childTokens);
|
|
1414
|
+
}), i.extensions = e), n.renderer) {
|
|
1415
|
+
const r = this.defaults.renderer || new B(this.defaults);
|
|
1416
|
+
for (const s in n.renderer) {
|
|
1417
|
+
if (!(s in r))
|
|
1418
|
+
throw new Error(`renderer '${s}' does not exist`);
|
|
1419
|
+
if (s === "options")
|
|
1420
|
+
continue;
|
|
1421
|
+
const l = s, o = n.renderer[l], p = r[l];
|
|
1422
|
+
r[l] = (...c) => {
|
|
1423
|
+
let u = o.apply(r, c);
|
|
1424
|
+
return u === !1 && (u = p.apply(r, c)), u || "";
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
i.renderer = r;
|
|
1428
|
+
}
|
|
1429
|
+
if (n.tokenizer) {
|
|
1430
|
+
const r = this.defaults.tokenizer || new Z(this.defaults);
|
|
1431
|
+
for (const s in n.tokenizer) {
|
|
1432
|
+
if (!(s in r))
|
|
1433
|
+
throw new Error(`tokenizer '${s}' does not exist`);
|
|
1434
|
+
if (["options", "rules", "lexer"].includes(s))
|
|
1435
|
+
continue;
|
|
1436
|
+
const l = s, o = n.tokenizer[l], p = r[l];
|
|
1437
|
+
r[l] = (...c) => {
|
|
1438
|
+
let u = o.apply(r, c);
|
|
1439
|
+
return u === !1 && (u = p.apply(r, c)), u;
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
i.tokenizer = r;
|
|
1443
|
+
}
|
|
1444
|
+
if (n.hooks) {
|
|
1445
|
+
const r = this.defaults.hooks || new j();
|
|
1446
|
+
for (const s in n.hooks) {
|
|
1447
|
+
if (!(s in r))
|
|
1448
|
+
throw new Error(`hook '${s}' does not exist`);
|
|
1449
|
+
if (s === "options")
|
|
1450
|
+
continue;
|
|
1451
|
+
const l = s, o = n.hooks[l], p = r[l];
|
|
1452
|
+
j.passThroughHooks.has(s) ? r[l] = (c) => {
|
|
1453
|
+
if (this.defaults.async)
|
|
1454
|
+
return Promise.resolve(o.call(r, c)).then((h) => p.call(r, h));
|
|
1455
|
+
const u = o.call(r, c);
|
|
1456
|
+
return p.call(r, u);
|
|
1457
|
+
} : r[l] = (...c) => {
|
|
1458
|
+
let u = o.apply(r, c);
|
|
1459
|
+
return u === !1 && (u = p.apply(r, c)), u;
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
i.hooks = r;
|
|
1463
|
+
}
|
|
1464
|
+
if (n.walkTokens) {
|
|
1465
|
+
const r = this.defaults.walkTokens, s = n.walkTokens;
|
|
1466
|
+
i.walkTokens = function(l) {
|
|
1467
|
+
let o = [];
|
|
1468
|
+
return o.push(s.call(this, l)), r && (o = o.concat(r.call(this, l))), o;
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
this.defaults = { ...this.defaults, ...i };
|
|
1472
|
+
}), this;
|
|
1473
|
+
}
|
|
1474
|
+
setOptions(t) {
|
|
1475
|
+
return this.defaults = { ...this.defaults, ...t }, this;
|
|
1476
|
+
}
|
|
1477
|
+
lexer(t, e) {
|
|
1478
|
+
return T.lex(t, e ?? this.defaults);
|
|
1479
|
+
}
|
|
1480
|
+
parser(t, e) {
|
|
1481
|
+
return z.parse(t, e ?? this.defaults);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
_ = new WeakSet(), H = function(t, e) {
|
|
1485
|
+
return (n, i) => {
|
|
1486
|
+
const r = { ...i }, s = { ...this.defaults, ...r };
|
|
1487
|
+
this.defaults.async === !0 && r.async === !1 && (s.silent || console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."), s.async = !0);
|
|
1488
|
+
const l = v(this, _, ye).call(this, !!s.silent, !!s.async);
|
|
1489
|
+
if (typeof n > "u" || n === null)
|
|
1490
|
+
return l(new Error("marked(): input parameter is undefined or null"));
|
|
1491
|
+
if (typeof n != "string")
|
|
1492
|
+
return l(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
|
|
1493
|
+
if (s.hooks && (s.hooks.options = s), s.async)
|
|
1494
|
+
return Promise.resolve(s.hooks ? s.hooks.preprocess(n) : n).then((o) => t(o, s)).then((o) => s.hooks ? s.hooks.processAllTokens(o) : o).then((o) => s.walkTokens ? Promise.all(this.walkTokens(o, s.walkTokens)).then(() => o) : o).then((o) => e(o, s)).then((o) => s.hooks ? s.hooks.postprocess(o) : o).catch(l);
|
|
1495
|
+
try {
|
|
1496
|
+
s.hooks && (n = s.hooks.preprocess(n));
|
|
1497
|
+
let o = t(n, s);
|
|
1498
|
+
s.hooks && (o = s.hooks.processAllTokens(o)), s.walkTokens && this.walkTokens(o, s.walkTokens);
|
|
1499
|
+
let p = e(o, s);
|
|
1500
|
+
return s.hooks && (p = s.hooks.postprocess(p)), p;
|
|
1501
|
+
} catch (o) {
|
|
1502
|
+
return l(o);
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
}, ye = function(t, e) {
|
|
1506
|
+
return (n) => {
|
|
1507
|
+
if (n.message += `
|
|
1508
|
+
Please report this to https://github.com/markedjs/marked.`, t) {
|
|
1509
|
+
const i = "<p>An error occurred:</p><pre>" + b(n.message + "", !0) + "</pre>";
|
|
1510
|
+
return e ? Promise.resolve(i) : i;
|
|
1511
|
+
}
|
|
1512
|
+
if (e)
|
|
1513
|
+
return Promise.reject(n);
|
|
1514
|
+
throw n;
|
|
1515
|
+
};
|
|
1516
|
+
};
|
|
1517
|
+
const S = new gt();
|
|
1518
|
+
function g(a, t) {
|
|
1519
|
+
return S.parse(a, t);
|
|
1520
|
+
}
|
|
1521
|
+
g.options = g.setOptions = function(a) {
|
|
1522
|
+
return S.setOptions(a), g.defaults = S.defaults, pe(g.defaults), g;
|
|
1523
|
+
};
|
|
1524
|
+
g.getDefaults = J;
|
|
1525
|
+
g.defaults = I;
|
|
1526
|
+
g.use = function(...a) {
|
|
1527
|
+
return S.use(...a), g.defaults = S.defaults, pe(g.defaults), g;
|
|
1528
|
+
};
|
|
1529
|
+
g.walkTokens = function(a, t) {
|
|
1530
|
+
return S.walkTokens(a, t);
|
|
1531
|
+
};
|
|
1532
|
+
g.parseInline = S.parseInline;
|
|
1533
|
+
g.Parser = z;
|
|
1534
|
+
g.parser = z.parse;
|
|
1535
|
+
g.Renderer = B;
|
|
1536
|
+
g.TextRenderer = V;
|
|
1537
|
+
g.Lexer = T;
|
|
1538
|
+
g.lexer = T.lex;
|
|
1539
|
+
g.Tokenizer = Z;
|
|
1540
|
+
g.Hooks = j;
|
|
1541
|
+
g.parse = g;
|
|
1542
|
+
g.options;
|
|
1543
|
+
g.setOptions;
|
|
1544
|
+
g.use;
|
|
1545
|
+
g.walkTokens;
|
|
1546
|
+
g.parseInline;
|
|
1547
|
+
z.parse;
|
|
1548
|
+
T.lex;
|
|
1549
|
+
function dt(a) {
|
|
1550
|
+
const t = a.replace(/^---[\s\S]*?---\n/, "");
|
|
1551
|
+
try {
|
|
1552
|
+
const e = g.lexer(t), n = [], i = [];
|
|
1553
|
+
for (const r of e)
|
|
1554
|
+
if (r.type === "heading") {
|
|
1555
|
+
const s = r, l = s.depth, o = $e(s.tokens), p = kt(o), c = {
|
|
1556
|
+
level: l,
|
|
1557
|
+
text: o,
|
|
1558
|
+
id: p,
|
|
1559
|
+
children: []
|
|
1560
|
+
};
|
|
1561
|
+
for (; i.length > 0 && i[i.length - 1].level >= l; )
|
|
1562
|
+
i.pop();
|
|
1563
|
+
i.length === 0 ? n.push(c) : i[i.length - 1].children.push(c), i.push(c);
|
|
1564
|
+
}
|
|
1565
|
+
return n;
|
|
1566
|
+
} catch (e) {
|
|
1567
|
+
return console.warn("Failed to extract TOC from markdown:", e), [];
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
function $e(a) {
|
|
1571
|
+
return a.map((t) => {
|
|
1572
|
+
if (t.type === "text")
|
|
1573
|
+
return t.text;
|
|
1574
|
+
if (t.type === "strong" || t.type === "em") {
|
|
1575
|
+
const e = t;
|
|
1576
|
+
if ("tokens" in e && Array.isArray(e.tokens))
|
|
1577
|
+
return $e(e.tokens);
|
|
1578
|
+
}
|
|
1579
|
+
return "";
|
|
1580
|
+
}).join("");
|
|
1581
|
+
}
|
|
1582
|
+
function kt(a) {
|
|
1583
|
+
return a.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").trim();
|
|
1584
|
+
}
|
|
1585
|
+
async function he(a, t) {
|
|
1586
|
+
const e = {};
|
|
1587
|
+
for (const [n, i] of Object.entries(a)) {
|
|
1588
|
+
const r = x.join(t, `${n}.md`);
|
|
1589
|
+
if (await m.pathExists(r)) {
|
|
1590
|
+
const s = await m.readFile(r, "utf-8"), l = dt(s);
|
|
1591
|
+
e[n] = l;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
return e;
|
|
1595
|
+
}
|
|
1596
|
+
const $ = Ce("WSXPress");
|
|
1597
|
+
function Tt(a) {
|
|
1598
|
+
const { docsRoot: t, api: e, outputDir: n = ".wsx-press" } = a;
|
|
1599
|
+
let i, r;
|
|
1600
|
+
return {
|
|
1601
|
+
name: "vite-plugin-wsx-press",
|
|
1602
|
+
enforce: "pre",
|
|
1603
|
+
/**
|
|
1604
|
+
* Vite 配置解析后,解析绝对路径
|
|
1605
|
+
*/
|
|
1606
|
+
configResolved(s) {
|
|
1607
|
+
const l = (o) => o.startsWith("/") || /^[A-Za-z]:/.test(o) || o.startsWith("\\\\");
|
|
1608
|
+
i = l(n) ? n : x.resolve(s.root, n), r = l(t) ? t : x.resolve(s.root, t);
|
|
1609
|
+
},
|
|
1610
|
+
/**
|
|
1611
|
+
* 构建开始时生成元数据和搜索索引
|
|
1612
|
+
*/
|
|
1613
|
+
async buildStart() {
|
|
1614
|
+
try {
|
|
1615
|
+
if (!i || !r) {
|
|
1616
|
+
const c = (u) => u.startsWith("/") || /^[A-Za-z]:/.test(u) || u.startsWith("\\\\");
|
|
1617
|
+
i = c(n) ? n : x.resolve(process.cwd(), n), r = c(t) ? t : x.resolve(process.cwd(), t);
|
|
1618
|
+
}
|
|
1619
|
+
await m.ensureDir(i), $.info("Starting documentation generation..."), $.info(`Docs root: ${r}`), $.info(`Output dir: ${i}`);
|
|
1620
|
+
const s = await O(r), l = x.join(i, "docs-meta.json");
|
|
1621
|
+
await m.writeJSON(l, s, { spaces: 2 }), $.info(
|
|
1622
|
+
`✅ Generated docs-meta.json with ${Object.keys(s).length} documents`
|
|
1623
|
+
);
|
|
1624
|
+
const o = await ie(s, r), p = x.join(i, "search-index.json");
|
|
1625
|
+
await m.writeJSON(p, o, { spaces: 2 }), $.info("✅ Generated search-index.json"), $.info("Generating TOC collection...");
|
|
1626
|
+
try {
|
|
1627
|
+
const c = await he(s, r), u = x.join(i, "docs-toc.json");
|
|
1628
|
+
await m.writeJSON(u, c, { spaces: 2 }), $.info(
|
|
1629
|
+
`✅ Generated docs-toc.json with ${Object.keys(c).length} documents`
|
|
1630
|
+
);
|
|
1631
|
+
} catch (c) {
|
|
1632
|
+
$.error("❌ Failed to generate TOC collection:", c);
|
|
1633
|
+
}
|
|
1634
|
+
if (e) {
|
|
1635
|
+
const c = e.outputDir || x.join(r, "api");
|
|
1636
|
+
await Pe({
|
|
1637
|
+
...e,
|
|
1638
|
+
outputDir: x.isAbsolute(c) ? c : x.resolve(process.cwd(), c)
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
} catch (s) {
|
|
1642
|
+
throw $.error("Failed to generate documentation:", s), s;
|
|
1643
|
+
}
|
|
1644
|
+
},
|
|
1645
|
+
/**
|
|
1646
|
+
* 配置开发服务器
|
|
1647
|
+
* 在开发模式下通过 /.wsx-press 路径提供元数据和搜索索引
|
|
1648
|
+
*/
|
|
1649
|
+
configureServer(s) {
|
|
1650
|
+
s.middlewares.use("/.wsx-press", async (l, o, p) => {
|
|
1651
|
+
try {
|
|
1652
|
+
const h = new URL(l.url || "/", `http://${l.headers.host}`).pathname.replace(/^\/\.wsx-press\/?/, "").replace(/^\//, "");
|
|
1653
|
+
if (h === "docs-meta.json" || h === "search-index.json" || h === "docs-toc.json") {
|
|
1654
|
+
const f = x.join(i, h);
|
|
1655
|
+
if (await m.pathExists(f)) {
|
|
1656
|
+
const w = await m.readFile(f, "utf-8");
|
|
1657
|
+
o.setHeader("Content-Type", "application/json"), o.end(w);
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
if (h === "docs-meta.json") {
|
|
1662
|
+
const f = await O(r);
|
|
1663
|
+
await m.ensureDir(i), await m.writeJSON(
|
|
1664
|
+
x.join(i, "docs-meta.json"),
|
|
1665
|
+
f,
|
|
1666
|
+
{
|
|
1667
|
+
spaces: 2
|
|
1668
|
+
}
|
|
1669
|
+
), o.setHeader("Content-Type", "application/json"), o.end(JSON.stringify(f, null, 2));
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
if (h === "search-index.json") {
|
|
1673
|
+
const f = await O(r), w = await ie(f, r);
|
|
1674
|
+
await m.ensureDir(i), await m.writeJSON(
|
|
1675
|
+
x.join(i, "search-index.json"),
|
|
1676
|
+
w,
|
|
1677
|
+
{ spaces: 2 }
|
|
1678
|
+
), o.setHeader("Content-Type", "application/json"), o.end(JSON.stringify(w, null, 2));
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
if (h === "docs-toc.json") {
|
|
1682
|
+
const f = await O(r), w = await he(
|
|
1683
|
+
f,
|
|
1684
|
+
r
|
|
1685
|
+
);
|
|
1686
|
+
await m.ensureDir(i), await m.writeJSON(
|
|
1687
|
+
x.join(i, "docs-toc.json"),
|
|
1688
|
+
w,
|
|
1689
|
+
{ spaces: 2 }
|
|
1690
|
+
), o.setHeader("Content-Type", "application/json"), o.end(JSON.stringify(w, null, 2));
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
p();
|
|
1694
|
+
} catch (c) {
|
|
1695
|
+
$.error("Middleware error:", c), o.statusCode = 500, o.end(JSON.stringify({ error: String(c) }));
|
|
1696
|
+
}
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
export {
|
|
1702
|
+
Ee as addPrevNextLinks,
|
|
1703
|
+
je as extractFrontmatter,
|
|
1704
|
+
Pe as generateApiDocs,
|
|
1705
|
+
ie as generateSearchIndex,
|
|
1706
|
+
O as scanDocsMetadata,
|
|
1707
|
+
Tt as wsxPress
|
|
1708
|
+
};
|