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