@nuucognition/flint-cli 0.5.6-dev.10 → 0.5.6-dev.11

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