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