|
1 |
| -/*! markdown-it 12.2.0 https://github.com/markdown-it/markdown-it @license MIT */ |
| 1 | +/*! markdown-it 12.3.0 https://github.com/markdown-it/markdown-it @license MIT */ |
2 | 2 | (function(global, factory) {
|
3 | 3 | typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self,
|
4 | 4 | global.markdownit = factory());
|
|
5906 | 5906 | marker: marker,
|
5907 | 5907 | length: 0,
|
5908 | 5908 | // disable "rule of 3" length checks meant for emphasis
|
5909 |
| - jump: i / 2, |
5910 |
| - // for `~~` 1 marker = 2 characters |
5911 | 5909 | token: state.tokens.length - 1,
|
5912 | 5910 | end: -1,
|
5913 | 5911 | open: scanned.can_open,
|
|
5999 | 5997 | marker: marker,
|
6000 | 5998 | // Total length of these series of delimiters.
|
6001 | 5999 | length: scanned.length,
|
6002 |
| - // An amount of characters before this one that's equivalent to |
6003 |
| - // current one. In plain English: if this delimiter does not open |
6004 |
| - // an emphasis, neither do previous `jump` characters. |
6005 |
| - // Used to skip sequences like "*****" in one step, for 1st asterisk |
6006 |
| - // value will be 0, for 2nd it's 1 and so on. |
6007 |
| - jump: i, |
6008 | 6000 | // A position of the token this delimiter corresponds to.
|
6009 | 6001 | token: state.tokens.length - 1,
|
6010 | 6002 | // If this delimiter is matched as a valid opener, `end` will be
|
|
6036 | 6028 |
|
6037 | 6029 | // `<em><em>whatever</em></em>` -> `<strong>whatever</strong>`
|
6038 | 6030 |
|
6039 |
| - isStrong = i > 0 && delimiters[i - 1].end === startDelim.end + 1 && delimiters[i - 1].token === startDelim.token - 1 && delimiters[startDelim.end + 1].token === endDelim.token + 1 && delimiters[i - 1].marker === startDelim.marker; |
| 6031 | + isStrong = i > 0 && delimiters[i - 1].end === startDelim.end + 1 && |
| 6032 | + // check that first two markers match and adjacent |
| 6033 | + delimiters[i - 1].marker === startDelim.marker && delimiters[i - 1].token === startDelim.token - 1 && |
| 6034 | + // check that last two markers are adjacent (we can safely assume they match) |
| 6035 | + delimiters[startDelim.end + 1].token === endDelim.token + 1; |
6040 | 6036 | ch = String.fromCharCode(startDelim.marker);
|
6041 | 6037 | token = state.tokens[startDelim.token];
|
6042 | 6038 | token.type = isStrong ? "strong_open" : "em_open";
|
|
6448 | 6444 | // For each opening emphasis-like marker find a matching closing one
|
6449 | 6445 | function processDelimiters(state, delimiters) {
|
6450 | 6446 | var closerIdx, openerIdx, closer, opener, minOpenerIdx, newMinOpenerIdx, isOddMatch, lastJump, openersBottom = {}, max = delimiters.length;
|
| 6447 | + if (!max) return; |
| 6448 | + // headerIdx is the first delimiter of the current (where closer is) delimiter run |
| 6449 | + var headerIdx = 0; |
| 6450 | + var lastTokenIdx = -2; |
| 6451 | + // needs any value lower than -1 |
| 6452 | + var jumps = []; |
6451 | 6453 | for (closerIdx = 0; closerIdx < max; closerIdx++) {
|
6452 | 6454 | closer = delimiters[closerIdx];
|
| 6455 | + jumps.push(0); |
| 6456 | + // markers belong to same delimiter run if: |
| 6457 | + // - they have adjacent tokens |
| 6458 | + // - AND markers are the same |
| 6459 | + |
| 6460 | + if (delimiters[headerIdx].marker !== closer.marker || lastTokenIdx !== closer.token - 1) { |
| 6461 | + headerIdx = closerIdx; |
| 6462 | + } |
| 6463 | + lastTokenIdx = closer.token; |
6453 | 6464 | // Length is only used for emphasis-specific "rule of 3",
|
6454 | 6465 | // if it's not defined (in strikethrough or 3rd party plugins),
|
6455 | 6466 | // we can default it to 0 to disable those checks.
|
|
6464 | 6475 | openersBottom[closer.marker] = [ -1, -1, -1, -1, -1, -1 ];
|
6465 | 6476 | }
|
6466 | 6477 | minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + closer.length % 3];
|
6467 |
| - openerIdx = closerIdx - closer.jump - 1; |
6468 |
| - // avoid crash if `closer.jump` is pointing outside of the array, see #742 |
6469 |
| - if (openerIdx < -1) openerIdx = -1; |
| 6478 | + openerIdx = headerIdx - jumps[headerIdx] - 1; |
6470 | 6479 | newMinOpenerIdx = openerIdx;
|
6471 |
| - for (;openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) { |
| 6480 | + for (;openerIdx > minOpenerIdx; openerIdx -= jumps[openerIdx] + 1) { |
6472 | 6481 | opener = delimiters[openerIdx];
|
6473 | 6482 | if (opener.marker !== closer.marker) continue;
|
6474 | 6483 | if (opener.open && opener.end < 0) {
|
|
6491 | 6500 | // If previous delimiter cannot be an opener, we can safely skip
|
6492 | 6501 | // the entire sequence in future checks. This is required to make
|
6493 | 6502 | // sure algorithm has linear complexity (see *_*_*_*_*_... case).
|
6494 |
| - lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? delimiters[openerIdx - 1].jump + 1 : 0; |
6495 |
| - closer.jump = closerIdx - openerIdx + lastJump; |
| 6503 | + lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ? jumps[openerIdx - 1] + 1 : 0; |
| 6504 | + jumps[closerIdx] = closerIdx - openerIdx + lastJump; |
| 6505 | + jumps[openerIdx] = lastJump; |
6496 | 6506 | closer.open = false;
|
6497 | 6507 | opener.end = closerIdx;
|
6498 |
| - opener.jump = lastJump; |
6499 | 6508 | opener.close = false;
|
6500 | 6509 | newMinOpenerIdx = -1;
|
| 6510 | + // treat next token as start of run, |
| 6511 | + // it optimizes skips in **<...>**a**<...>** pathological case |
| 6512 | + lastTokenIdx = -2; |
6501 | 6513 | break;
|
6502 | 6514 | }
|
6503 | 6515 | }
|
|
6794 | 6806 | re.src_auth = "(?:(?:(?!" + re.src_ZCc + "|[@/\\[\\]()]).)+@)?";
|
6795 | 6807 | re.src_port = "(?::(?:6(?:[0-4]\\d{3}|5(?:[0-4]\\d{2}|5(?:[0-2]\\d|3[0-5])))|[1-5]?\\d{1,4}))?";
|
6796 | 6808 | re.src_host_terminator = "(?=$|" + text_separators + "|" + re.src_ZPCc + ")(?!-|_|:\\d|\\.-|\\.(?!$|" + re.src_ZPCc + "))";
|
6797 |
| - re.src_path = "(?:" + "[/?#]" + "(?:" + "(?!" + re.src_ZCc + "|" + text_separators + "|[()[\\]{}.,\"'?!\\-]).|" + "\\[(?:(?!" + re.src_ZCc + "|\\]).)*\\]|" + "\\((?:(?!" + re.src_ZCc + "|[)]).)*\\)|" + "\\{(?:(?!" + re.src_ZCc + "|[}]).)*\\}|" + '\\"(?:(?!' + re.src_ZCc + '|["]).)+\\"|' + "\\'(?:(?!" + re.src_ZCc + "|[']).)+\\'|" + "\\'(?=" + re.src_pseudo_letter + "|[-]).|" + // allow `I'm_king` if no pair found |
| 6809 | + re.src_path = "(?:" + "[/?#]" + "(?:" + "(?!" + re.src_ZCc + "|" + text_separators + "|[()[\\]{}.,\"'?!\\-;]).|" + "\\[(?:(?!" + re.src_ZCc + "|\\]).)*\\]|" + "\\((?:(?!" + re.src_ZCc + "|[)]).)*\\)|" + "\\{(?:(?!" + re.src_ZCc + "|[}]).)*\\}|" + '\\"(?:(?!' + re.src_ZCc + '|["]).)+\\"|' + "\\'(?:(?!" + re.src_ZCc + "|[']).)+\\'|" + "\\'(?=" + re.src_pseudo_letter + "|[-]).|" + // allow `I'm_king` if no pair found |
6798 | 6810 | "\\.{2,}[a-zA-Z0-9%/&]|" + // google has many dots in "google search" links (#66, #81).
|
6799 | 6811 | // github has ... in commit range links,
|
6800 | 6812 | // Restrict to
|
|
6803 | 6815 | // - parts of file path
|
6804 | 6816 | // - params separator
|
6805 | 6817 | // until more examples found.
|
6806 |
| - "\\.(?!" + re.src_ZCc + "|[.]).|" + (opts && opts["---"] ? "\\-(?!--(?:[^-]|$))(?:-*)|" : "\\-+|") + "\\,(?!" + re.src_ZCc + ").|" + // allow `,,,` in paths |
| 6818 | + "\\.(?!" + re.src_ZCc + "|[.]).|" + (opts && opts["---"] ? "\\-(?!--(?:[^-]|$))(?:-*)|" : "\\-+|") + ",(?!" + re.src_ZCc + ").|" + // allow `,,,` in paths |
| 6819 | + ";(?!" + re.src_ZCc + ").|" + // allow `;` if not followed by space-like char |
6807 | 6820 | "\\!+(?!" + re.src_ZCc + "|[!]).|" + // allow `!!!` in paths, but not at the end
|
6808 | 6821 | "\\?(?!" + re.src_ZCc + "|[?])." + ")+" + "|\\/" + ")?";
|
6809 | 6822 | // Allow anything in markdown spec, forbid quote (") at the first position
|
|
0 commit comments