plutonium 0.16.1 → 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -144,8 +144,8 @@
144
144
  return NAN;
145
145
  }
146
146
  if (isObject(value)) {
147
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
148
- value = isObject(other) ? other + "" : other;
147
+ var other2 = typeof value.valueOf == "function" ? value.valueOf() : value;
148
+ value = isObject(other2) ? other2 + "" : other2;
149
149
  }
150
150
  if (typeof value != "string") {
151
151
  return value === 0 ? value : +value;
@@ -8430,10 +8430,200 @@
8430
8430
  function changeDefaults(newDefaults) {
8431
8431
  _defaults = newDefaults;
8432
8432
  }
8433
- var escapeTest = /[&<>"']/;
8434
- var escapeReplace = new RegExp(escapeTest.source, "g");
8435
- var escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
8436
- var escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, "g");
8433
+ var noopTest = { exec: () => null };
8434
+ function edit(regex, opt = "") {
8435
+ let source = typeof regex === "string" ? regex : regex.source;
8436
+ const obj = {
8437
+ replace: (name, val) => {
8438
+ let valSource = typeof val === "string" ? val : val.source;
8439
+ valSource = valSource.replace(other.caret, "$1");
8440
+ source = source.replace(name, valSource);
8441
+ return obj;
8442
+ },
8443
+ getRegex: () => {
8444
+ return new RegExp(source, opt);
8445
+ }
8446
+ };
8447
+ return obj;
8448
+ }
8449
+ var other = {
8450
+ codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
8451
+ outputLinkReplace: /\\([\[\]])/g,
8452
+ indentCodeCompensation: /^(\s+)(?:```)/,
8453
+ beginningSpace: /^\s+/,
8454
+ endingHash: /#$/,
8455
+ startingSpaceChar: /^ /,
8456
+ endingSpaceChar: / $/,
8457
+ nonSpaceChar: /[^ ]/,
8458
+ newLineCharGlobal: /\n/g,
8459
+ tabCharGlobal: /\t/g,
8460
+ multipleSpaceGlobal: /\s+/g,
8461
+ blankLine: /^[ \t]*$/,
8462
+ doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
8463
+ blockquoteStart: /^ {0,3}>/,
8464
+ blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
8465
+ blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
8466
+ listReplaceTabs: /^\t+/,
8467
+ listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
8468
+ listIsTask: /^\[[ xX]\] /,
8469
+ listReplaceTask: /^\[[ xX]\] +/,
8470
+ anyLine: /\n.*\n/,
8471
+ hrefBrackets: /^<(.*)>$/,
8472
+ tableDelimiter: /[:|]/,
8473
+ tableAlignChars: /^\||\| *$/g,
8474
+ tableRowBlankLine: /\n[ \t]*$/,
8475
+ tableAlignRight: /^ *-+: *$/,
8476
+ tableAlignCenter: /^ *:-+: *$/,
8477
+ tableAlignLeft: /^ *:-+ *$/,
8478
+ startATag: /^<a /i,
8479
+ endATag: /^<\/a>/i,
8480
+ startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
8481
+ endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
8482
+ startAngleBracket: /^</,
8483
+ endAngleBracket: />$/,
8484
+ pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
8485
+ unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
8486
+ escapeTest: /[&<>"']/,
8487
+ escapeReplace: /[&<>"']/g,
8488
+ escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
8489
+ escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
8490
+ unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
8491
+ caret: /(^|[^\[])\^/g,
8492
+ percentDecode: /%25/g,
8493
+ findPipe: /\|/g,
8494
+ splitPipe: / \|/,
8495
+ slashPipe: /\\\|/g,
8496
+ carriageReturn: /\r\n|\r/g,
8497
+ spaceLine: /^ +$/gm,
8498
+ notSpaceStart: /^\S*/,
8499
+ endingNewline: /\n$/,
8500
+ listItemRegex: (bull) => new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`),
8501
+ nextBulletRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
8502
+ hrRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
8503
+ fencesBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`),
8504
+ headingBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`),
8505
+ htmlBeginRegex: (indent) => new RegExp(`^ {0,${Math.min(3, indent - 1)}}<(?:[a-z].*>|!--)`, "i")
8506
+ };
8507
+ var newline = /^(?:[ \t]*(?:\n|$))+/;
8508
+ var blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
8509
+ var fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
8510
+ var hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
8511
+ var heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
8512
+ var bullet = /(?:[*+-]|\d{1,9}[.)])/;
8513
+ var lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).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/).getRegex();
8514
+ var _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
8515
+ var blockText = /^[^\n]+/;
8516
+ var _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
8517
+ 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();
8518
+ var list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
8519
+ 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";
8520
+ var _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
8521
+ var html2 = 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|/?>)[\\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();
8522
+ 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();
8523
+ var blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", paragraph).getRegex();
8524
+ var blockNormal = {
8525
+ blockquote,
8526
+ code: blockCode,
8527
+ def,
8528
+ fences,
8529
+ heading,
8530
+ hr,
8531
+ html: html2,
8532
+ lheading,
8533
+ list,
8534
+ newline,
8535
+ paragraph,
8536
+ table: noopTest,
8537
+ text: blockText
8538
+ };
8539
+ var 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();
8540
+ var blockGfm = {
8541
+ ...blockNormal,
8542
+ table: gfmTable,
8543
+ 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()
8544
+ };
8545
+ var blockPedantic = {
8546
+ ...blockNormal,
8547
+ 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(),
8548
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
8549
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
8550
+ fences: noopTest,
8551
+ // fences not supported
8552
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
8553
+ 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()
8554
+ };
8555
+ var escape$1 = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
8556
+ var inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
8557
+ var br = /^( {2,}|\\)\n(?!\s*$)/;
8558
+ var inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
8559
+ var _punctuation = /[\p{P}\p{S}]/u;
8560
+ var _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
8561
+ var _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
8562
+ var punctuation = edit(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, _punctuationOrSpace).getRegex();
8563
+ var blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
8564
+ var emStrongLDelim = edit(/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, "u").replace(/punct/g, _punctuation).getRegex();
8565
+ var emStrongRDelimAst = edit("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", "gu").replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
8566
+ var 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();
8567
+ var anyPunctuation = edit(/\\(punct)/, "gu").replace(/punct/g, _punctuation).getRegex();
8568
+ 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();
8569
+ var _inlineComment = edit(_comment).replace("(?:-->|$)", "-->").getRegex();
8570
+ var 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();
8571
+ var _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
8572
+ var link = edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label", _inlineLabel).replace("href", /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
8573
+ var reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace("label", _inlineLabel).replace("ref", _blockLabel).getRegex();
8574
+ var nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace("ref", _blockLabel).getRegex();
8575
+ var reflinkSearch = edit("reflink|nolink(?!\\()", "g").replace("reflink", reflink).replace("nolink", nolink).getRegex();
8576
+ var inlineNormal = {
8577
+ _backpedal: noopTest,
8578
+ // only used for GFM url
8579
+ anyPunctuation,
8580
+ autolink,
8581
+ blockSkip,
8582
+ br,
8583
+ code: inlineCode,
8584
+ del: noopTest,
8585
+ emStrongLDelim,
8586
+ emStrongRDelimAst,
8587
+ emStrongRDelimUnd,
8588
+ escape: escape$1,
8589
+ link,
8590
+ nolink,
8591
+ punctuation,
8592
+ reflink,
8593
+ reflinkSearch,
8594
+ tag,
8595
+ text: inlineText,
8596
+ url: noopTest
8597
+ };
8598
+ var inlinePedantic = {
8599
+ ...inlineNormal,
8600
+ link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", _inlineLabel).getRegex(),
8601
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", _inlineLabel).getRegex()
8602
+ };
8603
+ var inlineGfm = {
8604
+ ...inlineNormal,
8605
+ escape: edit(escape$1).replace("])", "~|])").getRegex(),
8606
+ 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(),
8607
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
8608
+ del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
8609
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
8610
+ };
8611
+ var inlineBreaks = {
8612
+ ...inlineGfm,
8613
+ br: edit(br).replace("{2,}", "*").getRegex(),
8614
+ text: edit(inlineGfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
8615
+ };
8616
+ var block = {
8617
+ normal: blockNormal,
8618
+ gfm: blockGfm,
8619
+ pedantic: blockPedantic
8620
+ };
8621
+ var inline = {
8622
+ normal: inlineNormal,
8623
+ gfm: inlineGfm,
8624
+ breaks: inlineBreaks,
8625
+ pedantic: inlinePedantic
8626
+ };
8437
8627
  var escapeReplacements = {
8438
8628
  "&": "&amp;",
8439
8629
  "<": "&lt;",
@@ -8442,58 +8632,28 @@
8442
8632
  "'": "&#39;"
8443
8633
  };
8444
8634
  var getEscapeReplacement = (ch) => escapeReplacements[ch];
8445
- function escape$1(html3, encode) {
8635
+ function escape(html3, encode) {
8446
8636
  if (encode) {
8447
- if (escapeTest.test(html3)) {
8448
- return html3.replace(escapeReplace, getEscapeReplacement);
8637
+ if (other.escapeTest.test(html3)) {
8638
+ return html3.replace(other.escapeReplace, getEscapeReplacement);
8449
8639
  }
8450
8640
  } else {
8451
- if (escapeTestNoEncode.test(html3)) {
8452
- return html3.replace(escapeReplaceNoEncode, getEscapeReplacement);
8641
+ if (other.escapeTestNoEncode.test(html3)) {
8642
+ return html3.replace(other.escapeReplaceNoEncode, getEscapeReplacement);
8453
8643
  }
8454
8644
  }
8455
8645
  return html3;
8456
8646
  }
8457
- var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
8458
- function unescape(html3) {
8459
- return html3.replace(unescapeTest, (_, n) => {
8460
- n = n.toLowerCase();
8461
- if (n === "colon")
8462
- return ":";
8463
- if (n.charAt(0) === "#") {
8464
- return n.charAt(1) === "x" ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
8465
- }
8466
- return "";
8467
- });
8468
- }
8469
- var caret = /(^|[^\[])\^/g;
8470
- function edit(regex, opt) {
8471
- let source = typeof regex === "string" ? regex : regex.source;
8472
- opt = opt || "";
8473
- const obj = {
8474
- replace: (name, val) => {
8475
- let valSource = typeof val === "string" ? val : val.source;
8476
- valSource = valSource.replace(caret, "$1");
8477
- source = source.replace(name, valSource);
8478
- return obj;
8479
- },
8480
- getRegex: () => {
8481
- return new RegExp(source, opt);
8482
- }
8483
- };
8484
- return obj;
8485
- }
8486
8647
  function cleanUrl(href) {
8487
8648
  try {
8488
- href = encodeURI(href).replace(/%25/g, "%");
8649
+ href = encodeURI(href).replace(other.percentDecode, "%");
8489
8650
  } catch {
8490
8651
  return null;
8491
8652
  }
8492
8653
  return href;
8493
8654
  }
8494
- var noopTest = { exec: () => null };
8495
8655
  function splitCells(tableRow, count) {
8496
- const row = tableRow.replace(/\|/g, (match, offset2, str) => {
8656
+ const row = tableRow.replace(other.findPipe, (match, offset2, str) => {
8497
8657
  let escaped = false;
8498
8658
  let curr = offset2;
8499
8659
  while (--curr >= 0 && str[curr] === "\\")
@@ -8503,12 +8663,12 @@
8503
8663
  } else {
8504
8664
  return " |";
8505
8665
  }
8506
- }), cells = row.split(/ \|/);
8666
+ }), cells = row.split(other.splitPipe);
8507
8667
  let i = 0;
8508
8668
  if (!cells[0].trim()) {
8509
8669
  cells.shift();
8510
8670
  }
8511
- if (cells.length > 0 && !cells[cells.length - 1].trim()) {
8671
+ if (cells.length > 0 && !cells.at(-1)?.trim()) {
8512
8672
  cells.pop();
8513
8673
  }
8514
8674
  if (count) {
@@ -8520,7 +8680,7 @@
8520
8680
  }
8521
8681
  }
8522
8682
  for (; i < cells.length; i++) {
8523
- cells[i] = cells[i].trim().replace(/\\\|/g, "|");
8683
+ cells[i] = cells[i].trim().replace(other.slashPipe, "|");
8524
8684
  }
8525
8685
  return cells;
8526
8686
  }
@@ -8561,10 +8721,10 @@
8561
8721
  }
8562
8722
  return -1;
8563
8723
  }
8564
- function outputLink(cap, link2, raw, lexer2) {
8724
+ function outputLink(cap, link2, raw, lexer2, rules) {
8565
8725
  const href = link2.href;
8566
- const title = link2.title ? escape$1(link2.title) : null;
8567
- const text2 = cap[1].replace(/\\([\[\]])/g, "$1");
8726
+ const title = link2.title || null;
8727
+ const text2 = cap[1].replace(rules.other.outputLinkReplace, "$1");
8568
8728
  if (cap[0].charAt(0) !== "!") {
8569
8729
  lexer2.state.inLink = true;
8570
8730
  const token = {
@@ -8583,17 +8743,17 @@
8583
8743
  raw,
8584
8744
  href,
8585
8745
  title,
8586
- text: escape$1(text2)
8746
+ text: text2
8587
8747
  };
8588
8748
  }
8589
- function indentCodeCompensation(raw, text2) {
8590
- const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
8749
+ function indentCodeCompensation(raw, text2, rules) {
8750
+ const matchIndentToCode = raw.match(rules.other.indentCodeCompensation);
8591
8751
  if (matchIndentToCode === null) {
8592
8752
  return text2;
8593
8753
  }
8594
8754
  const indentToCode = matchIndentToCode[1];
8595
8755
  return text2.split("\n").map((node) => {
8596
- const matchIndentInNode = node.match(/^\s+/);
8756
+ const matchIndentInNode = node.match(rules.other.beginningSpace);
8597
8757
  if (matchIndentInNode === null) {
8598
8758
  return node;
8599
8759
  }
@@ -8625,7 +8785,7 @@
8625
8785
  code(src) {
8626
8786
  const cap = this.rules.block.code.exec(src);
8627
8787
  if (cap) {
8628
- const text2 = cap[0].replace(/^ {1,4}/gm, "");
8788
+ const text2 = cap[0].replace(this.rules.other.codeRemoveIndent, "");
8629
8789
  return {
8630
8790
  type: "code",
8631
8791
  raw: cap[0],
@@ -8638,7 +8798,7 @@
8638
8798
  const cap = this.rules.block.fences.exec(src);
8639
8799
  if (cap) {
8640
8800
  const raw = cap[0];
8641
- const text2 = indentCodeCompensation(raw, cap[3] || "");
8801
+ const text2 = indentCodeCompensation(raw, cap[3] || "", this.rules);
8642
8802
  return {
8643
8803
  type: "code",
8644
8804
  raw,
@@ -8651,11 +8811,11 @@
8651
8811
  const cap = this.rules.block.heading.exec(src);
8652
8812
  if (cap) {
8653
8813
  let text2 = cap[2].trim();
8654
- if (/#$/.test(text2)) {
8814
+ if (this.rules.other.endingHash.test(text2)) {
8655
8815
  const trimmed = rtrim(text2, "#");
8656
8816
  if (this.options.pedantic) {
8657
8817
  text2 = trimmed.trim();
8658
- } else if (!trimmed || / $/.test(trimmed)) {
8818
+ } else if (!trimmed || this.rules.other.endingSpaceChar.test(trimmed)) {
8659
8819
  text2 = trimmed.trim();
8660
8820
  }
8661
8821
  }
@@ -8689,7 +8849,7 @@
8689
8849
  const currentLines = [];
8690
8850
  let i;
8691
8851
  for (i = 0; i < lines.length; i++) {
8692
- if (/^ {0,3}>/.test(lines[i])) {
8852
+ if (this.rules.other.blockquoteStart.test(lines[i])) {
8693
8853
  currentLines.push(lines[i]);
8694
8854
  inBlockquote = true;
8695
8855
  } else if (!inBlockquote) {
@@ -8700,7 +8860,7 @@
8700
8860
  }
8701
8861
  lines = lines.slice(i);
8702
8862
  const currentRaw = currentLines.join("\n");
8703
- const currentText = currentRaw.replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g, "\n $1").replace(/^ {0,3}>[ \t]?/gm, "");
8863
+ const currentText = currentRaw.replace(this.rules.other.blockquoteSetextReplace, "\n $1").replace(this.rules.other.blockquoteSetextReplace2, "");
8704
8864
  raw = raw ? `${raw}
8705
8865
  ${currentRaw}` : currentRaw;
8706
8866
  text2 = text2 ? `${text2}
@@ -8712,7 +8872,7 @@ ${currentText}` : currentText;
8712
8872
  if (lines.length === 0) {
8713
8873
  break;
8714
8874
  }
8715
- const lastToken = tokens[tokens.length - 1];
8875
+ const lastToken = tokens.at(-1);
8716
8876
  if (lastToken?.type === "code") {
8717
8877
  break;
8718
8878
  } else if (lastToken?.type === "blockquote") {
@@ -8730,7 +8890,7 @@ ${currentText}` : currentText;
8730
8890
  tokens[tokens.length - 1] = newToken;
8731
8891
  raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
8732
8892
  text2 = text2.substring(0, text2.length - oldToken.raw.length) + newToken.raw;
8733
- lines = newText.substring(tokens[tokens.length - 1].raw.length).split("\n");
8893
+ lines = newText.substring(tokens.at(-1).raw.length).split("\n");
8734
8894
  continue;
8735
8895
  }
8736
8896
  }
@@ -8759,7 +8919,7 @@ ${currentText}` : currentText;
8759
8919
  if (this.options.pedantic) {
8760
8920
  bull = isordered ? bull : "[*+-]";
8761
8921
  }
8762
- const itemRegex = new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`);
8922
+ const itemRegex = this.rules.other.listItemRegex(bull);
8763
8923
  let endsWithBlankLine = false;
8764
8924
  while (src) {
8765
8925
  let endEarly = false;
@@ -8773,7 +8933,7 @@ ${currentText}` : currentText;
8773
8933
  }
8774
8934
  raw = cap[0];
8775
8935
  src = src.substring(raw.length);
8776
- let line = cap[2].split("\n", 1)[0].replace(/^\t+/, (t) => " ".repeat(3 * t.length));
8936
+ let line = cap[2].split("\n", 1)[0].replace(this.rules.other.listReplaceTabs, (t) => " ".repeat(3 * t.length));
8777
8937
  let nextLine = src.split("\n", 1)[0];
8778
8938
  let blankLine = !line.trim();
8779
8939
  let indent = 0;
@@ -8783,26 +8943,31 @@ ${currentText}` : currentText;
8783
8943
  } else if (blankLine) {
8784
8944
  indent = cap[1].length + 1;
8785
8945
  } else {
8786
- indent = cap[2].search(/[^ ]/);
8946
+ indent = cap[2].search(this.rules.other.nonSpaceChar);
8787
8947
  indent = indent > 4 ? 1 : indent;
8788
8948
  itemContents = line.slice(indent);
8789
8949
  indent += cap[1].length;
8790
8950
  }
8791
- if (blankLine && /^ *$/.test(nextLine)) {
8951
+ if (blankLine && this.rules.other.blankLine.test(nextLine)) {
8792
8952
  raw += nextLine + "\n";
8793
8953
  src = src.substring(nextLine.length + 1);
8794
8954
  endEarly = true;
8795
8955
  }
8796
8956
  if (!endEarly) {
8797
- const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`);
8798
- const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
8799
- const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
8800
- const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
8957
+ const nextBulletRegex = this.rules.other.nextBulletRegex(indent);
8958
+ const hrRegex = this.rules.other.hrRegex(indent);
8959
+ const fencesBeginRegex = this.rules.other.fencesBeginRegex(indent);
8960
+ const headingBeginRegex = this.rules.other.headingBeginRegex(indent);
8961
+ const htmlBeginRegex = this.rules.other.htmlBeginRegex(indent);
8801
8962
  while (src) {
8802
8963
  const rawLine = src.split("\n", 1)[0];
8964
+ let nextLineWithoutTabs;
8803
8965
  nextLine = rawLine;
8804
8966
  if (this.options.pedantic) {
8805
- nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, " ");
8967
+ nextLine = nextLine.replace(this.rules.other.listReplaceNesting, " ");
8968
+ nextLineWithoutTabs = nextLine;
8969
+ } else {
8970
+ nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, " ");
8806
8971
  }
8807
8972
  if (fencesBeginRegex.test(nextLine)) {
8808
8973
  break;
@@ -8810,19 +8975,22 @@ ${currentText}` : currentText;
8810
8975
  if (headingBeginRegex.test(nextLine)) {
8811
8976
  break;
8812
8977
  }
8978
+ if (htmlBeginRegex.test(nextLine)) {
8979
+ break;
8980
+ }
8813
8981
  if (nextBulletRegex.test(nextLine)) {
8814
8982
  break;
8815
8983
  }
8816
- if (hrRegex.test(src)) {
8984
+ if (hrRegex.test(nextLine)) {
8817
8985
  break;
8818
8986
  }
8819
- if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) {
8820
- itemContents += "\n" + nextLine.slice(indent);
8987
+ if (nextLineWithoutTabs.search(this.rules.other.nonSpaceChar) >= indent || !nextLine.trim()) {
8988
+ itemContents += "\n" + nextLineWithoutTabs.slice(indent);
8821
8989
  } else {
8822
8990
  if (blankLine) {
8823
8991
  break;
8824
8992
  }
8825
- if (line.search(/[^ ]/) >= 4) {
8993
+ if (line.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4) {
8826
8994
  break;
8827
8995
  }
8828
8996
  if (fencesBeginRegex.test(line)) {
@@ -8841,23 +9009,23 @@ ${currentText}` : currentText;
8841
9009
  }
8842
9010
  raw += rawLine + "\n";
8843
9011
  src = src.substring(rawLine.length + 1);
8844
- line = nextLine.slice(indent);
9012
+ line = nextLineWithoutTabs.slice(indent);
8845
9013
  }
8846
9014
  }
8847
9015
  if (!list2.loose) {
8848
9016
  if (endsWithBlankLine) {
8849
9017
  list2.loose = true;
8850
- } else if (/\n *\n *$/.test(raw)) {
9018
+ } else if (this.rules.other.doubleBlankLine.test(raw)) {
8851
9019
  endsWithBlankLine = true;
8852
9020
  }
8853
9021
  }
8854
9022
  let istask = null;
8855
9023
  let ischecked;
8856
9024
  if (this.options.gfm) {
8857
- istask = /^\[[ xX]\] /.exec(itemContents);
9025
+ istask = this.rules.other.listIsTask.exec(itemContents);
8858
9026
  if (istask) {
8859
9027
  ischecked = istask[0] !== "[ ] ";
8860
- itemContents = itemContents.replace(/^\[[ xX]\] +/, "");
9028
+ itemContents = itemContents.replace(this.rules.other.listReplaceTask, "");
8861
9029
  }
8862
9030
  }
8863
9031
  list2.items.push({
@@ -8871,15 +9039,18 @@ ${currentText}` : currentText;
8871
9039
  });
8872
9040
  list2.raw += raw;
8873
9041
  }
8874
- list2.items[list2.items.length - 1].raw = list2.items[list2.items.length - 1].raw.trimEnd();
8875
- list2.items[list2.items.length - 1].text = list2.items[list2.items.length - 1].text.trimEnd();
9042
+ const lastItem = list2.items.at(-1);
9043
+ if (lastItem) {
9044
+ lastItem.raw = lastItem.raw.trimEnd();
9045
+ lastItem.text = lastItem.text.trimEnd();
9046
+ }
8876
9047
  list2.raw = list2.raw.trimEnd();
8877
9048
  for (let i = 0; i < list2.items.length; i++) {
8878
9049
  this.lexer.state.top = false;
8879
9050
  list2.items[i].tokens = this.lexer.blockTokens(list2.items[i].text, []);
8880
9051
  if (!list2.loose) {
8881
9052
  const spacers = list2.items[i].tokens.filter((t) => t.type === "space");
8882
- const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => /\n.*\n/.test(t.raw));
9053
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => this.rules.other.anyLine.test(t.raw));
8883
9054
  list2.loose = hasMultipleLineBreaks;
8884
9055
  }
8885
9056
  }
@@ -8907,8 +9078,8 @@ ${currentText}` : currentText;
8907
9078
  def(src) {
8908
9079
  const cap = this.rules.block.def.exec(src);
8909
9080
  if (cap) {
8910
- const tag2 = cap[1].toLowerCase().replace(/\s+/g, " ");
8911
- const href = cap[2] ? cap[2].replace(/^<(.*)>$/, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "";
9081
+ const tag2 = cap[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " ");
9082
+ const href = cap[2] ? cap[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "";
8912
9083
  const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : cap[3];
8913
9084
  return {
8914
9085
  type: "def",
@@ -8924,12 +9095,12 @@ ${currentText}` : currentText;
8924
9095
  if (!cap) {
8925
9096
  return;
8926
9097
  }
8927
- if (!/[:|]/.test(cap[2])) {
9098
+ if (!this.rules.other.tableDelimiter.test(cap[2])) {
8928
9099
  return;
8929
9100
  }
8930
9101
  const headers = splitCells(cap[1]);
8931
- const aligns = cap[2].replace(/^\||\| *$/g, "").split("|");
8932
- const rows = cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, "").split("\n") : [];
9102
+ const aligns = cap[2].replace(this.rules.other.tableAlignChars, "").split("|");
9103
+ const rows = cap[3]?.trim() ? cap[3].replace(this.rules.other.tableRowBlankLine, "").split("\n") : [];
8933
9104
  const item = {
8934
9105
  type: "table",
8935
9106
  raw: cap[0],
@@ -8941,11 +9112,11 @@ ${currentText}` : currentText;
8941
9112
  return;
8942
9113
  }
8943
9114
  for (const align of aligns) {
8944
- if (/^ *-+: *$/.test(align)) {
9115
+ if (this.rules.other.tableAlignRight.test(align)) {
8945
9116
  item.align.push("right");
8946
- } else if (/^ *:-+: *$/.test(align)) {
9117
+ } else if (this.rules.other.tableAlignCenter.test(align)) {
8947
9118
  item.align.push("center");
8948
- } else if (/^ *:-+ *$/.test(align)) {
9119
+ } else if (this.rules.other.tableAlignLeft.test(align)) {
8949
9120
  item.align.push("left");
8950
9121
  } else {
8951
9122
  item.align.push(null);
@@ -9012,21 +9183,21 @@ ${currentText}` : currentText;
9012
9183
  return {
9013
9184
  type: "escape",
9014
9185
  raw: cap[0],
9015
- text: escape$1(cap[1])
9186
+ text: cap[1]
9016
9187
  };
9017
9188
  }
9018
9189
  }
9019
9190
  tag(src) {
9020
9191
  const cap = this.rules.inline.tag.exec(src);
9021
9192
  if (cap) {
9022
- if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
9193
+ if (!this.lexer.state.inLink && this.rules.other.startATag.test(cap[0])) {
9023
9194
  this.lexer.state.inLink = true;
9024
- } else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
9195
+ } else if (this.lexer.state.inLink && this.rules.other.endATag.test(cap[0])) {
9025
9196
  this.lexer.state.inLink = false;
9026
9197
  }
9027
- if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
9198
+ if (!this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(cap[0])) {
9028
9199
  this.lexer.state.inRawBlock = true;
9029
- } else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
9200
+ } else if (this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(cap[0])) {
9030
9201
  this.lexer.state.inRawBlock = false;
9031
9202
  }
9032
9203
  return {
@@ -9043,8 +9214,8 @@ ${currentText}` : currentText;
9043
9214
  const cap = this.rules.inline.link.exec(src);
9044
9215
  if (cap) {
9045
9216
  const trimmedUrl = cap[2].trim();
9046
- if (!this.options.pedantic && /^</.test(trimmedUrl)) {
9047
- if (!/>$/.test(trimmedUrl)) {
9217
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(trimmedUrl)) {
9218
+ if (!this.rules.other.endAngleBracket.test(trimmedUrl)) {
9048
9219
  return;
9049
9220
  }
9050
9221
  const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), "\\");
@@ -9064,7 +9235,7 @@ ${currentText}` : currentText;
9064
9235
  let href = cap[2];
9065
9236
  let title = "";
9066
9237
  if (this.options.pedantic) {
9067
- const link2 = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
9238
+ const link2 = this.rules.other.pedanticHrefTitle.exec(href);
9068
9239
  if (link2) {
9069
9240
  href = link2[1];
9070
9241
  title = link2[3];
@@ -9073,8 +9244,8 @@ ${currentText}` : currentText;
9073
9244
  title = cap[3] ? cap[3].slice(1, -1) : "";
9074
9245
  }
9075
9246
  href = href.trim();
9076
- if (/^</.test(href)) {
9077
- if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
9247
+ if (this.rules.other.startAngleBracket.test(href)) {
9248
+ if (this.options.pedantic && !this.rules.other.endAngleBracket.test(trimmedUrl)) {
9078
9249
  href = href.slice(1);
9079
9250
  } else {
9080
9251
  href = href.slice(1, -1);
@@ -9083,13 +9254,13 @@ ${currentText}` : currentText;
9083
9254
  return outputLink(cap, {
9084
9255
  href: href ? href.replace(this.rules.inline.anyPunctuation, "$1") : href,
9085
9256
  title: title ? title.replace(this.rules.inline.anyPunctuation, "$1") : title
9086
- }, cap[0], this.lexer);
9257
+ }, cap[0], this.lexer, this.rules);
9087
9258
  }
9088
9259
  }
9089
9260
  reflink(src, links) {
9090
9261
  let cap;
9091
9262
  if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
9092
- const linkString = (cap[2] || cap[1]).replace(/\s+/g, " ");
9263
+ const linkString = (cap[2] || cap[1]).replace(this.rules.other.multipleSpaceGlobal, " ");
9093
9264
  const link2 = links[linkString.toLowerCase()];
9094
9265
  if (!link2) {
9095
9266
  const text2 = cap[0].charAt(0);
@@ -9099,14 +9270,14 @@ ${currentText}` : currentText;
9099
9270
  text: text2
9100
9271
  };
9101
9272
  }
9102
- return outputLink(cap, link2, cap[0], this.lexer);
9273
+ return outputLink(cap, link2, cap[0], this.lexer, this.rules);
9103
9274
  }
9104
9275
  }
9105
9276
  emStrong(src, maskedSrc, prevChar = "") {
9106
9277
  let match = this.rules.inline.emStrongLDelim.exec(src);
9107
9278
  if (!match)
9108
9279
  return;
9109
- if (match[3] && prevChar.match(/[\p{L}\p{N}]/u))
9280
+ if (match[3] && prevChar.match(this.rules.other.unicodeAlphaNumeric))
9110
9281
  return;
9111
9282
  const nextChar = match[1] || match[2] || "";
9112
9283
  if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
@@ -9157,13 +9328,12 @@ ${currentText}` : currentText;
9157
9328
  codespan(src) {
9158
9329
  const cap = this.rules.inline.code.exec(src);
9159
9330
  if (cap) {
9160
- let text2 = cap[2].replace(/\n/g, " ");
9161
- const hasNonSpaceChars = /[^ ]/.test(text2);
9162
- const hasSpaceCharsOnBothEnds = /^ /.test(text2) && / $/.test(text2);
9331
+ let text2 = cap[2].replace(this.rules.other.newLineCharGlobal, " ");
9332
+ const hasNonSpaceChars = this.rules.other.nonSpaceChar.test(text2);
9333
+ const hasSpaceCharsOnBothEnds = this.rules.other.startingSpaceChar.test(text2) && this.rules.other.endingSpaceChar.test(text2);
9163
9334
  if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
9164
9335
  text2 = text2.substring(1, text2.length - 1);
9165
9336
  }
9166
- text2 = escape$1(text2, true);
9167
9337
  return {
9168
9338
  type: "codespan",
9169
9339
  raw: cap[0],
@@ -9196,10 +9366,10 @@ ${currentText}` : currentText;
9196
9366
  if (cap) {
9197
9367
  let text2, href;
9198
9368
  if (cap[2] === "@") {
9199
- text2 = escape$1(cap[1]);
9369
+ text2 = cap[1];
9200
9370
  href = "mailto:" + text2;
9201
9371
  } else {
9202
- text2 = escape$1(cap[1]);
9372
+ text2 = cap[1];
9203
9373
  href = text2;
9204
9374
  }
9205
9375
  return {
@@ -9222,7 +9392,7 @@ ${currentText}` : currentText;
9222
9392
  if (cap = this.rules.inline.url.exec(src)) {
9223
9393
  let text2, href;
9224
9394
  if (cap[2] === "@") {
9225
- text2 = escape$1(cap[0]);
9395
+ text2 = cap[0];
9226
9396
  href = "mailto:" + text2;
9227
9397
  } else {
9228
9398
  let prevCapZero;
@@ -9230,7 +9400,7 @@ ${currentText}` : currentText;
9230
9400
  prevCapZero = cap[0];
9231
9401
  cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? "";
9232
9402
  } while (prevCapZero !== cap[0]);
9233
- text2 = escape$1(cap[0]);
9403
+ text2 = cap[0];
9234
9404
  if (cap[1] === "www.") {
9235
9405
  href = "http://" + cap[0];
9236
9406
  } else {
@@ -9255,138 +9425,16 @@ ${currentText}` : currentText;
9255
9425
  inlineText(src) {
9256
9426
  const cap = this.rules.inline.text.exec(src);
9257
9427
  if (cap) {
9258
- let text2;
9259
- if (this.lexer.state.inRawBlock) {
9260
- text2 = cap[0];
9261
- } else {
9262
- text2 = escape$1(cap[0]);
9263
- }
9428
+ const escaped = this.lexer.state.inRawBlock;
9264
9429
  return {
9265
9430
  type: "text",
9266
9431
  raw: cap[0],
9267
- text: text2
9432
+ text: cap[0],
9433
+ escaped
9268
9434
  };
9269
9435
  }
9270
9436
  }
9271
9437
  };
9272
- var newline = /^(?: *(?:\n|$))+/;
9273
- var blockCode = /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/;
9274
- var fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
9275
- var hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
9276
- var heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
9277
- var bullet = /(?:[*+-]|\d{1,9}[.)])/;
9278
- var lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g, bullet).replace(/blockCode/g, / {4}/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).getRegex();
9279
- var _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
9280
- var blockText = /^[^\n]+/;
9281
- var _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
9282
- var def = edit(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label", _blockLabel).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
9283
- var list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
9284
- 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";
9285
- var _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
9286
- var html2 = 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|/?>)[\\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();
9287
- 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();
9288
- var blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", paragraph).getRegex();
9289
- var blockNormal = {
9290
- blockquote,
9291
- code: blockCode,
9292
- def,
9293
- fences,
9294
- heading,
9295
- hr,
9296
- html: html2,
9297
- lheading,
9298
- list,
9299
- newline,
9300
- paragraph,
9301
- table: noopTest,
9302
- text: blockText
9303
- };
9304
- var 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}[^\\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();
9305
- var blockGfm = {
9306
- ...blockNormal,
9307
- table: gfmTable,
9308
- 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()
9309
- };
9310
- var blockPedantic = {
9311
- ...blockNormal,
9312
- 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(),
9313
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
9314
- heading: /^(#{1,6})(.*)(?:\n+|$)/,
9315
- fences: noopTest,
9316
- // fences not supported
9317
- lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
9318
- 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()
9319
- };
9320
- var escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
9321
- var inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
9322
- var br = /^( {2,}|\\)\n(?!\s*$)/;
9323
- var inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
9324
- var _punctuation = "\\p{P}\\p{S}";
9325
- var punctuation = edit(/^((?![*_])[\spunctuation])/, "u").replace(/punctuation/g, _punctuation).getRegex();
9326
- var blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
9327
- var emStrongLDelim = edit(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/, "u").replace(/punct/g, _punctuation).getRegex();
9328
- var emStrongRDelimAst = edit("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])", "gu").replace(/punct/g, _punctuation).getRegex();
9329
- var emStrongRDelimUnd = edit("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])", "gu").replace(/punct/g, _punctuation).getRegex();
9330
- var anyPunctuation = edit(/\\([punct])/, "gu").replace(/punct/g, _punctuation).getRegex();
9331
- 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();
9332
- var _inlineComment = edit(_comment).replace("(?:-->|$)", "-->").getRegex();
9333
- var 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();
9334
- var _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
9335
- var link = edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label", _inlineLabel).replace("href", /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
9336
- var reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace("label", _inlineLabel).replace("ref", _blockLabel).getRegex();
9337
- var nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace("ref", _blockLabel).getRegex();
9338
- var reflinkSearch = edit("reflink|nolink(?!\\()", "g").replace("reflink", reflink).replace("nolink", nolink).getRegex();
9339
- var inlineNormal = {
9340
- _backpedal: noopTest,
9341
- // only used for GFM url
9342
- anyPunctuation,
9343
- autolink,
9344
- blockSkip,
9345
- br,
9346
- code: inlineCode,
9347
- del: noopTest,
9348
- emStrongLDelim,
9349
- emStrongRDelimAst,
9350
- emStrongRDelimUnd,
9351
- escape,
9352
- link,
9353
- nolink,
9354
- punctuation,
9355
- reflink,
9356
- reflinkSearch,
9357
- tag,
9358
- text: inlineText,
9359
- url: noopTest
9360
- };
9361
- var inlinePedantic = {
9362
- ...inlineNormal,
9363
- link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", _inlineLabel).getRegex(),
9364
- reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", _inlineLabel).getRegex()
9365
- };
9366
- var inlineGfm = {
9367
- ...inlineNormal,
9368
- escape: edit(escape).replace("])", "~|])").getRegex(),
9369
- 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(),
9370
- _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
9371
- del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
9372
- text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
9373
- };
9374
- var inlineBreaks = {
9375
- ...inlineGfm,
9376
- br: edit(br).replace("{2,}", "*").getRegex(),
9377
- text: edit(inlineGfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
9378
- };
9379
- var block = {
9380
- normal: blockNormal,
9381
- gfm: blockGfm,
9382
- pedantic: blockPedantic
9383
- };
9384
- var inline = {
9385
- normal: inlineNormal,
9386
- gfm: inlineGfm,
9387
- breaks: inlineBreaks,
9388
- pedantic: inlinePedantic
9389
- };
9390
9438
  var _Lexer = class __Lexer {
9391
9439
  tokens;
9392
9440
  options;
@@ -9408,6 +9456,7 @@ ${currentText}` : currentText;
9408
9456
  top: true
9409
9457
  };
9410
9458
  const rules = {
9459
+ other,
9411
9460
  block: block.normal,
9412
9461
  inline: inline.normal
9413
9462
  };
@@ -9451,7 +9500,7 @@ ${currentText}` : currentText;
9451
9500
  * Preprocessing
9452
9501
  */
9453
9502
  lex(src) {
9454
- src = src.replace(/\r\n|\r/g, "\n");
9503
+ src = src.replace(other.carriageReturn, "\n");
9455
9504
  this.blockTokens(src, this.tokens);
9456
9505
  for (let i = 0; i < this.inlineQueue.length; i++) {
9457
9506
  const next = this.inlineQueue[i];
@@ -9462,17 +9511,11 @@ ${currentText}` : currentText;
9462
9511
  }
9463
9512
  blockTokens(src, tokens = [], lastParagraphClipped = false) {
9464
9513
  if (this.options.pedantic) {
9465
- src = src.replace(/\t/g, " ").replace(/^ +$/gm, "");
9466
- } else {
9467
- src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
9468
- return leading + " ".repeat(tabs.length);
9469
- });
9514
+ src = src.replace(other.tabCharGlobal, " ").replace(other.spaceLine, "");
9470
9515
  }
9471
- let token;
9472
- let lastToken;
9473
- let cutSrc;
9474
9516
  while (src) {
9475
- if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some((extTokenizer) => {
9517
+ let token;
9518
+ if (this.options.extensions?.block?.some((extTokenizer) => {
9476
9519
  if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
9477
9520
  src = src.substring(token.raw.length);
9478
9521
  tokens.push(token);
@@ -9484,8 +9527,9 @@ ${currentText}` : currentText;
9484
9527
  }
9485
9528
  if (token = this.tokenizer.space(src)) {
9486
9529
  src = src.substring(token.raw.length);
9487
- if (token.raw.length === 1 && tokens.length > 0) {
9488
- tokens[tokens.length - 1].raw += "\n";
9530
+ const lastToken = tokens.at(-1);
9531
+ if (token.raw.length === 1 && lastToken !== void 0) {
9532
+ lastToken.raw += "\n";
9489
9533
  } else {
9490
9534
  tokens.push(token);
9491
9535
  }
@@ -9493,11 +9537,11 @@ ${currentText}` : currentText;
9493
9537
  }
9494
9538
  if (token = this.tokenizer.code(src)) {
9495
9539
  src = src.substring(token.raw.length);
9496
- lastToken = tokens[tokens.length - 1];
9497
- if (lastToken && (lastToken.type === "paragraph" || lastToken.type === "text")) {
9540
+ const lastToken = tokens.at(-1);
9541
+ if (lastToken?.type === "paragraph" || lastToken?.type === "text") {
9498
9542
  lastToken.raw += "\n" + token.raw;
9499
9543
  lastToken.text += "\n" + token.text;
9500
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
9544
+ this.inlineQueue.at(-1).src = lastToken.text;
9501
9545
  } else {
9502
9546
  tokens.push(token);
9503
9547
  }
@@ -9535,11 +9579,11 @@ ${currentText}` : currentText;
9535
9579
  }
9536
9580
  if (token = this.tokenizer.def(src)) {
9537
9581
  src = src.substring(token.raw.length);
9538
- lastToken = tokens[tokens.length - 1];
9539
- if (lastToken && (lastToken.type === "paragraph" || lastToken.type === "text")) {
9582
+ const lastToken = tokens.at(-1);
9583
+ if (lastToken?.type === "paragraph" || lastToken?.type === "text") {
9540
9584
  lastToken.raw += "\n" + token.raw;
9541
9585
  lastToken.text += "\n" + token.raw;
9542
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
9586
+ this.inlineQueue.at(-1).src = lastToken.text;
9543
9587
  } else if (!this.tokens.links[token.tag]) {
9544
9588
  this.tokens.links[token.tag] = {
9545
9589
  href: token.href,
@@ -9558,8 +9602,8 @@ ${currentText}` : currentText;
9558
9602
  tokens.push(token);
9559
9603
  continue;
9560
9604
  }
9561
- cutSrc = src;
9562
- if (this.options.extensions && this.options.extensions.startBlock) {
9605
+ let cutSrc = src;
9606
+ if (this.options.extensions?.startBlock) {
9563
9607
  let startIndex = Infinity;
9564
9608
  const tempSrc = src.slice(1);
9565
9609
  let tempStart;
@@ -9574,12 +9618,12 @@ ${currentText}` : currentText;
9574
9618
  }
9575
9619
  }
9576
9620
  if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
9577
- lastToken = tokens[tokens.length - 1];
9621
+ const lastToken = tokens.at(-1);
9578
9622
  if (lastParagraphClipped && lastToken?.type === "paragraph") {
9579
9623
  lastToken.raw += "\n" + token.raw;
9580
9624
  lastToken.text += "\n" + token.text;
9581
9625
  this.inlineQueue.pop();
9582
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
9626
+ this.inlineQueue.at(-1).src = lastToken.text;
9583
9627
  } else {
9584
9628
  tokens.push(token);
9585
9629
  }
@@ -9589,12 +9633,12 @@ ${currentText}` : currentText;
9589
9633
  }
9590
9634
  if (token = this.tokenizer.text(src)) {
9591
9635
  src = src.substring(token.raw.length);
9592
- lastToken = tokens[tokens.length - 1];
9593
- if (lastToken && lastToken.type === "text") {
9636
+ const lastToken = tokens.at(-1);
9637
+ if (lastToken?.type === "text") {
9594
9638
  lastToken.raw += "\n" + token.raw;
9595
9639
  lastToken.text += "\n" + token.text;
9596
9640
  this.inlineQueue.pop();
9597
- this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
9641
+ this.inlineQueue.at(-1).src = lastToken.text;
9598
9642
  } else {
9599
9643
  tokens.push(token);
9600
9644
  }
@@ -9621,10 +9665,8 @@ ${currentText}` : currentText;
9621
9665
  * Lexing/Compiling
9622
9666
  */
9623
9667
  inlineTokens(src, tokens = []) {
9624
- let token, lastToken, cutSrc;
9625
9668
  let maskedSrc = src;
9626
- let match;
9627
- let keepPrevChar, prevChar;
9669
+ let match = null;
9628
9670
  if (this.tokens.links) {
9629
9671
  const links = Object.keys(this.tokens.links);
9630
9672
  if (links.length > 0) {
@@ -9641,12 +9683,15 @@ ${currentText}` : currentText;
9641
9683
  while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
9642
9684
  maskedSrc = maskedSrc.slice(0, match.index) + "++" + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
9643
9685
  }
9686
+ let keepPrevChar = false;
9687
+ let prevChar = "";
9644
9688
  while (src) {
9645
9689
  if (!keepPrevChar) {
9646
9690
  prevChar = "";
9647
9691
  }
9648
9692
  keepPrevChar = false;
9649
- if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some((extTokenizer) => {
9693
+ let token;
9694
+ if (this.options.extensions?.inline?.some((extTokenizer) => {
9650
9695
  if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
9651
9696
  src = src.substring(token.raw.length);
9652
9697
  tokens.push(token);
@@ -9663,13 +9708,7 @@ ${currentText}` : currentText;
9663
9708
  }
9664
9709
  if (token = this.tokenizer.tag(src)) {
9665
9710
  src = src.substring(token.raw.length);
9666
- lastToken = tokens[tokens.length - 1];
9667
- if (lastToken && token.type === "text" && lastToken.type === "text") {
9668
- lastToken.raw += token.raw;
9669
- lastToken.text += token.text;
9670
- } else {
9671
- tokens.push(token);
9672
- }
9711
+ tokens.push(token);
9673
9712
  continue;
9674
9713
  }
9675
9714
  if (token = this.tokenizer.link(src)) {
@@ -9679,8 +9718,8 @@ ${currentText}` : currentText;
9679
9718
  }
9680
9719
  if (token = this.tokenizer.reflink(src, this.tokens.links)) {
9681
9720
  src = src.substring(token.raw.length);
9682
- lastToken = tokens[tokens.length - 1];
9683
- if (lastToken && token.type === "text" && lastToken.type === "text") {
9721
+ const lastToken = tokens.at(-1);
9722
+ if (token.type === "text" && lastToken?.type === "text") {
9684
9723
  lastToken.raw += token.raw;
9685
9724
  lastToken.text += token.text;
9686
9725
  } else {
@@ -9718,8 +9757,8 @@ ${currentText}` : currentText;
9718
9757
  tokens.push(token);
9719
9758
  continue;
9720
9759
  }
9721
- cutSrc = src;
9722
- if (this.options.extensions && this.options.extensions.startInline) {
9760
+ let cutSrc = src;
9761
+ if (this.options.extensions?.startInline) {
9723
9762
  let startIndex = Infinity;
9724
9763
  const tempSrc = src.slice(1);
9725
9764
  let tempStart;
@@ -9739,8 +9778,8 @@ ${currentText}` : currentText;
9739
9778
  prevChar = token.raw.slice(-1);
9740
9779
  }
9741
9780
  keepPrevChar = true;
9742
- lastToken = tokens[tokens.length - 1];
9743
- if (lastToken && lastToken.type === "text") {
9781
+ const lastToken = tokens.at(-1);
9782
+ if (lastToken?.type === "text") {
9744
9783
  lastToken.raw += token.raw;
9745
9784
  lastToken.text += token.text;
9746
9785
  } else {
@@ -9772,12 +9811,12 @@ ${currentText}` : currentText;
9772
9811
  return "";
9773
9812
  }
9774
9813
  code({ text: text2, lang, escaped }) {
9775
- const langString = (lang || "").match(/^\S*/)?.[0];
9776
- const code = text2.replace(/\n$/, "") + "\n";
9814
+ const langString = (lang || "").match(other.notSpaceStart)?.[0];
9815
+ const code = text2.replace(other.endingNewline, "") + "\n";
9777
9816
  if (!langString) {
9778
- return "<pre><code>" + (escaped ? code : escape$1(code, true)) + "</code></pre>\n";
9817
+ return "<pre><code>" + (escaped ? code : escape(code, true)) + "</code></pre>\n";
9779
9818
  }
9780
- return '<pre><code class="language-' + escape$1(langString) + '">' + (escaped ? code : escape$1(code, true)) + "</code></pre>\n";
9819
+ return '<pre><code class="language-' + escape(langString) + '">' + (escaped ? code : escape(code, true)) + "</code></pre>\n";
9781
9820
  }
9782
9821
  blockquote({ tokens }) {
9783
9822
  const body = this.parser.parse(tokens);
@@ -9812,16 +9851,18 @@ ${body}</blockquote>
9812
9851
  if (item.task) {
9813
9852
  const checkbox = this.checkbox({ checked: !!item.checked });
9814
9853
  if (item.loose) {
9815
- if (item.tokens.length > 0 && item.tokens[0].type === "paragraph") {
9854
+ if (item.tokens[0]?.type === "paragraph") {
9816
9855
  item.tokens[0].text = checkbox + " " + item.tokens[0].text;
9817
9856
  if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
9818
- item.tokens[0].tokens[0].text = checkbox + " " + item.tokens[0].tokens[0].text;
9857
+ item.tokens[0].tokens[0].text = checkbox + " " + escape(item.tokens[0].tokens[0].text);
9858
+ item.tokens[0].tokens[0].escaped = true;
9819
9859
  }
9820
9860
  } else {
9821
9861
  item.tokens.unshift({
9822
9862
  type: "text",
9823
9863
  raw: checkbox + " ",
9824
- text: checkbox + " "
9864
+ text: checkbox + " ",
9865
+ escaped: true
9825
9866
  });
9826
9867
  }
9827
9868
  } else {
@@ -9881,7 +9922,7 @@ ${text2}</tr>
9881
9922
  return `<em>${this.parser.parseInline(tokens)}</em>`;
9882
9923
  }
9883
9924
  codespan({ text: text2 }) {
9884
- return `<code>${text2}</code>`;
9925
+ return `<code>${escape(text2, true)}</code>`;
9885
9926
  }
9886
9927
  br(token) {
9887
9928
  return "<br>";
@@ -9898,7 +9939,7 @@ ${text2}</tr>
9898
9939
  href = cleanHref;
9899
9940
  let out = '<a href="' + href + '"';
9900
9941
  if (title) {
9901
- out += ' title="' + title + '"';
9942
+ out += ' title="' + escape(title) + '"';
9902
9943
  }
9903
9944
  out += ">" + text2 + "</a>";
9904
9945
  return out;
@@ -9906,18 +9947,18 @@ ${text2}</tr>
9906
9947
  image({ href, title, text: text2 }) {
9907
9948
  const cleanHref = cleanUrl(href);
9908
9949
  if (cleanHref === null) {
9909
- return text2;
9950
+ return escape(text2);
9910
9951
  }
9911
9952
  href = cleanHref;
9912
9953
  let out = `<img src="${href}" alt="${text2}"`;
9913
9954
  if (title) {
9914
- out += ` title="${title}"`;
9955
+ out += ` title="${escape(title)}"`;
9915
9956
  }
9916
9957
  out += ">";
9917
9958
  return out;
9918
9959
  }
9919
9960
  text(token) {
9920
- return "tokens" in token && token.tokens ? this.parser.parseInline(token.tokens) : token.text;
9961
+ return "tokens" in token && token.tokens ? this.parser.parseInline(token.tokens) : "escaped" in token && token.escaped ? token.text : escape(token.text);
9921
9962
  }
9922
9963
  };
9923
9964
  var _TextRenderer = class {
@@ -9983,7 +10024,7 @@ ${text2}</tr>
9983
10024
  let out = "";
9984
10025
  for (let i = 0; i < tokens.length; i++) {
9985
10026
  const anyToken = tokens[i];
9986
- if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[anyToken.type]) {
10027
+ if (this.options.extensions?.renderers?.[anyToken.type]) {
9987
10028
  const genericToken = anyToken;
9988
10029
  const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
9989
10030
  if (ret !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(genericToken.type)) {
@@ -10041,7 +10082,7 @@ ${text2}</tr>
10041
10082
  type: "paragraph",
10042
10083
  raw: body,
10043
10084
  text: body,
10044
- tokens: [{ type: "text", raw: body, text: body }]
10085
+ tokens: [{ type: "text", raw: body, text: body, escaped: true }]
10045
10086
  });
10046
10087
  } else {
10047
10088
  out += body;
@@ -10064,12 +10105,11 @@ ${text2}</tr>
10064
10105
  /**
10065
10106
  * Parse Inline Tokens
10066
10107
  */
10067
- parseInline(tokens, renderer) {
10068
- renderer = renderer || this.renderer;
10108
+ parseInline(tokens, renderer = this.renderer) {
10069
10109
  let out = "";
10070
10110
  for (let i = 0; i < tokens.length; i++) {
10071
10111
  const anyToken = tokens[i];
10072
- if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[anyToken.type]) {
10112
+ if (this.options.extensions?.renderers?.[anyToken.type]) {
10073
10113
  const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
10074
10114
  if (ret !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(anyToken.type)) {
10075
10115
  out += ret || "";
@@ -10134,6 +10174,7 @@ ${text2}</tr>
10134
10174
  };
10135
10175
  var _Hooks = class {
10136
10176
  options;
10177
+ block;
10137
10178
  constructor(options2) {
10138
10179
  this.options = options2 || _defaults;
10139
10180
  }
@@ -10160,12 +10201,24 @@ ${text2}</tr>
10160
10201
  processAllTokens(tokens) {
10161
10202
  return tokens;
10162
10203
  }
10204
+ /**
10205
+ * Provide function to tokenize markdown
10206
+ */
10207
+ provideLexer() {
10208
+ return this.block ? _Lexer.lex : _Lexer.lexInline;
10209
+ }
10210
+ /**
10211
+ * Provide function to parse tokens
10212
+ */
10213
+ provideParser() {
10214
+ return this.block ? _Parser.parse : _Parser.parseInline;
10215
+ }
10163
10216
  };
10164
10217
  var Marked = class {
10165
10218
  defaults = _getDefaults();
10166
10219
  options = this.setOptions;
10167
- parse = this.#parseMarkdown(_Lexer.lex, _Parser.parse);
10168
- parseInline = this.#parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
10220
+ parse = this.parseMarkdown(true);
10221
+ parseInline = this.parseMarkdown(false);
10169
10222
  Parser = _Parser;
10170
10223
  Renderer = _Renderer;
10171
10224
  TextRenderer = _TextRenderer;
@@ -10281,10 +10334,7 @@ ${text2}</tr>
10281
10334
  continue;
10282
10335
  }
10283
10336
  const rendererProp = prop;
10284
- let rendererFunc = pack.renderer[rendererProp];
10285
- if (!pack.useNewRenderer) {
10286
- rendererFunc = this.#convertRendererFunction(rendererFunc, rendererProp, renderer);
10287
- }
10337
+ const rendererFunc = pack.renderer[rendererProp];
10288
10338
  const prevRenderer = renderer[rendererProp];
10289
10339
  renderer[rendererProp] = (...args2) => {
10290
10340
  let ret = rendererFunc.apply(renderer, args2);
@@ -10324,7 +10374,7 @@ ${text2}</tr>
10324
10374
  if (!(prop in hooks)) {
10325
10375
  throw new Error(`hook '${prop}' does not exist`);
10326
10376
  }
10327
- if (prop === "options") {
10377
+ if (["options", "block"].includes(prop)) {
10328
10378
  continue;
10329
10379
  }
10330
10380
  const hooksProp = prop;
@@ -10368,181 +10418,6 @@ ${text2}</tr>
10368
10418
  });
10369
10419
  return this;
10370
10420
  }
10371
- // TODO: Remove this in next major release
10372
- #convertRendererFunction(func, prop, renderer) {
10373
- switch (prop) {
10374
- case "heading":
10375
- return function(token) {
10376
- if (!token.type || token.type !== prop) {
10377
- return func.apply(this, arguments);
10378
- }
10379
- return func.call(this, renderer.parser.parseInline(token.tokens), token.depth, unescape(renderer.parser.parseInline(token.tokens, renderer.parser.textRenderer)));
10380
- };
10381
- case "code":
10382
- return function(token) {
10383
- if (!token.type || token.type !== prop) {
10384
- return func.apply(this, arguments);
10385
- }
10386
- return func.call(this, token.text, token.lang, !!token.escaped);
10387
- };
10388
- case "table":
10389
- return function(token) {
10390
- if (!token.type || token.type !== prop) {
10391
- return func.apply(this, arguments);
10392
- }
10393
- let header = "";
10394
- let cell = "";
10395
- for (let j = 0; j < token.header.length; j++) {
10396
- cell += this.tablecell({
10397
- text: token.header[j].text,
10398
- tokens: token.header[j].tokens,
10399
- header: true,
10400
- align: token.align[j]
10401
- });
10402
- }
10403
- header += this.tablerow({ text: cell });
10404
- let body = "";
10405
- for (let j = 0; j < token.rows.length; j++) {
10406
- const row = token.rows[j];
10407
- cell = "";
10408
- for (let k = 0; k < row.length; k++) {
10409
- cell += this.tablecell({
10410
- text: row[k].text,
10411
- tokens: row[k].tokens,
10412
- header: false,
10413
- align: token.align[k]
10414
- });
10415
- }
10416
- body += this.tablerow({ text: cell });
10417
- }
10418
- return func.call(this, header, body);
10419
- };
10420
- case "blockquote":
10421
- return function(token) {
10422
- if (!token.type || token.type !== prop) {
10423
- return func.apply(this, arguments);
10424
- }
10425
- const body = this.parser.parse(token.tokens);
10426
- return func.call(this, body);
10427
- };
10428
- case "list":
10429
- return function(token) {
10430
- if (!token.type || token.type !== prop) {
10431
- return func.apply(this, arguments);
10432
- }
10433
- const ordered = token.ordered;
10434
- const start3 = token.start;
10435
- const loose = token.loose;
10436
- let body = "";
10437
- for (let j = 0; j < token.items.length; j++) {
10438
- const item = token.items[j];
10439
- const checked = item.checked;
10440
- const task = item.task;
10441
- let itemBody = "";
10442
- if (item.task) {
10443
- const checkbox = this.checkbox({ checked: !!checked });
10444
- if (loose) {
10445
- if (item.tokens.length > 0 && item.tokens[0].type === "paragraph") {
10446
- item.tokens[0].text = checkbox + " " + item.tokens[0].text;
10447
- if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
10448
- item.tokens[0].tokens[0].text = checkbox + " " + item.tokens[0].tokens[0].text;
10449
- }
10450
- } else {
10451
- item.tokens.unshift({
10452
- type: "text",
10453
- text: checkbox + " "
10454
- });
10455
- }
10456
- } else {
10457
- itemBody += checkbox + " ";
10458
- }
10459
- }
10460
- itemBody += this.parser.parse(item.tokens, loose);
10461
- body += this.listitem({
10462
- type: "list_item",
10463
- raw: itemBody,
10464
- text: itemBody,
10465
- task,
10466
- checked: !!checked,
10467
- loose,
10468
- tokens: item.tokens
10469
- });
10470
- }
10471
- return func.call(this, body, ordered, start3);
10472
- };
10473
- case "html":
10474
- return function(token) {
10475
- if (!token.type || token.type !== prop) {
10476
- return func.apply(this, arguments);
10477
- }
10478
- return func.call(this, token.text, token.block);
10479
- };
10480
- case "paragraph":
10481
- return function(token) {
10482
- if (!token.type || token.type !== prop) {
10483
- return func.apply(this, arguments);
10484
- }
10485
- return func.call(this, this.parser.parseInline(token.tokens));
10486
- };
10487
- case "escape":
10488
- return function(token) {
10489
- if (!token.type || token.type !== prop) {
10490
- return func.apply(this, arguments);
10491
- }
10492
- return func.call(this, token.text);
10493
- };
10494
- case "link":
10495
- return function(token) {
10496
- if (!token.type || token.type !== prop) {
10497
- return func.apply(this, arguments);
10498
- }
10499
- return func.call(this, token.href, token.title, this.parser.parseInline(token.tokens));
10500
- };
10501
- case "image":
10502
- return function(token) {
10503
- if (!token.type || token.type !== prop) {
10504
- return func.apply(this, arguments);
10505
- }
10506
- return func.call(this, token.href, token.title, token.text);
10507
- };
10508
- case "strong":
10509
- return function(token) {
10510
- if (!token.type || token.type !== prop) {
10511
- return func.apply(this, arguments);
10512
- }
10513
- return func.call(this, this.parser.parseInline(token.tokens));
10514
- };
10515
- case "em":
10516
- return function(token) {
10517
- if (!token.type || token.type !== prop) {
10518
- return func.apply(this, arguments);
10519
- }
10520
- return func.call(this, this.parser.parseInline(token.tokens));
10521
- };
10522
- case "codespan":
10523
- return function(token) {
10524
- if (!token.type || token.type !== prop) {
10525
- return func.apply(this, arguments);
10526
- }
10527
- return func.call(this, token.text);
10528
- };
10529
- case "del":
10530
- return function(token) {
10531
- if (!token.type || token.type !== prop) {
10532
- return func.apply(this, arguments);
10533
- }
10534
- return func.call(this, this.parser.parseInline(token.tokens));
10535
- };
10536
- case "text":
10537
- return function(token) {
10538
- if (!token.type || token.type !== prop) {
10539
- return func.apply(this, arguments);
10540
- }
10541
- return func.call(this, token.text);
10542
- };
10543
- }
10544
- return func;
10545
- }
10546
10421
  setOptions(opt) {
10547
10422
  this.defaults = { ...this.defaults, ...opt };
10548
10423
  return this;
@@ -10553,17 +10428,14 @@ ${text2}</tr>
10553
10428
  parser(tokens, options2) {
10554
10429
  return _Parser.parse(tokens, options2 ?? this.defaults);
10555
10430
  }
10556
- #parseMarkdown(lexer2, parser2) {
10557
- return (src, options2) => {
10431
+ parseMarkdown(blockType) {
10432
+ const parse = (src, options2) => {
10558
10433
  const origOpt = { ...options2 };
10559
10434
  const opt = { ...this.defaults, ...origOpt };
10435
+ const throwError = this.onError(!!opt.silent, !!opt.async);
10560
10436
  if (this.defaults.async === true && origOpt.async === false) {
10561
- if (!opt.silent) {
10562
- console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.");
10563
- }
10564
- opt.async = true;
10437
+ 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."));
10565
10438
  }
10566
- const throwError = this.#onError(!!opt.silent, !!opt.async);
10567
10439
  if (typeof src === "undefined" || src === null) {
10568
10440
  return throwError(new Error("marked(): input parameter is undefined or null"));
10569
10441
  }
@@ -10572,7 +10444,10 @@ ${text2}</tr>
10572
10444
  }
10573
10445
  if (opt.hooks) {
10574
10446
  opt.hooks.options = opt;
10447
+ opt.hooks.block = blockType;
10575
10448
  }
10449
+ const lexer2 = opt.hooks ? opt.hooks.provideLexer() : blockType ? _Lexer.lex : _Lexer.lexInline;
10450
+ const parser2 = opt.hooks ? opt.hooks.provideParser() : blockType ? _Parser.parse : _Parser.parseInline;
10576
10451
  if (opt.async) {
10577
10452
  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((html3) => opt.hooks ? opt.hooks.postprocess(html3) : html3).catch(throwError);
10578
10453
  }
@@ -10596,12 +10471,13 @@ ${text2}</tr>
10596
10471
  return throwError(e);
10597
10472
  }
10598
10473
  };
10474
+ return parse;
10599
10475
  }
10600
- #onError(silent, async) {
10476
+ onError(silent, async) {
10601
10477
  return (e) => {
10602
10478
  e.message += "\nPlease report this to https://github.com/markedjs/marked.";
10603
10479
  if (silent) {
10604
- const msg = "<p>An error occurred:</p><pre>" + escape$1(e.message + "", true) + "</pre>";
10480
+ const msg = "<p>An error occurred:</p><pre>" + escape(e.message + "", true) + "</pre>";
10605
10481
  if (async) {
10606
10482
  return Promise.resolve(msg);
10607
10483
  }