@opentiny/webmcp-cli 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,2188 @@
1
1
  ;(function(){
2
2
  "use strict";
3
3
  (() => {
4
+ // ../../node_modules/.pnpm/marked@15.0.12/node_modules/marked/lib/marked.esm.js
5
+ function _getDefaults() {
6
+ return {
7
+ async: false,
8
+ breaks: false,
9
+ extensions: null,
10
+ gfm: true,
11
+ hooks: null,
12
+ pedantic: false,
13
+ renderer: null,
14
+ silent: false,
15
+ tokenizer: null,
16
+ walkTokens: null
17
+ };
18
+ }
19
+ var _defaults = _getDefaults();
20
+ function changeDefaults(newDefaults) {
21
+ _defaults = newDefaults;
22
+ }
23
+ var noopTest = { exec: () => null };
24
+ function edit(regex, opt = "") {
25
+ let source = typeof regex === "string" ? regex : regex.source;
26
+ const obj = {
27
+ replace: (name, val) => {
28
+ let valSource = typeof val === "string" ? val : val.source;
29
+ valSource = valSource.replace(other.caret, "$1");
30
+ source = source.replace(name, valSource);
31
+ return obj;
32
+ },
33
+ getRegex: () => {
34
+ return new RegExp(source, opt);
35
+ }
36
+ };
37
+ return obj;
38
+ }
39
+ var other = {
40
+ codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
41
+ outputLinkReplace: /\\([\[\]])/g,
42
+ indentCodeCompensation: /^(\s+)(?:```)/,
43
+ beginningSpace: /^\s+/,
44
+ endingHash: /#$/,
45
+ startingSpaceChar: /^ /,
46
+ endingSpaceChar: / $/,
47
+ nonSpaceChar: /[^ ]/,
48
+ newLineCharGlobal: /\n/g,
49
+ tabCharGlobal: /\t/g,
50
+ multipleSpaceGlobal: /\s+/g,
51
+ blankLine: /^[ \t]*$/,
52
+ doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
53
+ blockquoteStart: /^ {0,3}>/,
54
+ blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
55
+ blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
56
+ listReplaceTabs: /^\t+/,
57
+ listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
58
+ listIsTask: /^\[[ xX]\] /,
59
+ listReplaceTask: /^\[[ xX]\] +/,
60
+ anyLine: /\n.*\n/,
61
+ hrefBrackets: /^<(.*)>$/,
62
+ tableDelimiter: /[:|]/,
63
+ tableAlignChars: /^\||\| *$/g,
64
+ tableRowBlankLine: /\n[ \t]*$/,
65
+ tableAlignRight: /^ *-+: *$/,
66
+ tableAlignCenter: /^ *:-+: *$/,
67
+ tableAlignLeft: /^ *:-+ *$/,
68
+ startATag: /^<a /i,
69
+ endATag: /^<\/a>/i,
70
+ startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
71
+ endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
72
+ startAngleBracket: /^</,
73
+ endAngleBracket: />$/,
74
+ pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
75
+ unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
76
+ escapeTest: /[&<>"']/,
77
+ escapeReplace: /[&<>"']/g,
78
+ escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
79
+ escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
80
+ unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
81
+ caret: /(^|[^\[])\^/g,
82
+ percentDecode: /%25/g,
83
+ findPipe: /\|/g,
84
+ splitPipe: / \|/,
85
+ slashPipe: /\\\|/g,
86
+ carriageReturn: /\r\n|\r/g,
87
+ spaceLine: /^ +$/gm,
88
+ notSpaceStart: /^\S*/,
89
+ endingNewline: /\n$/,
90
+ listItemRegex: (bull) => new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`),
91
+ nextBulletRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
92
+ hrRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
93
+ fencesBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`),
94
+ headingBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`),
95
+ htmlBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}<(?:[a-z].*>|!--)`, "i")
96
+ };
97
+ var newline = /^(?:[ \t]*(?:\n|$))+/;
98
+ var blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
99
+ var fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
100
+ var hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
101
+ var heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
102
+ var bullet = /(?:[*+-]|\d{1,9}[.)])/;
103
+ var lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
104
+ var lheading = edit(lheadingCore).replace(/bull/g, bullet).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();
105
+ var lheadingGfm = edit(lheadingCore).replace(/bull/g, bullet).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();
106
+ var _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
107
+ var blockText = /^[^\n]+/;
108
+ var _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
109
+ var def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", _blockLabel).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
110
+ var list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
111
+ var _tag = "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";
112
+ var _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
113
+ var html = edit(
114
+ "^ {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|$))",
115
+ "i"
116
+ ).replace("comment", _comment).replace("tag", _tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
117
+ var paragraph = edit(_paragraph).replace("hr", hr).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", _tag).getRegex();
118
+ var blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", paragraph).getRegex();
119
+ var blockNormal = {
120
+ blockquote,
121
+ code: blockCode,
122
+ def,
123
+ fences,
124
+ heading,
125
+ hr,
126
+ html,
127
+ lheading,
128
+ list,
129
+ newline,
130
+ paragraph,
131
+ table: noopTest,
132
+ text: blockText
133
+ };
134
+ var gfmTable = edit(
135
+ "^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
136
+ ).replace("hr", hr).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", _tag).getRegex();
137
+ var blockGfm = {
138
+ ...blockNormal,
139
+ lheading: lheadingGfm,
140
+ table: gfmTable,
141
+ paragraph: edit(_paragraph).replace("hr", hr).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", gfmTable).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", _tag).getRegex()
142
+ };
143
+ var blockPedantic = {
144
+ ...blockNormal,
145
+ html: edit(
146
+ `^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
147
+ ).replace("comment", _comment).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(),
148
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
149
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
150
+ fences: noopTest,
151
+ // fences not supported
152
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
153
+ paragraph: edit(_paragraph).replace("hr", hr).replace("heading", " *#{1,6} *[^\n]").replace("lheading", lheading).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
154
+ };
155
+ var escape2 = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
156
+ var inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
157
+ var br = /^( {2,}|\\)\n(?!\s*$)/;
158
+ var inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
159
+ var _punctuation = /[\p{P}\p{S}]/u;
160
+ var _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
161
+ var _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
162
+ var punctuation = edit(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, _punctuationOrSpace).getRegex();
163
+ var _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
164
+ var _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
165
+ var _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
166
+ var blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
167
+ var emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
168
+ var emStrongLDelim = edit(emStrongLDelimCore, "u").replace(/punct/g, _punctuation).getRegex();
169
+ var emStrongLDelimGfm = edit(emStrongLDelimCore, "u").replace(/punct/g, _punctuationGfmStrongEm).getRegex();
170
+ var emStrongRDelimAstCore = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
171
+ var emStrongRDelimAst = edit(emStrongRDelimAstCore, "gu").replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
172
+ var emStrongRDelimAstGfm = edit(emStrongRDelimAstCore, "gu").replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmStrongEm).replace(/punctSpace/g, _punctuationOrSpaceGfmStrongEm).replace(/punct/g, _punctuationGfmStrongEm).getRegex();
173
+ var emStrongRDelimUnd = edit(
174
+ "^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)",
175
+ "gu"
176
+ ).replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
177
+ var anyPunctuation = edit(/\\(punct)/, "gu").replace(/punct/g, _punctuation).getRegex();
178
+ var autolink = edit(/^<(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();
179
+ var _inlineComment = edit(_comment).replace("(?:-->|$)", "-->").getRegex();
180
+ var tag = edit(
181
+ "^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>"
182
+ ).replace("comment", _inlineComment).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
183
+ var _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
184
+ var link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", _inlineLabel).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
185
+ var reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace("label", _inlineLabel).replace("ref", _blockLabel).getRegex();
186
+ var nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace("ref", _blockLabel).getRegex();
187
+ var reflinkSearch = edit("reflink|nolink(?!\\()", "g").replace("reflink", reflink).replace("nolink", nolink).getRegex();
188
+ var inlineNormal = {
189
+ _backpedal: noopTest,
190
+ // only used for GFM url
191
+ anyPunctuation,
192
+ autolink,
193
+ blockSkip,
194
+ br,
195
+ code: inlineCode,
196
+ del: noopTest,
197
+ emStrongLDelim,
198
+ emStrongRDelimAst,
199
+ emStrongRDelimUnd,
200
+ escape: escape2,
201
+ link,
202
+ nolink,
203
+ punctuation,
204
+ reflink,
205
+ reflinkSearch,
206
+ tag,
207
+ text: inlineText,
208
+ url: noopTest
209
+ };
210
+ var inlinePedantic = {
211
+ ...inlineNormal,
212
+ link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", _inlineLabel).getRegex(),
213
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", _inlineLabel).getRegex()
214
+ };
215
+ var inlineGfm = {
216
+ ...inlineNormal,
217
+ emStrongRDelimAst: emStrongRDelimAstGfm,
218
+ emStrongLDelim: emStrongLDelimGfm,
219
+ url: edit(/^((?: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(),
220
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
221
+ del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
222
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
223
+ };
224
+ var inlineBreaks = {
225
+ ...inlineGfm,
226
+ br: edit(br).replace("{2,}", "*").getRegex(),
227
+ text: edit(inlineGfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
228
+ };
229
+ var block = {
230
+ normal: blockNormal,
231
+ gfm: blockGfm,
232
+ pedantic: blockPedantic
233
+ };
234
+ var inline = {
235
+ normal: inlineNormal,
236
+ gfm: inlineGfm,
237
+ breaks: inlineBreaks,
238
+ pedantic: inlinePedantic
239
+ };
240
+ var escapeReplacements = {
241
+ "&": "&amp;",
242
+ "<": "&lt;",
243
+ ">": "&gt;",
244
+ '"': "&quot;",
245
+ "'": "&#39;"
246
+ };
247
+ var getEscapeReplacement = (ch) => escapeReplacements[ch];
248
+ function escape22(html2, encode) {
249
+ if (encode) {
250
+ if (other.escapeTest.test(html2)) {
251
+ return html2.replace(other.escapeReplace, getEscapeReplacement);
252
+ }
253
+ } else {
254
+ if (other.escapeTestNoEncode.test(html2)) {
255
+ return html2.replace(other.escapeReplaceNoEncode, getEscapeReplacement);
256
+ }
257
+ }
258
+ return html2;
259
+ }
260
+ function cleanUrl(href) {
261
+ try {
262
+ href = encodeURI(href).replace(other.percentDecode, "%");
263
+ } catch {
264
+ return null;
265
+ }
266
+ return href;
267
+ }
268
+ function splitCells(tableRow, count) {
269
+ const row = tableRow.replace(other.findPipe, (match, offset, str) => {
270
+ let escaped = false;
271
+ let curr = offset;
272
+ while (--curr >= 0 && str[curr] === "\\") escaped = !escaped;
273
+ if (escaped) {
274
+ return "|";
275
+ } else {
276
+ return " |";
277
+ }
278
+ }), cells = row.split(other.splitPipe);
279
+ let i = 0;
280
+ if (!cells[0].trim()) {
281
+ cells.shift();
282
+ }
283
+ if (cells.length > 0 && !cells.at(-1)?.trim()) {
284
+ cells.pop();
285
+ }
286
+ if (count) {
287
+ if (cells.length > count) {
288
+ cells.splice(count);
289
+ } else {
290
+ while (cells.length < count) cells.push("");
291
+ }
292
+ }
293
+ for (; i < cells.length; i++) {
294
+ cells[i] = cells[i].trim().replace(other.slashPipe, "|");
295
+ }
296
+ return cells;
297
+ }
298
+ function rtrim(str, c, invert) {
299
+ const l = str.length;
300
+ if (l === 0) {
301
+ return "";
302
+ }
303
+ let suffLen = 0;
304
+ while (suffLen < l) {
305
+ const currChar = str.charAt(l - suffLen - 1);
306
+ if (currChar === c && !invert) {
307
+ suffLen++;
308
+ } else if (currChar !== c && invert) {
309
+ suffLen++;
310
+ } else {
311
+ break;
312
+ }
313
+ }
314
+ return str.slice(0, l - suffLen);
315
+ }
316
+ function findClosingBracket(str, b) {
317
+ if (str.indexOf(b[1]) === -1) {
318
+ return -1;
319
+ }
320
+ let level = 0;
321
+ for (let i = 0; i < str.length; i++) {
322
+ if (str[i] === "\\") {
323
+ i++;
324
+ } else if (str[i] === b[0]) {
325
+ level++;
326
+ } else if (str[i] === b[1]) {
327
+ level--;
328
+ if (level < 0) {
329
+ return i;
330
+ }
331
+ }
332
+ }
333
+ if (level > 0) {
334
+ return -2;
335
+ }
336
+ return -1;
337
+ }
338
+ function outputLink(cap, link2, raw, lexer2, rules) {
339
+ const href = link2.href;
340
+ const title = link2.title || null;
341
+ const text = cap[1].replace(rules.other.outputLinkReplace, "$1");
342
+ lexer2.state.inLink = true;
343
+ const token = {
344
+ type: cap[0].charAt(0) === "!" ? "image" : "link",
345
+ raw,
346
+ href,
347
+ title,
348
+ text,
349
+ tokens: lexer2.inlineTokens(text)
350
+ };
351
+ lexer2.state.inLink = false;
352
+ return token;
353
+ }
354
+ function indentCodeCompensation(raw, text, rules) {
355
+ const matchIndentToCode = raw.match(rules.other.indentCodeCompensation);
356
+ if (matchIndentToCode === null) {
357
+ return text;
358
+ }
359
+ const indentToCode = matchIndentToCode[1];
360
+ return text.split("\n").map((node) => {
361
+ const matchIndentInNode = node.match(rules.other.beginningSpace);
362
+ if (matchIndentInNode === null) {
363
+ return node;
364
+ }
365
+ const [indentInNode] = matchIndentInNode;
366
+ if (indentInNode.length >= indentToCode.length) {
367
+ return node.slice(indentToCode.length);
368
+ }
369
+ return node;
370
+ }).join("\n");
371
+ }
372
+ var _Tokenizer = class {
373
+ options;
374
+ rules;
375
+ // set by the lexer
376
+ lexer;
377
+ // set by the lexer
378
+ constructor(options2) {
379
+ this.options = options2 || _defaults;
380
+ }
381
+ space(src) {
382
+ const cap = this.rules.block.newline.exec(src);
383
+ if (cap && cap[0].length > 0) {
384
+ return {
385
+ type: "space",
386
+ raw: cap[0]
387
+ };
388
+ }
389
+ }
390
+ code(src) {
391
+ const cap = this.rules.block.code.exec(src);
392
+ if (cap) {
393
+ const text = cap[0].replace(this.rules.other.codeRemoveIndent, "");
394
+ return {
395
+ type: "code",
396
+ raw: cap[0],
397
+ codeBlockStyle: "indented",
398
+ text: !this.options.pedantic ? rtrim(text, "\n") : text
399
+ };
400
+ }
401
+ }
402
+ fences(src) {
403
+ const cap = this.rules.block.fences.exec(src);
404
+ if (cap) {
405
+ const raw = cap[0];
406
+ const text = indentCodeCompensation(raw, cap[3] || "", this.rules);
407
+ return {
408
+ type: "code",
409
+ raw,
410
+ lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : cap[2],
411
+ text
412
+ };
413
+ }
414
+ }
415
+ heading(src) {
416
+ const cap = this.rules.block.heading.exec(src);
417
+ if (cap) {
418
+ let text = cap[2].trim();
419
+ if (this.rules.other.endingHash.test(text)) {
420
+ const trimmed = rtrim(text, "#");
421
+ if (this.options.pedantic) {
422
+ text = trimmed.trim();
423
+ } else if (!trimmed || this.rules.other.endingSpaceChar.test(trimmed)) {
424
+ text = trimmed.trim();
425
+ }
426
+ }
427
+ return {
428
+ type: "heading",
429
+ raw: cap[0],
430
+ depth: cap[1].length,
431
+ text,
432
+ tokens: this.lexer.inline(text)
433
+ };
434
+ }
435
+ }
436
+ hr(src) {
437
+ const cap = this.rules.block.hr.exec(src);
438
+ if (cap) {
439
+ return {
440
+ type: "hr",
441
+ raw: rtrim(cap[0], "\n")
442
+ };
443
+ }
444
+ }
445
+ blockquote(src) {
446
+ const cap = this.rules.block.blockquote.exec(src);
447
+ if (cap) {
448
+ let lines = rtrim(cap[0], "\n").split("\n");
449
+ let raw = "";
450
+ let text = "";
451
+ const tokens = [];
452
+ while (lines.length > 0) {
453
+ let inBlockquote = false;
454
+ const currentLines = [];
455
+ let i;
456
+ for (i = 0; i < lines.length; i++) {
457
+ if (this.rules.other.blockquoteStart.test(lines[i])) {
458
+ currentLines.push(lines[i]);
459
+ inBlockquote = true;
460
+ } else if (!inBlockquote) {
461
+ currentLines.push(lines[i]);
462
+ } else {
463
+ break;
464
+ }
465
+ }
466
+ lines = lines.slice(i);
467
+ const currentRaw = currentLines.join("\n");
468
+ const currentText = currentRaw.replace(this.rules.other.blockquoteSetextReplace, "\n $1").replace(this.rules.other.blockquoteSetextReplace2, "");
469
+ raw = raw ? `${raw}
470
+ ${currentRaw}` : currentRaw;
471
+ text = text ? `${text}
472
+ ${currentText}` : currentText;
473
+ const top = this.lexer.state.top;
474
+ this.lexer.state.top = true;
475
+ this.lexer.blockTokens(currentText, tokens, true);
476
+ this.lexer.state.top = top;
477
+ if (lines.length === 0) {
478
+ break;
479
+ }
480
+ const lastToken = tokens.at(-1);
481
+ if (lastToken?.type === "code") {
482
+ break;
483
+ } else if (lastToken?.type === "blockquote") {
484
+ const oldToken = lastToken;
485
+ const newText = oldToken.raw + "\n" + lines.join("\n");
486
+ const newToken = this.blockquote(newText);
487
+ tokens[tokens.length - 1] = newToken;
488
+ raw = raw.substring(0, raw.length - oldToken.raw.length) + newToken.raw;
489
+ text = text.substring(0, text.length - oldToken.text.length) + newToken.text;
490
+ break;
491
+ } else if (lastToken?.type === "list") {
492
+ const oldToken = lastToken;
493
+ const newText = oldToken.raw + "\n" + lines.join("\n");
494
+ const newToken = this.list(newText);
495
+ tokens[tokens.length - 1] = newToken;
496
+ raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
497
+ text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
498
+ lines = newText.substring(tokens.at(-1).raw.length).split("\n");
499
+ continue;
500
+ }
501
+ }
502
+ return {
503
+ type: "blockquote",
504
+ raw,
505
+ tokens,
506
+ text
507
+ };
508
+ }
509
+ }
510
+ list(src) {
511
+ let cap = this.rules.block.list.exec(src);
512
+ if (cap) {
513
+ let bull = cap[1].trim();
514
+ const isordered = bull.length > 1;
515
+ const list2 = {
516
+ type: "list",
517
+ raw: "",
518
+ ordered: isordered,
519
+ start: isordered ? +bull.slice(0, -1) : "",
520
+ loose: false,
521
+ items: []
522
+ };
523
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
524
+ if (this.options.pedantic) {
525
+ bull = isordered ? bull : "[*+-]";
526
+ }
527
+ const itemRegex = this.rules.other.listItemRegex(bull);
528
+ let endsWithBlankLine = false;
529
+ while (src) {
530
+ let endEarly = false;
531
+ let raw = "";
532
+ let itemContents = "";
533
+ if (!(cap = itemRegex.exec(src))) {
534
+ break;
535
+ }
536
+ if (this.rules.block.hr.test(src)) {
537
+ break;
538
+ }
539
+ raw = cap[0];
540
+ src = src.substring(raw.length);
541
+ let line = cap[2].split("\n", 1)[0].replace(this.rules.other.listReplaceTabs, (t) => " ".repeat(3 * t.length));
542
+ let nextLine = src.split("\n", 1)[0];
543
+ let blankLine = !line.trim();
544
+ let indent = 0;
545
+ if (this.options.pedantic) {
546
+ indent = 2;
547
+ itemContents = line.trimStart();
548
+ } else if (blankLine) {
549
+ indent = cap[1].length + 1;
550
+ } else {
551
+ indent = cap[2].search(this.rules.other.nonSpaceChar);
552
+ indent = indent > 4 ? 1 : indent;
553
+ itemContents = line.slice(indent);
554
+ indent += cap[1].length;
555
+ }
556
+ if (blankLine && this.rules.other.blankLine.test(nextLine)) {
557
+ raw += nextLine + "\n";
558
+ src = src.substring(nextLine.length + 1);
559
+ endEarly = true;
560
+ }
561
+ if (!endEarly) {
562
+ const nextBulletRegex = this.rules.other.nextBulletRegex(indent);
563
+ const hrRegex = this.rules.other.hrRegex(indent);
564
+ const fencesBeginRegex = this.rules.other.fencesBeginRegex(indent);
565
+ const headingBeginRegex = this.rules.other.headingBeginRegex(indent);
566
+ const htmlBeginRegex = this.rules.other.htmlBeginRegex(indent);
567
+ while (src) {
568
+ const rawLine = src.split("\n", 1)[0];
569
+ let nextLineWithoutTabs;
570
+ nextLine = rawLine;
571
+ if (this.options.pedantic) {
572
+ nextLine = nextLine.replace(this.rules.other.listReplaceNesting, " ");
573
+ nextLineWithoutTabs = nextLine;
574
+ } else {
575
+ nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, " ");
576
+ }
577
+ if (fencesBeginRegex.test(nextLine)) {
578
+ break;
579
+ }
580
+ if (headingBeginRegex.test(nextLine)) {
581
+ break;
582
+ }
583
+ if (htmlBeginRegex.test(nextLine)) {
584
+ break;
585
+ }
586
+ if (nextBulletRegex.test(nextLine)) {
587
+ break;
588
+ }
589
+ if (hrRegex.test(nextLine)) {
590
+ break;
591
+ }
592
+ if (nextLineWithoutTabs.search(this.rules.other.nonSpaceChar) >= indent || !nextLine.trim()) {
593
+ itemContents += "\n" + nextLineWithoutTabs.slice(indent);
594
+ } else {
595
+ if (blankLine) {
596
+ break;
597
+ }
598
+ if (line.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4) {
599
+ break;
600
+ }
601
+ if (fencesBeginRegex.test(line)) {
602
+ break;
603
+ }
604
+ if (headingBeginRegex.test(line)) {
605
+ break;
606
+ }
607
+ if (hrRegex.test(line)) {
608
+ break;
609
+ }
610
+ itemContents += "\n" + nextLine;
611
+ }
612
+ if (!blankLine && !nextLine.trim()) {
613
+ blankLine = true;
614
+ }
615
+ raw += rawLine + "\n";
616
+ src = src.substring(rawLine.length + 1);
617
+ line = nextLineWithoutTabs.slice(indent);
618
+ }
619
+ }
620
+ if (!list2.loose) {
621
+ if (endsWithBlankLine) {
622
+ list2.loose = true;
623
+ } else if (this.rules.other.doubleBlankLine.test(raw)) {
624
+ endsWithBlankLine = true;
625
+ }
626
+ }
627
+ let istask = null;
628
+ let ischecked;
629
+ if (this.options.gfm) {
630
+ istask = this.rules.other.listIsTask.exec(itemContents);
631
+ if (istask) {
632
+ ischecked = istask[0] !== "[ ] ";
633
+ itemContents = itemContents.replace(this.rules.other.listReplaceTask, "");
634
+ }
635
+ }
636
+ list2.items.push({
637
+ type: "list_item",
638
+ raw,
639
+ task: !!istask,
640
+ checked: ischecked,
641
+ loose: false,
642
+ text: itemContents,
643
+ tokens: []
644
+ });
645
+ list2.raw += raw;
646
+ }
647
+ const lastItem = list2.items.at(-1);
648
+ if (lastItem) {
649
+ lastItem.raw = lastItem.raw.trimEnd();
650
+ lastItem.text = lastItem.text.trimEnd();
651
+ } else {
652
+ return;
653
+ }
654
+ list2.raw = list2.raw.trimEnd();
655
+ for (let i = 0; i < list2.items.length; i++) {
656
+ this.lexer.state.top = false;
657
+ list2.items[i].tokens = this.lexer.blockTokens(list2.items[i].text, []);
658
+ if (!list2.loose) {
659
+ const spacers = list2.items[i].tokens.filter((t) => t.type === "space");
660
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => this.rules.other.anyLine.test(t.raw));
661
+ list2.loose = hasMultipleLineBreaks;
662
+ }
663
+ }
664
+ if (list2.loose) {
665
+ for (let i = 0; i < list2.items.length; i++) {
666
+ list2.items[i].loose = true;
667
+ }
668
+ }
669
+ return list2;
670
+ }
671
+ }
672
+ html(src) {
673
+ const cap = this.rules.block.html.exec(src);
674
+ if (cap) {
675
+ const token = {
676
+ type: "html",
677
+ block: true,
678
+ raw: cap[0],
679
+ pre: cap[1] === "pre" || cap[1] === "script" || cap[1] === "style",
680
+ text: cap[0]
681
+ };
682
+ return token;
683
+ }
684
+ }
685
+ def(src) {
686
+ const cap = this.rules.block.def.exec(src);
687
+ if (cap) {
688
+ const tag2 = cap[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " ");
689
+ const href = cap[2] ? cap[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "";
690
+ const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : cap[3];
691
+ return {
692
+ type: "def",
693
+ tag: tag2,
694
+ raw: cap[0],
695
+ href,
696
+ title
697
+ };
698
+ }
699
+ }
700
+ table(src) {
701
+ const cap = this.rules.block.table.exec(src);
702
+ if (!cap) {
703
+ return;
704
+ }
705
+ if (!this.rules.other.tableDelimiter.test(cap[2])) {
706
+ return;
707
+ }
708
+ const headers = splitCells(cap[1]);
709
+ const aligns = cap[2].replace(this.rules.other.tableAlignChars, "").split("|");
710
+ const rows = cap[3]?.trim() ? cap[3].replace(this.rules.other.tableRowBlankLine, "").split("\n") : [];
711
+ const item = {
712
+ type: "table",
713
+ raw: cap[0],
714
+ header: [],
715
+ align: [],
716
+ rows: []
717
+ };
718
+ if (headers.length !== aligns.length) {
719
+ return;
720
+ }
721
+ for (const align of aligns) {
722
+ if (this.rules.other.tableAlignRight.test(align)) {
723
+ item.align.push("right");
724
+ } else if (this.rules.other.tableAlignCenter.test(align)) {
725
+ item.align.push("center");
726
+ } else if (this.rules.other.tableAlignLeft.test(align)) {
727
+ item.align.push("left");
728
+ } else {
729
+ item.align.push(null);
730
+ }
731
+ }
732
+ for (let i = 0; i < headers.length; i++) {
733
+ item.header.push({
734
+ text: headers[i],
735
+ tokens: this.lexer.inline(headers[i]),
736
+ header: true,
737
+ align: item.align[i]
738
+ });
739
+ }
740
+ for (const row of rows) {
741
+ item.rows.push(splitCells(row, item.header.length).map((cell, i) => {
742
+ return {
743
+ text: cell,
744
+ tokens: this.lexer.inline(cell),
745
+ header: false,
746
+ align: item.align[i]
747
+ };
748
+ }));
749
+ }
750
+ return item;
751
+ }
752
+ lheading(src) {
753
+ const cap = this.rules.block.lheading.exec(src);
754
+ if (cap) {
755
+ return {
756
+ type: "heading",
757
+ raw: cap[0],
758
+ depth: cap[2].charAt(0) === "=" ? 1 : 2,
759
+ text: cap[1],
760
+ tokens: this.lexer.inline(cap[1])
761
+ };
762
+ }
763
+ }
764
+ paragraph(src) {
765
+ const cap = this.rules.block.paragraph.exec(src);
766
+ if (cap) {
767
+ const text = cap[1].charAt(cap[1].length - 1) === "\n" ? cap[1].slice(0, -1) : cap[1];
768
+ return {
769
+ type: "paragraph",
770
+ raw: cap[0],
771
+ text,
772
+ tokens: this.lexer.inline(text)
773
+ };
774
+ }
775
+ }
776
+ text(src) {
777
+ const cap = this.rules.block.text.exec(src);
778
+ if (cap) {
779
+ return {
780
+ type: "text",
781
+ raw: cap[0],
782
+ text: cap[0],
783
+ tokens: this.lexer.inline(cap[0])
784
+ };
785
+ }
786
+ }
787
+ escape(src) {
788
+ const cap = this.rules.inline.escape.exec(src);
789
+ if (cap) {
790
+ return {
791
+ type: "escape",
792
+ raw: cap[0],
793
+ text: cap[1]
794
+ };
795
+ }
796
+ }
797
+ tag(src) {
798
+ const cap = this.rules.inline.tag.exec(src);
799
+ if (cap) {
800
+ if (!this.lexer.state.inLink && this.rules.other.startATag.test(cap[0])) {
801
+ this.lexer.state.inLink = true;
802
+ } else if (this.lexer.state.inLink && this.rules.other.endATag.test(cap[0])) {
803
+ this.lexer.state.inLink = false;
804
+ }
805
+ if (!this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(cap[0])) {
806
+ this.lexer.state.inRawBlock = true;
807
+ } else if (this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(cap[0])) {
808
+ this.lexer.state.inRawBlock = false;
809
+ }
810
+ return {
811
+ type: "html",
812
+ raw: cap[0],
813
+ inLink: this.lexer.state.inLink,
814
+ inRawBlock: this.lexer.state.inRawBlock,
815
+ block: false,
816
+ text: cap[0]
817
+ };
818
+ }
819
+ }
820
+ link(src) {
821
+ const cap = this.rules.inline.link.exec(src);
822
+ if (cap) {
823
+ const trimmedUrl = cap[2].trim();
824
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(trimmedUrl)) {
825
+ if (!this.rules.other.endAngleBracket.test(trimmedUrl)) {
826
+ return;
827
+ }
828
+ const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), "\\");
829
+ if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
830
+ return;
831
+ }
832
+ } else {
833
+ const lastParenIndex = findClosingBracket(cap[2], "()");
834
+ if (lastParenIndex === -2) {
835
+ return;
836
+ }
837
+ if (lastParenIndex > -1) {
838
+ const start = cap[0].indexOf("!") === 0 ? 5 : 4;
839
+ const linkLen = start + cap[1].length + lastParenIndex;
840
+ cap[2] = cap[2].substring(0, lastParenIndex);
841
+ cap[0] = cap[0].substring(0, linkLen).trim();
842
+ cap[3] = "";
843
+ }
844
+ }
845
+ let href = cap[2];
846
+ let title = "";
847
+ if (this.options.pedantic) {
848
+ const link2 = this.rules.other.pedanticHrefTitle.exec(href);
849
+ if (link2) {
850
+ href = link2[1];
851
+ title = link2[3];
852
+ }
853
+ } else {
854
+ title = cap[3] ? cap[3].slice(1, -1) : "";
855
+ }
856
+ href = href.trim();
857
+ if (this.rules.other.startAngleBracket.test(href)) {
858
+ if (this.options.pedantic && !this.rules.other.endAngleBracket.test(trimmedUrl)) {
859
+ href = href.slice(1);
860
+ } else {
861
+ href = href.slice(1, -1);
862
+ }
863
+ }
864
+ return outputLink(cap, {
865
+ href: href ? href.replace(this.rules.inline.anyPunctuation, "$1") : href,
866
+ title: title ? title.replace(this.rules.inline.anyPunctuation, "$1") : title
867
+ }, cap[0], this.lexer, this.rules);
868
+ }
869
+ }
870
+ reflink(src, links) {
871
+ let cap;
872
+ if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
873
+ const linkString = (cap[2] || cap[1]).replace(this.rules.other.multipleSpaceGlobal, " ");
874
+ const link2 = links[linkString.toLowerCase()];
875
+ if (!link2) {
876
+ const text = cap[0].charAt(0);
877
+ return {
878
+ type: "text",
879
+ raw: text,
880
+ text
881
+ };
882
+ }
883
+ return outputLink(cap, link2, cap[0], this.lexer, this.rules);
884
+ }
885
+ }
886
+ emStrong(src, maskedSrc, prevChar = "") {
887
+ let match = this.rules.inline.emStrongLDelim.exec(src);
888
+ if (!match) return;
889
+ if (match[3] && prevChar.match(this.rules.other.unicodeAlphaNumeric)) return;
890
+ const nextChar = match[1] || match[2] || "";
891
+ if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
892
+ const lLength = [...match[0]].length - 1;
893
+ let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
894
+ const endReg = match[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
895
+ endReg.lastIndex = 0;
896
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
897
+ while ((match = endReg.exec(maskedSrc)) != null) {
898
+ rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
899
+ if (!rDelim) continue;
900
+ rLength = [...rDelim].length;
901
+ if (match[3] || match[4]) {
902
+ delimTotal += rLength;
903
+ continue;
904
+ } else if (match[5] || match[6]) {
905
+ if (lLength % 3 && !((lLength + rLength) % 3)) {
906
+ midDelimTotal += rLength;
907
+ continue;
908
+ }
909
+ }
910
+ delimTotal -= rLength;
911
+ if (delimTotal > 0) continue;
912
+ rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
913
+ const lastCharLength = [...match[0]][0].length;
914
+ const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
915
+ if (Math.min(lLength, rLength) % 2) {
916
+ const text2 = raw.slice(1, -1);
917
+ return {
918
+ type: "em",
919
+ raw,
920
+ text: text2,
921
+ tokens: this.lexer.inlineTokens(text2)
922
+ };
923
+ }
924
+ const text = raw.slice(2, -2);
925
+ return {
926
+ type: "strong",
927
+ raw,
928
+ text,
929
+ tokens: this.lexer.inlineTokens(text)
930
+ };
931
+ }
932
+ }
933
+ }
934
+ codespan(src) {
935
+ const cap = this.rules.inline.code.exec(src);
936
+ if (cap) {
937
+ let text = cap[2].replace(this.rules.other.newLineCharGlobal, " ");
938
+ const hasNonSpaceChars = this.rules.other.nonSpaceChar.test(text);
939
+ const hasSpaceCharsOnBothEnds = this.rules.other.startingSpaceChar.test(text) && this.rules.other.endingSpaceChar.test(text);
940
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
941
+ text = text.substring(1, text.length - 1);
942
+ }
943
+ return {
944
+ type: "codespan",
945
+ raw: cap[0],
946
+ text
947
+ };
948
+ }
949
+ }
950
+ br(src) {
951
+ const cap = this.rules.inline.br.exec(src);
952
+ if (cap) {
953
+ return {
954
+ type: "br",
955
+ raw: cap[0]
956
+ };
957
+ }
958
+ }
959
+ del(src) {
960
+ const cap = this.rules.inline.del.exec(src);
961
+ if (cap) {
962
+ return {
963
+ type: "del",
964
+ raw: cap[0],
965
+ text: cap[2],
966
+ tokens: this.lexer.inlineTokens(cap[2])
967
+ };
968
+ }
969
+ }
970
+ autolink(src) {
971
+ const cap = this.rules.inline.autolink.exec(src);
972
+ if (cap) {
973
+ let text, href;
974
+ if (cap[2] === "@") {
975
+ text = cap[1];
976
+ href = "mailto:" + text;
977
+ } else {
978
+ text = cap[1];
979
+ href = text;
980
+ }
981
+ return {
982
+ type: "link",
983
+ raw: cap[0],
984
+ text,
985
+ href,
986
+ tokens: [
987
+ {
988
+ type: "text",
989
+ raw: text,
990
+ text
991
+ }
992
+ ]
993
+ };
994
+ }
995
+ }
996
+ url(src) {
997
+ let cap;
998
+ if (cap = this.rules.inline.url.exec(src)) {
999
+ let text, href;
1000
+ if (cap[2] === "@") {
1001
+ text = cap[0];
1002
+ href = "mailto:" + text;
1003
+ } else {
1004
+ let prevCapZero;
1005
+ do {
1006
+ prevCapZero = cap[0];
1007
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? "";
1008
+ } while (prevCapZero !== cap[0]);
1009
+ text = cap[0];
1010
+ if (cap[1] === "www.") {
1011
+ href = "http://" + cap[0];
1012
+ } else {
1013
+ href = cap[0];
1014
+ }
1015
+ }
1016
+ return {
1017
+ type: "link",
1018
+ raw: cap[0],
1019
+ text,
1020
+ href,
1021
+ tokens: [
1022
+ {
1023
+ type: "text",
1024
+ raw: text,
1025
+ text
1026
+ }
1027
+ ]
1028
+ };
1029
+ }
1030
+ }
1031
+ inlineText(src) {
1032
+ const cap = this.rules.inline.text.exec(src);
1033
+ if (cap) {
1034
+ const escaped = this.lexer.state.inRawBlock;
1035
+ return {
1036
+ type: "text",
1037
+ raw: cap[0],
1038
+ text: cap[0],
1039
+ escaped
1040
+ };
1041
+ }
1042
+ }
1043
+ };
1044
+ var _Lexer = class __Lexer {
1045
+ tokens;
1046
+ options;
1047
+ state;
1048
+ tokenizer;
1049
+ inlineQueue;
1050
+ constructor(options2) {
1051
+ this.tokens = [];
1052
+ this.tokens.links = /* @__PURE__ */ Object.create(null);
1053
+ this.options = options2 || _defaults;
1054
+ this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
1055
+ this.tokenizer = this.options.tokenizer;
1056
+ this.tokenizer.options = this.options;
1057
+ this.tokenizer.lexer = this;
1058
+ this.inlineQueue = [];
1059
+ this.state = {
1060
+ inLink: false,
1061
+ inRawBlock: false,
1062
+ top: true
1063
+ };
1064
+ const rules = {
1065
+ other,
1066
+ block: block.normal,
1067
+ inline: inline.normal
1068
+ };
1069
+ if (this.options.pedantic) {
1070
+ rules.block = block.pedantic;
1071
+ rules.inline = inline.pedantic;
1072
+ } else if (this.options.gfm) {
1073
+ rules.block = block.gfm;
1074
+ if (this.options.breaks) {
1075
+ rules.inline = inline.breaks;
1076
+ } else {
1077
+ rules.inline = inline.gfm;
1078
+ }
1079
+ }
1080
+ this.tokenizer.rules = rules;
1081
+ }
1082
+ /**
1083
+ * Expose Rules
1084
+ */
1085
+ static get rules() {
1086
+ return {
1087
+ block,
1088
+ inline
1089
+ };
1090
+ }
1091
+ /**
1092
+ * Static Lex Method
1093
+ */
1094
+ static lex(src, options2) {
1095
+ const lexer2 = new __Lexer(options2);
1096
+ return lexer2.lex(src);
1097
+ }
1098
+ /**
1099
+ * Static Lex Inline Method
1100
+ */
1101
+ static lexInline(src, options2) {
1102
+ const lexer2 = new __Lexer(options2);
1103
+ return lexer2.inlineTokens(src);
1104
+ }
1105
+ /**
1106
+ * Preprocessing
1107
+ */
1108
+ lex(src) {
1109
+ src = src.replace(other.carriageReturn, "\n");
1110
+ this.blockTokens(src, this.tokens);
1111
+ for (let i = 0; i < this.inlineQueue.length; i++) {
1112
+ const next = this.inlineQueue[i];
1113
+ this.inlineTokens(next.src, next.tokens);
1114
+ }
1115
+ this.inlineQueue = [];
1116
+ return this.tokens;
1117
+ }
1118
+ blockTokens(src, tokens = [], lastParagraphClipped = false) {
1119
+ if (this.options.pedantic) {
1120
+ src = src.replace(other.tabCharGlobal, " ").replace(other.spaceLine, "");
1121
+ }
1122
+ while (src) {
1123
+ let token;
1124
+ if (this.options.extensions?.block?.some((extTokenizer) => {
1125
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1126
+ src = src.substring(token.raw.length);
1127
+ tokens.push(token);
1128
+ return true;
1129
+ }
1130
+ return false;
1131
+ })) {
1132
+ continue;
1133
+ }
1134
+ if (token = this.tokenizer.space(src)) {
1135
+ src = src.substring(token.raw.length);
1136
+ const lastToken = tokens.at(-1);
1137
+ if (token.raw.length === 1 && lastToken !== void 0) {
1138
+ lastToken.raw += "\n";
1139
+ } else {
1140
+ tokens.push(token);
1141
+ }
1142
+ continue;
1143
+ }
1144
+ if (token = this.tokenizer.code(src)) {
1145
+ src = src.substring(token.raw.length);
1146
+ const lastToken = tokens.at(-1);
1147
+ if (lastToken?.type === "paragraph" || lastToken?.type === "text") {
1148
+ lastToken.raw += "\n" + token.raw;
1149
+ lastToken.text += "\n" + token.text;
1150
+ this.inlineQueue.at(-1).src = lastToken.text;
1151
+ } else {
1152
+ tokens.push(token);
1153
+ }
1154
+ continue;
1155
+ }
1156
+ if (token = this.tokenizer.fences(src)) {
1157
+ src = src.substring(token.raw.length);
1158
+ tokens.push(token);
1159
+ continue;
1160
+ }
1161
+ if (token = this.tokenizer.heading(src)) {
1162
+ src = src.substring(token.raw.length);
1163
+ tokens.push(token);
1164
+ continue;
1165
+ }
1166
+ if (token = this.tokenizer.hr(src)) {
1167
+ src = src.substring(token.raw.length);
1168
+ tokens.push(token);
1169
+ continue;
1170
+ }
1171
+ if (token = this.tokenizer.blockquote(src)) {
1172
+ src = src.substring(token.raw.length);
1173
+ tokens.push(token);
1174
+ continue;
1175
+ }
1176
+ if (token = this.tokenizer.list(src)) {
1177
+ src = src.substring(token.raw.length);
1178
+ tokens.push(token);
1179
+ continue;
1180
+ }
1181
+ if (token = this.tokenizer.html(src)) {
1182
+ src = src.substring(token.raw.length);
1183
+ tokens.push(token);
1184
+ continue;
1185
+ }
1186
+ if (token = this.tokenizer.def(src)) {
1187
+ src = src.substring(token.raw.length);
1188
+ const lastToken = tokens.at(-1);
1189
+ if (lastToken?.type === "paragraph" || lastToken?.type === "text") {
1190
+ lastToken.raw += "\n" + token.raw;
1191
+ lastToken.text += "\n" + token.raw;
1192
+ this.inlineQueue.at(-1).src = lastToken.text;
1193
+ } else if (!this.tokens.links[token.tag]) {
1194
+ this.tokens.links[token.tag] = {
1195
+ href: token.href,
1196
+ title: token.title
1197
+ };
1198
+ }
1199
+ continue;
1200
+ }
1201
+ if (token = this.tokenizer.table(src)) {
1202
+ src = src.substring(token.raw.length);
1203
+ tokens.push(token);
1204
+ continue;
1205
+ }
1206
+ if (token = this.tokenizer.lheading(src)) {
1207
+ src = src.substring(token.raw.length);
1208
+ tokens.push(token);
1209
+ continue;
1210
+ }
1211
+ let cutSrc = src;
1212
+ if (this.options.extensions?.startBlock) {
1213
+ let startIndex = Infinity;
1214
+ const tempSrc = src.slice(1);
1215
+ let tempStart;
1216
+ this.options.extensions.startBlock.forEach((getStartIndex) => {
1217
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1218
+ if (typeof tempStart === "number" && tempStart >= 0) {
1219
+ startIndex = Math.min(startIndex, tempStart);
1220
+ }
1221
+ });
1222
+ if (startIndex < Infinity && startIndex >= 0) {
1223
+ cutSrc = src.substring(0, startIndex + 1);
1224
+ }
1225
+ }
1226
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1227
+ const lastToken = tokens.at(-1);
1228
+ if (lastParagraphClipped && lastToken?.type === "paragraph") {
1229
+ lastToken.raw += "\n" + token.raw;
1230
+ lastToken.text += "\n" + token.text;
1231
+ this.inlineQueue.pop();
1232
+ this.inlineQueue.at(-1).src = lastToken.text;
1233
+ } else {
1234
+ tokens.push(token);
1235
+ }
1236
+ lastParagraphClipped = cutSrc.length !== src.length;
1237
+ src = src.substring(token.raw.length);
1238
+ continue;
1239
+ }
1240
+ if (token = this.tokenizer.text(src)) {
1241
+ src = src.substring(token.raw.length);
1242
+ const lastToken = tokens.at(-1);
1243
+ if (lastToken?.type === "text") {
1244
+ lastToken.raw += "\n" + token.raw;
1245
+ lastToken.text += "\n" + token.text;
1246
+ this.inlineQueue.pop();
1247
+ this.inlineQueue.at(-1).src = lastToken.text;
1248
+ } else {
1249
+ tokens.push(token);
1250
+ }
1251
+ continue;
1252
+ }
1253
+ if (src) {
1254
+ const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
1255
+ if (this.options.silent) {
1256
+ console.error(errMsg);
1257
+ break;
1258
+ } else {
1259
+ throw new Error(errMsg);
1260
+ }
1261
+ }
1262
+ }
1263
+ this.state.top = true;
1264
+ return tokens;
1265
+ }
1266
+ inline(src, tokens = []) {
1267
+ this.inlineQueue.push({ src, tokens });
1268
+ return tokens;
1269
+ }
1270
+ /**
1271
+ * Lexing/Compiling
1272
+ */
1273
+ inlineTokens(src, tokens = []) {
1274
+ let maskedSrc = src;
1275
+ let match = null;
1276
+ if (this.tokens.links) {
1277
+ const links = Object.keys(this.tokens.links);
1278
+ if (links.length > 0) {
1279
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1280
+ if (links.includes(match[0].slice(match[0].lastIndexOf("[") + 1, -1))) {
1281
+ maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1282
+ }
1283
+ }
1284
+ }
1285
+ }
1286
+ while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
1287
+ maskedSrc = maskedSrc.slice(0, match.index) + "++" + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1288
+ }
1289
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1290
+ maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1291
+ }
1292
+ let keepPrevChar = false;
1293
+ let prevChar = "";
1294
+ while (src) {
1295
+ if (!keepPrevChar) {
1296
+ prevChar = "";
1297
+ }
1298
+ keepPrevChar = false;
1299
+ let token;
1300
+ if (this.options.extensions?.inline?.some((extTokenizer) => {
1301
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1302
+ src = src.substring(token.raw.length);
1303
+ tokens.push(token);
1304
+ return true;
1305
+ }
1306
+ return false;
1307
+ })) {
1308
+ continue;
1309
+ }
1310
+ if (token = this.tokenizer.escape(src)) {
1311
+ src = src.substring(token.raw.length);
1312
+ tokens.push(token);
1313
+ continue;
1314
+ }
1315
+ if (token = this.tokenizer.tag(src)) {
1316
+ src = src.substring(token.raw.length);
1317
+ tokens.push(token);
1318
+ continue;
1319
+ }
1320
+ if (token = this.tokenizer.link(src)) {
1321
+ src = src.substring(token.raw.length);
1322
+ tokens.push(token);
1323
+ continue;
1324
+ }
1325
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1326
+ src = src.substring(token.raw.length);
1327
+ const lastToken = tokens.at(-1);
1328
+ if (token.type === "text" && lastToken?.type === "text") {
1329
+ lastToken.raw += token.raw;
1330
+ lastToken.text += token.text;
1331
+ } else {
1332
+ tokens.push(token);
1333
+ }
1334
+ continue;
1335
+ }
1336
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1337
+ src = src.substring(token.raw.length);
1338
+ tokens.push(token);
1339
+ continue;
1340
+ }
1341
+ if (token = this.tokenizer.codespan(src)) {
1342
+ src = src.substring(token.raw.length);
1343
+ tokens.push(token);
1344
+ continue;
1345
+ }
1346
+ if (token = this.tokenizer.br(src)) {
1347
+ src = src.substring(token.raw.length);
1348
+ tokens.push(token);
1349
+ continue;
1350
+ }
1351
+ if (token = this.tokenizer.del(src)) {
1352
+ src = src.substring(token.raw.length);
1353
+ tokens.push(token);
1354
+ continue;
1355
+ }
1356
+ if (token = this.tokenizer.autolink(src)) {
1357
+ src = src.substring(token.raw.length);
1358
+ tokens.push(token);
1359
+ continue;
1360
+ }
1361
+ if (!this.state.inLink && (token = this.tokenizer.url(src))) {
1362
+ src = src.substring(token.raw.length);
1363
+ tokens.push(token);
1364
+ continue;
1365
+ }
1366
+ let cutSrc = src;
1367
+ if (this.options.extensions?.startInline) {
1368
+ let startIndex = Infinity;
1369
+ const tempSrc = src.slice(1);
1370
+ let tempStart;
1371
+ this.options.extensions.startInline.forEach((getStartIndex) => {
1372
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1373
+ if (typeof tempStart === "number" && tempStart >= 0) {
1374
+ startIndex = Math.min(startIndex, tempStart);
1375
+ }
1376
+ });
1377
+ if (startIndex < Infinity && startIndex >= 0) {
1378
+ cutSrc = src.substring(0, startIndex + 1);
1379
+ }
1380
+ }
1381
+ if (token = this.tokenizer.inlineText(cutSrc)) {
1382
+ src = src.substring(token.raw.length);
1383
+ if (token.raw.slice(-1) !== "_") {
1384
+ prevChar = token.raw.slice(-1);
1385
+ }
1386
+ keepPrevChar = true;
1387
+ const lastToken = tokens.at(-1);
1388
+ if (lastToken?.type === "text") {
1389
+ lastToken.raw += token.raw;
1390
+ lastToken.text += token.text;
1391
+ } else {
1392
+ tokens.push(token);
1393
+ }
1394
+ continue;
1395
+ }
1396
+ if (src) {
1397
+ const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
1398
+ if (this.options.silent) {
1399
+ console.error(errMsg);
1400
+ break;
1401
+ } else {
1402
+ throw new Error(errMsg);
1403
+ }
1404
+ }
1405
+ }
1406
+ return tokens;
1407
+ }
1408
+ };
1409
+ var _Renderer = class {
1410
+ options;
1411
+ parser;
1412
+ // set by the parser
1413
+ constructor(options2) {
1414
+ this.options = options2 || _defaults;
1415
+ }
1416
+ space(token) {
1417
+ return "";
1418
+ }
1419
+ code({ text, lang, escaped }) {
1420
+ const langString = (lang || "").match(other.notSpaceStart)?.[0];
1421
+ const code = text.replace(other.endingNewline, "") + "\n";
1422
+ if (!langString) {
1423
+ return "<pre><code>" + (escaped ? code : escape22(code, true)) + "</code></pre>\n";
1424
+ }
1425
+ return '<pre><code class="language-' + escape22(langString) + '">' + (escaped ? code : escape22(code, true)) + "</code></pre>\n";
1426
+ }
1427
+ blockquote({ tokens }) {
1428
+ const body = this.parser.parse(tokens);
1429
+ return `<blockquote>
1430
+ ${body}</blockquote>
1431
+ `;
1432
+ }
1433
+ html({ text }) {
1434
+ return text;
1435
+ }
1436
+ heading({ tokens, depth }) {
1437
+ return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>
1438
+ `;
1439
+ }
1440
+ hr(token) {
1441
+ return "<hr>\n";
1442
+ }
1443
+ list(token) {
1444
+ const ordered = token.ordered;
1445
+ const start = token.start;
1446
+ let body = "";
1447
+ for (let j = 0; j < token.items.length; j++) {
1448
+ const item = token.items[j];
1449
+ body += this.listitem(item);
1450
+ }
1451
+ const type = ordered ? "ol" : "ul";
1452
+ const startAttr = ordered && start !== 1 ? ' start="' + start + '"' : "";
1453
+ return "<" + type + startAttr + ">\n" + body + "</" + type + ">\n";
1454
+ }
1455
+ listitem(item) {
1456
+ let itemBody = "";
1457
+ if (item.task) {
1458
+ const checkbox = this.checkbox({ checked: !!item.checked });
1459
+ if (item.loose) {
1460
+ if (item.tokens[0]?.type === "paragraph") {
1461
+ item.tokens[0].text = checkbox + " " + item.tokens[0].text;
1462
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
1463
+ item.tokens[0].tokens[0].text = checkbox + " " + escape22(item.tokens[0].tokens[0].text);
1464
+ item.tokens[0].tokens[0].escaped = true;
1465
+ }
1466
+ } else {
1467
+ item.tokens.unshift({
1468
+ type: "text",
1469
+ raw: checkbox + " ",
1470
+ text: checkbox + " ",
1471
+ escaped: true
1472
+ });
1473
+ }
1474
+ } else {
1475
+ itemBody += checkbox + " ";
1476
+ }
1477
+ }
1478
+ itemBody += this.parser.parse(item.tokens, !!item.loose);
1479
+ return `<li>${itemBody}</li>
1480
+ `;
1481
+ }
1482
+ checkbox({ checked }) {
1483
+ return "<input " + (checked ? 'checked="" ' : "") + 'disabled="" type="checkbox">';
1484
+ }
1485
+ paragraph({ tokens }) {
1486
+ return `<p>${this.parser.parseInline(tokens)}</p>
1487
+ `;
1488
+ }
1489
+ table(token) {
1490
+ let header = "";
1491
+ let cell = "";
1492
+ for (let j = 0; j < token.header.length; j++) {
1493
+ cell += this.tablecell(token.header[j]);
1494
+ }
1495
+ header += this.tablerow({ text: cell });
1496
+ let body = "";
1497
+ for (let j = 0; j < token.rows.length; j++) {
1498
+ const row = token.rows[j];
1499
+ cell = "";
1500
+ for (let k = 0; k < row.length; k++) {
1501
+ cell += this.tablecell(row[k]);
1502
+ }
1503
+ body += this.tablerow({ text: cell });
1504
+ }
1505
+ if (body) body = `<tbody>${body}</tbody>`;
1506
+ return "<table>\n<thead>\n" + header + "</thead>\n" + body + "</table>\n";
1507
+ }
1508
+ tablerow({ text }) {
1509
+ return `<tr>
1510
+ ${text}</tr>
1511
+ `;
1512
+ }
1513
+ tablecell(token) {
1514
+ const content = this.parser.parseInline(token.tokens);
1515
+ const type = token.header ? "th" : "td";
1516
+ const tag2 = token.align ? `<${type} align="${token.align}">` : `<${type}>`;
1517
+ return tag2 + content + `</${type}>
1518
+ `;
1519
+ }
1520
+ /**
1521
+ * span level renderer
1522
+ */
1523
+ strong({ tokens }) {
1524
+ return `<strong>${this.parser.parseInline(tokens)}</strong>`;
1525
+ }
1526
+ em({ tokens }) {
1527
+ return `<em>${this.parser.parseInline(tokens)}</em>`;
1528
+ }
1529
+ codespan({ text }) {
1530
+ return `<code>${escape22(text, true)}</code>`;
1531
+ }
1532
+ br(token) {
1533
+ return "<br>";
1534
+ }
1535
+ del({ tokens }) {
1536
+ return `<del>${this.parser.parseInline(tokens)}</del>`;
1537
+ }
1538
+ link({ href, title, tokens }) {
1539
+ const text = this.parser.parseInline(tokens);
1540
+ const cleanHref = cleanUrl(href);
1541
+ if (cleanHref === null) {
1542
+ return text;
1543
+ }
1544
+ href = cleanHref;
1545
+ let out = '<a href="' + href + '"';
1546
+ if (title) {
1547
+ out += ' title="' + escape22(title) + '"';
1548
+ }
1549
+ out += ">" + text + "</a>";
1550
+ return out;
1551
+ }
1552
+ image({ href, title, text, tokens }) {
1553
+ if (tokens) {
1554
+ text = this.parser.parseInline(tokens, this.parser.textRenderer);
1555
+ }
1556
+ const cleanHref = cleanUrl(href);
1557
+ if (cleanHref === null) {
1558
+ return escape22(text);
1559
+ }
1560
+ href = cleanHref;
1561
+ let out = `<img src="${href}" alt="${text}"`;
1562
+ if (title) {
1563
+ out += ` title="${escape22(title)}"`;
1564
+ }
1565
+ out += ">";
1566
+ return out;
1567
+ }
1568
+ text(token) {
1569
+ return "tokens" in token && token.tokens ? this.parser.parseInline(token.tokens) : "escaped" in token && token.escaped ? token.text : escape22(token.text);
1570
+ }
1571
+ };
1572
+ var _TextRenderer = class {
1573
+ // no need for block level renderers
1574
+ strong({ text }) {
1575
+ return text;
1576
+ }
1577
+ em({ text }) {
1578
+ return text;
1579
+ }
1580
+ codespan({ text }) {
1581
+ return text;
1582
+ }
1583
+ del({ text }) {
1584
+ return text;
1585
+ }
1586
+ html({ text }) {
1587
+ return text;
1588
+ }
1589
+ text({ text }) {
1590
+ return text;
1591
+ }
1592
+ link({ text }) {
1593
+ return "" + text;
1594
+ }
1595
+ image({ text }) {
1596
+ return "" + text;
1597
+ }
1598
+ br() {
1599
+ return "";
1600
+ }
1601
+ };
1602
+ var _Parser = class __Parser {
1603
+ options;
1604
+ renderer;
1605
+ textRenderer;
1606
+ constructor(options2) {
1607
+ this.options = options2 || _defaults;
1608
+ this.options.renderer = this.options.renderer || new _Renderer();
1609
+ this.renderer = this.options.renderer;
1610
+ this.renderer.options = this.options;
1611
+ this.renderer.parser = this;
1612
+ this.textRenderer = new _TextRenderer();
1613
+ }
1614
+ /**
1615
+ * Static Parse Method
1616
+ */
1617
+ static parse(tokens, options2) {
1618
+ const parser2 = new __Parser(options2);
1619
+ return parser2.parse(tokens);
1620
+ }
1621
+ /**
1622
+ * Static Parse Inline Method
1623
+ */
1624
+ static parseInline(tokens, options2) {
1625
+ const parser2 = new __Parser(options2);
1626
+ return parser2.parseInline(tokens);
1627
+ }
1628
+ /**
1629
+ * Parse Loop
1630
+ */
1631
+ parse(tokens, top = true) {
1632
+ let out = "";
1633
+ for (let i = 0; i < tokens.length; i++) {
1634
+ const anyToken = tokens[i];
1635
+ if (this.options.extensions?.renderers?.[anyToken.type]) {
1636
+ const genericToken = anyToken;
1637
+ const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
1638
+ if (ret !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(genericToken.type)) {
1639
+ out += ret || "";
1640
+ continue;
1641
+ }
1642
+ }
1643
+ const token = anyToken;
1644
+ switch (token.type) {
1645
+ case "space": {
1646
+ out += this.renderer.space(token);
1647
+ continue;
1648
+ }
1649
+ case "hr": {
1650
+ out += this.renderer.hr(token);
1651
+ continue;
1652
+ }
1653
+ case "heading": {
1654
+ out += this.renderer.heading(token);
1655
+ continue;
1656
+ }
1657
+ case "code": {
1658
+ out += this.renderer.code(token);
1659
+ continue;
1660
+ }
1661
+ case "table": {
1662
+ out += this.renderer.table(token);
1663
+ continue;
1664
+ }
1665
+ case "blockquote": {
1666
+ out += this.renderer.blockquote(token);
1667
+ continue;
1668
+ }
1669
+ case "list": {
1670
+ out += this.renderer.list(token);
1671
+ continue;
1672
+ }
1673
+ case "html": {
1674
+ out += this.renderer.html(token);
1675
+ continue;
1676
+ }
1677
+ case "paragraph": {
1678
+ out += this.renderer.paragraph(token);
1679
+ continue;
1680
+ }
1681
+ case "text": {
1682
+ let textToken = token;
1683
+ let body = this.renderer.text(textToken);
1684
+ while (i + 1 < tokens.length && tokens[i + 1].type === "text") {
1685
+ textToken = tokens[++i];
1686
+ body += "\n" + this.renderer.text(textToken);
1687
+ }
1688
+ if (top) {
1689
+ out += this.renderer.paragraph({
1690
+ type: "paragraph",
1691
+ raw: body,
1692
+ text: body,
1693
+ tokens: [{ type: "text", raw: body, text: body, escaped: true }]
1694
+ });
1695
+ } else {
1696
+ out += body;
1697
+ }
1698
+ continue;
1699
+ }
1700
+ default: {
1701
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
1702
+ if (this.options.silent) {
1703
+ console.error(errMsg);
1704
+ return "";
1705
+ } else {
1706
+ throw new Error(errMsg);
1707
+ }
1708
+ }
1709
+ }
1710
+ }
1711
+ return out;
1712
+ }
1713
+ /**
1714
+ * Parse Inline Tokens
1715
+ */
1716
+ parseInline(tokens, renderer = this.renderer) {
1717
+ let out = "";
1718
+ for (let i = 0; i < tokens.length; i++) {
1719
+ const anyToken = tokens[i];
1720
+ if (this.options.extensions?.renderers?.[anyToken.type]) {
1721
+ const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
1722
+ if (ret !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(anyToken.type)) {
1723
+ out += ret || "";
1724
+ continue;
1725
+ }
1726
+ }
1727
+ const token = anyToken;
1728
+ switch (token.type) {
1729
+ case "escape": {
1730
+ out += renderer.text(token);
1731
+ break;
1732
+ }
1733
+ case "html": {
1734
+ out += renderer.html(token);
1735
+ break;
1736
+ }
1737
+ case "link": {
1738
+ out += renderer.link(token);
1739
+ break;
1740
+ }
1741
+ case "image": {
1742
+ out += renderer.image(token);
1743
+ break;
1744
+ }
1745
+ case "strong": {
1746
+ out += renderer.strong(token);
1747
+ break;
1748
+ }
1749
+ case "em": {
1750
+ out += renderer.em(token);
1751
+ break;
1752
+ }
1753
+ case "codespan": {
1754
+ out += renderer.codespan(token);
1755
+ break;
1756
+ }
1757
+ case "br": {
1758
+ out += renderer.br(token);
1759
+ break;
1760
+ }
1761
+ case "del": {
1762
+ out += renderer.del(token);
1763
+ break;
1764
+ }
1765
+ case "text": {
1766
+ out += renderer.text(token);
1767
+ break;
1768
+ }
1769
+ default: {
1770
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
1771
+ if (this.options.silent) {
1772
+ console.error(errMsg);
1773
+ return "";
1774
+ } else {
1775
+ throw new Error(errMsg);
1776
+ }
1777
+ }
1778
+ }
1779
+ }
1780
+ return out;
1781
+ }
1782
+ };
1783
+ var _Hooks = class {
1784
+ options;
1785
+ block;
1786
+ constructor(options2) {
1787
+ this.options = options2 || _defaults;
1788
+ }
1789
+ static passThroughHooks = /* @__PURE__ */ new Set([
1790
+ "preprocess",
1791
+ "postprocess",
1792
+ "processAllTokens"
1793
+ ]);
1794
+ /**
1795
+ * Process markdown before marked
1796
+ */
1797
+ preprocess(markdown) {
1798
+ return markdown;
1799
+ }
1800
+ /**
1801
+ * Process HTML after marked is finished
1802
+ */
1803
+ postprocess(html2) {
1804
+ return html2;
1805
+ }
1806
+ /**
1807
+ * Process all tokens before walk tokens
1808
+ */
1809
+ processAllTokens(tokens) {
1810
+ return tokens;
1811
+ }
1812
+ /**
1813
+ * Provide function to tokenize markdown
1814
+ */
1815
+ provideLexer() {
1816
+ return this.block ? _Lexer.lex : _Lexer.lexInline;
1817
+ }
1818
+ /**
1819
+ * Provide function to parse tokens
1820
+ */
1821
+ provideParser() {
1822
+ return this.block ? _Parser.parse : _Parser.parseInline;
1823
+ }
1824
+ };
1825
+ var Marked = class {
1826
+ defaults = _getDefaults();
1827
+ options = this.setOptions;
1828
+ parse = this.parseMarkdown(true);
1829
+ parseInline = this.parseMarkdown(false);
1830
+ Parser = _Parser;
1831
+ Renderer = _Renderer;
1832
+ TextRenderer = _TextRenderer;
1833
+ Lexer = _Lexer;
1834
+ Tokenizer = _Tokenizer;
1835
+ Hooks = _Hooks;
1836
+ constructor(...args) {
1837
+ this.use(...args);
1838
+ }
1839
+ /**
1840
+ * Run callback for every token
1841
+ */
1842
+ walkTokens(tokens, callback) {
1843
+ let values = [];
1844
+ for (const token of tokens) {
1845
+ values = values.concat(callback.call(this, token));
1846
+ switch (token.type) {
1847
+ case "table": {
1848
+ const tableToken = token;
1849
+ for (const cell of tableToken.header) {
1850
+ values = values.concat(this.walkTokens(cell.tokens, callback));
1851
+ }
1852
+ for (const row of tableToken.rows) {
1853
+ for (const cell of row) {
1854
+ values = values.concat(this.walkTokens(cell.tokens, callback));
1855
+ }
1856
+ }
1857
+ break;
1858
+ }
1859
+ case "list": {
1860
+ const listToken = token;
1861
+ values = values.concat(this.walkTokens(listToken.items, callback));
1862
+ break;
1863
+ }
1864
+ default: {
1865
+ const genericToken = token;
1866
+ if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
1867
+ this.defaults.extensions.childTokens[genericToken.type].forEach((childTokens) => {
1868
+ const tokens2 = genericToken[childTokens].flat(Infinity);
1869
+ values = values.concat(this.walkTokens(tokens2, callback));
1870
+ });
1871
+ } else if (genericToken.tokens) {
1872
+ values = values.concat(this.walkTokens(genericToken.tokens, callback));
1873
+ }
1874
+ }
1875
+ }
1876
+ }
1877
+ return values;
1878
+ }
1879
+ use(...args) {
1880
+ const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
1881
+ args.forEach((pack) => {
1882
+ const opts = { ...pack };
1883
+ opts.async = this.defaults.async || opts.async || false;
1884
+ if (pack.extensions) {
1885
+ pack.extensions.forEach((ext) => {
1886
+ if (!ext.name) {
1887
+ throw new Error("extension name required");
1888
+ }
1889
+ if ("renderer" in ext) {
1890
+ const prevRenderer = extensions.renderers[ext.name];
1891
+ if (prevRenderer) {
1892
+ extensions.renderers[ext.name] = function(...args2) {
1893
+ let ret = ext.renderer.apply(this, args2);
1894
+ if (ret === false) {
1895
+ ret = prevRenderer.apply(this, args2);
1896
+ }
1897
+ return ret;
1898
+ };
1899
+ } else {
1900
+ extensions.renderers[ext.name] = ext.renderer;
1901
+ }
1902
+ }
1903
+ if ("tokenizer" in ext) {
1904
+ if (!ext.level || ext.level !== "block" && ext.level !== "inline") {
1905
+ throw new Error("extension level must be 'block' or 'inline'");
1906
+ }
1907
+ const extLevel = extensions[ext.level];
1908
+ if (extLevel) {
1909
+ extLevel.unshift(ext.tokenizer);
1910
+ } else {
1911
+ extensions[ext.level] = [ext.tokenizer];
1912
+ }
1913
+ if (ext.start) {
1914
+ if (ext.level === "block") {
1915
+ if (extensions.startBlock) {
1916
+ extensions.startBlock.push(ext.start);
1917
+ } else {
1918
+ extensions.startBlock = [ext.start];
1919
+ }
1920
+ } else if (ext.level === "inline") {
1921
+ if (extensions.startInline) {
1922
+ extensions.startInline.push(ext.start);
1923
+ } else {
1924
+ extensions.startInline = [ext.start];
1925
+ }
1926
+ }
1927
+ }
1928
+ }
1929
+ if ("childTokens" in ext && ext.childTokens) {
1930
+ extensions.childTokens[ext.name] = ext.childTokens;
1931
+ }
1932
+ });
1933
+ opts.extensions = extensions;
1934
+ }
1935
+ if (pack.renderer) {
1936
+ const renderer = this.defaults.renderer || new _Renderer(this.defaults);
1937
+ for (const prop in pack.renderer) {
1938
+ if (!(prop in renderer)) {
1939
+ throw new Error(`renderer '${prop}' does not exist`);
1940
+ }
1941
+ if (["options", "parser"].includes(prop)) {
1942
+ continue;
1943
+ }
1944
+ const rendererProp = prop;
1945
+ const rendererFunc = pack.renderer[rendererProp];
1946
+ const prevRenderer = renderer[rendererProp];
1947
+ renderer[rendererProp] = (...args2) => {
1948
+ let ret = rendererFunc.apply(renderer, args2);
1949
+ if (ret === false) {
1950
+ ret = prevRenderer.apply(renderer, args2);
1951
+ }
1952
+ return ret || "";
1953
+ };
1954
+ }
1955
+ opts.renderer = renderer;
1956
+ }
1957
+ if (pack.tokenizer) {
1958
+ const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
1959
+ for (const prop in pack.tokenizer) {
1960
+ if (!(prop in tokenizer)) {
1961
+ throw new Error(`tokenizer '${prop}' does not exist`);
1962
+ }
1963
+ if (["options", "rules", "lexer"].includes(prop)) {
1964
+ continue;
1965
+ }
1966
+ const tokenizerProp = prop;
1967
+ const tokenizerFunc = pack.tokenizer[tokenizerProp];
1968
+ const prevTokenizer = tokenizer[tokenizerProp];
1969
+ tokenizer[tokenizerProp] = (...args2) => {
1970
+ let ret = tokenizerFunc.apply(tokenizer, args2);
1971
+ if (ret === false) {
1972
+ ret = prevTokenizer.apply(tokenizer, args2);
1973
+ }
1974
+ return ret;
1975
+ };
1976
+ }
1977
+ opts.tokenizer = tokenizer;
1978
+ }
1979
+ if (pack.hooks) {
1980
+ const hooks = this.defaults.hooks || new _Hooks();
1981
+ for (const prop in pack.hooks) {
1982
+ if (!(prop in hooks)) {
1983
+ throw new Error(`hook '${prop}' does not exist`);
1984
+ }
1985
+ if (["options", "block"].includes(prop)) {
1986
+ continue;
1987
+ }
1988
+ const hooksProp = prop;
1989
+ const hooksFunc = pack.hooks[hooksProp];
1990
+ const prevHook = hooks[hooksProp];
1991
+ if (_Hooks.passThroughHooks.has(prop)) {
1992
+ hooks[hooksProp] = (arg) => {
1993
+ if (this.defaults.async) {
1994
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then((ret2) => {
1995
+ return prevHook.call(hooks, ret2);
1996
+ });
1997
+ }
1998
+ const ret = hooksFunc.call(hooks, arg);
1999
+ return prevHook.call(hooks, ret);
2000
+ };
2001
+ } else {
2002
+ hooks[hooksProp] = (...args2) => {
2003
+ let ret = hooksFunc.apply(hooks, args2);
2004
+ if (ret === false) {
2005
+ ret = prevHook.apply(hooks, args2);
2006
+ }
2007
+ return ret;
2008
+ };
2009
+ }
2010
+ }
2011
+ opts.hooks = hooks;
2012
+ }
2013
+ if (pack.walkTokens) {
2014
+ const walkTokens2 = this.defaults.walkTokens;
2015
+ const packWalktokens = pack.walkTokens;
2016
+ opts.walkTokens = function(token) {
2017
+ let values = [];
2018
+ values.push(packWalktokens.call(this, token));
2019
+ if (walkTokens2) {
2020
+ values = values.concat(walkTokens2.call(this, token));
2021
+ }
2022
+ return values;
2023
+ };
2024
+ }
2025
+ this.defaults = { ...this.defaults, ...opts };
2026
+ });
2027
+ return this;
2028
+ }
2029
+ setOptions(opt) {
2030
+ this.defaults = { ...this.defaults, ...opt };
2031
+ return this;
2032
+ }
2033
+ lexer(src, options2) {
2034
+ return _Lexer.lex(src, options2 ?? this.defaults);
2035
+ }
2036
+ parser(tokens, options2) {
2037
+ return _Parser.parse(tokens, options2 ?? this.defaults);
2038
+ }
2039
+ parseMarkdown(blockType) {
2040
+ const parse2 = (src, options2) => {
2041
+ const origOpt = { ...options2 };
2042
+ const opt = { ...this.defaults, ...origOpt };
2043
+ const throwError = this.onError(!!opt.silent, !!opt.async);
2044
+ if (this.defaults.async === true && origOpt.async === false) {
2045
+ return throwError(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
2046
+ }
2047
+ if (typeof src === "undefined" || src === null) {
2048
+ return throwError(new Error("marked(): input parameter is undefined or null"));
2049
+ }
2050
+ if (typeof src !== "string") {
2051
+ return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
2052
+ }
2053
+ if (opt.hooks) {
2054
+ opt.hooks.options = opt;
2055
+ opt.hooks.block = blockType;
2056
+ }
2057
+ const lexer2 = opt.hooks ? opt.hooks.provideLexer() : blockType ? _Lexer.lex : _Lexer.lexInline;
2058
+ const parser2 = opt.hooks ? opt.hooks.provideParser() : blockType ? _Parser.parse : _Parser.parseInline;
2059
+ if (opt.async) {
2060
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then((src2) => lexer2(src2, opt)).then((tokens) => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens).then((tokens) => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then((tokens) => parser2(tokens, opt)).then((html2) => opt.hooks ? opt.hooks.postprocess(html2) : html2).catch(throwError);
2061
+ }
2062
+ try {
2063
+ if (opt.hooks) {
2064
+ src = opt.hooks.preprocess(src);
2065
+ }
2066
+ let tokens = lexer2(src, opt);
2067
+ if (opt.hooks) {
2068
+ tokens = opt.hooks.processAllTokens(tokens);
2069
+ }
2070
+ if (opt.walkTokens) {
2071
+ this.walkTokens(tokens, opt.walkTokens);
2072
+ }
2073
+ let html2 = parser2(tokens, opt);
2074
+ if (opt.hooks) {
2075
+ html2 = opt.hooks.postprocess(html2);
2076
+ }
2077
+ return html2;
2078
+ } catch (e) {
2079
+ return throwError(e);
2080
+ }
2081
+ };
2082
+ return parse2;
2083
+ }
2084
+ onError(silent, async) {
2085
+ return (e) => {
2086
+ e.message += "\nPlease report this to https://github.com/markedjs/marked.";
2087
+ if (silent) {
2088
+ const msg = "<p>An error occurred:</p><pre>" + escape22(e.message + "", true) + "</pre>";
2089
+ if (async) {
2090
+ return Promise.resolve(msg);
2091
+ }
2092
+ return msg;
2093
+ }
2094
+ if (async) {
2095
+ return Promise.reject(e);
2096
+ }
2097
+ throw e;
2098
+ };
2099
+ }
2100
+ };
2101
+ var markedInstance = new Marked();
2102
+ function marked(src, opt) {
2103
+ return markedInstance.parse(src, opt);
2104
+ }
2105
+ marked.options = marked.setOptions = function(options2) {
2106
+ markedInstance.setOptions(options2);
2107
+ marked.defaults = markedInstance.defaults;
2108
+ changeDefaults(marked.defaults);
2109
+ return marked;
2110
+ };
2111
+ marked.getDefaults = _getDefaults;
2112
+ marked.defaults = _defaults;
2113
+ marked.use = function(...args) {
2114
+ markedInstance.use(...args);
2115
+ marked.defaults = markedInstance.defaults;
2116
+ changeDefaults(marked.defaults);
2117
+ return marked;
2118
+ };
2119
+ marked.walkTokens = function(tokens, callback) {
2120
+ return markedInstance.walkTokens(tokens, callback);
2121
+ };
2122
+ marked.parseInline = markedInstance.parseInline;
2123
+ marked.Parser = _Parser;
2124
+ marked.parser = _Parser.parse;
2125
+ marked.Renderer = _Renderer;
2126
+ marked.TextRenderer = _TextRenderer;
2127
+ marked.Lexer = _Lexer;
2128
+ marked.lexer = _Lexer.lex;
2129
+ marked.Tokenizer = _Tokenizer;
2130
+ marked.Hooks = _Hooks;
2131
+ marked.parse = marked;
2132
+ var options = marked.options;
2133
+ var setOptions = marked.setOptions;
2134
+ var use = marked.use;
2135
+ var walkTokens = marked.walkTokens;
2136
+ var parseInline = marked.parseInline;
2137
+ var parser = _Parser.parse;
2138
+ var lexer = _Lexer.lex;
2139
+
2140
+ // webmcp-tools/zhuanlan.zhihu.com/markdown.ts
2141
+ function stripLeadingH1(markdown) {
2142
+ return markdown.replace(/^#\s+[^\n]*\n+/, "");
2143
+ }
2144
+ function escapeHtml(text) {
2145
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2146
+ }
2147
+ function sanitizeHref(href) {
2148
+ if (!href) return "#";
2149
+ const trimmed = href.trim();
2150
+ if (/^(https?:|mailto:|#|\/)/i.test(trimmed)) return trimmed;
2151
+ return "#";
2152
+ }
2153
+ function markdownToHtml(markdown) {
2154
+ const marked2 = new Marked({
2155
+ gfm: true,
2156
+ breaks: false,
2157
+ renderer: {
2158
+ html({ text }) {
2159
+ return escapeHtml(text);
2160
+ },
2161
+ code({ text, lang }) {
2162
+ const langClass = lang ? ` class="language-${escapeHtml(lang)}"` : "";
2163
+ return `<pre><code${langClass}>${escapeHtml(text)}</code></pre>`;
2164
+ },
2165
+ codespan({ text }) {
2166
+ return `<code>${escapeHtml(text)}</code>`;
2167
+ },
2168
+ link({ href, title, text }) {
2169
+ const safeHref = escapeHtml(sanitizeHref(href));
2170
+ const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
2171
+ return `<a href="${safeHref}"${titleAttr}>${text}</a>`;
2172
+ },
2173
+ image({ href, title, text }) {
2174
+ const safeHref = escapeHtml(sanitizeHref(href));
2175
+ const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
2176
+ return `<img src="${safeHref}" alt="${escapeHtml(text || "")}"${titleAttr}>`;
2177
+ }
2178
+ }
2179
+ });
2180
+ return marked2.parse(markdown);
2181
+ }
2182
+ function decodeBase64Content(content) {
2183
+ return decodeURIComponent(escape(atob(content)));
2184
+ }
2185
+
4
2186
  // webmcp-tools/zhuanlan.zhihu.com/index.ts
5
2187
  function isZhihuWritePage() {
6
2188
  return /^https:\/\/zhuanlan\.zhihu\.com\/(write|p\/\d+\/edit)/.test(location.href);
@@ -39,6 +2221,39 @@
39
2221
  function delay(ms) {
40
2222
  return new Promise((resolve) => setTimeout(resolve, ms));
41
2223
  }
2224
+ async function pasteHtmlToDraftEditor(editor, html2) {
2225
+ editor.focus();
2226
+ document.execCommand("selectAll");
2227
+ document.execCommand("delete");
2228
+ await delay(200);
2229
+ const plain = html2.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
2230
+ const dt = new DataTransfer();
2231
+ dt.setData("text/html", html2);
2232
+ dt.setData("text/plain", plain);
2233
+ editor.dispatchEvent(
2234
+ new ClipboardEvent("paste", {
2235
+ clipboardData: dt,
2236
+ bubbles: true,
2237
+ cancelable: true
2238
+ })
2239
+ );
2240
+ await delay(800);
2241
+ const probe = plain.slice(0, 15);
2242
+ let text = getEditorText(editor);
2243
+ const normalizedText = text.replace(/\s+/g, "");
2244
+ const normalizedProbe = probe.replace(/\s+/g, "");
2245
+ if (!normalizedProbe || !normalizedText.includes(normalizedProbe)) {
2246
+ editor.focus();
2247
+ document.execCommand("selectAll");
2248
+ document.execCommand("delete");
2249
+ const inserted = document.execCommand("insertHTML", false, html2);
2250
+ await delay(500);
2251
+ text = getEditorText(editor);
2252
+ if (!inserted || !text.replace(/\s+/g, "").includes(normalizedProbe)) {
2253
+ throw new Error("\u6B63\u6587\u586B\u5199\u5931\u8D25\uFF08Markdown \u8F6C HTML \u7C98\u8D34\u672A\u751F\u6548\uFF09\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5");
2254
+ }
2255
+ }
2256
+ }
42
2257
  async function addTopic(topic, scope) {
43
2258
  const addTopicBtn = Array.from(scope.querySelectorAll("button")).find(
44
2259
  (btn) => /添加话题|添加专栏话题/.test(btn.textContent?.trim() || "")
@@ -83,7 +2298,7 @@
83
2298
  mcp.registerTool({
84
2299
  name: "create_article",
85
2300
  title: "\u586B\u5199\u77E5\u4E4E\u4E13\u680F\u6587\u7AE0",
86
- description: "\u63A5\u6536\u6587\u7AE0\u7684\u6807\u9898\u548C Markdown \u6B63\u6587\uFF0C\u586B\u5199\u5230\u77E5\u4E4E\u4E13\u680F\u7F16\u8F91\u5668\u3002\u6B63\u6587 Markdown \u8F6C HTML \u7C98\u8D34\u7531 webmcp-cli CLI \u5728 Node \u7AEF\u5B8C\u6210\uFF0C\u8BF7\u901A\u8FC7 webmcp-cli run create_article \u8C03\u7528\u3002",
2301
+ description: "\u63A5\u6536\u6587\u7AE0\u7684\u6807\u9898\u548C Markdown \u6B63\u6587\uFF0C\u586B\u5199\u5230\u77E5\u4E4E\u4E13\u680F\u7F16\u8F91\u5668\u3002\u6B63\u6587\u4F1A\u5728\u9875\u9762\u5185\u8F6C\u6362\u4E3A HTML \u5E76\u7C98\u8D34\u5230 Draft.js \u7F16\u8F91\u5668\u3002",
87
2302
  inputSchema: {
88
2303
  type: "object",
89
2304
  properties: {
@@ -93,15 +2308,55 @@
93
2308
  },
94
2309
  content: {
95
2310
  type: "string",
96
- description: "\u6587\u7AE0 Markdown \u6B63\u6587\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32\uFF0C\u5FC5\u586B\u3002CLI \u4F1A\u81EA\u52A8\u8F6C\u6362\u4E3A HTML \u540E\u7C98\u8D34\u5230 Draft.js \u7F16\u8F91\u5668\u3002"
2311
+ description: "\u6587\u7AE0 Markdown \u6B63\u6587\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32\uFF0C\u5FC5\u586B\u3002\u9875\u9762\u5185\u4F1A\u8F6C\u6362\u4E3A HTML \u540E\u7C98\u8D34\u5230 Draft.js \u7F16\u8F91\u5668\u3002"
97
2312
  }
98
2313
  },
99
2314
  required: ["title", "content"]
100
2315
  },
101
- execute: async () => {
102
- throw new Error(
103
- "create_article \u6B63\u6587\u586B\u5199\u7531 webmcp-cli CLI \u5728 Node \u7AEF\u6267\u884C\uFF08Markdown \u8F6C HTML + \u7CFB\u7EDF\u526A\u8D34\u677F\u7C98\u8D34\uFF09\uFF0C\u8BF7\u4F7F\u7528 webmcp-cli run create_article \u547D\u4EE4"
104
- );
2316
+ execute: async ({ title, content }) => {
2317
+ if (!title?.trim()) {
2318
+ throw new Error("\u53C2\u6570 title \u4E0D\u80FD\u4E3A\u7A7A");
2319
+ }
2320
+ if (!content?.trim()) {
2321
+ throw new Error("\u53C2\u6570 content \u4E0D\u80FD\u4E3A\u7A7A");
2322
+ }
2323
+ if (!isZhihuWritePage()) {
2324
+ throw new Error("\u5F53\u524D\u9875\u9762\u4E0D\u662F\u77E5\u4E4E\u4E13\u680F\u7F16\u8F91\u5668\uFF0C\u8BF7\u5148\u6253\u5F00 https://zhuanlan.zhihu.com/write");
2325
+ }
2326
+ let markdown;
2327
+ try {
2328
+ markdown = stripLeadingH1(decodeBase64Content(content));
2329
+ } catch {
2330
+ throw new Error("content \u4E0D\u662F\u6709\u6548\u7684 Base64 \u7F16\u7801\uFF0C\u8BF7\u68C0\u67E5\u53C2\u6570\u6216\u4F7F\u7528 @base64file: \u5F15\u7528\u6587\u4EF6");
2331
+ }
2332
+ if (!markdown.trim()) {
2333
+ throw new Error("\u6B63\u6587\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5 Markdown \u6587\u4EF6");
2334
+ }
2335
+ const titleInput = findTitleInput();
2336
+ if (!titleInput) {
2337
+ throw new Error("\u672A\u627E\u5230\u6807\u9898\u8F93\u5165\u6846\uFF0C\u8BF7\u786E\u8BA4\u7F16\u8F91\u5668\u9875\u9762\u5DF2\u5B8C\u5168\u52A0\u8F7D");
2338
+ }
2339
+ setNativeInputValue(titleInput, title.trim());
2340
+ if (titleInput.value.trim() !== title.trim()) {
2341
+ throw new Error("\u6807\u9898\u586B\u5199\u5931\u8D25\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5");
2342
+ }
2343
+ const editor = findContentEditor();
2344
+ if (!editor) {
2345
+ throw new Error("\u672A\u627E\u5230\u6B63\u6587\u7F16\u8F91\u5668\uFF0C\u8BF7\u786E\u8BA4\u7F16\u8F91\u5668\u9875\u9762\u5DF2\u5B8C\u5168\u52A0\u8F7D");
2346
+ }
2347
+ await delay(300);
2348
+ await pasteHtmlToDraftEditor(editor, markdownToHtml(markdown));
2349
+ return {
2350
+ content: [{
2351
+ type: "text",
2352
+ text: JSON.stringify({
2353
+ success: true,
2354
+ message: "\u6587\u7AE0\u6807\u9898\u548C\u6B63\u6587\u5DF2\u6210\u529F\u586B\u5199\u5230\u77E5\u4E4E\u4E13\u680F\u7F16\u8F91\u5668\uFF08Markdown \u5DF2\u8F6C\u4E3A\u5BCC\u6587\u672C\uFF09\uFF0C\u8349\u7A3F\u5C06\u81EA\u52A8\u4FDD\u5B58",
2355
+ title: title.trim(),
2356
+ contentLength: markdown.length
2357
+ })
2358
+ }]
2359
+ };
105
2360
  }
106
2361
  });
107
2362
  mcp.registerTool({