|
1 |
| -/*! markdown-it 12.0.2 https://github.com/markdown-it/markdown-it @license MIT */ |
| 1 | +/*! markdown-it 12.0.3 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());
|
|
2965 | 2965 | if (code === 10 /* \n */) {
|
2966 | 2966 | return result;
|
2967 | 2967 | }
|
| 2968 | + if (code === 60 /* < */) { |
| 2969 | + return result; |
| 2970 | + } |
2968 | 2971 | if (code === 62 /* > */) {
|
2969 | 2972 | result.pos = pos + 1;
|
2970 | 2973 | result.str = unescapeAll(str.slice(start + 1, pos));
|
|
2992 | 2995 | break;
|
2993 | 2996 | }
|
2994 | 2997 | if (code === 92 /* \ */ && pos + 1 < max) {
|
| 2998 | + if (str.charCodeAt(pos + 1) === 32) { |
| 2999 | + break; |
| 3000 | + } |
2995 | 3001 | pos += 2;
|
2996 | 3002 | continue;
|
2997 | 3003 | }
|
2998 | 3004 | if (code === 40 /* ( */) {
|
2999 | 3005 | level++;
|
| 3006 | + if (level > 32) { |
| 3007 | + return result; |
| 3008 | + } |
3000 | 3009 | }
|
3001 | 3010 | if (code === 41 /* ) */) {
|
3002 | 3011 | if (level === 0) {
|
|
3046 | 3055 | result.str = unescapeAll$1(str.slice(start + 1, pos));
|
3047 | 3056 | result.ok = true;
|
3048 | 3057 | return result;
|
| 3058 | + } else if (code === 40 /* ( */ && marker === 41 /* ) */) { |
| 3059 | + return result; |
3049 | 3060 | } else if (code === 10) {
|
3050 | 3061 | lines++;
|
3051 | 3062 | } else if (code === 92 /* \ */ && pos + 1 < max) {
|
|
5262 | 5273 | return true;
|
5263 | 5274 | };
|
5264 | 5275 | // List of valid html blocks names, accorting to commonmark spec
|
5265 |
| - var html_blocks = [ "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", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hr", "html", "iframe", "legend", "li", "link", "main", "menu", "menuitem", "meta", "nav", "noframes", "ol", "optgroup", "option", "p", "param", "section", "source", "summary", "table", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track", "ul" ]; |
| 5276 | + var html_blocks = [ "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", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hr", "html", "iframe", "legend", "li", "link", "main", "menu", "menuitem", "nav", "noframes", "ol", "optgroup", "option", "p", "param", "section", "source", "summary", "table", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track", "ul" ]; |
5266 | 5277 | // Regexps to match html elements
|
5267 | 5278 | var attr_name = "[a-zA-Z_:][a-zA-Z0-9:._-]*";
|
5268 | 5279 | var unquoted = "[^\"'=<>`\\x00-\\x20]+";
|
|
5273 | 5284 | var open_tag = "<[A-Za-z][A-Za-z0-9\\-]*" + attribute + "*\\s*\\/?>";
|
5274 | 5285 | var close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>";
|
5275 | 5286 | var comment = "\x3c!----\x3e|\x3c!--(?:-?[^>-])(?:-?[^-])*--\x3e";
|
5276 |
| - var processing = "<[?].*?[?]>"; |
| 5287 | + var processing = "<[?][\\s\\S]*?[?]>"; |
5277 | 5288 | var declaration = "<![A-Z]+\\s+[^>]*>";
|
5278 | 5289 | var cdata = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>";
|
5279 | 5290 | var HTML_TAG_RE = new RegExp("^(?:" + open_tag + "|" + close_tag + "|" + comment + "|" + processing + "|" + declaration + "|" + cdata + ")");
|
|
5797 | 5808 | };
|
5798 | 5809 | // Parse backticks
|
5799 | 5810 | var backticks = function backtick(state, silent) {
|
5800 |
| - var start, max, marker, matchStart, matchEnd, token, pos = state.pos, ch = state.src.charCodeAt(pos); |
| 5811 | + var start, max, marker, token, matchStart, matchEnd, openerLength, closerLength, pos = state.pos, ch = state.src.charCodeAt(pos); |
5801 | 5812 | if (ch !== 96 /* ` */) {
|
5802 | 5813 | return false;
|
5803 | 5814 | }
|
5804 | 5815 | start = pos;
|
5805 | 5816 | pos++;
|
5806 | 5817 | max = state.posMax;
|
5807 |
| - while (pos < max && state.src.charCodeAt(pos) === 96 /* ` */) { |
| 5818 | + // scan marker length |
| 5819 | + while (pos < max && state.src.charCodeAt(pos) === 96 /* ` */) { |
5808 | 5820 | pos++;
|
5809 | 5821 | }
|
5810 | 5822 | marker = state.src.slice(start, pos);
|
| 5823 | + openerLength = marker.length; |
| 5824 | + if (state.backticksScanned && (state.backticks[openerLength] || 0) <= start) { |
| 5825 | + if (!silent) state.pending += marker; |
| 5826 | + state.pos += openerLength; |
| 5827 | + return true; |
| 5828 | + } |
5811 | 5829 | matchStart = matchEnd = pos;
|
5812 |
| - while ((matchStart = state.src.indexOf("`", matchEnd)) !== -1) { |
| 5830 | + // Nothing found in the cache, scan until the end of the line (or until marker is found) |
| 5831 | + while ((matchStart = state.src.indexOf("`", matchEnd)) !== -1) { |
5813 | 5832 | matchEnd = matchStart + 1;
|
5814 |
| - while (matchEnd < max && state.src.charCodeAt(matchEnd) === 96 /* ` */) { |
| 5833 | + // scan marker length |
| 5834 | + while (matchEnd < max && state.src.charCodeAt(matchEnd) === 96 /* ` */) { |
5815 | 5835 | matchEnd++;
|
5816 | 5836 | }
|
5817 |
| - if (matchEnd - matchStart === marker.length) { |
| 5837 | + closerLength = matchEnd - matchStart; |
| 5838 | + if (closerLength === openerLength) { |
| 5839 | + // Found matching closer length. |
5818 | 5840 | if (!silent) {
|
5819 | 5841 | token = state.push("code_inline", "code", 0);
|
5820 | 5842 | token.markup = marker;
|
|
5823 | 5845 | state.pos = matchEnd;
|
5824 | 5846 | return true;
|
5825 | 5847 | }
|
| 5848 | + // Some different length found, put it in cache as upper limit of where closer can be found |
| 5849 | + state.backticks[closerLength] = matchStart; |
5826 | 5850 | }
|
5827 |
| - if (!silent) { |
5828 |
| - state.pending += marker; |
5829 |
| - } |
5830 |
| - state.pos += marker.length; |
| 5851 | + // Scanned through the end, didn't find anything |
| 5852 | + state.backticksScanned = true; |
| 5853 | + if (!silent) state.pending += marker; |
| 5854 | + state.pos += openerLength; |
5831 | 5855 | return true;
|
5832 | 5856 | };
|
5833 | 5857 | // ~~strike through~~
|
|
6027 | 6051 | var normalizeReference$1 = utils.normalizeReference;
|
6028 | 6052 | var isSpace$9 = utils.isSpace;
|
6029 | 6053 | var link = function link(state, silent) {
|
6030 |
| - var attrs, code, label, labelEnd, labelStart, pos, res, ref, title, token, href = "", oldPos = state.pos, max = state.posMax, start = state.pos, parseReference = true; |
| 6054 | + var attrs, code, label, labelEnd, labelStart, pos, res, ref, token, href = "", title = "", oldPos = state.pos, max = state.posMax, start = state.pos, parseReference = true; |
6031 | 6055 | if (state.src.charCodeAt(state.pos) !== 91 /* [ */) {
|
6032 | 6056 | return false;
|
6033 | 6057 | }
|
|
6065 | 6089 | } else {
|
6066 | 6090 | href = "";
|
6067 | 6091 | }
|
6068 |
| - } |
6069 |
| - // [link]( <href> "title" ) |
6070 |
| - // ^^ skipping these spaces |
6071 |
| - start = pos; |
6072 |
| - for (;pos < max; pos++) { |
6073 |
| - code = state.src.charCodeAt(pos); |
6074 |
| - if (!isSpace$9(code) && code !== 10) { |
6075 |
| - break; |
6076 |
| - } |
6077 |
| - } |
6078 |
| - // [link]( <href> "title" ) |
6079 |
| - // ^^^^^^^ parsing link title |
6080 |
| - res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); |
6081 |
| - if (pos < max && start !== pos && res.ok) { |
6082 |
| - title = res.str; |
6083 |
| - pos = res.pos; |
6084 | 6092 | // [link]( <href> "title" )
|
6085 |
| - // ^^ skipping these spaces |
6086 |
| - for (;pos < max; pos++) { |
| 6093 | + // ^^ skipping these spaces |
| 6094 | + start = pos; |
| 6095 | + for (;pos < max; pos++) { |
6087 | 6096 | code = state.src.charCodeAt(pos);
|
6088 | 6097 | if (!isSpace$9(code) && code !== 10) {
|
6089 | 6098 | break;
|
6090 | 6099 | }
|
6091 | 6100 | }
|
6092 |
| - } else { |
6093 |
| - title = ""; |
| 6101 | + // [link]( <href> "title" ) |
| 6102 | + // ^^^^^^^ parsing link title |
| 6103 | + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax); |
| 6104 | + if (pos < max && start !== pos && res.ok) { |
| 6105 | + title = res.str; |
| 6106 | + pos = res.pos; |
| 6107 | + // [link]( <href> "title" ) |
| 6108 | + // ^^ skipping these spaces |
| 6109 | + for (;pos < max; pos++) { |
| 6110 | + code = state.src.charCodeAt(pos); |
| 6111 | + if (!isSpace$9(code) && code !== 10) { |
| 6112 | + break; |
| 6113 | + } |
| 6114 | + } |
| 6115 | + } |
6094 | 6116 | }
|
6095 | 6117 | if (pos >= max || state.src.charCodeAt(pos) !== 41 /* ) */) {
|
6096 | 6118 | // parsing a valid shortcut link failed, fallback to reference
|
|
6269 | 6291 | return true;
|
6270 | 6292 | };
|
6271 | 6293 | // Process autolinks '<protocol:...>'
|
6272 |
| - /*eslint max-len:0*/ var EMAIL_RE = /^<([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])?)*)>/; |
6273 |
| - var AUTOLINK_RE = /^<([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)>/; |
| 6294 | + /*eslint max-len:0*/ var EMAIL_RE = /^([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])?)*)$/; |
| 6295 | + var AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)$/; |
6274 | 6296 | var autolink = function autolink(state, silent) {
|
6275 |
| - var tail, linkMatch, emailMatch, url, fullUrl, token, pos = state.pos; |
| 6297 | + var url, fullUrl, token, ch, start, max, pos = state.pos; |
6276 | 6298 | if (state.src.charCodeAt(pos) !== 60 /* < */) {
|
6277 | 6299 | return false;
|
6278 | 6300 | }
|
6279 |
| - tail = state.src.slice(pos); |
6280 |
| - if (tail.indexOf(">") < 0) { |
6281 |
| - return false; |
| 6301 | + start = state.pos; |
| 6302 | + max = state.posMax; |
| 6303 | + for (;;) { |
| 6304 | + if (++pos >= max) return false; |
| 6305 | + ch = state.src.charCodeAt(pos); |
| 6306 | + if (ch === 60 /* < */) return false; |
| 6307 | + if (ch === 62 /* > */) break; |
6282 | 6308 | }
|
6283 |
| - if (AUTOLINK_RE.test(tail)) { |
6284 |
| - linkMatch = tail.match(AUTOLINK_RE); |
6285 |
| - url = linkMatch[0].slice(1, -1); |
| 6309 | + url = state.src.slice(start + 1, pos); |
| 6310 | + if (AUTOLINK_RE.test(url)) { |
6286 | 6311 | fullUrl = state.md.normalizeLink(url);
|
6287 | 6312 | if (!state.md.validateLink(fullUrl)) {
|
6288 | 6313 | return false;
|
|
6298 | 6323 | token.markup = "autolink";
|
6299 | 6324 | token.info = "auto";
|
6300 | 6325 | }
|
6301 |
| - state.pos += linkMatch[0].length; |
| 6326 | + state.pos += url.length + 2; |
6302 | 6327 | return true;
|
6303 | 6328 | }
|
6304 |
| - if (EMAIL_RE.test(tail)) { |
6305 |
| - emailMatch = tail.match(EMAIL_RE); |
6306 |
| - url = emailMatch[0].slice(1, -1); |
| 6329 | + if (EMAIL_RE.test(url)) { |
6307 | 6330 | fullUrl = state.md.normalizeLink("mailto:" + url);
|
6308 | 6331 | if (!state.md.validateLink(fullUrl)) {
|
6309 | 6332 | return false;
|
|
6319 | 6342 | token.markup = "autolink";
|
6320 | 6343 | token.info = "auto";
|
6321 | 6344 | }
|
6322 |
| - state.pos += emailMatch[0].length; |
| 6345 | + state.pos += url.length + 2; |
6323 | 6346 | return true;
|
6324 | 6347 | }
|
6325 | 6348 | return false;
|
|
6415 | 6438 | openersBottom[closer.marker] = [ -1, -1, -1 ];
|
6416 | 6439 | }
|
6417 | 6440 | minOpenerIdx = openersBottom[closer.marker][closer.length % 3];
|
6418 |
| - newMinOpenerIdx = -1; |
6419 | 6441 | openerIdx = closerIdx - closer.jump - 1;
|
| 6442 | + newMinOpenerIdx = openerIdx; |
6420 | 6443 | for (;openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) {
|
6421 | 6444 | opener = delimiters[openerIdx];
|
6422 | 6445 | if (opener.marker !== closer.marker) continue;
|
6423 |
| - if (newMinOpenerIdx === -1) newMinOpenerIdx = openerIdx; |
6424 | 6446 | if (opener.open && opener.end < 0) {
|
6425 | 6447 | isOddMatch = false;
|
6426 | 6448 | // from spec:
|
|
6517 | 6539 | this.delimiters = [];
|
6518 | 6540 | // Stack of delimiter lists for upper level tags
|
6519 | 6541 | this._prev_delimiters = [];
|
| 6542 | + // backtick length => last seen position |
| 6543 | + this.backticks = {}; |
| 6544 | + this.backticksScanned = false; |
6520 | 6545 | }
|
6521 | 6546 | // Flush pending text
|
6522 | 6547 |
|
|
0 commit comments