ai-helper-core 1.0.0
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/dist/ai-helper-core.js +1663 -0
- package/dist/ai-helper-core.umd.cjs +56 -0
- package/dist/api/client.d.ts +23 -0
- package/dist/config.d.ts +11 -0
- package/dist/index.d.ts +6 -0
- package/dist/markdown/renderer.d.ts +1 -0
- package/dist/state/manager.d.ts +21 -0
- package/dist/theme/detector.d.ts +2 -0
- package/dist/types.d.ts +115 -0
- package/package.json +32 -0
- package/src/api/client.ts +221 -0
- package/src/config.ts +75 -0
- package/src/index.ts +21 -0
- package/src/markdown/renderer.ts +5 -0
- package/src/state/manager.ts +115 -0
- package/src/theme/detector.ts +25 -0
- package/src/types.ts +136 -0
|
@@ -0,0 +1,1663 @@
|
|
|
1
|
+
//#region src/config.ts
|
|
2
|
+
var e = {
|
|
3
|
+
apiBase: "/api/ai-chat",
|
|
4
|
+
branding: {
|
|
5
|
+
name: "坤土智脑",
|
|
6
|
+
icon: "data:image/svg+xml,<svg viewBox=%220 0 1051 1024%22 xmlns=%22http://www.w3.org/2000/svg%22><path d=%22M451.99 1005.12a369.77 369.77 0 0 1-369.81-369.81 369.81 369.81 0 0 1 369.81-369.81h147.93a369.81 369.81 0 0 1 369.81 369.81 369.77 369.77 0 0 1-369.81 369.81zM208.96 709.25a197.25 197.25 0 0 0 197.25 197.25h239.48a197.25 197.25 0 0 0 197.25-197.25 197.22 197.22 0 0 0-197.25-197.22h-239.48a197.22 197.22 0 0 0-197.25 197.18z m475.86 98.65a31.99 31.99 0 0 1-31.99-31.99v-133.28a31.99 31.99 0 0 1 31.99-31.99h6.46a31.99 31.99 0 0 1 31.99 31.99v133.28a31.99 31.99 0 0 1-31.99 31.99z m-324.07 0a31.99 31.99 0 0 1-31.99-31.99v-133.28a31.99 31.99 0 0 1 31.99-31.99h6.5a31.99 31.99 0 0 1 31.99 31.99v133.28a31.99 31.99 0 0 1-31.99 31.99z m91.92-624.2a20.73 20.73 0 0 1-13.37-26.17 88 88 0 0 1 87.39-49.59 91.85 91.85 0 0 1 85.09 43.7 20.77 20.77 0 0 1-10.12 27.57 20.81 20.81 0 0 1-27.65-10.16 53.48 53.48 0 0 0-47.32-19.56 51.32 51.32 0 0 0-47.85 20.77 20.77 20.77 0 0 1-19.79 14.43 20.54 20.54 0 0 1-6.42-0.98z m-69.41-78.78a20.77 20.77 0 0 1-2.34-29.27 194.08 194.08 0 0 1 145.74-56.65 193.52 193.52 0 0 1 144.12 54.91 20.81 20.81 0 0 1-1.78 29.38 20.85 20.85 0 0 1-29.38-1.78 154.39 154.39 0 0 0-112.96-40.94 154.5 154.5 0 0 0-114.09 42.11 20.58 20.58 0 0 1-15.82 7.29 20.88 20.88 0 0 1-13.52-5.02z%22 fill=%22%23fff%22 p-id=%223539%22/><path d=%22M0.04 643.54a115.04 115.04 0 0 0 115.04 115.04v-230.11A115.04 115.04 0 0 0 0.04 643.54z%22 fill=%22%23fff%22 opacity=%22.74%22 p-id=%223540%22/><path d=%22M936.87 528.5v230.11a115.04 115.04 0 0 0 115.04-115.04 115.04 115.04 0 0 0-115.04-115.07z%22 fill=%22%23fff%22 opacity=%22.74%22 p-id=%223541%22/></svg>",
|
|
7
|
+
welcomeTitle: "你好,我是坤土智脑",
|
|
8
|
+
welcomeDesc: "我可以帮你查询数据、分析趋势、生成图表"
|
|
9
|
+
},
|
|
10
|
+
theme: "auto",
|
|
11
|
+
showQuickQuestions: !0,
|
|
12
|
+
endpoints: {
|
|
13
|
+
chat: "/chat",
|
|
14
|
+
history: "/history",
|
|
15
|
+
prompts: "/prompts"
|
|
16
|
+
},
|
|
17
|
+
closeOnRouteChange: !0
|
|
18
|
+
}, t = class {
|
|
19
|
+
constructor(e) {
|
|
20
|
+
this.config = this.buildConfig(e);
|
|
21
|
+
}
|
|
22
|
+
set(e) {
|
|
23
|
+
this.config = this.buildConfig(e);
|
|
24
|
+
}
|
|
25
|
+
merge(e) {
|
|
26
|
+
this.config = this.buildConfig(e);
|
|
27
|
+
}
|
|
28
|
+
get() {
|
|
29
|
+
return { ...this.config };
|
|
30
|
+
}
|
|
31
|
+
getApiUrl(e) {
|
|
32
|
+
return `${this.config.apiBase.replace(/\/$/, "")}${e.startsWith("/") ? e : `/${e}`}`;
|
|
33
|
+
}
|
|
34
|
+
buildConfig(t) {
|
|
35
|
+
return t ? {
|
|
36
|
+
apiBase: t.apiBase ?? e.apiBase,
|
|
37
|
+
branding: {
|
|
38
|
+
name: t.branding?.name ?? e.branding.name,
|
|
39
|
+
icon: t.branding?.icon ?? e.branding.icon,
|
|
40
|
+
welcomeTitle: t.branding?.welcomeTitle ?? e.branding.welcomeTitle,
|
|
41
|
+
welcomeDesc: t.branding?.welcomeDesc ?? e.branding.welcomeDesc
|
|
42
|
+
},
|
|
43
|
+
theme: t.theme ?? e.theme,
|
|
44
|
+
getHeaders: t.getHeaders,
|
|
45
|
+
showQuickQuestions: t.showQuickQuestions ?? e.showQuickQuestions,
|
|
46
|
+
endpoints: {
|
|
47
|
+
chat: t.endpoints?.chat ?? e.endpoints.chat,
|
|
48
|
+
history: t.endpoints?.history ?? e.endpoints.history,
|
|
49
|
+
prompts: t.endpoints?.prompts ?? e.endpoints.prompts
|
|
50
|
+
},
|
|
51
|
+
closeOnRouteChange: t.closeOnRouteChange ?? e.closeOnRouteChange,
|
|
52
|
+
buildChatBody: t.buildChatBody,
|
|
53
|
+
parseChatChunk: t.parseChatChunk,
|
|
54
|
+
parseHistoryResponse: t.parseHistoryResponse,
|
|
55
|
+
parsePromptResponse: t.parsePromptResponse
|
|
56
|
+
} : { ...e };
|
|
57
|
+
}
|
|
58
|
+
}, n = new t(), r = class {
|
|
59
|
+
constructor(e) {
|
|
60
|
+
this.config = e;
|
|
61
|
+
}
|
|
62
|
+
defaultBuildChatBody(e) {
|
|
63
|
+
return JSON.stringify({ message: e.message });
|
|
64
|
+
}
|
|
65
|
+
defaultParseChatChunk(e) {
|
|
66
|
+
try {
|
|
67
|
+
let t = JSON.parse(e);
|
|
68
|
+
return t.content === "" ? {
|
|
69
|
+
content: "",
|
|
70
|
+
done: !0
|
|
71
|
+
} : typeof t.content == "string" ? { content: t.content } : { content: "" };
|
|
72
|
+
} catch {
|
|
73
|
+
return e === "[DONE]" ? {
|
|
74
|
+
content: "",
|
|
75
|
+
done: !0
|
|
76
|
+
} : { content: e };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
defaultParseHistory(e) {
|
|
80
|
+
let t = e;
|
|
81
|
+
return {
|
|
82
|
+
messages: Array.isArray(t.messages) ? t.messages.map((e) => ({
|
|
83
|
+
role: e.role ?? "assistant",
|
|
84
|
+
content: e.content ?? "",
|
|
85
|
+
timestamp: e.timestamp ?? ""
|
|
86
|
+
})) : [],
|
|
87
|
+
total: typeof t.total == "number" ? t.total : 0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
defaultParsePrompts(e) {
|
|
91
|
+
let t = e;
|
|
92
|
+
return {
|
|
93
|
+
items: Array.isArray(t.items) ? t.items : [],
|
|
94
|
+
total: typeof t.total == "number" ? t.total : 0
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
get buildChatBodyFn() {
|
|
98
|
+
return this.config.buildChatBody ?? this.defaultBuildChatBody.bind(this);
|
|
99
|
+
}
|
|
100
|
+
get parseChatChunkFn() {
|
|
101
|
+
return this.config.parseChatChunk ?? this.defaultParseChatChunk.bind(this);
|
|
102
|
+
}
|
|
103
|
+
get parseHistoryFn() {
|
|
104
|
+
return this.config.parseHistoryResponse ?? this.defaultParseHistory.bind(this);
|
|
105
|
+
}
|
|
106
|
+
get parsePromptsFn() {
|
|
107
|
+
return this.config.parsePromptResponse ?? this.defaultParsePrompts.bind(this);
|
|
108
|
+
}
|
|
109
|
+
async resolveHeaders() {
|
|
110
|
+
return {
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
...this.config.getHeaders ? await this.config.getHeaders() : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
resolveEndpoint(e) {
|
|
116
|
+
let t = this.config.apiBase.replace(/\/$/, ""), n = this.config.endpoints;
|
|
117
|
+
return e === "/chat" ? `${t}${n.chat}` : e === "/history" ? `${t}${n.history}` : e === "/prompts" ? `${t}${n.prompts}` : `${t}${e.startsWith("/") ? e : `/${e}`}`;
|
|
118
|
+
}
|
|
119
|
+
async request(e, t) {
|
|
120
|
+
let n = this.resolveEndpoint(e);
|
|
121
|
+
if (t?.params) {
|
|
122
|
+
let e = new URLSearchParams();
|
|
123
|
+
for (let [n, r] of Object.entries(t.params)) r !== void 0 && e.set(n, String(r));
|
|
124
|
+
let r = e.toString();
|
|
125
|
+
r && (n += (n.includes("?") ? "&" : "?") + r);
|
|
126
|
+
}
|
|
127
|
+
let { params: r, ...i } = t ?? {}, a = await this.resolveHeaders(), o = await fetch(n, {
|
|
128
|
+
credentials: "include",
|
|
129
|
+
...i,
|
|
130
|
+
headers: {
|
|
131
|
+
...a,
|
|
132
|
+
...i.headers
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (!o.ok) throw Error(`Request failed: ${o.status} ${o.statusText}`);
|
|
136
|
+
return o.json();
|
|
137
|
+
}
|
|
138
|
+
async chatStream(e, t, n) {
|
|
139
|
+
let r = new AbortController(), i = await this.resolveHeaders(), a = null, o = () => {
|
|
140
|
+
a !== null && clearTimeout(a), a = setTimeout(() => {
|
|
141
|
+
n?.();
|
|
142
|
+
}, 6e4);
|
|
143
|
+
}, s = (e) => {
|
|
144
|
+
o(), t(e);
|
|
145
|
+
}, c = () => {
|
|
146
|
+
a !== null && clearTimeout(a), n?.();
|
|
147
|
+
}, l = this.parseChatChunkFn, u = this.buildChatBodyFn;
|
|
148
|
+
return (async () => {
|
|
149
|
+
try {
|
|
150
|
+
let n = await fetch(this.resolveEndpoint("/chat"), {
|
|
151
|
+
method: "POST",
|
|
152
|
+
headers: i,
|
|
153
|
+
credentials: "include",
|
|
154
|
+
signal: r.signal,
|
|
155
|
+
body: u({ message: e })
|
|
156
|
+
});
|
|
157
|
+
if (!n.ok) {
|
|
158
|
+
t(`请求失败: ${n.status} ${n.statusText}`), c();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let a = n.body?.getReader();
|
|
162
|
+
if (!a) {
|
|
163
|
+
c();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
let o = new TextDecoder(), d = "";
|
|
167
|
+
for (;;) {
|
|
168
|
+
let { done: e, value: t } = await a.read();
|
|
169
|
+
if (e) {
|
|
170
|
+
c();
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
d += o.decode(t, { stream: !0 });
|
|
174
|
+
let n = d.split(/\r?\n/);
|
|
175
|
+
d = n.pop() || "";
|
|
176
|
+
for (let e of n) {
|
|
177
|
+
let t = e.trim();
|
|
178
|
+
if (!t) continue;
|
|
179
|
+
let n = t.startsWith("data:") ? t.slice(5).trim() : t;
|
|
180
|
+
if (!n || n.startsWith(":") || n.startsWith("id:") || n.startsWith("event:")) continue;
|
|
181
|
+
let r = l(n);
|
|
182
|
+
if (r.content && s(r.content), r.done) {
|
|
183
|
+
c();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} catch (e) {
|
|
189
|
+
if (e instanceof DOMException && e.name === "AbortError") return;
|
|
190
|
+
c();
|
|
191
|
+
}
|
|
192
|
+
})(), o(), r;
|
|
193
|
+
}
|
|
194
|
+
async getPrompts(e) {
|
|
195
|
+
let t = await this.request("/prompts", {
|
|
196
|
+
method: "GET",
|
|
197
|
+
params: e
|
|
198
|
+
});
|
|
199
|
+
return this.parsePromptsFn(t);
|
|
200
|
+
}
|
|
201
|
+
async getHistory(e) {
|
|
202
|
+
let t = await this.request("/history", {
|
|
203
|
+
method: "GET",
|
|
204
|
+
params: e
|
|
205
|
+
});
|
|
206
|
+
return this.parseHistoryFn(t);
|
|
207
|
+
}
|
|
208
|
+
}, i = class {
|
|
209
|
+
constructor() {
|
|
210
|
+
this.state = {
|
|
211
|
+
messages: [],
|
|
212
|
+
isVisible: !1,
|
|
213
|
+
isLoading: !1,
|
|
214
|
+
isInitial: !0
|
|
215
|
+
}, this.listeners = /* @__PURE__ */ new Map();
|
|
216
|
+
}
|
|
217
|
+
on(e, t) {
|
|
218
|
+
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), () => this.off(e, t);
|
|
219
|
+
}
|
|
220
|
+
off(e, t) {
|
|
221
|
+
this.listeners.get(e)?.delete(t);
|
|
222
|
+
}
|
|
223
|
+
emit(e) {
|
|
224
|
+
let t = this.listeners.get(e);
|
|
225
|
+
if (t) for (let e of t) e(this.state);
|
|
226
|
+
if (e !== "stateChange") {
|
|
227
|
+
let e = this.listeners.get("stateChange");
|
|
228
|
+
if (e) for (let t of e) t(this.state);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
getState() {
|
|
232
|
+
return this.state;
|
|
233
|
+
}
|
|
234
|
+
show() {
|
|
235
|
+
this.state.isVisible = !0, this.emit("stateChange");
|
|
236
|
+
}
|
|
237
|
+
hide() {
|
|
238
|
+
this.state.isVisible = !1, this.emit("stateChange");
|
|
239
|
+
}
|
|
240
|
+
toggleVisibility() {
|
|
241
|
+
this.state.isVisible = !this.state.isVisible, this.emit("stateChange");
|
|
242
|
+
}
|
|
243
|
+
addUserMessage(e) {
|
|
244
|
+
let t = {
|
|
245
|
+
id: Date.now(),
|
|
246
|
+
role: "user",
|
|
247
|
+
content: e
|
|
248
|
+
};
|
|
249
|
+
return this.state.messages = [...this.state.messages, t], this.state.isInitial = !1, this.emit("messageChange"), t;
|
|
250
|
+
}
|
|
251
|
+
startAssistantMessage() {
|
|
252
|
+
let e = {
|
|
253
|
+
id: Date.now() + 1,
|
|
254
|
+
role: "assistant",
|
|
255
|
+
content: "",
|
|
256
|
+
isStreaming: !0
|
|
257
|
+
};
|
|
258
|
+
return this.state.messages = [...this.state.messages, e], this.state.isLoading = !0, this.emit("messageChange"), e;
|
|
259
|
+
}
|
|
260
|
+
appendToAssistantMessage(e) {
|
|
261
|
+
let t = this.state.messages[this.state.messages.length - 1];
|
|
262
|
+
if (t && t.role === "assistant") {
|
|
263
|
+
let n = t.content + e, r = {
|
|
264
|
+
...t,
|
|
265
|
+
content: n
|
|
266
|
+
};
|
|
267
|
+
this.state.messages = [...this.state.messages.slice(0, -1), r], this.emit("messageChange");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
finishAssistantMessage() {
|
|
271
|
+
let e = this.state.messages[this.state.messages.length - 1];
|
|
272
|
+
e && e.role === "assistant" && (e.isStreaming = !1), this.state.isLoading = !1, this.emit("messageChange");
|
|
273
|
+
}
|
|
274
|
+
setMessages(e) {
|
|
275
|
+
this.state.messages = e, this.state.isInitial = e.length === 0, this.emit("messageChange");
|
|
276
|
+
}
|
|
277
|
+
clearMessages() {
|
|
278
|
+
this.state.messages = [], this.state.isInitial = !0, this.emit("messageChange");
|
|
279
|
+
}
|
|
280
|
+
setLoading(e) {
|
|
281
|
+
this.state.isLoading = e, this.emit("stateChange");
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/theme/detector.ts
|
|
286
|
+
function a() {
|
|
287
|
+
return typeof document > "u" ? "light" : document.documentElement.classList.contains("dark") ? "dark" : "light";
|
|
288
|
+
}
|
|
289
|
+
function o(e) {
|
|
290
|
+
if (typeof document > "u" || typeof window > "u") return () => {};
|
|
291
|
+
let t = new MutationObserver(() => {
|
|
292
|
+
e(a());
|
|
293
|
+
});
|
|
294
|
+
t.observe(document.documentElement, {
|
|
295
|
+
attributes: !0,
|
|
296
|
+
attributeFilter: ["class"]
|
|
297
|
+
});
|
|
298
|
+
let n = window.matchMedia("(prefers-color-scheme: dark)"), r = () => e(a());
|
|
299
|
+
return n.addEventListener("change", r), () => {
|
|
300
|
+
t.disconnect(), n.removeEventListener("change", r);
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region ../../node_modules/marked/lib/marked.esm.js
|
|
305
|
+
function s() {
|
|
306
|
+
return {
|
|
307
|
+
async: !1,
|
|
308
|
+
breaks: !1,
|
|
309
|
+
extensions: null,
|
|
310
|
+
gfm: !0,
|
|
311
|
+
hooks: null,
|
|
312
|
+
pedantic: !1,
|
|
313
|
+
renderer: null,
|
|
314
|
+
silent: !1,
|
|
315
|
+
tokenizer: null,
|
|
316
|
+
walkTokens: null
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
var c = s();
|
|
320
|
+
function l(e) {
|
|
321
|
+
c = e;
|
|
322
|
+
}
|
|
323
|
+
var u = { exec: () => null };
|
|
324
|
+
function d(e, t = "") {
|
|
325
|
+
let n = typeof e == "string" ? e : e.source, r = {
|
|
326
|
+
replace: (e, t) => {
|
|
327
|
+
let i = typeof t == "string" ? t : t.source;
|
|
328
|
+
return i = i.replace(f.caret, "$1"), n = n.replace(e, i), r;
|
|
329
|
+
},
|
|
330
|
+
getRegex: () => new RegExp(n, t)
|
|
331
|
+
};
|
|
332
|
+
return r;
|
|
333
|
+
}
|
|
334
|
+
var f = {
|
|
335
|
+
codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
|
|
336
|
+
outputLinkReplace: /\\([\[\]])/g,
|
|
337
|
+
indentCodeCompensation: /^(\s+)(?:```)/,
|
|
338
|
+
beginningSpace: /^\s+/,
|
|
339
|
+
endingHash: /#$/,
|
|
340
|
+
startingSpaceChar: /^ /,
|
|
341
|
+
endingSpaceChar: / $/,
|
|
342
|
+
nonSpaceChar: /[^ ]/,
|
|
343
|
+
newLineCharGlobal: /\n/g,
|
|
344
|
+
tabCharGlobal: /\t/g,
|
|
345
|
+
multipleSpaceGlobal: /\s+/g,
|
|
346
|
+
blankLine: /^[ \t]*$/,
|
|
347
|
+
doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
|
|
348
|
+
blockquoteStart: /^ {0,3}>/,
|
|
349
|
+
blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
|
|
350
|
+
blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
|
|
351
|
+
listReplaceTabs: /^\t+/,
|
|
352
|
+
listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
|
|
353
|
+
listIsTask: /^\[[ xX]\] /,
|
|
354
|
+
listReplaceTask: /^\[[ xX]\] +/,
|
|
355
|
+
anyLine: /\n.*\n/,
|
|
356
|
+
hrefBrackets: /^<(.*)>$/,
|
|
357
|
+
tableDelimiter: /[:|]/,
|
|
358
|
+
tableAlignChars: /^\||\| *$/g,
|
|
359
|
+
tableRowBlankLine: /\n[ \t]*$/,
|
|
360
|
+
tableAlignRight: /^ *-+: *$/,
|
|
361
|
+
tableAlignCenter: /^ *:-+: *$/,
|
|
362
|
+
tableAlignLeft: /^ *:-+ *$/,
|
|
363
|
+
startATag: /^<a /i,
|
|
364
|
+
endATag: /^<\/a>/i,
|
|
365
|
+
startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
|
|
366
|
+
endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
|
|
367
|
+
startAngleBracket: /^</,
|
|
368
|
+
endAngleBracket: />$/,
|
|
369
|
+
pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
|
|
370
|
+
unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
|
|
371
|
+
escapeTest: /[&<>"']/,
|
|
372
|
+
escapeReplace: /[&<>"']/g,
|
|
373
|
+
escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
|
|
374
|
+
escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
|
|
375
|
+
unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,
|
|
376
|
+
caret: /(^|[^\[])\^/g,
|
|
377
|
+
percentDecode: /%25/g,
|
|
378
|
+
findPipe: /\|/g,
|
|
379
|
+
splitPipe: / \|/,
|
|
380
|
+
slashPipe: /\\\|/g,
|
|
381
|
+
carriageReturn: /\r\n|\r/g,
|
|
382
|
+
spaceLine: /^ +$/gm,
|
|
383
|
+
notSpaceStart: /^\S*/,
|
|
384
|
+
endingNewline: /\n$/,
|
|
385
|
+
listItemRegex: (e) => RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
386
|
+
nextBulletRegex: (e) => RegExp(`^ {0,${Math.min(3, e - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
|
|
387
|
+
hrRegex: (e) => RegExp(`^ {0,${Math.min(3, e - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
|
|
388
|
+
fencesBeginRegex: (e) => RegExp(`^ {0,${Math.min(3, e - 1)}}(?:\`\`\`|~~~)`),
|
|
389
|
+
headingBeginRegex: (e) => RegExp(`^ {0,${Math.min(3, e - 1)}}#`),
|
|
390
|
+
htmlBeginRegex: (e) => RegExp(`^ {0,${Math.min(3, e - 1)}}<(?:[a-z].*>|!--)`, "i")
|
|
391
|
+
}, p = /^(?:[ \t]*(?:\n|$))+/, ee = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/, te = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/, m = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/, ne = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/, h = /(?:[*+-]|\d{1,9}[.)])/, g = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/, _ = d(g).replace(/bull/g, h).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).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/).replace(/\|table/g, "").getRegex(), re = d(g).replace(/bull/g, h).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).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/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(), v = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/, ie = /^[^\n]+/, y = /(?!\s*\])(?:\\.|[^\[\]\\])+/, ae = d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", y).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(), oe = d(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, h).getRegex(), b = "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", x = /<!--(?:-?>|[\s\S]*?(?:-->|$))/, se = 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", x).replace("tag", b).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(), S = d(v).replace("hr", m).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", b).getRegex(), C = {
|
|
392
|
+
blockquote: d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", S).getRegex(),
|
|
393
|
+
code: ee,
|
|
394
|
+
def: ae,
|
|
395
|
+
fences: te,
|
|
396
|
+
heading: ne,
|
|
397
|
+
hr: m,
|
|
398
|
+
html: se,
|
|
399
|
+
lheading: _,
|
|
400
|
+
list: oe,
|
|
401
|
+
newline: p,
|
|
402
|
+
paragraph: S,
|
|
403
|
+
table: u,
|
|
404
|
+
text: ie
|
|
405
|
+
}, w = d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", m).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\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", b).getRegex(), ce = {
|
|
406
|
+
...C,
|
|
407
|
+
lheading: re,
|
|
408
|
+
table: w,
|
|
409
|
+
paragraph: d(v).replace("hr", m).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", w).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", b).getRegex()
|
|
410
|
+
}, le = {
|
|
411
|
+
...C,
|
|
412
|
+
html: d("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment", x).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(),
|
|
413
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
414
|
+
heading: /^(#{1,6})(.*)(?:\n+|$)/,
|
|
415
|
+
fences: u,
|
|
416
|
+
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
417
|
+
paragraph: d(v).replace("hr", m).replace("heading", " *#{1,6} *[^\n]").replace("lheading", _).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
|
|
418
|
+
}, ue = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, de = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, T = /^( {2,}|\\)\n(?!\s*$)/, fe = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/, E = /[\p{P}\p{S}]/u, D = /[\s\p{P}\p{S}]/u, O = /[^\s\p{P}\p{S}]/u, pe = d(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, D).getRegex(), k = /(?!~)[\p{P}\p{S}]/u, me = /(?!~)[\s\p{P}\p{S}]/u, he = /(?:[^\s\p{P}\p{S}]|~)/u, ge = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g, A = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, _e = d(A, "u").replace(/punct/g, E).getRegex(), ve = d(A, "u").replace(/punct/g, k).getRegex(), j = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", M = d(j, "gu").replace(/notPunctSpace/g, O).replace(/punctSpace/g, D).replace(/punct/g, E).getRegex(), ye = d(j, "gu").replace(/notPunctSpace/g, he).replace(/punctSpace/g, me).replace(/punct/g, k).getRegex(), be = d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, O).replace(/punctSpace/g, D).replace(/punct/g, E).getRegex(), xe = d(/\\(punct)/, "gu").replace(/punct/g, E).getRegex(), Se = 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(), Ce = d(x).replace("(?:-->|$)", "-->").getRegex(), we = 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", Ce).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(), N = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/, Te = d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", N).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(), P = d(/^!?\[(label)\]\[(ref)\]/).replace("label", N).replace("ref", y).getRegex(), F = d(/^!?\[(ref)\](?:\[\])?/).replace("ref", y).getRegex(), I = {
|
|
419
|
+
_backpedal: u,
|
|
420
|
+
anyPunctuation: xe,
|
|
421
|
+
autolink: Se,
|
|
422
|
+
blockSkip: ge,
|
|
423
|
+
br: T,
|
|
424
|
+
code: de,
|
|
425
|
+
del: u,
|
|
426
|
+
emStrongLDelim: _e,
|
|
427
|
+
emStrongRDelimAst: M,
|
|
428
|
+
emStrongRDelimUnd: be,
|
|
429
|
+
escape: ue,
|
|
430
|
+
link: Te,
|
|
431
|
+
nolink: F,
|
|
432
|
+
punctuation: pe,
|
|
433
|
+
reflink: P,
|
|
434
|
+
reflinkSearch: d("reflink|nolink(?!\\()", "g").replace("reflink", P).replace("nolink", F).getRegex(),
|
|
435
|
+
tag: we,
|
|
436
|
+
text: fe,
|
|
437
|
+
url: u
|
|
438
|
+
}, Ee = {
|
|
439
|
+
...I,
|
|
440
|
+
link: d(/^!?\[(label)\]\((.*?)\)/).replace("label", N).getRegex(),
|
|
441
|
+
reflink: d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", N).getRegex()
|
|
442
|
+
}, L = {
|
|
443
|
+
...I,
|
|
444
|
+
emStrongRDelimAst: ye,
|
|
445
|
+
emStrongLDelim: ve,
|
|
446
|
+
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(),
|
|
447
|
+
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
448
|
+
del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
|
|
449
|
+
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
|
|
450
|
+
}, De = {
|
|
451
|
+
...L,
|
|
452
|
+
br: d(T).replace("{2,}", "*").getRegex(),
|
|
453
|
+
text: d(L.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
|
|
454
|
+
}, R = {
|
|
455
|
+
normal: C,
|
|
456
|
+
gfm: ce,
|
|
457
|
+
pedantic: le
|
|
458
|
+
}, z = {
|
|
459
|
+
normal: I,
|
|
460
|
+
gfm: L,
|
|
461
|
+
breaks: De,
|
|
462
|
+
pedantic: Ee
|
|
463
|
+
}, Oe = {
|
|
464
|
+
"&": "&",
|
|
465
|
+
"<": "<",
|
|
466
|
+
">": ">",
|
|
467
|
+
"\"": """,
|
|
468
|
+
"'": "'"
|
|
469
|
+
}, B = (e) => Oe[e];
|
|
470
|
+
function V(e, t) {
|
|
471
|
+
if (t) {
|
|
472
|
+
if (f.escapeTest.test(e)) return e.replace(f.escapeReplace, B);
|
|
473
|
+
} else if (f.escapeTestNoEncode.test(e)) return e.replace(f.escapeReplaceNoEncode, B);
|
|
474
|
+
return e;
|
|
475
|
+
}
|
|
476
|
+
function H(e) {
|
|
477
|
+
try {
|
|
478
|
+
e = encodeURI(e).replace(f.percentDecode, "%");
|
|
479
|
+
} catch {
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
return e;
|
|
483
|
+
}
|
|
484
|
+
function U(e, t) {
|
|
485
|
+
let n = e.replace(f.findPipe, (e, t, n) => {
|
|
486
|
+
let r = !1, i = t;
|
|
487
|
+
for (; --i >= 0 && n[i] === "\\";) r = !r;
|
|
488
|
+
return r ? "|" : " |";
|
|
489
|
+
}).split(f.splitPipe), r = 0;
|
|
490
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), t) if (n.length > t) n.splice(t);
|
|
491
|
+
else for (; n.length < t;) n.push("");
|
|
492
|
+
for (; r < n.length; r++) n[r] = n[r].trim().replace(f.slashPipe, "|");
|
|
493
|
+
return n;
|
|
494
|
+
}
|
|
495
|
+
function W(e, t, n) {
|
|
496
|
+
let r = e.length;
|
|
497
|
+
if (r === 0) return "";
|
|
498
|
+
let i = 0;
|
|
499
|
+
for (; i < r;) {
|
|
500
|
+
let a = e.charAt(r - i - 1);
|
|
501
|
+
if (a === t && !n) i++;
|
|
502
|
+
else if (a !== t && n) i++;
|
|
503
|
+
else break;
|
|
504
|
+
}
|
|
505
|
+
return e.slice(0, r - i);
|
|
506
|
+
}
|
|
507
|
+
function ke(e, t) {
|
|
508
|
+
if (e.indexOf(t[1]) === -1) return -1;
|
|
509
|
+
let n = 0;
|
|
510
|
+
for (let r = 0; r < e.length; r++) if (e[r] === "\\") r++;
|
|
511
|
+
else if (e[r] === t[0]) n++;
|
|
512
|
+
else if (e[r] === t[1] && (n--, n < 0)) return r;
|
|
513
|
+
return n > 0 ? -2 : -1;
|
|
514
|
+
}
|
|
515
|
+
function G(e, t, n, r, i) {
|
|
516
|
+
let a = t.href, o = t.title || null, s = e[1].replace(i.other.outputLinkReplace, "$1");
|
|
517
|
+
r.state.inLink = !0;
|
|
518
|
+
let c = {
|
|
519
|
+
type: e[0].charAt(0) === "!" ? "image" : "link",
|
|
520
|
+
raw: n,
|
|
521
|
+
href: a,
|
|
522
|
+
title: o,
|
|
523
|
+
text: s,
|
|
524
|
+
tokens: r.inlineTokens(s)
|
|
525
|
+
};
|
|
526
|
+
return r.state.inLink = !1, c;
|
|
527
|
+
}
|
|
528
|
+
function Ae(e, t, n) {
|
|
529
|
+
let r = e.match(n.other.indentCodeCompensation);
|
|
530
|
+
if (r === null) return t;
|
|
531
|
+
let i = r[1];
|
|
532
|
+
return t.split("\n").map((e) => {
|
|
533
|
+
let t = e.match(n.other.beginningSpace);
|
|
534
|
+
if (t === null) return e;
|
|
535
|
+
let [r] = t;
|
|
536
|
+
return r.length >= i.length ? e.slice(i.length) : e;
|
|
537
|
+
}).join("\n");
|
|
538
|
+
}
|
|
539
|
+
var K = class {
|
|
540
|
+
options;
|
|
541
|
+
rules;
|
|
542
|
+
lexer;
|
|
543
|
+
constructor(e) {
|
|
544
|
+
this.options = e || c;
|
|
545
|
+
}
|
|
546
|
+
space(e) {
|
|
547
|
+
let t = this.rules.block.newline.exec(e);
|
|
548
|
+
if (t && t[0].length > 0) return {
|
|
549
|
+
type: "space",
|
|
550
|
+
raw: t[0]
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
code(e) {
|
|
554
|
+
let t = this.rules.block.code.exec(e);
|
|
555
|
+
if (t) {
|
|
556
|
+
let e = t[0].replace(this.rules.other.codeRemoveIndent, "");
|
|
557
|
+
return {
|
|
558
|
+
type: "code",
|
|
559
|
+
raw: t[0],
|
|
560
|
+
codeBlockStyle: "indented",
|
|
561
|
+
text: this.options.pedantic ? e : W(e, "\n")
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
fences(e) {
|
|
566
|
+
let t = this.rules.block.fences.exec(e);
|
|
567
|
+
if (t) {
|
|
568
|
+
let e = t[0], n = Ae(e, t[3] || "", this.rules);
|
|
569
|
+
return {
|
|
570
|
+
type: "code",
|
|
571
|
+
raw: e,
|
|
572
|
+
lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
|
|
573
|
+
text: n
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
heading(e) {
|
|
578
|
+
let t = this.rules.block.heading.exec(e);
|
|
579
|
+
if (t) {
|
|
580
|
+
let e = t[2].trim();
|
|
581
|
+
if (this.rules.other.endingHash.test(e)) {
|
|
582
|
+
let t = W(e, "#");
|
|
583
|
+
(this.options.pedantic || !t || this.rules.other.endingSpaceChar.test(t)) && (e = t.trim());
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
type: "heading",
|
|
587
|
+
raw: t[0],
|
|
588
|
+
depth: t[1].length,
|
|
589
|
+
text: e,
|
|
590
|
+
tokens: this.lexer.inline(e)
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
hr(e) {
|
|
595
|
+
let t = this.rules.block.hr.exec(e);
|
|
596
|
+
if (t) return {
|
|
597
|
+
type: "hr",
|
|
598
|
+
raw: W(t[0], "\n")
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
blockquote(e) {
|
|
602
|
+
let t = this.rules.block.blockquote.exec(e);
|
|
603
|
+
if (t) {
|
|
604
|
+
let e = W(t[0], "\n").split("\n"), n = "", r = "", i = [];
|
|
605
|
+
for (; e.length > 0;) {
|
|
606
|
+
let t = !1, a = [], o;
|
|
607
|
+
for (o = 0; o < e.length; o++) if (this.rules.other.blockquoteStart.test(e[o])) a.push(e[o]), t = !0;
|
|
608
|
+
else if (!t) a.push(e[o]);
|
|
609
|
+
else break;
|
|
610
|
+
e = e.slice(o);
|
|
611
|
+
let s = a.join("\n"), c = s.replace(this.rules.other.blockquoteSetextReplace, "\n $1").replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
612
|
+
n = n ? `${n}
|
|
613
|
+
${s}` : s, r = r ? `${r}
|
|
614
|
+
${c}` : c;
|
|
615
|
+
let l = this.lexer.state.top;
|
|
616
|
+
if (this.lexer.state.top = !0, this.lexer.blockTokens(c, i, !0), this.lexer.state.top = l, e.length === 0) break;
|
|
617
|
+
let u = i.at(-1);
|
|
618
|
+
if (u?.type === "code") break;
|
|
619
|
+
if (u?.type === "blockquote") {
|
|
620
|
+
let t = u, a = t.raw + "\n" + e.join("\n"), o = this.blockquote(a);
|
|
621
|
+
i[i.length - 1] = o, n = n.substring(0, n.length - t.raw.length) + o.raw, r = r.substring(0, r.length - t.text.length) + o.text;
|
|
622
|
+
break;
|
|
623
|
+
} else if (u?.type === "list") {
|
|
624
|
+
let t = u, a = t.raw + "\n" + e.join("\n"), o = this.list(a);
|
|
625
|
+
i[i.length - 1] = o, n = n.substring(0, n.length - u.raw.length) + o.raw, r = r.substring(0, r.length - t.raw.length) + o.raw, e = a.substring(i.at(-1).raw.length).split("\n");
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return {
|
|
630
|
+
type: "blockquote",
|
|
631
|
+
raw: n,
|
|
632
|
+
tokens: i,
|
|
633
|
+
text: r
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
list(e) {
|
|
638
|
+
let t = this.rules.block.list.exec(e);
|
|
639
|
+
if (t) {
|
|
640
|
+
let n = t[1].trim(), r = n.length > 1, i = {
|
|
641
|
+
type: "list",
|
|
642
|
+
raw: "",
|
|
643
|
+
ordered: r,
|
|
644
|
+
start: r ? +n.slice(0, -1) : "",
|
|
645
|
+
loose: !1,
|
|
646
|
+
items: []
|
|
647
|
+
};
|
|
648
|
+
n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
|
|
649
|
+
let a = this.rules.other.listItemRegex(n), o = !1;
|
|
650
|
+
for (; e;) {
|
|
651
|
+
let n = !1, r = "", s = "";
|
|
652
|
+
if (!(t = a.exec(e)) || this.rules.block.hr.test(e)) break;
|
|
653
|
+
r = t[0], e = e.substring(r.length);
|
|
654
|
+
let c = t[2].split("\n", 1)[0].replace(this.rules.other.listReplaceTabs, (e) => " ".repeat(3 * e.length)), l = e.split("\n", 1)[0], u = !c.trim(), d = 0;
|
|
655
|
+
if (this.options.pedantic ? (d = 2, s = c.trimStart()) : u ? d = t[1].length + 1 : (d = t[2].search(this.rules.other.nonSpaceChar), d = d > 4 ? 1 : d, s = c.slice(d), d += t[1].length), u && this.rules.other.blankLine.test(l) && (r += l + "\n", e = e.substring(l.length + 1), n = !0), !n) {
|
|
656
|
+
let t = this.rules.other.nextBulletRegex(d), n = this.rules.other.hrRegex(d), i = this.rules.other.fencesBeginRegex(d), a = this.rules.other.headingBeginRegex(d), o = this.rules.other.htmlBeginRegex(d);
|
|
657
|
+
for (; e;) {
|
|
658
|
+
let f = e.split("\n", 1)[0], p;
|
|
659
|
+
if (l = f, this.options.pedantic ? (l = l.replace(this.rules.other.listReplaceNesting, " "), p = l) : p = l.replace(this.rules.other.tabCharGlobal, " "), i.test(l) || a.test(l) || o.test(l) || t.test(l) || n.test(l)) break;
|
|
660
|
+
if (p.search(this.rules.other.nonSpaceChar) >= d || !l.trim()) s += "\n" + p.slice(d);
|
|
661
|
+
else {
|
|
662
|
+
if (u || c.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || i.test(c) || a.test(c) || n.test(c)) break;
|
|
663
|
+
s += "\n" + l;
|
|
664
|
+
}
|
|
665
|
+
!u && !l.trim() && (u = !0), r += f + "\n", e = e.substring(f.length + 1), c = p.slice(d);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
i.loose || (o ? i.loose = !0 : this.rules.other.doubleBlankLine.test(r) && (o = !0));
|
|
669
|
+
let f = null, p;
|
|
670
|
+
this.options.gfm && (f = this.rules.other.listIsTask.exec(s), f && (p = f[0] !== "[ ] ", s = s.replace(this.rules.other.listReplaceTask, ""))), i.items.push({
|
|
671
|
+
type: "list_item",
|
|
672
|
+
raw: r,
|
|
673
|
+
task: !!f,
|
|
674
|
+
checked: p,
|
|
675
|
+
loose: !1,
|
|
676
|
+
text: s,
|
|
677
|
+
tokens: []
|
|
678
|
+
}), i.raw += r;
|
|
679
|
+
}
|
|
680
|
+
let s = i.items.at(-1);
|
|
681
|
+
if (s) s.raw = s.raw.trimEnd(), s.text = s.text.trimEnd();
|
|
682
|
+
else return;
|
|
683
|
+
i.raw = i.raw.trimEnd();
|
|
684
|
+
for (let e = 0; e < i.items.length; e++) if (this.lexer.state.top = !1, i.items[e].tokens = this.lexer.blockTokens(i.items[e].text, []), !i.loose) {
|
|
685
|
+
let t = i.items[e].tokens.filter((e) => e.type === "space");
|
|
686
|
+
i.loose = t.length > 0 && t.some((e) => this.rules.other.anyLine.test(e.raw));
|
|
687
|
+
}
|
|
688
|
+
if (i.loose) for (let e = 0; e < i.items.length; e++) i.items[e].loose = !0;
|
|
689
|
+
return i;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
html(e) {
|
|
693
|
+
let t = this.rules.block.html.exec(e);
|
|
694
|
+
if (t) return {
|
|
695
|
+
type: "html",
|
|
696
|
+
block: !0,
|
|
697
|
+
raw: t[0],
|
|
698
|
+
pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
|
|
699
|
+
text: t[0]
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
def(e) {
|
|
703
|
+
let t = this.rules.block.def.exec(e);
|
|
704
|
+
if (t) {
|
|
705
|
+
let e = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), n = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
|
|
706
|
+
return {
|
|
707
|
+
type: "def",
|
|
708
|
+
tag: e,
|
|
709
|
+
raw: t[0],
|
|
710
|
+
href: n,
|
|
711
|
+
title: r
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
table(e) {
|
|
716
|
+
let t = this.rules.block.table.exec(e);
|
|
717
|
+
if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
|
|
718
|
+
let n = U(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split("\n") : [], a = {
|
|
719
|
+
type: "table",
|
|
720
|
+
raw: t[0],
|
|
721
|
+
header: [],
|
|
722
|
+
align: [],
|
|
723
|
+
rows: []
|
|
724
|
+
};
|
|
725
|
+
if (n.length === r.length) {
|
|
726
|
+
for (let e of r) this.rules.other.tableAlignRight.test(e) ? a.align.push("right") : this.rules.other.tableAlignCenter.test(e) ? a.align.push("center") : this.rules.other.tableAlignLeft.test(e) ? a.align.push("left") : a.align.push(null);
|
|
727
|
+
for (let e = 0; e < n.length; e++) a.header.push({
|
|
728
|
+
text: n[e],
|
|
729
|
+
tokens: this.lexer.inline(n[e]),
|
|
730
|
+
header: !0,
|
|
731
|
+
align: a.align[e]
|
|
732
|
+
});
|
|
733
|
+
for (let e of i) a.rows.push(U(e, a.header.length).map((e, t) => ({
|
|
734
|
+
text: e,
|
|
735
|
+
tokens: this.lexer.inline(e),
|
|
736
|
+
header: !1,
|
|
737
|
+
align: a.align[t]
|
|
738
|
+
})));
|
|
739
|
+
return a;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
lheading(e) {
|
|
743
|
+
let t = this.rules.block.lheading.exec(e);
|
|
744
|
+
if (t) return {
|
|
745
|
+
type: "heading",
|
|
746
|
+
raw: t[0],
|
|
747
|
+
depth: t[2].charAt(0) === "=" ? 1 : 2,
|
|
748
|
+
text: t[1],
|
|
749
|
+
tokens: this.lexer.inline(t[1])
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
paragraph(e) {
|
|
753
|
+
let t = this.rules.block.paragraph.exec(e);
|
|
754
|
+
if (t) {
|
|
755
|
+
let e = t[1].charAt(t[1].length - 1) === "\n" ? t[1].slice(0, -1) : t[1];
|
|
756
|
+
return {
|
|
757
|
+
type: "paragraph",
|
|
758
|
+
raw: t[0],
|
|
759
|
+
text: e,
|
|
760
|
+
tokens: this.lexer.inline(e)
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
text(e) {
|
|
765
|
+
let t = this.rules.block.text.exec(e);
|
|
766
|
+
if (t) return {
|
|
767
|
+
type: "text",
|
|
768
|
+
raw: t[0],
|
|
769
|
+
text: t[0],
|
|
770
|
+
tokens: this.lexer.inline(t[0])
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
escape(e) {
|
|
774
|
+
let t = this.rules.inline.escape.exec(e);
|
|
775
|
+
if (t) return {
|
|
776
|
+
type: "escape",
|
|
777
|
+
raw: t[0],
|
|
778
|
+
text: t[1]
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
tag(e) {
|
|
782
|
+
let t = this.rules.inline.tag.exec(e);
|
|
783
|
+
if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = !1), {
|
|
784
|
+
type: "html",
|
|
785
|
+
raw: t[0],
|
|
786
|
+
inLink: this.lexer.state.inLink,
|
|
787
|
+
inRawBlock: this.lexer.state.inRawBlock,
|
|
788
|
+
block: !1,
|
|
789
|
+
text: t[0]
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
link(e) {
|
|
793
|
+
let t = this.rules.inline.link.exec(e);
|
|
794
|
+
if (t) {
|
|
795
|
+
let e = t[2].trim();
|
|
796
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(e)) {
|
|
797
|
+
if (!this.rules.other.endAngleBracket.test(e)) return;
|
|
798
|
+
let t = W(e.slice(0, -1), "\\");
|
|
799
|
+
if ((e.length - t.length) % 2 == 0) return;
|
|
800
|
+
} else {
|
|
801
|
+
let e = ke(t[2], "()");
|
|
802
|
+
if (e === -2) return;
|
|
803
|
+
if (e > -1) {
|
|
804
|
+
let n = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + e;
|
|
805
|
+
t[2] = t[2].substring(0, e), t[0] = t[0].substring(0, n).trim(), t[3] = "";
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
let n = t[2], r = "";
|
|
809
|
+
if (this.options.pedantic) {
|
|
810
|
+
let e = this.rules.other.pedanticHrefTitle.exec(n);
|
|
811
|
+
e && (n = e[1], r = e[3]);
|
|
812
|
+
} else r = t[3] ? t[3].slice(1, -1) : "";
|
|
813
|
+
return n = n.trim(), this.rules.other.startAngleBracket.test(n) && (n = this.options.pedantic && !this.rules.other.endAngleBracket.test(e) ? n.slice(1) : n.slice(1, -1)), G(t, {
|
|
814
|
+
href: n && n.replace(this.rules.inline.anyPunctuation, "$1"),
|
|
815
|
+
title: r && r.replace(this.rules.inline.anyPunctuation, "$1")
|
|
816
|
+
}, t[0], this.lexer, this.rules);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
reflink(e, t) {
|
|
820
|
+
let n;
|
|
821
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
822
|
+
let e = t[(n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " ").toLowerCase()];
|
|
823
|
+
if (!e) {
|
|
824
|
+
let e = n[0].charAt(0);
|
|
825
|
+
return {
|
|
826
|
+
type: "text",
|
|
827
|
+
raw: e,
|
|
828
|
+
text: e
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
return G(n, e, n[0], this.lexer, this.rules);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
emStrong(e, t, n = "") {
|
|
835
|
+
let r = this.rules.inline.emStrongLDelim.exec(e);
|
|
836
|
+
if (r && !(r[3] && n.match(this.rules.other.unicodeAlphaNumeric)) && (!(r[1] || r[2]) || !n || this.rules.inline.punctuation.exec(n))) {
|
|
837
|
+
let n = [...r[0]].length - 1, i, a, o = n, s = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
838
|
+
for (c.lastIndex = 0, t = t.slice(-1 * e.length + n); (r = c.exec(t)) != null;) {
|
|
839
|
+
if (i = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !i) continue;
|
|
840
|
+
if (a = [...i].length, r[3] || r[4]) {
|
|
841
|
+
o += a;
|
|
842
|
+
continue;
|
|
843
|
+
} else if ((r[5] || r[6]) && n % 3 && !((n + a) % 3)) {
|
|
844
|
+
s += a;
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
if (o -= a, o > 0) continue;
|
|
848
|
+
a = Math.min(a, a + o + s);
|
|
849
|
+
let t = [...r[0]][0].length, c = e.slice(0, n + r.index + t + a);
|
|
850
|
+
if (Math.min(n, a) % 2) {
|
|
851
|
+
let e = c.slice(1, -1);
|
|
852
|
+
return {
|
|
853
|
+
type: "em",
|
|
854
|
+
raw: c,
|
|
855
|
+
text: e,
|
|
856
|
+
tokens: this.lexer.inlineTokens(e)
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
let l = c.slice(2, -2);
|
|
860
|
+
return {
|
|
861
|
+
type: "strong",
|
|
862
|
+
raw: c,
|
|
863
|
+
text: l,
|
|
864
|
+
tokens: this.lexer.inlineTokens(l)
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
codespan(e) {
|
|
870
|
+
let t = this.rules.inline.code.exec(e);
|
|
871
|
+
if (t) {
|
|
872
|
+
let e = t[2].replace(this.rules.other.newLineCharGlobal, " "), n = this.rules.other.nonSpaceChar.test(e), r = this.rules.other.startingSpaceChar.test(e) && this.rules.other.endingSpaceChar.test(e);
|
|
873
|
+
return n && r && (e = e.substring(1, e.length - 1)), {
|
|
874
|
+
type: "codespan",
|
|
875
|
+
raw: t[0],
|
|
876
|
+
text: e
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
br(e) {
|
|
881
|
+
let t = this.rules.inline.br.exec(e);
|
|
882
|
+
if (t) return {
|
|
883
|
+
type: "br",
|
|
884
|
+
raw: t[0]
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
del(e) {
|
|
888
|
+
let t = this.rules.inline.del.exec(e);
|
|
889
|
+
if (t) return {
|
|
890
|
+
type: "del",
|
|
891
|
+
raw: t[0],
|
|
892
|
+
text: t[2],
|
|
893
|
+
tokens: this.lexer.inlineTokens(t[2])
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
autolink(e) {
|
|
897
|
+
let t = this.rules.inline.autolink.exec(e);
|
|
898
|
+
if (t) {
|
|
899
|
+
let e, n;
|
|
900
|
+
return t[2] === "@" ? (e = t[1], n = "mailto:" + e) : (e = t[1], n = e), {
|
|
901
|
+
type: "link",
|
|
902
|
+
raw: t[0],
|
|
903
|
+
text: e,
|
|
904
|
+
href: n,
|
|
905
|
+
tokens: [{
|
|
906
|
+
type: "text",
|
|
907
|
+
raw: e,
|
|
908
|
+
text: e
|
|
909
|
+
}]
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
url(e) {
|
|
914
|
+
let t;
|
|
915
|
+
if (t = this.rules.inline.url.exec(e)) {
|
|
916
|
+
let e, n;
|
|
917
|
+
if (t[2] === "@") e = t[0], n = "mailto:" + e;
|
|
918
|
+
else {
|
|
919
|
+
let r;
|
|
920
|
+
do
|
|
921
|
+
r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
|
|
922
|
+
while (r !== t[0]);
|
|
923
|
+
e = t[0], n = t[1] === "www." ? "http://" + t[0] : t[0];
|
|
924
|
+
}
|
|
925
|
+
return {
|
|
926
|
+
type: "link",
|
|
927
|
+
raw: t[0],
|
|
928
|
+
text: e,
|
|
929
|
+
href: n,
|
|
930
|
+
tokens: [{
|
|
931
|
+
type: "text",
|
|
932
|
+
raw: e,
|
|
933
|
+
text: e
|
|
934
|
+
}]
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
inlineText(e) {
|
|
939
|
+
let t = this.rules.inline.text.exec(e);
|
|
940
|
+
if (t) {
|
|
941
|
+
let e = this.lexer.state.inRawBlock;
|
|
942
|
+
return {
|
|
943
|
+
type: "text",
|
|
944
|
+
raw: t[0],
|
|
945
|
+
text: t[0],
|
|
946
|
+
escaped: e
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}, q = class e {
|
|
951
|
+
tokens;
|
|
952
|
+
options;
|
|
953
|
+
state;
|
|
954
|
+
tokenizer;
|
|
955
|
+
inlineQueue;
|
|
956
|
+
constructor(e) {
|
|
957
|
+
this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || c, this.options.tokenizer = this.options.tokenizer || new K(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
|
|
958
|
+
inLink: !1,
|
|
959
|
+
inRawBlock: !1,
|
|
960
|
+
top: !0
|
|
961
|
+
};
|
|
962
|
+
let t = {
|
|
963
|
+
other: f,
|
|
964
|
+
block: R.normal,
|
|
965
|
+
inline: z.normal
|
|
966
|
+
};
|
|
967
|
+
this.options.pedantic ? (t.block = R.pedantic, t.inline = z.pedantic) : this.options.gfm && (t.block = R.gfm, this.options.breaks ? t.inline = z.breaks : t.inline = z.gfm), this.tokenizer.rules = t;
|
|
968
|
+
}
|
|
969
|
+
static get rules() {
|
|
970
|
+
return {
|
|
971
|
+
block: R,
|
|
972
|
+
inline: z
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
static lex(t, n) {
|
|
976
|
+
return new e(n).lex(t);
|
|
977
|
+
}
|
|
978
|
+
static lexInline(t, n) {
|
|
979
|
+
return new e(n).inlineTokens(t);
|
|
980
|
+
}
|
|
981
|
+
lex(e) {
|
|
982
|
+
e = e.replace(f.carriageReturn, "\n"), this.blockTokens(e, this.tokens);
|
|
983
|
+
for (let e = 0; e < this.inlineQueue.length; e++) {
|
|
984
|
+
let t = this.inlineQueue[e];
|
|
985
|
+
this.inlineTokens(t.src, t.tokens);
|
|
986
|
+
}
|
|
987
|
+
return this.inlineQueue = [], this.tokens;
|
|
988
|
+
}
|
|
989
|
+
blockTokens(e, t = [], n = !1) {
|
|
990
|
+
for (this.options.pedantic && (e = e.replace(f.tabCharGlobal, " ").replace(f.spaceLine, "")); e;) {
|
|
991
|
+
let r;
|
|
992
|
+
if (this.options.extensions?.block?.some((n) => (r = n.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), !0) : !1)) continue;
|
|
993
|
+
if (r = this.tokenizer.space(e)) {
|
|
994
|
+
e = e.substring(r.raw.length);
|
|
995
|
+
let n = t.at(-1);
|
|
996
|
+
r.raw.length === 1 && n !== void 0 ? n.raw += "\n" : t.push(r);
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
if (r = this.tokenizer.code(e)) {
|
|
1000
|
+
e = e.substring(r.raw.length);
|
|
1001
|
+
let n = t.at(-1);
|
|
1002
|
+
n?.type === "paragraph" || n?.type === "text" ? (n.raw += "\n" + r.raw, n.text += "\n" + r.text, this.inlineQueue.at(-1).src = n.text) : t.push(r);
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
if (r = this.tokenizer.fences(e)) {
|
|
1006
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
if (r = this.tokenizer.heading(e)) {
|
|
1010
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
if (r = this.tokenizer.hr(e)) {
|
|
1014
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
if (r = this.tokenizer.blockquote(e)) {
|
|
1018
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
if (r = this.tokenizer.list(e)) {
|
|
1022
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
if (r = this.tokenizer.html(e)) {
|
|
1026
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
if (r = this.tokenizer.def(e)) {
|
|
1030
|
+
e = e.substring(r.raw.length);
|
|
1031
|
+
let n = t.at(-1);
|
|
1032
|
+
n?.type === "paragraph" || n?.type === "text" ? (n.raw += "\n" + r.raw, n.text += "\n" + r.raw, this.inlineQueue.at(-1).src = n.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = {
|
|
1033
|
+
href: r.href,
|
|
1034
|
+
title: r.title
|
|
1035
|
+
});
|
|
1036
|
+
continue;
|
|
1037
|
+
}
|
|
1038
|
+
if (r = this.tokenizer.table(e)) {
|
|
1039
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
if (r = this.tokenizer.lheading(e)) {
|
|
1043
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
let i = e;
|
|
1047
|
+
if (this.options.extensions?.startBlock) {
|
|
1048
|
+
let t = Infinity, n = e.slice(1), r;
|
|
1049
|
+
this.options.extensions.startBlock.forEach((e) => {
|
|
1050
|
+
r = e.call({ lexer: this }, n), typeof r == "number" && r >= 0 && (t = Math.min(t, r));
|
|
1051
|
+
}), t < Infinity && t >= 0 && (i = e.substring(0, t + 1));
|
|
1052
|
+
}
|
|
1053
|
+
if (this.state.top && (r = this.tokenizer.paragraph(i))) {
|
|
1054
|
+
let a = t.at(-1);
|
|
1055
|
+
n && a?.type === "paragraph" ? (a.raw += "\n" + r.raw, a.text += "\n" + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = a.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
if (r = this.tokenizer.text(e)) {
|
|
1059
|
+
e = e.substring(r.raw.length);
|
|
1060
|
+
let n = t.at(-1);
|
|
1061
|
+
n?.type === "text" ? (n.raw += "\n" + r.raw, n.text += "\n" + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = n.text) : t.push(r);
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
if (e) {
|
|
1065
|
+
let t = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
1066
|
+
if (this.options.silent) {
|
|
1067
|
+
console.error(t);
|
|
1068
|
+
break;
|
|
1069
|
+
} else throw Error(t);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return this.state.top = !0, t;
|
|
1073
|
+
}
|
|
1074
|
+
inline(e, t = []) {
|
|
1075
|
+
return this.inlineQueue.push({
|
|
1076
|
+
src: e,
|
|
1077
|
+
tokens: t
|
|
1078
|
+
}), t;
|
|
1079
|
+
}
|
|
1080
|
+
inlineTokens(e, t = []) {
|
|
1081
|
+
let n = e, r = null;
|
|
1082
|
+
if (this.tokens.links) {
|
|
1083
|
+
let e = Object.keys(this.tokens.links);
|
|
1084
|
+
if (e.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null;) e.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
|
|
1085
|
+
}
|
|
1086
|
+
for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null;) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
1087
|
+
for (; (r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null;) n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
1088
|
+
let i = !1, a = "";
|
|
1089
|
+
for (; e;) {
|
|
1090
|
+
i || (a = ""), i = !1;
|
|
1091
|
+
let r;
|
|
1092
|
+
if (this.options.extensions?.inline?.some((n) => (r = n.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), !0) : !1)) continue;
|
|
1093
|
+
if (r = this.tokenizer.escape(e)) {
|
|
1094
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
if (r = this.tokenizer.tag(e)) {
|
|
1098
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1099
|
+
continue;
|
|
1100
|
+
}
|
|
1101
|
+
if (r = this.tokenizer.link(e)) {
|
|
1102
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
if (r = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
1106
|
+
e = e.substring(r.raw.length);
|
|
1107
|
+
let n = t.at(-1);
|
|
1108
|
+
r.type === "text" && n?.type === "text" ? (n.raw += r.raw, n.text += r.text) : t.push(r);
|
|
1109
|
+
continue;
|
|
1110
|
+
}
|
|
1111
|
+
if (r = this.tokenizer.emStrong(e, n, a)) {
|
|
1112
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
if (r = this.tokenizer.codespan(e)) {
|
|
1116
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
if (r = this.tokenizer.br(e)) {
|
|
1120
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
if (r = this.tokenizer.del(e)) {
|
|
1124
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1127
|
+
if (r = this.tokenizer.autolink(e)) {
|
|
1128
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1129
|
+
continue;
|
|
1130
|
+
}
|
|
1131
|
+
if (!this.state.inLink && (r = this.tokenizer.url(e))) {
|
|
1132
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
1133
|
+
continue;
|
|
1134
|
+
}
|
|
1135
|
+
let o = e;
|
|
1136
|
+
if (this.options.extensions?.startInline) {
|
|
1137
|
+
let t = Infinity, n = e.slice(1), r;
|
|
1138
|
+
this.options.extensions.startInline.forEach((e) => {
|
|
1139
|
+
r = e.call({ lexer: this }, n), typeof r == "number" && r >= 0 && (t = Math.min(t, r));
|
|
1140
|
+
}), t < Infinity && t >= 0 && (o = e.substring(0, t + 1));
|
|
1141
|
+
}
|
|
1142
|
+
if (r = this.tokenizer.inlineText(o)) {
|
|
1143
|
+
e = e.substring(r.raw.length), r.raw.slice(-1) !== "_" && (a = r.raw.slice(-1)), i = !0;
|
|
1144
|
+
let n = t.at(-1);
|
|
1145
|
+
n?.type === "text" ? (n.raw += r.raw, n.text += r.text) : t.push(r);
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (e) {
|
|
1149
|
+
let t = "Infinite loop on byte: " + e.charCodeAt(0);
|
|
1150
|
+
if (this.options.silent) {
|
|
1151
|
+
console.error(t);
|
|
1152
|
+
break;
|
|
1153
|
+
} else throw Error(t);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return t;
|
|
1157
|
+
}
|
|
1158
|
+
}, J = class {
|
|
1159
|
+
options;
|
|
1160
|
+
parser;
|
|
1161
|
+
constructor(e) {
|
|
1162
|
+
this.options = e || c;
|
|
1163
|
+
}
|
|
1164
|
+
space(e) {
|
|
1165
|
+
return "";
|
|
1166
|
+
}
|
|
1167
|
+
code({ text: e, lang: t, escaped: n }) {
|
|
1168
|
+
let r = (t || "").match(f.notSpaceStart)?.[0], i = e.replace(f.endingNewline, "") + "\n";
|
|
1169
|
+
return r ? "<pre><code class=\"language-" + V(r) + "\">" + (n ? i : V(i, !0)) + "</code></pre>\n" : "<pre><code>" + (n ? i : V(i, !0)) + "</code></pre>\n";
|
|
1170
|
+
}
|
|
1171
|
+
blockquote({ tokens: e }) {
|
|
1172
|
+
return `<blockquote>
|
|
1173
|
+
${this.parser.parse(e)}</blockquote>
|
|
1174
|
+
`;
|
|
1175
|
+
}
|
|
1176
|
+
html({ text: e }) {
|
|
1177
|
+
return e;
|
|
1178
|
+
}
|
|
1179
|
+
heading({ tokens: e, depth: t }) {
|
|
1180
|
+
return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
1181
|
+
`;
|
|
1182
|
+
}
|
|
1183
|
+
hr(e) {
|
|
1184
|
+
return "<hr>\n";
|
|
1185
|
+
}
|
|
1186
|
+
list(e) {
|
|
1187
|
+
let t = e.ordered, n = e.start, r = "";
|
|
1188
|
+
for (let t = 0; t < e.items.length; t++) {
|
|
1189
|
+
let n = e.items[t];
|
|
1190
|
+
r += this.listitem(n);
|
|
1191
|
+
}
|
|
1192
|
+
let i = t ? "ol" : "ul", a = t && n !== 1 ? " start=\"" + n + "\"" : "";
|
|
1193
|
+
return "<" + i + a + ">\n" + r + "</" + i + ">\n";
|
|
1194
|
+
}
|
|
1195
|
+
listitem(e) {
|
|
1196
|
+
let t = "";
|
|
1197
|
+
if (e.task) {
|
|
1198
|
+
let n = this.checkbox({ checked: !!e.checked });
|
|
1199
|
+
e.loose ? e.tokens[0]?.type === "paragraph" ? (e.tokens[0].text = n + " " + e.tokens[0].text, e.tokens[0].tokens && e.tokens[0].tokens.length > 0 && e.tokens[0].tokens[0].type === "text" && (e.tokens[0].tokens[0].text = n + " " + V(e.tokens[0].tokens[0].text), e.tokens[0].tokens[0].escaped = !0)) : e.tokens.unshift({
|
|
1200
|
+
type: "text",
|
|
1201
|
+
raw: n + " ",
|
|
1202
|
+
text: n + " ",
|
|
1203
|
+
escaped: !0
|
|
1204
|
+
}) : t += n + " ";
|
|
1205
|
+
}
|
|
1206
|
+
return t += this.parser.parse(e.tokens, !!e.loose), `<li>${t}</li>
|
|
1207
|
+
`;
|
|
1208
|
+
}
|
|
1209
|
+
checkbox({ checked: e }) {
|
|
1210
|
+
return "<input " + (e ? "checked=\"\" " : "") + "disabled=\"\" type=\"checkbox\">";
|
|
1211
|
+
}
|
|
1212
|
+
paragraph({ tokens: e }) {
|
|
1213
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
1214
|
+
`;
|
|
1215
|
+
}
|
|
1216
|
+
table(e) {
|
|
1217
|
+
let t = "", n = "";
|
|
1218
|
+
for (let t = 0; t < e.header.length; t++) n += this.tablecell(e.header[t]);
|
|
1219
|
+
t += this.tablerow({ text: n });
|
|
1220
|
+
let r = "";
|
|
1221
|
+
for (let t = 0; t < e.rows.length; t++) {
|
|
1222
|
+
let i = e.rows[t];
|
|
1223
|
+
n = "";
|
|
1224
|
+
for (let e = 0; e < i.length; e++) n += this.tablecell(i[e]);
|
|
1225
|
+
r += this.tablerow({ text: n });
|
|
1226
|
+
}
|
|
1227
|
+
return r &&= `<tbody>${r}</tbody>`, "<table>\n<thead>\n" + t + "</thead>\n" + r + "</table>\n";
|
|
1228
|
+
}
|
|
1229
|
+
tablerow({ text: e }) {
|
|
1230
|
+
return `<tr>
|
|
1231
|
+
${e}</tr>
|
|
1232
|
+
`;
|
|
1233
|
+
}
|
|
1234
|
+
tablecell(e) {
|
|
1235
|
+
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
1236
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
1237
|
+
`;
|
|
1238
|
+
}
|
|
1239
|
+
strong({ tokens: e }) {
|
|
1240
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
1241
|
+
}
|
|
1242
|
+
em({ tokens: e }) {
|
|
1243
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
1244
|
+
}
|
|
1245
|
+
codespan({ text: e }) {
|
|
1246
|
+
return `<code>${V(e, !0)}</code>`;
|
|
1247
|
+
}
|
|
1248
|
+
br(e) {
|
|
1249
|
+
return "<br>";
|
|
1250
|
+
}
|
|
1251
|
+
del({ tokens: e }) {
|
|
1252
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
1253
|
+
}
|
|
1254
|
+
link({ href: e, title: t, tokens: n }) {
|
|
1255
|
+
let r = this.parser.parseInline(n), i = H(e);
|
|
1256
|
+
if (i === null) return r;
|
|
1257
|
+
e = i;
|
|
1258
|
+
let a = "<a href=\"" + e + "\"";
|
|
1259
|
+
return t && (a += " title=\"" + V(t) + "\""), a += ">" + r + "</a>", a;
|
|
1260
|
+
}
|
|
1261
|
+
image({ href: e, title: t, text: n, tokens: r }) {
|
|
1262
|
+
r && (n = this.parser.parseInline(r, this.parser.textRenderer));
|
|
1263
|
+
let i = H(e);
|
|
1264
|
+
if (i === null) return V(n);
|
|
1265
|
+
e = i;
|
|
1266
|
+
let a = `<img src="${e}" alt="${n}"`;
|
|
1267
|
+
return t && (a += ` title="${V(t)}"`), a += ">", a;
|
|
1268
|
+
}
|
|
1269
|
+
text(e) {
|
|
1270
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : V(e.text);
|
|
1271
|
+
}
|
|
1272
|
+
}, Y = class {
|
|
1273
|
+
strong({ text: e }) {
|
|
1274
|
+
return e;
|
|
1275
|
+
}
|
|
1276
|
+
em({ text: e }) {
|
|
1277
|
+
return e;
|
|
1278
|
+
}
|
|
1279
|
+
codespan({ text: e }) {
|
|
1280
|
+
return e;
|
|
1281
|
+
}
|
|
1282
|
+
del({ text: e }) {
|
|
1283
|
+
return e;
|
|
1284
|
+
}
|
|
1285
|
+
html({ text: e }) {
|
|
1286
|
+
return e;
|
|
1287
|
+
}
|
|
1288
|
+
text({ text: e }) {
|
|
1289
|
+
return e;
|
|
1290
|
+
}
|
|
1291
|
+
link({ text: e }) {
|
|
1292
|
+
return "" + e;
|
|
1293
|
+
}
|
|
1294
|
+
image({ text: e }) {
|
|
1295
|
+
return "" + e;
|
|
1296
|
+
}
|
|
1297
|
+
br() {
|
|
1298
|
+
return "";
|
|
1299
|
+
}
|
|
1300
|
+
}, X = class e {
|
|
1301
|
+
options;
|
|
1302
|
+
renderer;
|
|
1303
|
+
textRenderer;
|
|
1304
|
+
constructor(e) {
|
|
1305
|
+
this.options = e || c, this.options.renderer = this.options.renderer || new J(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new Y();
|
|
1306
|
+
}
|
|
1307
|
+
static parse(t, n) {
|
|
1308
|
+
return new e(n).parse(t);
|
|
1309
|
+
}
|
|
1310
|
+
static parseInline(t, n) {
|
|
1311
|
+
return new e(n).parseInline(t);
|
|
1312
|
+
}
|
|
1313
|
+
parse(e, t = !0) {
|
|
1314
|
+
let n = "";
|
|
1315
|
+
for (let r = 0; r < e.length; r++) {
|
|
1316
|
+
let i = e[r];
|
|
1317
|
+
if (this.options.extensions?.renderers?.[i.type]) {
|
|
1318
|
+
let e = i, t = this.options.extensions.renderers[e.type].call({ parser: this }, e);
|
|
1319
|
+
if (t !== !1 || ![
|
|
1320
|
+
"space",
|
|
1321
|
+
"hr",
|
|
1322
|
+
"heading",
|
|
1323
|
+
"code",
|
|
1324
|
+
"table",
|
|
1325
|
+
"blockquote",
|
|
1326
|
+
"list",
|
|
1327
|
+
"html",
|
|
1328
|
+
"paragraph",
|
|
1329
|
+
"text"
|
|
1330
|
+
].includes(e.type)) {
|
|
1331
|
+
n += t || "";
|
|
1332
|
+
continue;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
let a = i;
|
|
1336
|
+
switch (a.type) {
|
|
1337
|
+
case "space":
|
|
1338
|
+
n += this.renderer.space(a);
|
|
1339
|
+
continue;
|
|
1340
|
+
case "hr":
|
|
1341
|
+
n += this.renderer.hr(a);
|
|
1342
|
+
continue;
|
|
1343
|
+
case "heading":
|
|
1344
|
+
n += this.renderer.heading(a);
|
|
1345
|
+
continue;
|
|
1346
|
+
case "code":
|
|
1347
|
+
n += this.renderer.code(a);
|
|
1348
|
+
continue;
|
|
1349
|
+
case "table":
|
|
1350
|
+
n += this.renderer.table(a);
|
|
1351
|
+
continue;
|
|
1352
|
+
case "blockquote":
|
|
1353
|
+
n += this.renderer.blockquote(a);
|
|
1354
|
+
continue;
|
|
1355
|
+
case "list":
|
|
1356
|
+
n += this.renderer.list(a);
|
|
1357
|
+
continue;
|
|
1358
|
+
case "html":
|
|
1359
|
+
n += this.renderer.html(a);
|
|
1360
|
+
continue;
|
|
1361
|
+
case "paragraph":
|
|
1362
|
+
n += this.renderer.paragraph(a);
|
|
1363
|
+
continue;
|
|
1364
|
+
case "text": {
|
|
1365
|
+
let i = a, o = this.renderer.text(i);
|
|
1366
|
+
for (; r + 1 < e.length && e[r + 1].type === "text";) i = e[++r], o += "\n" + this.renderer.text(i);
|
|
1367
|
+
t ? n += this.renderer.paragraph({
|
|
1368
|
+
type: "paragraph",
|
|
1369
|
+
raw: o,
|
|
1370
|
+
text: o,
|
|
1371
|
+
tokens: [{
|
|
1372
|
+
type: "text",
|
|
1373
|
+
raw: o,
|
|
1374
|
+
text: o,
|
|
1375
|
+
escaped: !0
|
|
1376
|
+
}]
|
|
1377
|
+
}) : n += o;
|
|
1378
|
+
continue;
|
|
1379
|
+
}
|
|
1380
|
+
default: {
|
|
1381
|
+
let e = "Token with \"" + a.type + "\" type was not found.";
|
|
1382
|
+
if (this.options.silent) return console.error(e), "";
|
|
1383
|
+
throw Error(e);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
return n;
|
|
1388
|
+
}
|
|
1389
|
+
parseInline(e, t = this.renderer) {
|
|
1390
|
+
let n = "";
|
|
1391
|
+
for (let r = 0; r < e.length; r++) {
|
|
1392
|
+
let i = e[r];
|
|
1393
|
+
if (this.options.extensions?.renderers?.[i.type]) {
|
|
1394
|
+
let e = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
1395
|
+
if (e !== !1 || ![
|
|
1396
|
+
"escape",
|
|
1397
|
+
"html",
|
|
1398
|
+
"link",
|
|
1399
|
+
"image",
|
|
1400
|
+
"strong",
|
|
1401
|
+
"em",
|
|
1402
|
+
"codespan",
|
|
1403
|
+
"br",
|
|
1404
|
+
"del",
|
|
1405
|
+
"text"
|
|
1406
|
+
].includes(i.type)) {
|
|
1407
|
+
n += e || "";
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
let a = i;
|
|
1412
|
+
switch (a.type) {
|
|
1413
|
+
case "escape":
|
|
1414
|
+
n += t.text(a);
|
|
1415
|
+
break;
|
|
1416
|
+
case "html":
|
|
1417
|
+
n += t.html(a);
|
|
1418
|
+
break;
|
|
1419
|
+
case "link":
|
|
1420
|
+
n += t.link(a);
|
|
1421
|
+
break;
|
|
1422
|
+
case "image":
|
|
1423
|
+
n += t.image(a);
|
|
1424
|
+
break;
|
|
1425
|
+
case "strong":
|
|
1426
|
+
n += t.strong(a);
|
|
1427
|
+
break;
|
|
1428
|
+
case "em":
|
|
1429
|
+
n += t.em(a);
|
|
1430
|
+
break;
|
|
1431
|
+
case "codespan":
|
|
1432
|
+
n += t.codespan(a);
|
|
1433
|
+
break;
|
|
1434
|
+
case "br":
|
|
1435
|
+
n += t.br(a);
|
|
1436
|
+
break;
|
|
1437
|
+
case "del":
|
|
1438
|
+
n += t.del(a);
|
|
1439
|
+
break;
|
|
1440
|
+
case "text":
|
|
1441
|
+
n += t.text(a);
|
|
1442
|
+
break;
|
|
1443
|
+
default: {
|
|
1444
|
+
let e = "Token with \"" + a.type + "\" type was not found.";
|
|
1445
|
+
if (this.options.silent) return console.error(e), "";
|
|
1446
|
+
throw Error(e);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return n;
|
|
1451
|
+
}
|
|
1452
|
+
}, Z = class {
|
|
1453
|
+
options;
|
|
1454
|
+
block;
|
|
1455
|
+
constructor(e) {
|
|
1456
|
+
this.options = e || c;
|
|
1457
|
+
}
|
|
1458
|
+
static passThroughHooks = /* @__PURE__ */ new Set([
|
|
1459
|
+
"preprocess",
|
|
1460
|
+
"postprocess",
|
|
1461
|
+
"processAllTokens"
|
|
1462
|
+
]);
|
|
1463
|
+
preprocess(e) {
|
|
1464
|
+
return e;
|
|
1465
|
+
}
|
|
1466
|
+
postprocess(e) {
|
|
1467
|
+
return e;
|
|
1468
|
+
}
|
|
1469
|
+
processAllTokens(e) {
|
|
1470
|
+
return e;
|
|
1471
|
+
}
|
|
1472
|
+
provideLexer() {
|
|
1473
|
+
return this.block ? q.lex : q.lexInline;
|
|
1474
|
+
}
|
|
1475
|
+
provideParser() {
|
|
1476
|
+
return this.block ? X.parse : X.parseInline;
|
|
1477
|
+
}
|
|
1478
|
+
}, Q = new class {
|
|
1479
|
+
defaults = s();
|
|
1480
|
+
options = this.setOptions;
|
|
1481
|
+
parse = this.parseMarkdown(!0);
|
|
1482
|
+
parseInline = this.parseMarkdown(!1);
|
|
1483
|
+
Parser = X;
|
|
1484
|
+
Renderer = J;
|
|
1485
|
+
TextRenderer = Y;
|
|
1486
|
+
Lexer = q;
|
|
1487
|
+
Tokenizer = K;
|
|
1488
|
+
Hooks = Z;
|
|
1489
|
+
constructor(...e) {
|
|
1490
|
+
this.use(...e);
|
|
1491
|
+
}
|
|
1492
|
+
walkTokens(e, t) {
|
|
1493
|
+
let n = [];
|
|
1494
|
+
for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
|
|
1495
|
+
case "table": {
|
|
1496
|
+
let e = r;
|
|
1497
|
+
for (let r of e.header) n = n.concat(this.walkTokens(r.tokens, t));
|
|
1498
|
+
for (let r of e.rows) for (let e of r) n = n.concat(this.walkTokens(e.tokens, t));
|
|
1499
|
+
break;
|
|
1500
|
+
}
|
|
1501
|
+
case "list": {
|
|
1502
|
+
let e = r;
|
|
1503
|
+
n = n.concat(this.walkTokens(e.items, t));
|
|
1504
|
+
break;
|
|
1505
|
+
}
|
|
1506
|
+
default: {
|
|
1507
|
+
let e = r;
|
|
1508
|
+
this.defaults.extensions?.childTokens?.[e.type] ? this.defaults.extensions.childTokens[e.type].forEach((r) => {
|
|
1509
|
+
let i = e[r].flat(Infinity);
|
|
1510
|
+
n = n.concat(this.walkTokens(i, t));
|
|
1511
|
+
}) : e.tokens && (n = n.concat(this.walkTokens(e.tokens, t)));
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return n;
|
|
1515
|
+
}
|
|
1516
|
+
use(...e) {
|
|
1517
|
+
let t = this.defaults.extensions || {
|
|
1518
|
+
renderers: {},
|
|
1519
|
+
childTokens: {}
|
|
1520
|
+
};
|
|
1521
|
+
return e.forEach((e) => {
|
|
1522
|
+
let n = { ...e };
|
|
1523
|
+
if (n.async = this.defaults.async || n.async || !1, e.extensions && (e.extensions.forEach((e) => {
|
|
1524
|
+
if (!e.name) throw Error("extension name required");
|
|
1525
|
+
if ("renderer" in e) {
|
|
1526
|
+
let n = t.renderers[e.name];
|
|
1527
|
+
n ? t.renderers[e.name] = function(...t) {
|
|
1528
|
+
let r = e.renderer.apply(this, t);
|
|
1529
|
+
return r === !1 && (r = n.apply(this, t)), r;
|
|
1530
|
+
} : t.renderers[e.name] = e.renderer;
|
|
1531
|
+
}
|
|
1532
|
+
if ("tokenizer" in e) {
|
|
1533
|
+
if (!e.level || e.level !== "block" && e.level !== "inline") throw Error("extension level must be 'block' or 'inline'");
|
|
1534
|
+
let n = t[e.level];
|
|
1535
|
+
n ? n.unshift(e.tokenizer) : t[e.level] = [e.tokenizer], e.start && (e.level === "block" ? t.startBlock ? t.startBlock.push(e.start) : t.startBlock = [e.start] : e.level === "inline" && (t.startInline ? t.startInline.push(e.start) : t.startInline = [e.start]));
|
|
1536
|
+
}
|
|
1537
|
+
"childTokens" in e && e.childTokens && (t.childTokens[e.name] = e.childTokens);
|
|
1538
|
+
}), n.extensions = t), e.renderer) {
|
|
1539
|
+
let t = this.defaults.renderer || new J(this.defaults);
|
|
1540
|
+
for (let n in e.renderer) {
|
|
1541
|
+
if (!(n in t)) throw Error(`renderer '${n}' does not exist`);
|
|
1542
|
+
if (["options", "parser"].includes(n)) continue;
|
|
1543
|
+
let r = n, i = e.renderer[r], a = t[r];
|
|
1544
|
+
t[r] = (...e) => {
|
|
1545
|
+
let n = i.apply(t, e);
|
|
1546
|
+
return n === !1 && (n = a.apply(t, e)), n || "";
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
n.renderer = t;
|
|
1550
|
+
}
|
|
1551
|
+
if (e.tokenizer) {
|
|
1552
|
+
let t = this.defaults.tokenizer || new K(this.defaults);
|
|
1553
|
+
for (let n in e.tokenizer) {
|
|
1554
|
+
if (!(n in t)) throw Error(`tokenizer '${n}' does not exist`);
|
|
1555
|
+
if ([
|
|
1556
|
+
"options",
|
|
1557
|
+
"rules",
|
|
1558
|
+
"lexer"
|
|
1559
|
+
].includes(n)) continue;
|
|
1560
|
+
let r = n, i = e.tokenizer[r], a = t[r];
|
|
1561
|
+
t[r] = (...e) => {
|
|
1562
|
+
let n = i.apply(t, e);
|
|
1563
|
+
return n === !1 && (n = a.apply(t, e)), n;
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
n.tokenizer = t;
|
|
1567
|
+
}
|
|
1568
|
+
if (e.hooks) {
|
|
1569
|
+
let t = this.defaults.hooks || new Z();
|
|
1570
|
+
for (let n in e.hooks) {
|
|
1571
|
+
if (!(n in t)) throw Error(`hook '${n}' does not exist`);
|
|
1572
|
+
if (["options", "block"].includes(n)) continue;
|
|
1573
|
+
let r = n, i = e.hooks[r], a = t[r];
|
|
1574
|
+
Z.passThroughHooks.has(n) ? t[r] = (e) => {
|
|
1575
|
+
if (this.defaults.async) return Promise.resolve(i.call(t, e)).then((e) => a.call(t, e));
|
|
1576
|
+
let n = i.call(t, e);
|
|
1577
|
+
return a.call(t, n);
|
|
1578
|
+
} : t[r] = (...e) => {
|
|
1579
|
+
let n = i.apply(t, e);
|
|
1580
|
+
return n === !1 && (n = a.apply(t, e)), n;
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
n.hooks = t;
|
|
1584
|
+
}
|
|
1585
|
+
if (e.walkTokens) {
|
|
1586
|
+
let t = this.defaults.walkTokens, r = e.walkTokens;
|
|
1587
|
+
n.walkTokens = function(e) {
|
|
1588
|
+
let n = [];
|
|
1589
|
+
return n.push(r.call(this, e)), t && (n = n.concat(t.call(this, e))), n;
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
this.defaults = {
|
|
1593
|
+
...this.defaults,
|
|
1594
|
+
...n
|
|
1595
|
+
};
|
|
1596
|
+
}), this;
|
|
1597
|
+
}
|
|
1598
|
+
setOptions(e) {
|
|
1599
|
+
return this.defaults = {
|
|
1600
|
+
...this.defaults,
|
|
1601
|
+
...e
|
|
1602
|
+
}, this;
|
|
1603
|
+
}
|
|
1604
|
+
lexer(e, t) {
|
|
1605
|
+
return q.lex(e, t ?? this.defaults);
|
|
1606
|
+
}
|
|
1607
|
+
parser(e, t) {
|
|
1608
|
+
return X.parse(e, t ?? this.defaults);
|
|
1609
|
+
}
|
|
1610
|
+
parseMarkdown(e) {
|
|
1611
|
+
return (t, n) => {
|
|
1612
|
+
let r = { ...n }, i = {
|
|
1613
|
+
...this.defaults,
|
|
1614
|
+
...r
|
|
1615
|
+
}, a = this.onError(!!i.silent, !!i.async);
|
|
1616
|
+
if (this.defaults.async === !0 && r.async === !1) return a(/* @__PURE__ */ Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
1617
|
+
if (t == null) return a(/* @__PURE__ */ Error("marked(): input parameter is undefined or null"));
|
|
1618
|
+
if (typeof t != "string") return a(/* @__PURE__ */ Error("marked(): input parameter is of type " + Object.prototype.toString.call(t) + ", string expected"));
|
|
1619
|
+
i.hooks && (i.hooks.options = i, i.hooks.block = e);
|
|
1620
|
+
let o = i.hooks ? i.hooks.provideLexer() : e ? q.lex : q.lexInline, s = i.hooks ? i.hooks.provideParser() : e ? X.parse : X.parseInline;
|
|
1621
|
+
if (i.async) return Promise.resolve(i.hooks ? i.hooks.preprocess(t) : t).then((e) => o(e, i)).then((e) => i.hooks ? i.hooks.processAllTokens(e) : e).then((e) => i.walkTokens ? Promise.all(this.walkTokens(e, i.walkTokens)).then(() => e) : e).then((e) => s(e, i)).then((e) => i.hooks ? i.hooks.postprocess(e) : e).catch(a);
|
|
1622
|
+
try {
|
|
1623
|
+
i.hooks && (t = i.hooks.preprocess(t));
|
|
1624
|
+
let e = o(t, i);
|
|
1625
|
+
i.hooks && (e = i.hooks.processAllTokens(e)), i.walkTokens && this.walkTokens(e, i.walkTokens);
|
|
1626
|
+
let n = s(e, i);
|
|
1627
|
+
return i.hooks && (n = i.hooks.postprocess(n)), n;
|
|
1628
|
+
} catch (e) {
|
|
1629
|
+
return a(e);
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
onError(e, t) {
|
|
1634
|
+
return (n) => {
|
|
1635
|
+
if (n.message += "\nPlease report this to https://github.com/markedjs/marked.", e) {
|
|
1636
|
+
let e = "<p>An error occurred:</p><pre>" + V(n.message + "", !0) + "</pre>";
|
|
1637
|
+
return t ? Promise.resolve(e) : e;
|
|
1638
|
+
}
|
|
1639
|
+
if (t) return Promise.reject(n);
|
|
1640
|
+
throw n;
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
}();
|
|
1644
|
+
function $(e, t) {
|
|
1645
|
+
return Q.parse(e, t);
|
|
1646
|
+
}
|
|
1647
|
+
$.options = $.setOptions = function(e) {
|
|
1648
|
+
return Q.setOptions(e), $.defaults = Q.defaults, l($.defaults), $;
|
|
1649
|
+
}, $.getDefaults = s, $.defaults = c, $.use = function(...e) {
|
|
1650
|
+
return Q.use(...e), $.defaults = Q.defaults, l($.defaults), $;
|
|
1651
|
+
}, $.walkTokens = function(e, t) {
|
|
1652
|
+
return Q.walkTokens(e, t);
|
|
1653
|
+
}, $.parseInline = Q.parseInline, $.Parser = X, $.parser = X.parse, $.Renderer = J, $.TextRenderer = Y, $.Lexer = q, $.lexer = q.lex, $.Tokenizer = K, $.Hooks = Z, $.parse = $, $.options, $.setOptions, $.use, $.walkTokens, $.parseInline, X.parse, q.lex;
|
|
1654
|
+
//#endregion
|
|
1655
|
+
//#region src/markdown/renderer.ts
|
|
1656
|
+
function je(e, t) {
|
|
1657
|
+
return $.parse(e, {
|
|
1658
|
+
breaks: !0,
|
|
1659
|
+
gfm: !0
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
//#endregion
|
|
1663
|
+
export { r as AiHelperApiClient, t as AiHelperConfigManager, i as AiHelperStateManager, n as configManager, a as detectTheme, o as onThemeChange, je as renderMarkdown };
|