diff --git a/lib/marked.esm.js b/lib/marked.esm.js index 6543d556..99f86a76 100644 --- a/lib/marked.esm.js +++ b/lib/marked.esm.js @@ -561,11 +561,12 @@ var rules = { }; const { defaults: defaults$1 } = defaults; -const { block: block$1 } = rules; +const { block: block$1, inline: inline$1 } = rules; const { rtrim: rtrim$1, splitCells: splitCells$1, - escape: escape$1 + escape: escape$1, + findClosingBracket: findClosingBracket$1 } = helpers; /** @@ -576,12 +577,21 @@ var Lexer_1 = class Lexer { this.tokens = []; this.tokens.links = Object.create(null); this.options = options || defaults$1; - this.rules = block$1.normal; + this.rules = { + block: block$1.normal, + inline: inline$1.normal + }; if (this.options.pedantic) { - this.rules = block$1.pedantic; + this.rules.block = block$1.pedantic; + this.rules.inline = inline$1.pedantic; } else if (this.options.gfm) { - this.rules = block$1.gfm; + this.rules.block = block$1.gfm; + if (this.options.breaks) { + this.rules.inline = inline$1.breaks; + } else { + this.rules.inline = inline$1.gfm; + } } } @@ -589,7 +599,10 @@ var Lexer_1 = class Lexer { * Expose Block Rules */ static get rules() { - return block$1; + return { + block: block$1, + inline: inline$1 + }; } /** @@ -598,7 +611,7 @@ var Lexer_1 = class Lexer { static lex(src, options) { const lexer = new Lexer(options); return lexer.lex(src); - }; + } /** * Preprocessing @@ -608,13 +621,17 @@ var Lexer_1 = class Lexer { .replace(/\r\n|\r/g, '\n') .replace(/\t/g, ' '); - return this.token(src, true); - }; + this.blockTokens(this.tokens, src, true); + + this.inlineTokens(this.tokens); + + return this.tokens; + } /** * Lexing */ - token(src, top) { + blockTokens(tokens, src, top) { src = src.replace(/^ +$/gm, ''); let next, loose, @@ -622,39 +639,43 @@ var Lexer_1 = class Lexer { bull, b, item, - listStart, - listItems, - t, + list, space, i, tag, l, isordered, istask, - ischecked; + ischecked, + raw; while (src) { // newline - if (cap = this.rules.newline.exec(src)) { + if (cap = this.rules.block.newline.exec(src)) { src = src.substring(cap[0].length); + raw = cap[0]; if (cap[0].length > 1) { - this.tokens.push({ - type: 'space' + tokens.push({ + type: 'space', + raw }); } } // code - if (cap = this.rules.code.exec(src)) { - const lastToken = this.tokens[this.tokens.length - 1]; + if (cap = this.rules.block.code.exec(src)) { + const lastToken = tokens[tokens.length - 1]; src = src.substring(cap[0].length); + raw = cap[0]; // An indented code block cannot interrupt a paragraph. if (lastToken && lastToken.type === 'paragraph') { lastToken.text += '\n' + cap[0].trimRight(); + lastToken.raw += '\n' + raw; } else { cap = cap[0].replace(/^ {4}/gm, ''); - this.tokens.push({ + tokens.push({ type: 'code', + raw, codeBlockStyle: 'indented', text: !this.options.pedantic ? rtrim$1(cap, '\n') @@ -665,10 +686,12 @@ var Lexer_1 = class Lexer { } // fences - if (cap = this.rules.fences.exec(src)) { + if (cap = this.rules.block.fences.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'code', + raw, lang: cap[2] ? cap[2].trim() : cap[2], text: cap[3] || '' }); @@ -676,10 +699,12 @@ var Lexer_1 = class Lexer { } // heading - if (cap = this.rules.heading.exec(src)) { + if (cap = this.rules.block.heading.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'heading', + raw, depth: cap[1].length, text: cap[2] }); @@ -687,7 +712,7 @@ var Lexer_1 = class Lexer { } // table no leading pipe (gfm) - if (cap = this.rules.nptable.exec(src)) { + if (cap = this.rules.block.nptable.exec(src)) { item = { type: 'table', header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), @@ -697,8 +722,11 @@ var Lexer_1 = class Lexer { if (item.header.length === item.align.length) { src = src.substring(cap[0].length); + raw = cap[0]; + item.raw = raw; - for (i = 0; i < item.align.length; i++) { + l = item.align.length; + for (i = 0; i < l; i++) { if (/^ *-+: *$/.test(item.align[i])) { item.align[i] = 'right'; } else if (/^ *:-+: *$/.test(item.align[i])) { @@ -710,72 +738,71 @@ var Lexer_1 = class Lexer { } } - for (i = 0; i < item.cells.length; i++) { + l = item.cells.length; + for (i = 0; i < l; i++) { item.cells[i] = splitCells$1(item.cells[i], item.header.length); } - this.tokens.push(item); + tokens.push(item); continue; } } // hr - if (cap = this.rules.hr.exec(src)) { + if (cap = this.rules.block.hr.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' + raw = cap[0]; + tokens.push({ + type: 'hr', + raw }); continue; } // blockquote - if (cap = this.rules.blockquote.exec(src)) { + if (cap = this.rules.block.blockquote.exec(src)) { src = src.substring(cap[0].length); - - this.tokens.push({ - type: 'blockquote_start' - }); + raw = cap[0]; cap = cap[0].replace(/^ *> ?/gm, ''); - // Pass `top` to keep the current - // "toplevel" state. This is exactly - // how markdown.pl works. - this.token(cap, top); - - this.tokens.push({ - type: 'blockquote_end' + tokens.push({ + type: 'blockquote', + raw, + tokens: this.blockTokens([], cap, top) }); continue; } // list - if (cap = this.rules.list.exec(src)) { + if (cap = this.rules.block.list.exec(src)) { src = src.substring(cap[0].length); + raw = cap[0]; bull = cap[2]; isordered = bull.length > 1; - listStart = { - type: 'list_start', + list = { + type: 'list', + raw, ordered: isordered, start: isordered ? +bull : '', - loose: false + loose: false, + items: [] }; - this.tokens.push(listStart); + tokens.push(list); // Get each top-level item. - cap = cap[0].match(this.rules.item); + cap = cap[0].match(this.rules.block.item); - listItems = []; next = false; - l = cap.length; - i = 0; - for (; i < l; i++) { + l = cap.length; + for (i = 0; i < l; i++) { item = cap[i]; + raw = item.trim(); // Remove the list item's bullet // so it is seen as the next token. @@ -797,7 +824,9 @@ var Lexer_1 = class Lexer { b = block$1.bullet.exec(cap[i + 1])[0]; if (bull.length > 1 ? b.length === 1 : (b.length > 1 || (this.options.smartLists && b !== bull))) { - src = cap.slice(i + 1).join('\n') + src; + const addBack = cap.slice(i + 1).join('\n'); + src = addBack + src; + list.raw = list.raw.substring(list.raw.length - addBack.length); i = l - 1; } } @@ -812,7 +841,7 @@ var Lexer_1 = class Lexer { } if (loose) { - listStart.loose = true; + list.loose = true; } // Check for task list items @@ -823,46 +852,27 @@ var Lexer_1 = class Lexer { item = item.replace(/^\[[ xX]\] +/, ''); } - t = { - type: 'list_item_start', + list.items.push({ + raw, task: istask, checked: ischecked, - loose: loose - }; - - listItems.push(t); - this.tokens.push(t); - - // Recurse. - this.token(item, false); - - this.tokens.push({ - type: 'list_item_end' + loose: loose, + tokens: this.blockTokens([], item, false) }); } - if (listStart.loose) { - l = listItems.length; - i = 0; - for (; i < l; i++) { - listItems[i].loose = true; - } - } - - this.tokens.push({ - type: 'list_end' - }); - continue; } // html - if (cap = this.rules.html.exec(src)) { + if (cap = this.rules.block.html.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: this.options.sanitize ? 'paragraph' : 'html', + raw, pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'), text: this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0])) : cap[0] @@ -871,7 +881,7 @@ var Lexer_1 = class Lexer { } // def - if (top && (cap = this.rules.def.exec(src))) { + if (top && (cap = this.rules.block.def.exec(src))) { src = src.substring(cap[0].length); if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1); tag = cap[1].toLowerCase().replace(/\s+/g, ' '); @@ -885,7 +895,7 @@ var Lexer_1 = class Lexer { } // table (gfm) - if (cap = this.rules.table.exec(src)) { + if (cap = this.rules.block.table.exec(src)) { item = { type: 'table', header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), @@ -895,8 +905,10 @@ var Lexer_1 = class Lexer { if (item.header.length === item.align.length) { src = src.substring(cap[0].length); + item.raw = cap[0]; - for (i = 0; i < item.align.length; i++) { + l = item.align.length; + for (i = 0; i < l; i++) { if (/^ *-+: *$/.test(item.align[i])) { item.align[i] = 'right'; } else if (/^ *:-+: *$/.test(item.align[i])) { @@ -908,23 +920,26 @@ var Lexer_1 = class Lexer { } } - for (i = 0; i < item.cells.length; i++) { + l = item.cells.length; + for (i = 0; i < l; i++) { item.cells[i] = splitCells$1( item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length); } - this.tokens.push(item); + tokens.push(item); continue; } } // lheading - if (cap = this.rules.lheading.exec(src)) { + if (cap = this.rules.block.lheading.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'heading', + raw, depth: cap[2].charAt(0) === '=' ? 1 : 2, text: cap[1] }); @@ -932,10 +947,12 @@ var Lexer_1 = class Lexer { } // top-level paragraph - if (top && (cap = this.rules.paragraph.exec(src))) { + if (top && (cap = this.rules.block.paragraph.exec(src))) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'paragraph', + raw, text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1] @@ -944,23 +961,459 @@ var Lexer_1 = class Lexer { } // text - if (cap = this.rules.text.exec(src)) { + if (cap = this.rules.block.text.exec(src)) { // Top-level should never reach here. src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'text', + raw, text: cap[0] }); continue; } if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0); + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } } } - return this.tokens; - }; + return tokens; + } + + inlineTokens(tokens) { + let i, + j, + k, + l2, + row, + token; + + const l = tokens.length; + for (i = 0; i < l; i++) { + token = tokens[i]; + switch (token.type) { + case 'paragraph': + case 'text': + case 'heading': { + token.tokens = []; + this.inlineOutput(token.text, token.tokens); + break; + } + case 'table': { + token.tokens = { + header: [], + cells: [] + }; + + // header + l2 = token.header.length; + for (j = 0; j < l2; j++) { + token.tokens.header[j] = []; + this.inlineOutput(token.header[j], token.tokens.header[j]); + } + + // cells + l2 = token.cells.length; + for (j = 0; j < l2; j++) { + row = token.cells[j]; + token.tokens.cells[j] = []; + for (k = 0; k < row.length; k++) { + token.tokens.cells[j][k] = []; + this.inlineOutput(row[k], token.tokens.cells[j][k]); + } + } + + break; + } + case 'blockquote': { + this.inlineTokens(token.tokens); + break; + } + case 'list': { + l2 = token.items.length; + for (j = 0; j < l2; j++) { + this.inlineTokens(token.items[j].tokens); + } + break; + } + } + } + + return tokens; + } + + /** + * Lexing/Compiling + */ + inlineOutput(src, tokens) { + let out = '', + link, + text, + newTokens, + href, + title, + cap, + prevCapZero, + raw; + + while (src) { + // escape + if (cap = this.rules.inline.escape.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + text = escape$1(cap[1]); + out += text; + tokens.push({ + type: 'escape', + raw, + text + }); + continue; + } + + // tag + if (cap = this.rules.inline.tag.exec(src)) { + if (!this.inLink && /^/i.test(cap[0])) { + this.inLink = false; + } + if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { + this.inRawBlock = true; + } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { + this.inRawBlock = false; + } + + src = src.substring(cap[0].length); + raw = cap[0]; + text = this.options.sanitize + ? (this.options.sanitizer + ? this.options.sanitizer(cap[0]) + : escape$1(cap[0])) + : cap[0]; + tokens.push({ + type: this.options.sanitize + ? 'text' + : 'html', + raw, + text + }); + out += text; + continue; + } + + // link + if (cap = this.rules.inline.link.exec(src)) { + const lastParenIndex = findClosingBracket$1(cap[2], '()'); + if (lastParenIndex > -1) { + const start = cap[0].indexOf('!') === 0 ? 5 : 4; + const linkLen = start + cap[1].length + lastParenIndex; + cap[2] = cap[2].substring(0, lastParenIndex); + cap[0] = cap[0].substring(0, linkLen).trim(); + cap[3] = ''; + } + src = src.substring(cap[0].length); + raw = cap[0]; + this.inLink = true; + href = cap[2]; + if (this.options.pedantic) { + link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); + + if (link) { + href = link[1]; + title = link[3]; + } else { + title = ''; + } + } else { + title = cap[3] ? cap[3].slice(1, -1) : ''; + } + href = href.trim().replace(/^<([\s\S]*)>$/, '$1'); + out += this.outputLink(cap, { + href: this.escapes(href), + title: this.escapes(title) + }, tokens, raw); + this.inLink = false; + continue; + } + + // reflink, nolink + if ((cap = this.rules.inline.reflink.exec(src)) + || (cap = this.rules.inline.nolink.exec(src))) { + src = src.substring(cap[0].length); + raw = cap[0]; + link = (cap[2] || cap[1]).replace(/\s+/g, ' '); + link = this.tokens.links[link.toLowerCase()]; + if (!link || !link.href) { + text = cap[0].charAt(0); + out += text; + tokens.push({ + type: 'text', + raw: text, + text + }); + src = cap[0].substring(1) + src; + continue; + } + this.inLink = true; + out += this.outputLink(cap, link, tokens, raw); + this.inLink = false; + continue; + } + + // strong + if (cap = this.rules.inline.strong.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + newTokens = tokens ? [] : null; + text = this.inlineOutput(cap[4] || cap[3] || cap[2] || cap[1], newTokens); + + tokens.push({ + type: 'strong', + raw, + text, + tokens: newTokens + }); + out += text; + continue; + } + + // em + if (cap = this.rules.inline.em.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + newTokens = tokens ? [] : null; + text = this.inlineOutput(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1], newTokens); + tokens.push({ + type: 'em', + raw, + text, + tokens: newTokens + }); + out += text; + continue; + } + + // code + if (cap = this.rules.inline.code.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + text = escape$1(cap[2].trim(), true); + tokens.push({ + type: 'codespan', + raw, + text + }); + out += text; + continue; + } + + // br + if (cap = this.rules.inline.br.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + tokens.push({ + type: 'br', + raw + }); + out += '\n'; + continue; + } + + // del (gfm) + if (cap = this.rules.inline.del.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + newTokens = tokens ? [] : null; + text = this.inlineOutput(cap[1], newTokens); + tokens.push({ + type: 'del', + raw, + text, + tokens: newTokens + }); + out += text; + continue; + } + + // autolink + if (cap = this.rules.inline.autolink.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + if (cap[2] === '@') { + text = escape$1(this.options.mangle ? this.mangle(cap[1]) : cap[1]); + href = 'mailto:' + text; + } else { + text = escape$1(cap[1]); + href = text; + } + tokens.push({ + type: 'link', + raw, + text, + href, + tokens: [ + { + type: 'text', + raw: text, + text + } + ] + }); + out += text; + continue; + } + + // url (gfm) + if (!this.inLink && (cap = this.rules.inline.url.exec(src))) { + if (cap[2] === '@') { + text = escape$1(this.options.mangle ? this.mangle(cap[0]) : cap[0]); + href = 'mailto:' + text; + } else { + // do extended autolink path validation + do { + prevCapZero = cap[0]; + cap[0] = this.rules.inline._backpedal.exec(cap[0])[0]; + } while (prevCapZero !== cap[0]); + text = escape$1(cap[0]); + if (cap[1] === 'www.') { + href = 'http://' + text; + } else { + href = text; + } + } + src = src.substring(cap[0].length); + raw = cap[0]; + tokens.push({ + type: 'link', + raw, + text, + href, + tokens: [ + { + type: 'text', + raw: text, + text + } + ] + }); + out += text; + continue; + } + + // text + if (cap = this.rules.inline.text.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + if (this.inRawBlock) { + text = this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0])) : cap[0]; + } else { + text = escape$1(this.options.smartypants ? this.smartypants(cap[0]) : cap[0]); + } + tokens.push({ + type: 'text', + raw, + text + }); + out += text; + continue; + } + + if (src) { + const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0); + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } + } + } + + return out; + } + + escapes(text) { + return text ? text.replace(inline$1._escapes, '$1') : text; + } + + /** + * tokenize Link + */ + outputLink(cap, link, tokens, raw) { + const href = link.href; + const title = link.title ? escape$1(link.title) : null; + const newTokens = tokens ? [] : null; + + if (cap[0].charAt(0) !== '!') { + const text = this.inlineOutput(cap[1], newTokens); + tokens.push({ + type: 'link', + raw, + text, + href, + title, + tokens: newTokens + }); + return text; + } else { + const text = escape$1(cap[1]); + tokens.push({ + type: 'image', + raw, + text, + href, + title + }); + return text; + } + } + + /** + * Smartypants Transformations + */ + smartypants(text) { + return text + // em-dashes + .replace(/---/g, '\u2014') + // en-dashes + .replace(/--/g, '\u2013') + // opening singles + .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018') + // closing singles & apostrophes + .replace(/'/g, '\u2019') + // opening doubles + .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c') + // closing doubles + .replace(/"/g, '\u201d') + // ellipses + .replace(/\.{3}/g, '\u2026'); + } + + /** + * Mangle Links + */ + mangle(text) { + let out = '', + i, + ch; + + const l = text.length; + for (i = 0; i < l; i++) { + ch = text.charCodeAt(i); + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } + out += '&#' + ch + ';'; + } + + return out; + } }; const { defaults: defaults$2 } = defaults; @@ -999,15 +1452,15 @@ var Renderer_1 = class Renderer { + '">' + (escaped ? code : escape$2(code, true)) + '\n'; - }; + } blockquote(quote) { return '
\n' + quote + '
\n'; - }; + } html(html) { return html; - }; + } heading(text, level, raw, slugger) { if (this.options.headerIds) { @@ -1024,21 +1477,21 @@ var Renderer_1 = class Renderer { } // ignore IDs return '' + text + '\n'; - }; + } hr() { return this.options.xhtml ? '
\n' : '
\n'; - }; + } list(body, ordered, start) { const type = ordered ? 'ol' : 'ul', startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; return '<' + type + startatt + '>\n' + body + '\n'; - }; + } listitem(text) { return '
  • ' + text + '
  • \n'; - }; + } checkbox(checked) { return ' '; - }; + } paragraph(text) { return '

    ' + text + '

    \n'; - }; + } table(header, body) { if (body) body = '' + body + ''; @@ -1061,11 +1514,11 @@ var Renderer_1 = class Renderer { + '\n' + body + '\n'; - }; + } tablerow(content) { return '\n' + content + '\n'; - }; + } tablecell(content, flags) { const type = flags.header ? 'th' : 'td'; @@ -1073,28 +1526,28 @@ var Renderer_1 = class Renderer { ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; return tag + content + '\n'; - }; + } // span level renderer strong(text) { return '' + text + ''; - }; + } em(text) { return '' + text + ''; - }; + } codespan(text) { return '' + text + ''; - }; + } br() { return this.options.xhtml ? '
    ' : '
    '; - }; + } del(text) { return '' + text + ''; - }; + } link(href, title, text) { href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); @@ -1107,7 +1560,7 @@ var Renderer_1 = class Renderer { } out += '>' + text + '
    '; return out; - }; + } image(href, title, text) { href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); @@ -1121,337 +1574,10 @@ var Renderer_1 = class Renderer { } out += this.options.xhtml ? '/>' : '>'; return out; - }; + } text(text) { return text; - }; -}; - -/** - * Slugger generates header id - */ -var Slugger_1 = class Slugger { - constructor() { - this.seen = {}; - } - - /** - * Convert string to unique id - */ - slug(value) { - let slug = value - .toLowerCase() - .trim() - // remove html tags - .replace(/<[!\/a-z].*?>/ig, '') - // remove unwanted chars - .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '') - .replace(/\s/g, '-'); - - if (this.seen.hasOwnProperty(slug)) { - const originalSlug = slug; - do { - this.seen[originalSlug]++; - slug = originalSlug + '-' + this.seen[originalSlug]; - } while (this.seen.hasOwnProperty(slug)); - } - this.seen[slug] = 0; - - return slug; - }; -}; - -const { defaults: defaults$3 } = defaults; -const { inline: inline$1 } = rules; -const { - findClosingBracket: findClosingBracket$1, - escape: escape$3 -} = helpers; - -/** - * Inline Lexer & Compiler - */ -var InlineLexer_1 = class InlineLexer { - constructor(links, options) { - this.options = options || defaults$3; - this.links = links; - this.rules = inline$1.normal; - this.options.renderer = this.options.renderer || new Renderer_1(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - - if (!this.links) { - throw new Error('Tokens array requires a `links` property.'); - } - - if (this.options.pedantic) { - this.rules = inline$1.pedantic; - } else if (this.options.gfm) { - if (this.options.breaks) { - this.rules = inline$1.breaks; - } else { - this.rules = inline$1.gfm; - } - } - } - - /** - * Expose Inline Rules - */ - static get rules() { - return inline$1; - } - - /** - * Static Lexing/Compiling Method - */ - static output(src, links, options) { - const inline = new InlineLexer(links, options); - return inline.output(src); - } - - /** - * Lexing/Compiling - */ - output(src) { - let out = '', - link, - text, - href, - title, - cap, - prevCapZero; - - while (src) { - // escape - if (cap = this.rules.escape.exec(src)) { - src = src.substring(cap[0].length); - out += escape$3(cap[1]); - continue; - } - - // tag - if (cap = this.rules.tag.exec(src)) { - if (!this.inLink && /^/i.test(cap[0])) { - this.inLink = false; - } - if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { - this.inRawBlock = true; - } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { - this.inRawBlock = false; - } - - src = src.substring(cap[0].length); - out += this.renderer.html(this.options.sanitize - ? (this.options.sanitizer - ? this.options.sanitizer(cap[0]) - : escape$3(cap[0])) - : cap[0]); - continue; - } - - // link - if (cap = this.rules.link.exec(src)) { - const lastParenIndex = findClosingBracket$1(cap[2], '()'); - if (lastParenIndex > -1) { - const start = cap[0].indexOf('!') === 0 ? 5 : 4; - const linkLen = start + cap[1].length + lastParenIndex; - cap[2] = cap[2].substring(0, lastParenIndex); - cap[0] = cap[0].substring(0, linkLen).trim(); - cap[3] = ''; - } - src = src.substring(cap[0].length); - this.inLink = true; - href = cap[2]; - if (this.options.pedantic) { - link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); - - if (link) { - href = link[1]; - title = link[3]; - } else { - title = ''; - } - } else { - title = cap[3] ? cap[3].slice(1, -1) : ''; - } - href = href.trim().replace(/^<([\s\S]*)>$/, '$1'); - out += this.outputLink(cap, { - href: InlineLexer.escapes(href), - title: InlineLexer.escapes(title) - }); - this.inLink = false; - continue; - } - - // reflink, nolink - if ((cap = this.rules.reflink.exec(src)) - || (cap = this.rules.nolink.exec(src))) { - src = src.substring(cap[0].length); - link = (cap[2] || cap[1]).replace(/\s+/g, ' '); - link = this.links[link.toLowerCase()]; - if (!link || !link.href) { - out += cap[0].charAt(0); - src = cap[0].substring(1) + src; - continue; - } - this.inLink = true; - out += this.outputLink(cap, link); - this.inLink = false; - continue; - } - - // strong - if (cap = this.rules.strong.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1])); - continue; - } - - // em - if (cap = this.rules.em.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1])); - continue; - } - - // code - if (cap = this.rules.code.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.codespan(escape$3(cap[2].trim(), true)); - continue; - } - - // br - if (cap = this.rules.br.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.br(); - continue; - } - - // del (gfm) - if (cap = this.rules.del.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.del(this.output(cap[1])); - continue; - } - - // autolink - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); - if (cap[2] === '@') { - text = escape$3(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape$3(cap[1]); - href = text; - } - out += this.renderer.link(href, null, text); - continue; - } - - // url (gfm) - if (!this.inLink && (cap = this.rules.url.exec(src))) { - if (cap[2] === '@') { - text = escape$3(cap[0]); - href = 'mailto:' + text; - } else { - // do extended autolink path validation - do { - prevCapZero = cap[0]; - cap[0] = this.rules._backpedal.exec(cap[0])[0]; - } while (prevCapZero !== cap[0]); - text = escape$3(cap[0]); - if (cap[1] === 'www.') { - href = 'http://' + text; - } else { - href = text; - } - } - src = src.substring(cap[0].length); - out += this.renderer.link(href, null, text); - continue; - } - - // text - if (cap = this.rules.text.exec(src)) { - src = src.substring(cap[0].length); - if (this.inRawBlock) { - out += this.renderer.text(this.options.sanitize ? (this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0])) : cap[0]); - } else { - out += this.renderer.text(escape$3(this.smartypants(cap[0]))); - } - continue; - } - - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } - } - - return out; - } - - static escapes(text) { - return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; - } - - /** - * Compile Link - */ - outputLink(cap, link) { - const href = link.href, - title = link.title ? escape$3(link.title) : null; - - return cap[0].charAt(0) !== '!' - ? this.renderer.link(href, title, this.output(cap[1])) - : this.renderer.image(href, title, escape$3(cap[1])); - } - - /** - * Smartypants Transformations - */ - smartypants(text) { - if (!this.options.smartypants) return text; - return text - // em-dashes - .replace(/---/g, '\u2014') - // en-dashes - .replace(/--/g, '\u2013') - // opening singles - .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018') - // closing singles & apostrophes - .replace(/'/g, '\u2019') - // opening doubles - .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c') - // closing doubles - .replace(/"/g, '\u201d') - // ellipses - .replace(/\.{3}/g, '\u2026'); - } - - /** - * Mangle Links - */ - mangle(text) { - if (!this.options.mangle) return text; - const l = text.length; - let out = '', - i = 0, - ch; - - for (; i < l; i++) { - ch = text.charCodeAt(i); - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); - } - out += '&#' + ch + ';'; - } - - return out; } }; @@ -1498,9 +1624,42 @@ var TextRenderer_1 = class TextRenderer { } }; -const { defaults: defaults$4 } = defaults; +/** + * Slugger generates header id + */ +var Slugger_1 = class Slugger { + constructor() { + this.seen = {}; + } + + /** + * Convert string to unique id + */ + slug(value) { + let slug = value + .toLowerCase() + .trim() + // remove html tags + .replace(/<[!\/a-z].*?>/ig, '') + // remove unwanted chars + .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '') + .replace(/\s/g, '-'); + + if (this.seen.hasOwnProperty(slug)) { + const originalSlug = slug; + do { + this.seen[originalSlug]++; + slug = originalSlug + '-' + this.seen[originalSlug]; + } while (this.seen.hasOwnProperty(slug)); + } + this.seen[slug] = 0; + + return slug; + } +}; + +const { defaults: defaults$3 } = defaults; const { - merge: merge$2, unescape: unescape$1 } = helpers; @@ -1509,11 +1668,10 @@ const { */ var Parser_1 = class Parser { constructor(options) { - this.tokens = []; - this.token = null; - this.options = options || defaults$4; + this.options = options || defaults$3; this.options.renderer = this.options.renderer || new Renderer_1(); this.renderer = this.options.renderer; + this.textRenderer = new TextRenderer_1(); this.renderer.options = this.options; this.slugger = new Slugger_1(); } @@ -1524,192 +1682,233 @@ var Parser_1 = class Parser { static parse(tokens, options) { const parser = new Parser(options); return parser.parse(tokens); - }; + } /** * Parse Loop */ - parse(tokens) { - this.inline = new InlineLexer_1(tokens.links, this.options); - // use an InlineLexer with a TextRenderer to extract pure text - this.inlineText = new InlineLexer_1( - tokens.links, - merge$2({}, this.options, { renderer: new TextRenderer_1() }) - ); - this.tokens = tokens.reverse(); + parse(tokens, top = true) { + let out = '', + body, + token; - let out = ''; - while (this.next()) { - out += this.tok(); + const l = tokens.length; + for (let i = 0; i < l; i++) { + token = tokens[i]; + switch (token.type) { + case 'space': { + continue; + } + case 'hr': { + out += this.renderer.hr(); + continue; + } + case 'heading': { + out += this.renderer.heading( + this.parseInline(token.tokens), + token.depth, + unescape$1(this.parseInline(token.tokens, this.textRenderer)), + this.slugger); + continue; + } + case 'code': { + out += this.renderer.code(token.text, + token.lang, + token.escaped); + continue; + } + case 'table': { + let header = '', + i, + row, + cell, + j, + l2, + l3; + + // header + cell = ''; + l2 = token.header.length; + for (i = 0; i < l2; i++) { + cell += this.renderer.tablecell( + this.parseInline(token.tokens.header[i]), + { header: true, align: token.align[i] } + ); + } + header += this.renderer.tablerow(cell); + + body = ''; + l2 = token.cells.length; + for (i = 0; i < l2; i++) { + row = token.tokens.cells[i]; + + cell = ''; + l3 = row.length; + for (j = 0; j < l3; j++) { + cell += this.renderer.tablecell( + this.parseInline(row[j]), + { header: false, align: token.align[j] } + ); + } + + body += this.renderer.tablerow(cell); + } + out += this.renderer.table(header, body); + continue; + } + case 'blockquote': { + body = this.parse(token.tokens); + out += this.renderer.blockquote(body); + continue; + } + case 'list': { + const ordered = token.ordered, + start = token.start, + loose = token.loose, + l2 = token.items.length; + let itemBody; + + body = ''; + for (let j = 0; j < l2; j++) { + const item = token.items[j]; + const checked = item.checked; + const task = item.task; + + itemBody = ''; + if (item.task) { + const checkbox = this.renderer.checkbox(checked); + if (loose) { + if (item.tokens[0].type === 'text') { + item.tokens[0].text = checkbox + ' ' + item.tokens[0].text; + if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') { + item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text; + } + } else { + item.tokens.unshift({ + type: 'text', + text: checkbox + }); + } + } else { + itemBody += checkbox; + } + } + + itemBody += this.parse(item.tokens, loose); + body += this.renderer.listitem(itemBody, task, checked); + } + + out += this.renderer.list(body, ordered, start); + continue; + } + case 'html': { + // TODO parse inline content if parameter markdown=1 + out += this.renderer.html(token.text); + continue; + } + case 'paragraph': { + out += this.renderer.paragraph(this.parseInline(token.tokens)); + continue; + } + case 'text': { + body = token.tokens ? this.parseInline(token.tokens) : token.text; + while (i + 1 < l && tokens[i + 1].type === 'text') { + token = tokens[++i]; + body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text); + } + out += top ? this.renderer.paragraph(body) : body; + continue; + } + default: { + const errMsg = 'Token with "' + token.type + '" type was not found.'; + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } + } + } } return out; - }; + } /** - * Next Token + * Parse Inline Tokens */ - next() { - this.token = this.tokens.pop(); - return this.token; - }; + parseInline(tokens, renderer) { + renderer = renderer || this.renderer; + let out = '', + i, + token; - /** - * Preview Next Token - */ - peek() { - return this.tokens[this.tokens.length - 1] || 0; - }; - - /** - * Parse Text Tokens - */ - parseText() { - let body = this.token.text; - - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } - - return this.inline.output(body); - }; - - /** - * Parse Current Token - */ - tok() { - let body = ''; - switch (this.token.type) { - case 'space': { - return ''; - } - case 'hr': { - return this.renderer.hr(); - } - case 'heading': { - return this.renderer.heading( - this.inline.output(this.token.text), - this.token.depth, - unescape$1(this.inlineText.output(this.token.text)), - this.slugger); - } - case 'code': { - return this.renderer.code(this.token.text, - this.token.lang, - this.token.escaped); - } - case 'table': { - let header = '', - i, - row, - cell, - j; - - // header - cell = ''; - for (i = 0; i < this.token.header.length; i++) { - cell += this.renderer.tablecell( - this.inline.output(this.token.header[i]), - { header: true, align: this.token.align[i] } - ); + const l = tokens.length; + for (i = 0; i < l; i++) { + token = tokens[i]; + switch (token.type) { + case 'escape': { + out += token.text; + break; } - header += this.renderer.tablerow(cell); - - for (i = 0; i < this.token.cells.length; i++) { - row = this.token.cells[i]; - - cell = ''; - for (j = 0; j < row.length; j++) { - cell += this.renderer.tablecell( - this.inline.output(row[j]), - { header: false, align: this.token.align[j] } - ); - } - - body += this.renderer.tablerow(cell); + case 'html': { + out += renderer.html(token.text); + break; } - return this.renderer.table(header, body); - } - case 'blockquote_start': { - body = ''; - - while (this.next().type !== 'blockquote_end') { - body += this.tok(); + case 'link': { + out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer)); + break; } - - return this.renderer.blockquote(body); - } - case 'list_start': { - body = ''; - const ordered = this.token.ordered, - start = this.token.start; - - while (this.next().type !== 'list_end') { - body += this.tok(); + case 'image': { + out += renderer.image(token.href, token.title, token.text); + break; } - - return this.renderer.list(body, ordered, start); - } - case 'list_item_start': { - body = ''; - const loose = this.token.loose; - const checked = this.token.checked; - const task = this.token.task; - - if (this.token.task) { - if (loose) { - if (this.peek().type === 'text') { - const nextToken = this.peek(); - nextToken.text = this.renderer.checkbox(checked) + ' ' + nextToken.text; - } else { - this.tokens.push({ - type: 'text', - text: this.renderer.checkbox(checked) - }); - } + case 'strong': { + out += renderer.strong(this.parseInline(token.tokens, renderer)); + break; + } + case 'em': { + out += renderer.em(this.parseInline(token.tokens, renderer)); + break; + } + case 'codespan': { + out += renderer.codespan(token.text); + break; + } + case 'br': { + out += renderer.br(); + break; + } + case 'del': { + out += renderer.del(this.parseInline(token.tokens, renderer)); + break; + } + case 'text': { + out += renderer.text(token.text); + break; + } + default: { + const errMsg = 'Inline token with "' + this.token.type + '" type was not found.'; + if (this.options.silent) { + console.error(errMsg); } else { - body += this.renderer.checkbox(checked); + throw new Error(errMsg); } } - - while (this.next().type !== 'list_item_end') { - body += !loose && this.token.type === 'text' - ? this.parseText() - : this.tok(); - } - return this.renderer.listitem(body, task, checked); - } - case 'html': { - // TODO parse inline content if parameter markdown=1 - return this.renderer.html(this.token.text); - } - case 'paragraph': { - return this.renderer.paragraph(this.inline.output(this.token.text)); - } - case 'text': { - return this.renderer.paragraph(this.parseText()); - } - default: { - const errMsg = 'Token with "' + this.token.type + '" type was not found.'; - if (this.options.silent) { - console.log(errMsg); - } else { - throw new Error(errMsg); - } } } - }; + return out; + } }; const { - merge: merge$3, + merge: merge$2, checkSanitizeDeprecation: checkSanitizeDeprecation$1, - escape: escape$4 + escape: escape$3 } = helpers; const { getDefaults, changeDefaults, - defaults: defaults$5 + defaults: defaults$4 } = defaults; /** @@ -1731,7 +1930,7 @@ function marked(src, opt, callback) { opt = null; } - opt = merge$3({}, marked.defaults, opt || {}); + opt = merge$2({}, marked.defaults, opt || {}); checkSanitizeDeprecation$1(opt); const highlight = opt.highlight; let tokens, @@ -1795,14 +1994,14 @@ function marked(src, opt, callback) { return; } try { - opt = merge$3({}, marked.defaults, opt || {}); + opt = merge$2({}, marked.defaults, opt || {}); checkSanitizeDeprecation$1(opt); return Parser_1.parse(Lexer_1.lex(src, opt), opt); } catch (e) { e.message += '\nPlease report this to https://github.com/markedjs/marked.'; if ((opt || marked.defaults).silent) { return '

    An error occurred:

    '
    -        + escape$4(e.message + '', true)
    +        + escape$3(e.message + '', true)
             + '
    '; } throw e; @@ -1815,14 +2014,14 @@ function marked(src, opt, callback) { marked.options = marked.setOptions = function(opt) { - merge$3(marked.defaults, opt); + merge$2(marked.defaults, opt); changeDefaults(marked.defaults); return marked; }; marked.getDefaults = getDefaults; -marked.defaults = defaults$5; +marked.defaults = defaults$4; /** * Expose @@ -1837,9 +2036,6 @@ marked.TextRenderer = TextRenderer_1; marked.Lexer = Lexer_1; marked.lexer = Lexer_1.lex; -marked.InlineLexer = InlineLexer_1; -marked.inlineLexer = InlineLexer_1.output; - marked.Slugger = Slugger_1; marked.parse = marked; diff --git a/lib/marked.js b/lib/marked.js index af3f9123..2809bbdb 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -510,10 +510,12 @@ }; var defaults$1 = defaults.defaults; - var block$1 = rules.block; + var block$1 = rules.block, + inline$1 = rules.inline; var rtrim$1 = helpers.rtrim, splitCells$1 = helpers.splitCells, - escape$1 = helpers.escape; + escape$1 = helpers.escape, + findClosingBracket$1 = helpers.findClosingBracket; /** * Block Lexer */ @@ -523,12 +525,22 @@ this.tokens = []; this.tokens.links = Object.create(null); this.options = options || defaults$1; - this.rules = block$1.normal; + this.rules = { + block: block$1.normal, + inline: inline$1.normal + }; if (this.options.pedantic) { - this.rules = block$1.pedantic; + this.rules.block = block$1.pedantic; + this.rules.inline = inline$1.pedantic; } else if (this.options.gfm) { - this.rules = block$1.gfm; + this.rules.block = block$1.gfm; + + if (this.options.breaks) { + this.rules.inline = inline$1.breaks; + } else { + this.rules.inline = inline$1.gfm; + } } } /** @@ -542,48 +554,57 @@ Lexer.lex = function lex(src, options) { var lexer = new Lexer(options); return lexer.lex(src); - }; - - var _proto = Lexer.prototype; - + } /** * Preprocessing */ + ; + + var _proto = Lexer.prototype; + _proto.lex = function lex(src) { src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' '); - return this.token(src, true); - }; - + this.blockTokens(this.tokens, src, true); + this.inlineTokens(this.tokens); + return this.tokens; + } /** * Lexing */ - _proto.token = function token(src, top) { + ; + + _proto.blockTokens = function blockTokens(tokens, src, top) { src = src.replace(/^ +$/gm, ''); - var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked; + var next, loose, cap, bull, b, item, list, space, i, tag, l, isordered, istask, ischecked, raw; while (src) { // newline - if (cap = this.rules.newline.exec(src)) { + if (cap = this.rules.block.newline.exec(src)) { src = src.substring(cap[0].length); + raw = cap[0]; if (cap[0].length > 1) { - this.tokens.push({ - type: 'space' + tokens.push({ + type: 'space', + raw: raw }); } } // code - if (cap = this.rules.code.exec(src)) { - var lastToken = this.tokens[this.tokens.length - 1]; - src = src.substring(cap[0].length); // An indented code block cannot interrupt a paragraph. + if (cap = this.rules.block.code.exec(src)) { + var lastToken = tokens[tokens.length - 1]; + src = src.substring(cap[0].length); + raw = cap[0]; // An indented code block cannot interrupt a paragraph. if (lastToken && lastToken.type === 'paragraph') { lastToken.text += '\n' + cap[0].trimRight(); + lastToken.raw += '\n' + raw; } else { cap = cap[0].replace(/^ {4}/gm, ''); - this.tokens.push({ + tokens.push({ type: 'code', + raw: raw, codeBlockStyle: 'indented', text: !this.options.pedantic ? rtrim$1(cap, '\n') : cap }); @@ -593,10 +614,12 @@ } // fences - if (cap = this.rules.fences.exec(src)) { + if (cap = this.rules.block.fences.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'code', + raw: raw, lang: cap[2] ? cap[2].trim() : cap[2], text: cap[3] || '' }); @@ -604,10 +627,12 @@ } // heading - if (cap = this.rules.heading.exec(src)) { + if (cap = this.rules.block.heading.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'heading', + raw: raw, depth: cap[1].length, text: cap[2] }); @@ -615,7 +640,7 @@ } // table no leading pipe (gfm) - if (cap = this.rules.nptable.exec(src)) { + if (cap = this.rules.block.nptable.exec(src)) { item = { type: 'table', header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), @@ -625,8 +650,11 @@ if (item.header.length === item.align.length) { src = src.substring(cap[0].length); + raw = cap[0]; + item.raw = raw; + l = item.align.length; - for (i = 0; i < item.align.length; i++) { + for (i = 0; i < l; i++) { if (/^ *-+: *$/.test(item.align[i])) { item.align[i] = 'right'; } else if (/^ *:-+: *$/.test(item.align[i])) { @@ -638,62 +666,64 @@ } } - for (i = 0; i < item.cells.length; i++) { + l = item.cells.length; + + for (i = 0; i < l; i++) { item.cells[i] = splitCells$1(item.cells[i], item.header.length); } - this.tokens.push(item); + tokens.push(item); continue; } } // hr - if (cap = this.rules.hr.exec(src)) { + if (cap = this.rules.block.hr.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' + raw = cap[0]; + tokens.push({ + type: 'hr', + raw: raw }); continue; } // blockquote - if (cap = this.rules.blockquote.exec(src)) { + if (cap = this.rules.block.blockquote.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ - type: 'blockquote_start' - }); - cap = cap[0].replace(/^ *> ?/gm, ''); // Pass `top` to keep the current - // "toplevel" state. This is exactly - // how markdown.pl works. - - this.token(cap, top); - this.tokens.push({ - type: 'blockquote_end' + raw = cap[0]; + cap = cap[0].replace(/^ *> ?/gm, ''); + tokens.push({ + type: 'blockquote', + raw: raw, + tokens: this.blockTokens([], cap, top) }); continue; } // list - if (cap = this.rules.list.exec(src)) { + if (cap = this.rules.block.list.exec(src)) { src = src.substring(cap[0].length); + raw = cap[0]; bull = cap[2]; isordered = bull.length > 1; - listStart = { - type: 'list_start', + list = { + type: 'list', + raw: raw, ordered: isordered, start: isordered ? +bull : '', - loose: false + loose: false, + items: [] }; - this.tokens.push(listStart); // Get each top-level item. + tokens.push(list); // Get each top-level item. - cap = cap[0].match(this.rules.item); - listItems = []; + cap = cap[0].match(this.rules.block.item); next = false; l = cap.length; - i = 0; - for (; i < l; i++) { - item = cap[i]; // Remove the list item's bullet + for (i = 0; i < l; i++) { + item = cap[i]; + raw = item.trim(); // Remove the list item's bullet // so it is seen as the next token. space = item.length; @@ -711,7 +741,9 @@ b = block$1.bullet.exec(cap[i + 1])[0]; if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) { - src = cap.slice(i + 1).join('\n') + src; + var addBack = cap.slice(i + 1).join('\n'); + src = addBack + src; + list.raw = list.raw.substring(list.raw.length - addBack.length); i = l - 1; } } // Determine whether item is loose or not. @@ -727,7 +759,7 @@ } if (loose) { - listStart.loose = true; + list.loose = true; } // Check for task list items @@ -739,41 +771,25 @@ item = item.replace(/^\[[ xX]\] +/, ''); } - t = { - type: 'list_item_start', + list.items.push({ + raw: raw, task: istask, checked: ischecked, - loose: loose - }; - listItems.push(t); - this.tokens.push(t); // Recurse. - - this.token(item, false); - this.tokens.push({ - type: 'list_item_end' + loose: loose, + tokens: this.blockTokens([], item, false) }); } - if (listStart.loose) { - l = listItems.length; - i = 0; - - for (; i < l; i++) { - listItems[i].loose = true; - } - } - - this.tokens.push({ - type: 'list_end' - }); continue; } // html - if (cap = this.rules.html.exec(src)) { + if (cap = this.rules.block.html.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: this.options.sanitize ? 'paragraph' : 'html', + raw: raw, pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'), text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0]) : cap[0] }); @@ -781,7 +797,7 @@ } // def - if (top && (cap = this.rules.def.exec(src))) { + if (top && (cap = this.rules.block.def.exec(src))) { src = src.substring(cap[0].length); if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1); tag = cap[1].toLowerCase().replace(/\s+/g, ' '); @@ -797,7 +813,7 @@ } // table (gfm) - if (cap = this.rules.table.exec(src)) { + if (cap = this.rules.block.table.exec(src)) { item = { type: 'table', header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), @@ -807,8 +823,10 @@ if (item.header.length === item.align.length) { src = src.substring(cap[0].length); + item.raw = cap[0]; + l = item.align.length; - for (i = 0; i < item.align.length; i++) { + for (i = 0; i < l; i++) { if (/^ *-+: *$/.test(item.align[i])) { item.align[i] = 'right'; } else if (/^ *:-+: *$/.test(item.align[i])) { @@ -820,20 +838,24 @@ } } - for (i = 0; i < item.cells.length; i++) { + l = item.cells.length; + + for (i = 0; i < l; i++) { item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length); } - this.tokens.push(item); + tokens.push(item); continue; } } // lheading - if (cap = this.rules.lheading.exec(src)) { + if (cap = this.rules.block.lheading.exec(src)) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'heading', + raw: raw, depth: cap[2].charAt(0) === '=' ? 1 : 2, text: cap[1] }); @@ -841,38 +863,490 @@ } // top-level paragraph - if (top && (cap = this.rules.paragraph.exec(src))) { + if (top && (cap = this.rules.block.paragraph.exec(src))) { src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'paragraph', + raw: raw, text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1] }); continue; } // text - if (cap = this.rules.text.exec(src)) { + if (cap = this.rules.block.text.exec(src)) { // Top-level should never reach here. src = src.substring(cap[0].length); - this.tokens.push({ + raw = cap[0]; + tokens.push({ type: 'text', + raw: raw, text: cap[0] }); continue; } if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0); + + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } } } - return this.tokens; + return tokens; + }; + + _proto.inlineTokens = function inlineTokens(tokens) { + var i, j, k, l2, row, token; + var l = tokens.length; + + for (i = 0; i < l; i++) { + token = tokens[i]; + + switch (token.type) { + case 'paragraph': + case 'text': + case 'heading': + { + token.tokens = []; + this.inlineOutput(token.text, token.tokens); + break; + } + + case 'table': + { + token.tokens = { + header: [], + cells: [] + }; // header + + l2 = token.header.length; + + for (j = 0; j < l2; j++) { + token.tokens.header[j] = []; + this.inlineOutput(token.header[j], token.tokens.header[j]); + } // cells + + + l2 = token.cells.length; + + for (j = 0; j < l2; j++) { + row = token.cells[j]; + token.tokens.cells[j] = []; + + for (k = 0; k < row.length; k++) { + token.tokens.cells[j][k] = []; + this.inlineOutput(row[k], token.tokens.cells[j][k]); + } + } + + break; + } + + case 'blockquote': + { + this.inlineTokens(token.tokens); + break; + } + + case 'list': + { + l2 = token.items.length; + + for (j = 0; j < l2; j++) { + this.inlineTokens(token.items[j].tokens); + } + + break; + } + } + } + + return tokens; + } + /** + * Lexing/Compiling + */ + ; + + _proto.inlineOutput = function inlineOutput(src, tokens) { + var out = '', + link, + text, + newTokens, + href, + title, + cap, + prevCapZero, + raw; + + while (src) { + // escape + if (cap = this.rules.inline.escape.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + text = escape$1(cap[1]); + out += text; + tokens.push({ + type: 'escape', + raw: raw, + text: text + }); + continue; + } // tag + + + if (cap = this.rules.inline.tag.exec(src)) { + if (!this.inLink && /^
    /i.test(cap[0])) { + this.inLink = false; + } + + if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { + this.inRawBlock = true; + } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { + this.inRawBlock = false; + } + + src = src.substring(cap[0].length); + raw = cap[0]; + text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0]) : cap[0]; + tokens.push({ + type: this.options.sanitize ? 'text' : 'html', + raw: raw, + text: text + }); + out += text; + continue; + } // link + + + if (cap = this.rules.inline.link.exec(src)) { + var lastParenIndex = findClosingBracket$1(cap[2], '()'); + + if (lastParenIndex > -1) { + var start = cap[0].indexOf('!') === 0 ? 5 : 4; + var linkLen = start + cap[1].length + lastParenIndex; + cap[2] = cap[2].substring(0, lastParenIndex); + cap[0] = cap[0].substring(0, linkLen).trim(); + cap[3] = ''; + } + + src = src.substring(cap[0].length); + raw = cap[0]; + this.inLink = true; + href = cap[2]; + + if (this.options.pedantic) { + link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); + + if (link) { + href = link[1]; + title = link[3]; + } else { + title = ''; + } + } else { + title = cap[3] ? cap[3].slice(1, -1) : ''; + } + + href = href.trim().replace(/^<([\s\S]*)>$/, '$1'); + out += this.outputLink(cap, { + href: this.escapes(href), + title: this.escapes(title) + }, tokens, raw); + this.inLink = false; + continue; + } // reflink, nolink + + + if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) { + src = src.substring(cap[0].length); + raw = cap[0]; + link = (cap[2] || cap[1]).replace(/\s+/g, ' '); + link = this.tokens.links[link.toLowerCase()]; + + if (!link || !link.href) { + text = cap[0].charAt(0); + out += text; + tokens.push({ + type: 'text', + raw: text, + text: text + }); + src = cap[0].substring(1) + src; + continue; + } + + this.inLink = true; + out += this.outputLink(cap, link, tokens, raw); + this.inLink = false; + continue; + } // strong + + + if (cap = this.rules.inline.strong.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + newTokens = tokens ? [] : null; + text = this.inlineOutput(cap[4] || cap[3] || cap[2] || cap[1], newTokens); + tokens.push({ + type: 'strong', + raw: raw, + text: text, + tokens: newTokens + }); + out += text; + continue; + } // em + + + if (cap = this.rules.inline.em.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + newTokens = tokens ? [] : null; + text = this.inlineOutput(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1], newTokens); + tokens.push({ + type: 'em', + raw: raw, + text: text, + tokens: newTokens + }); + out += text; + continue; + } // code + + + if (cap = this.rules.inline.code.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + text = escape$1(cap[2].trim(), true); + tokens.push({ + type: 'codespan', + raw: raw, + text: text + }); + out += text; + continue; + } // br + + + if (cap = this.rules.inline.br.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + tokens.push({ + type: 'br', + raw: raw + }); + out += '\n'; + continue; + } // del (gfm) + + + if (cap = this.rules.inline.del.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + newTokens = tokens ? [] : null; + text = this.inlineOutput(cap[1], newTokens); + tokens.push({ + type: 'del', + raw: raw, + text: text, + tokens: newTokens + }); + out += text; + continue; + } // autolink + + + if (cap = this.rules.inline.autolink.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + + if (cap[2] === '@') { + text = escape$1(this.options.mangle ? this.mangle(cap[1]) : cap[1]); + href = 'mailto:' + text; + } else { + text = escape$1(cap[1]); + href = text; + } + + tokens.push({ + type: 'link', + raw: raw, + text: text, + href: href, + tokens: [{ + type: 'text', + raw: text, + text: text + }] + }); + out += text; + continue; + } // url (gfm) + + + if (!this.inLink && (cap = this.rules.inline.url.exec(src))) { + if (cap[2] === '@') { + text = escape$1(this.options.mangle ? this.mangle(cap[0]) : cap[0]); + href = 'mailto:' + text; + } else { + // do extended autolink path validation + do { + prevCapZero = cap[0]; + cap[0] = this.rules.inline._backpedal.exec(cap[0])[0]; + } while (prevCapZero !== cap[0]); + + text = escape$1(cap[0]); + + if (cap[1] === 'www.') { + href = 'http://' + text; + } else { + href = text; + } + } + + src = src.substring(cap[0].length); + raw = cap[0]; + tokens.push({ + type: 'link', + raw: raw, + text: text, + href: href, + tokens: [{ + type: 'text', + raw: text, + text: text + }] + }); + out += text; + continue; + } // text + + + if (cap = this.rules.inline.text.exec(src)) { + src = src.substring(cap[0].length); + raw = cap[0]; + + if (this.inRawBlock) { + text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$1(cap[0]) : cap[0]; + } else { + text = escape$1(this.options.smartypants ? this.smartypants(cap[0]) : cap[0]); + } + + tokens.push({ + type: 'text', + raw: raw, + text: text + }); + out += text; + continue; + } + + if (src) { + var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0); + + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } + } + } + + return out; + }; + + _proto.escapes = function escapes(text) { + return text ? text.replace(inline$1._escapes, '$1') : text; + } + /** + * tokenize Link + */ + ; + + _proto.outputLink = function outputLink(cap, link, tokens, raw) { + var href = link.href; + var title = link.title ? escape$1(link.title) : null; + var newTokens = tokens ? [] : null; + + if (cap[0].charAt(0) !== '!') { + var text = this.inlineOutput(cap[1], newTokens); + tokens.push({ + type: 'link', + raw: raw, + text: text, + href: href, + title: title, + tokens: newTokens + }); + return text; + } else { + var _text = escape$1(cap[1]); + + tokens.push({ + type: 'image', + raw: raw, + text: _text, + href: href, + title: title + }); + return _text; + } + } + /** + * Smartypants Transformations + */ + ; + + _proto.smartypants = function smartypants(text) { + return text // em-dashes + .replace(/---/g, "\u2014") // en-dashes + .replace(/--/g, "\u2013") // opening singles + .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes + .replace(/'/g, "\u2019") // opening doubles + .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles + .replace(/"/g, "\u201D") // ellipses + .replace(/\.{3}/g, "\u2026"); + } + /** + * Mangle Links + */ + ; + + _proto.mangle = function mangle(text) { + var out = '', + i, + ch; + var l = text.length; + + for (i = 0; i < l; i++) { + ch = text.charCodeAt(i); + + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } + + out += '&#' + ch + ';'; + } + + return out; }; _createClass(Lexer, null, [{ key: "rules", get: function get() { - return block$1; + return { + block: block$1, + inline: inline$1 + }; } }]); @@ -964,9 +1438,9 @@ var type = flags.header ? 'th' : 'td'; var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; return tag + content + '\n'; - }; + } // span level renderer + ; - // span level renderer _proto.strong = function strong(text) { return '' + text + ''; }; @@ -1028,345 +1502,6 @@ return Renderer; }(); - /** - * Slugger generates header id - */ - var Slugger_1 = /*#__PURE__*/function () { - function Slugger() { - this.seen = {}; - } - /** - * Convert string to unique id - */ - - - var _proto = Slugger.prototype; - - _proto.slug = function slug(value) { - var slug = value.toLowerCase().trim() // remove html tags - .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars - .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-'); - - if (this.seen.hasOwnProperty(slug)) { - var originalSlug = slug; - - do { - this.seen[originalSlug]++; - slug = originalSlug + '-' + this.seen[originalSlug]; - } while (this.seen.hasOwnProperty(slug)); - } - - this.seen[slug] = 0; - return slug; - }; - - return Slugger; - }(); - - var defaults$3 = defaults.defaults; - var inline$1 = rules.inline; - var findClosingBracket$1 = helpers.findClosingBracket, - escape$3 = helpers.escape; - /** - * Inline Lexer & Compiler - */ - - var InlineLexer_1 = /*#__PURE__*/function () { - function InlineLexer(links, options) { - this.options = options || defaults$3; - this.links = links; - this.rules = inline$1.normal; - this.options.renderer = this.options.renderer || new Renderer_1(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - - if (!this.links) { - throw new Error('Tokens array requires a `links` property.'); - } - - if (this.options.pedantic) { - this.rules = inline$1.pedantic; - } else if (this.options.gfm) { - if (this.options.breaks) { - this.rules = inline$1.breaks; - } else { - this.rules = inline$1.gfm; - } - } - } - /** - * Expose Inline Rules - */ - - - /** - * Static Lexing/Compiling Method - */ - InlineLexer.output = function output(src, links, options) { - var inline = new InlineLexer(links, options); - return inline.output(src); - } - /** - * Lexing/Compiling - */ - ; - - var _proto = InlineLexer.prototype; - - _proto.output = function output(src) { - var out = '', - link, - text, - href, - title, - cap, - prevCapZero; - - while (src) { - // escape - if (cap = this.rules.escape.exec(src)) { - src = src.substring(cap[0].length); - out += escape$3(cap[1]); - continue; - } // tag - - - if (cap = this.rules.tag.exec(src)) { - if (!this.inLink && /^/i.test(cap[0])) { - this.inLink = false; - } - - if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { - this.inRawBlock = true; - } else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) { - this.inRawBlock = false; - } - - src = src.substring(cap[0].length); - out += this.renderer.html(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]); - continue; - } // link - - - if (cap = this.rules.link.exec(src)) { - var lastParenIndex = findClosingBracket$1(cap[2], '()'); - - if (lastParenIndex > -1) { - var start = cap[0].indexOf('!') === 0 ? 5 : 4; - var linkLen = start + cap[1].length + lastParenIndex; - cap[2] = cap[2].substring(0, lastParenIndex); - cap[0] = cap[0].substring(0, linkLen).trim(); - cap[3] = ''; - } - - src = src.substring(cap[0].length); - this.inLink = true; - href = cap[2]; - - if (this.options.pedantic) { - link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); - - if (link) { - href = link[1]; - title = link[3]; - } else { - title = ''; - } - } else { - title = cap[3] ? cap[3].slice(1, -1) : ''; - } - - href = href.trim().replace(/^<([\s\S]*)>$/, '$1'); - out += this.outputLink(cap, { - href: InlineLexer.escapes(href), - title: InlineLexer.escapes(title) - }); - this.inLink = false; - continue; - } // reflink, nolink - - - if ((cap = this.rules.reflink.exec(src)) || (cap = this.rules.nolink.exec(src))) { - src = src.substring(cap[0].length); - link = (cap[2] || cap[1]).replace(/\s+/g, ' '); - link = this.links[link.toLowerCase()]; - - if (!link || !link.href) { - out += cap[0].charAt(0); - src = cap[0].substring(1) + src; - continue; - } - - this.inLink = true; - out += this.outputLink(cap, link); - this.inLink = false; - continue; - } // strong - - - if (cap = this.rules.strong.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1])); - continue; - } // em - - - if (cap = this.rules.em.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1])); - continue; - } // code - - - if (cap = this.rules.code.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.codespan(escape$3(cap[2].trim(), true)); - continue; - } // br - - - if (cap = this.rules.br.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.br(); - continue; - } // del (gfm) - - - if (cap = this.rules.del.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.del(this.output(cap[1])); - continue; - } // autolink - - - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); - - if (cap[2] === '@') { - text = escape$3(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape$3(cap[1]); - href = text; - } - - out += this.renderer.link(href, null, text); - continue; - } // url (gfm) - - - if (!this.inLink && (cap = this.rules.url.exec(src))) { - if (cap[2] === '@') { - text = escape$3(cap[0]); - href = 'mailto:' + text; - } else { - // do extended autolink path validation - do { - prevCapZero = cap[0]; - cap[0] = this.rules._backpedal.exec(cap[0])[0]; - } while (prevCapZero !== cap[0]); - - text = escape$3(cap[0]); - - if (cap[1] === 'www.') { - href = 'http://' + text; - } else { - href = text; - } - } - - src = src.substring(cap[0].length); - out += this.renderer.link(href, null, text); - continue; - } // text - - - if (cap = this.rules.text.exec(src)) { - src = src.substring(cap[0].length); - - if (this.inRawBlock) { - out += this.renderer.text(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]); - } else { - out += this.renderer.text(escape$3(this.smartypants(cap[0]))); - } - - continue; - } - - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } - } - - return out; - }; - - InlineLexer.escapes = function escapes(text) { - return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; - } - /** - * Compile Link - */ - ; - - _proto.outputLink = function outputLink(cap, link) { - var href = link.href, - title = link.title ? escape$3(link.title) : null; - return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) : this.renderer.image(href, title, escape$3(cap[1])); - } - /** - * Smartypants Transformations - */ - ; - - _proto.smartypants = function smartypants(text) { - if (!this.options.smartypants) return text; - return text // em-dashes - .replace(/---/g, "\u2014") // en-dashes - .replace(/--/g, "\u2013") // opening singles - .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes - .replace(/'/g, "\u2019") // opening doubles - .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles - .replace(/"/g, "\u201D") // ellipses - .replace(/\.{3}/g, "\u2026"); - } - /** - * Mangle Links - */ - ; - - _proto.mangle = function mangle(text) { - if (!this.options.mangle) return text; - var l = text.length; - var out = '', - i = 0, - ch; - - for (; i < l; i++) { - ch = text.charCodeAt(i); - - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); - } - - out += '&#' + ch + ';'; - } - - return out; - }; - - _createClass(InlineLexer, null, [{ - key: "rules", - get: function get() { - return inline$1; - } - }]); - - return InlineLexer; - }(); - /** * TextRenderer * returns only the textual part of the token @@ -1416,20 +1551,53 @@ return TextRenderer; }(); - var defaults$4 = defaults.defaults; - var merge$2 = helpers.merge, - unescape$1 = helpers.unescape; + /** + * Slugger generates header id + */ + var Slugger_1 = /*#__PURE__*/function () { + function Slugger() { + this.seen = {}; + } + /** + * Convert string to unique id + */ + + + var _proto = Slugger.prototype; + + _proto.slug = function slug(value) { + var slug = value.toLowerCase().trim() // remove html tags + .replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars + .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-'); + + if (this.seen.hasOwnProperty(slug)) { + var originalSlug = slug; + + do { + this.seen[originalSlug]++; + slug = originalSlug + '-' + this.seen[originalSlug]; + } while (this.seen.hasOwnProperty(slug)); + } + + this.seen[slug] = 0; + return slug; + }; + + return Slugger; + }(); + + var defaults$3 = defaults.defaults; + var unescape$1 = helpers.unescape; /** * Parsing & Compiling */ var Parser_1 = /*#__PURE__*/function () { function Parser(options) { - this.tokens = []; - this.token = null; - this.options = options || defaults$4; + this.options = options || defaults$3; this.options.renderer = this.options.renderer || new Renderer_1(); this.renderer = this.options.renderer; + this.textRenderer = new TextRenderer_1(); this.renderer.options = this.options; this.slugger = new Slugger_1(); } @@ -1441,212 +1609,288 @@ Parser.parse = function parse(tokens, options) { var parser = new Parser(options); return parser.parse(tokens); - }; - - var _proto = Parser.prototype; - + } /** * Parse Loop */ - _proto.parse = function parse(tokens) { - this.inline = new InlineLexer_1(tokens.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text + ; - this.inlineText = new InlineLexer_1(tokens.links, merge$2({}, this.options, { - renderer: new TextRenderer_1() - })); - this.tokens = tokens.reverse(); - var out = ''; + var _proto = Parser.prototype; - while (this.next()) { - out += this.tok(); + _proto.parse = function parse(tokens, top) { + if (top === void 0) { + top = true; + } + + var out = '', + body, + token; + var l = tokens.length; + + for (var i = 0; i < l; i++) { + token = tokens[i]; + + switch (token.type) { + case 'space': + { + continue; + } + + case 'hr': + { + out += this.renderer.hr(); + continue; + } + + case 'heading': + { + out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape$1(this.parseInline(token.tokens, this.textRenderer)), this.slugger); + continue; + } + + case 'code': + { + out += this.renderer.code(token.text, token.lang, token.escaped); + continue; + } + + case 'table': + { + var header = '', + _i = void 0, + row = void 0, + cell = void 0, + j = void 0, + l2 = void 0, + l3 = void 0; // header + + + cell = ''; + l2 = token.header.length; + + for (_i = 0; _i < l2; _i++) { + cell += this.renderer.tablecell(this.parseInline(token.tokens.header[_i]), { + header: true, + align: token.align[_i] + }); + } + + header += this.renderer.tablerow(cell); + body = ''; + l2 = token.cells.length; + + for (_i = 0; _i < l2; _i++) { + row = token.tokens.cells[_i]; + cell = ''; + l3 = row.length; + + for (j = 0; j < l3; j++) { + cell += this.renderer.tablecell(this.parseInline(row[j]), { + header: false, + align: token.align[j] + }); + } + + body += this.renderer.tablerow(cell); + } + + out += this.renderer.table(header, body); + continue; + } + + case 'blockquote': + { + body = this.parse(token.tokens); + out += this.renderer.blockquote(body); + continue; + } + + case 'list': + { + var ordered = token.ordered, + start = token.start, + loose = token.loose, + _l = token.items.length; + var itemBody = void 0; + body = ''; + + for (var _j = 0; _j < _l; _j++) { + var item = token.items[_j]; + var checked = item.checked; + var task = item.task; + itemBody = ''; + + if (item.task) { + var checkbox = this.renderer.checkbox(checked); + + if (loose) { + if (item.tokens[0].type === 'text') { + item.tokens[0].text = checkbox + ' ' + item.tokens[0].text; + + if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') { + item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text; + } + } else { + item.tokens.unshift({ + type: 'text', + text: checkbox + }); + } + } else { + itemBody += checkbox; + } + } + + itemBody += this.parse(item.tokens, loose); + body += this.renderer.listitem(itemBody, task, checked); + } + + out += this.renderer.list(body, ordered, start); + continue; + } + + case 'html': + { + // TODO parse inline content if parameter markdown=1 + out += this.renderer.html(token.text); + continue; + } + + case 'paragraph': + { + out += this.renderer.paragraph(this.parseInline(token.tokens)); + continue; + } + + case 'text': + { + body = token.tokens ? this.parseInline(token.tokens) : token.text; + + while (i + 1 < l && tokens[i + 1].type === 'text') { + token = tokens[++i]; + body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text); + } + + out += top ? this.renderer.paragraph(body) : body; + continue; + } + + default: + { + var errMsg = 'Token with "' + token.type + '" type was not found.'; + + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } + } + } + } + + return out; + } + /** + * Parse Inline Tokens + */ + ; + + _proto.parseInline = function parseInline(tokens, renderer) { + renderer = renderer || this.renderer; + var out = '', + i, + token; + var l = tokens.length; + + for (i = 0; i < l; i++) { + token = tokens[i]; + + switch (token.type) { + case 'escape': + { + out += token.text; + break; + } + + case 'html': + { + out += renderer.html(token.text); + break; + } + + case 'link': + { + out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer)); + break; + } + + case 'image': + { + out += renderer.image(token.href, token.title, token.text); + break; + } + + case 'strong': + { + out += renderer.strong(this.parseInline(token.tokens, renderer)); + break; + } + + case 'em': + { + out += renderer.em(this.parseInline(token.tokens, renderer)); + break; + } + + case 'codespan': + { + out += renderer.codespan(token.text); + break; + } + + case 'br': + { + out += renderer.br(); + break; + } + + case 'del': + { + out += renderer.del(this.parseInline(token.tokens, renderer)); + break; + } + + case 'text': + { + out += renderer.text(token.text); + break; + } + + default: + { + var errMsg = 'Inline token with "' + this.token.type + '" type was not found.'; + + if (this.options.silent) { + console.error(errMsg); + } else { + throw new Error(errMsg); + } + } + } } return out; }; - /** - * Next Token - */ - _proto.next = function next() { - this.token = this.tokens.pop(); - return this.token; - }; - - /** - * Preview Next Token - */ - _proto.peek = function peek() { - return this.tokens[this.tokens.length - 1] || 0; - }; - - /** - * Parse Text Tokens - */ - _proto.parseText = function parseText() { - var body = this.token.text; - - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } - - return this.inline.output(body); - }; - - /** - * Parse Current Token - */ - _proto.tok = function tok() { - var body = ''; - - switch (this.token.type) { - case 'space': - { - return ''; - } - - case 'hr': - { - return this.renderer.hr(); - } - - case 'heading': - { - return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, unescape$1(this.inlineText.output(this.token.text)), this.slugger); - } - - case 'code': - { - return this.renderer.code(this.token.text, this.token.lang, this.token.escaped); - } - - case 'table': - { - var header = '', - i, - row, - cell, - j; // header - - cell = ''; - - for (i = 0; i < this.token.header.length; i++) { - cell += this.renderer.tablecell(this.inline.output(this.token.header[i]), { - header: true, - align: this.token.align[i] - }); - } - - header += this.renderer.tablerow(cell); - - for (i = 0; i < this.token.cells.length; i++) { - row = this.token.cells[i]; - cell = ''; - - for (j = 0; j < row.length; j++) { - cell += this.renderer.tablecell(this.inline.output(row[j]), { - header: false, - align: this.token.align[j] - }); - } - - body += this.renderer.tablerow(cell); - } - - return this.renderer.table(header, body); - } - - case 'blockquote_start': - { - body = ''; - - while (this.next().type !== 'blockquote_end') { - body += this.tok(); - } - - return this.renderer.blockquote(body); - } - - case 'list_start': - { - body = ''; - var ordered = this.token.ordered, - start = this.token.start; - - while (this.next().type !== 'list_end') { - body += this.tok(); - } - - return this.renderer.list(body, ordered, start); - } - - case 'list_item_start': - { - body = ''; - var loose = this.token.loose; - var checked = this.token.checked; - var task = this.token.task; - - if (this.token.task) { - if (loose) { - if (this.peek().type === 'text') { - var nextToken = this.peek(); - nextToken.text = this.renderer.checkbox(checked) + ' ' + nextToken.text; - } else { - this.tokens.push({ - type: 'text', - text: this.renderer.checkbox(checked) - }); - } - } else { - body += this.renderer.checkbox(checked); - } - } - - while (this.next().type !== 'list_item_end') { - body += !loose && this.token.type === 'text' ? this.parseText() : this.tok(); - } - - return this.renderer.listitem(body, task, checked); - } - - case 'html': - { - // TODO parse inline content if parameter markdown=1 - return this.renderer.html(this.token.text); - } - - case 'paragraph': - { - return this.renderer.paragraph(this.inline.output(this.token.text)); - } - - case 'text': - { - return this.renderer.paragraph(this.parseText()); - } - - default: - { - var errMsg = 'Token with "' + this.token.type + '" type was not found.'; - - if (this.options.silent) { - console.log(errMsg); - } else { - throw new Error(errMsg); - } - } - } - }; - return Parser; }(); - var merge$3 = helpers.merge, + var merge$2 = helpers.merge, checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation, - escape$4 = helpers.escape; + escape$3 = helpers.escape; var getDefaults = defaults.getDefaults, changeDefaults = defaults.changeDefaults, - defaults$5 = defaults.defaults; + defaults$4 = defaults.defaults; /** * Marked */ @@ -1668,7 +1912,7 @@ opt = null; } - opt = merge$3({}, marked.defaults, opt || {}); + opt = merge$2({}, marked.defaults, opt || {}); checkSanitizeDeprecation$1(opt); var highlight = opt.highlight; var tokens, @@ -1743,14 +1987,14 @@ } try { - opt = merge$3({}, marked.defaults, opt || {}); + opt = merge$2({}, marked.defaults, opt || {}); checkSanitizeDeprecation$1(opt); return Parser_1.parse(Lexer_1.lex(src, opt), opt); } catch (e) { e.message += '\nPlease report this to https://github.com/markedjs/marked.'; if ((opt || marked.defaults).silent) { - return '

    An error occurred:

    ' + escape$4(e.message + '', true) + '
    '; + return '

    An error occurred:

    ' + escape$3(e.message + '', true) + '
    '; } throw e; @@ -1762,13 +2006,13 @@ marked.options = marked.setOptions = function (opt) { - merge$3(marked.defaults, opt); + merge$2(marked.defaults, opt); changeDefaults(marked.defaults); return marked; }; marked.getDefaults = getDefaults; - marked.defaults = defaults$5; + marked.defaults = defaults$4; /** * Expose */ @@ -1779,8 +2023,6 @@ marked.TextRenderer = TextRenderer_1; marked.Lexer = Lexer_1; marked.lexer = Lexer_1.lex; - marked.InlineLexer = InlineLexer_1; - marked.inlineLexer = InlineLexer_1.output; marked.Slugger = Slugger_1; marked.parse = marked; var marked_1 = marked; diff --git a/marked.min.js b/marked.min.js index 7c4f6a08..9586cd0c 100644 --- a/marked.min.js +++ b/marked.min.js @@ -3,4 +3,4 @@ * Copyright (c) 2011-2020, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).marked=t()}(this,function(){"use strict";function r(e,t){for(var n=0;n"']/),l=/[&<>"']/g,a=/[<>"']|&(?!#?\w+;)/,o=/[<>"']|&(?!#?\w+;)/g,h={"&":"&","<":"<",">":">",'"':""","'":"'"};var u=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function c(e){return e.replace(u,function(e,t){return"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""})}var p=/(^|[^\[])\^/g;var g=/[^\w:]/g,f=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;var d={},b=/^[^:]+:\/*[^/]*$/,m=/^([^:]+:)[\s\S]*$/,k=/^([^:]+:\/*[^/]*)[\s\S]*$/;function x(e,t){d[" "+e]||(b.test(e)?d[" "+e]=e+"/":d[" "+e]=_(e,"/",!0));var n=-1===(e=d[" "+e]).indexOf(":");return"//"===t.substring(0,2)?n?t:e.replace(m,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(k,"$1")+t:e+t}function _(e,t,n){var r=e.length;if(0===r)return"";for(var s=0;st)n.splice(t);else for(;n.length ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:"^ {0,3}(?:<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,nptable:Z,table:Z,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/,_label:/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,_title:/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/};C.def=q(C.def).replace("label",C._label).replace("title",C._title).getRegex(),C.bullet=/(?:[*+-]|\d{1,9}\.)/,C.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,C.item=q(C.item,"gm").replace(/bull/g,C.bullet).getRegex(),C.list=q(C.list).replace(/bull/g,C.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+C.def.source+")").getRegex(),C._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|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",C._comment=//,C.html=q(C.html,"i").replace("comment",C._comment).replace("tag",C._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),C.paragraph=q(C._paragraph).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.blockquote=q(C.blockquote).replace("paragraph",C.paragraph).getRegex(),C.normal=L({},C),C.gfm=L({},C.normal,{nptable:"^ *([^|\\n ].*\\|.*)\\n *([-:]+ *\\|[-| :]*)(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)",table:"^ *\\|(.+)\\n *\\|?( *[-:]+[-| :]*)(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"}),C.gfm.nptable=q(C.gfm.nptable).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").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",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.gfm.table=q(C.gfm.table).replace("hr",C.hr).replace("heading"," {0,3}#{1,6} ").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",")|<(?:script|pre|style|!--)").replace("tag",C._tag).getRegex(),C.pedantic=L({},C.normal,{html:q("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",C._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(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:Z,paragraph:q(C.normal._paragraph).replace("hr",C.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",C.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var O={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Z,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,nolink:/^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,strong:/^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,em:/^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Z,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};O.em=q(O.em).replace(/punctuation/g,O._punctuation).getRegex(),O._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,O._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,O._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])?)+(?![-_])/,O.autolink=q(O.autolink).replace("scheme",O._scheme).replace("email",O._email).getRegex(),O._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,O.tag=q(O.tag).replace("comment",C._comment).replace("attribute",O._attribute).getRegex(),O._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,O._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,O._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,O.link=q(O.link).replace("label",O._label).replace("href",O._href).replace("title",O._title).getRegex(),O.reflink=q(O.reflink).replace("label",O._label).getRegex(),O.normal=L({},O),O.pedantic=L({},O.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:q(/^!?\[(label)\]\((.*?)\)/).replace("label",O._label).getRegex(),reflink:q(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",O._label).getRegex()}),O.gfm=L({},O.normal,{escape:q(O.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^~+(?=\S)([\s\S]*?\S)~+/,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\ ?/gm,""),this.token(s,t),this.tokens.push({type:"blockquote_end"});else if(s=this.rules.list.exec(e)){for(e=e.substring(s[0].length),o={type:"list_start",ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(o),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,p=0;p'+(n?e:N(e,!0))+"\n":"
    "+(n?e:N(e,!0))+"
    "},t.blockquote=function(e){return"
    \n"+e+"
    \n"},t.html=function(e){return e},t.heading=function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"},t.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},t.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},t.listitem=function(e){return"
  • "+e+"
  • \n"},t.checkbox=function(e){return" "},t.paragraph=function(e){return"

    "+e+"

    \n"},t.table=function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"},t.tablerow=function(e){return"\n"+e+"\n"},t.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},t.strong=function(e){return""+e+""},t.em=function(e){return""+e+""},t.codespan=function(e){return""+e+""},t.br=function(){return this.options.xhtml?"
    ":"
    "},t.del=function(e){return""+e+""},t.link=function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "},t.image=function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"},t.text=function(e){return e},e}(),G=function(){function e(){this.seen={}}return e.prototype.slug=function(e){var t=e.toLowerCase().trim().replace(/<[!\/a-z].*?>/gi,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-");if(this.seen.hasOwnProperty(t))for(var n=t;this.seen[n]++,t=n+"-"+this.seen[n],this.seen.hasOwnProperty(t););return this.seen[t]=0,t},e}(),M=s.defaults,V=D.inline,H=A,J=y,K=function(){function u(e,t){if(this.options=t||M,this.links=e,this.rules=V.normal,this.options.renderer=this.options.renderer||new X,this.renderer=this.options.renderer,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.pedantic?this.rules=V.pedantic:this.options.gfm&&(this.options.breaks?this.rules=V.breaks:this.rules=V.gfm)}u.output=function(e,t,n){return new u(t,n).output(e)};var e=u.prototype;return e.output=function(e){for(var t,n,r,s,i,l,a="";e;)if(i=this.rules.escape.exec(e))e=e.substring(i[0].length),a+=J(i[1]);else if(i=this.rules.tag.exec(e))!this.inLink&&/^/i.test(i[0])&&(this.inLink=!1),!this.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(i[0])?this.inRawBlock=!0:this.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(i[0])&&(this.inRawBlock=!1),e=e.substring(i[0].length),a+=this.renderer.html(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):J(i[0]):i[0]);else if(i=this.rules.link.exec(e)){var o=H(i[2],"()");if(-1$/,"$1"),a+=this.outputLink(i,{href:u.escapes(r),title:u.escapes(s)}),this.inLink=!1}else if((i=this.rules.reflink.exec(e))||(i=this.rules.nolink.exec(e))){if(e=e.substring(i[0].length),t=(i[2]||i[1]).replace(/\s+/g," "),!(t=this.links[t.toLowerCase()])||!t.href){a+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,a+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),a+=this.renderer.strong(this.output(i[4]||i[3]||i[2]||i[1]));else if(i=this.rules.em.exec(e))e=e.substring(i[0].length),a+=this.renderer.em(this.output(i[6]||i[5]||i[4]||i[3]||i[2]||i[1]));else if(i=this.rules.code.exec(e))e=e.substring(i[0].length),a+=this.renderer.codespan(J(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),a+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),a+=this.renderer.del(this.output(i[1]));else if(i=this.rules.autolink.exec(e))e=e.substring(i[0].length),r="@"===i[2]?"mailto:"+(n=J(this.mangle(i[1]))):n=J(i[1]),a+=this.renderer.link(r,null,n);else if(this.inLink||!(i=this.rules.url.exec(e))){if(i=this.rules.text.exec(e))e=e.substring(i[0].length),this.inRawBlock?a+=this.renderer.text(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):J(i[0]):i[0]):a+=this.renderer.text(J(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=J(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=J(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),a+=this.renderer.link(r,null,n)}return a},u.escapes=function(e){return e?e.replace(u.rules._escapes,"$1"):e},e.outputLink=function(e,t){var n=t.href,r=t.title?J(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,J(e[1]))},e.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},e.mangle=function(e){if(!this.options.mangle)return e;for(var t,n=e.length,r="",s=0;sAn error occurred:

    "+se(e.message+"",!0)+"
    ";throw e}}return oe.options=oe.setOptions=function(e){return ne(oe.defaults,e),le(oe.defaults),oe},oe.getDefaults=ie,oe.defaults=ae,oe.Parser=te,oe.parser=te.parse,oe.Renderer=X,oe.TextRenderer=Q,oe.Lexer=B,oe.lexer=B.lex,oe.InlineLexer=K,oe.inlineLexer=K.output,oe.Slugger=G,oe.parse=oe}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).marked=t()}(this,function(){"use strict";function r(e,t){for(var n=0;n"']/),l=/[&<>"']/g,a=/[<>"']|&(?!#?\w+;)/,o=/[<>"']|&(?!#?\w+;)/g,h={"&":"&","<":"<",">":">",'"':""","'":"'"};var c=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function u(e){return e.replace(c,function(e,t){return"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""})}var p=/(^|[^\[])\^/g;var g=/[^\w:]/g,f=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;var d={},k=/^[^:]+:\/*[^/]*$/,b=/^([^:]+:)[\s\S]*$/,m=/^([^:]+:\/*[^/]*)[\s\S]*$/;function x(e,t){d[" "+e]||(k.test(e)?d[" "+e]=e+"/":d[" "+e]=_(e,"/",!0));var n=-1===(e=d[" "+e]).indexOf(":");return"//"===t.substring(0,2)?n?t:e.replace(b,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(m,"$1")+t:e+t}function _(e,t,n){var r=e.length;if(0===r)return"";for(var s=0;st)n.splice(t);else for(;n.length ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:"^ {0,3}(?:<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,nptable:Z,table:Z,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/,_label:/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,_title:/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/};L.def=q(L.def).replace("label",L._label).replace("title",L._title).getRegex(),L.bullet=/(?:[*+-]|\d{1,9}\.)/,L.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,L.item=q(L.item,"gm").replace(/bull/g,L.bullet).getRegex(),L.list=q(L.list).replace(/bull/g,L.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+L.def.source+")").getRegex(),L._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|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",L._comment=//,L.html=q(L.html,"i").replace("comment",L._comment).replace("tag",L._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),L.paragraph=q(L._paragraph).replace("hr",L.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",L._tag).getRegex(),L.blockquote=q(L.blockquote).replace("paragraph",L.paragraph).getRegex(),L.normal=I({},L),L.gfm=I({},L.normal,{nptable:"^ *([^|\\n ].*\\|.*)\\n *([-:]+ *\\|[-| :]*)(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)",table:"^ *\\|(.+)\\n *\\|?( *[-:]+[-| :]*)(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"}),L.gfm.nptable=q(L.gfm.nptable).replace("hr",L.hr).replace("heading"," {0,3}#{1,6} ").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",")|<(?:script|pre|style|!--)").replace("tag",L._tag).getRegex(),L.gfm.table=q(L.gfm.table).replace("hr",L.hr).replace("heading"," {0,3}#{1,6} ").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",")|<(?:script|pre|style|!--)").replace("tag",L._tag).getRegex(),L.pedantic=I({},L.normal,{html:q("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",L._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(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:Z,paragraph:q(L.normal._paragraph).replace("hr",L.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",L.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var C={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:Z,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,nolink:/^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,strong:/^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,em:/^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:Z,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};C.em=q(C.em).replace(/punctuation/g,C._punctuation).getRegex(),C._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,C._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,C._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])?)+(?![-_])/,C.autolink=q(C.autolink).replace("scheme",C._scheme).replace("email",C._email).getRegex(),C._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,C.tag=q(C.tag).replace("comment",L._comment).replace("attribute",C._attribute).getRegex(),C._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,C._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,C._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,C.link=q(C.link).replace("label",C._label).replace("href",C._href).replace("title",C._title).getRegex(),C.reflink=q(C.reflink).replace("label",C._label).getRegex(),C.normal=I({},C),C.pedantic=I({},C.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:q(/^!?\[(label)\]\((.*?)\)/).replace("label",C._label).getRegex(),reflink:q(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",C._label).getRegex()}),C.gfm=I({},C.normal,{escape:q(C.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^~+(?=\S)([\s\S]*?\S)~+/,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\ ?/gm,""),this.token(s,t),this.tokens.push({type:"blockquote_end"});else if(s=this.rules.list.exec(e)){for(e=e.substring(s[0].length),o={type:"list_start",raw:m=s[0],ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(o),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,p=0;p'+(n?e:N(e,!0))+"\n":"
    "+(n?e:N(e,!0))+"
    "},t.blockquote=function(e){return"
    \n"+e+"
    \n"},t.html=function(e){return e},t.heading=function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"},t.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},t.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},t.listitem=function(e){return"
  • "+e+"
  • \n"},t.checkbox=function(e){return" "},t.paragraph=function(e){return"

    "+e+"

    \n"},t.table=function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"},t.tablerow=function(e){return"\n"+e+"\n"},t.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},t.strong=function(e){return""+e+""},t.em=function(e){return""+e+""},t.codespan=function(e){return""+e+""},t.br=function(){return this.options.xhtml?"
    ":"
    "},t.del=function(e){return""+e+""},t.link=function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "},t.image=function(e,t,n){if(null===(e=F(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"},t.text=function(e){return e},e}(),G=function(){function e(){}var t=e.prototype;return t.strong=function(e){return e},t.em=function(e){return e},t.codespan=function(e){return e},t.del=function(e){return e},t.html=function(e){return e},t.text=function(e){return e},t.link=function(e,t,n){return""+n},t.image=function(e,t,n){return""+n},t.br=function(){return""},e}(),M=function(){function e(){this.seen={}}return e.prototype.slug=function(e){var t=e.toLowerCase().trim().replace(/<[!\/a-z].*?>/gi,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-");if(this.seen.hasOwnProperty(t))for(var n=t;this.seen[n]++,t=n+"-"+this.seen[n],this.seen.hasOwnProperty(t););return this.seen[t]=0,t},e}(),V=s.defaults,H=y,J=function(){function n(e){this.tokens=[],this.token=null,this.options=e||V,this.options.renderer=this.options.renderer||new X,this.renderer=this.options.renderer,this.textRenderer=new G,this.renderer.options=this.options,this.slugger=new M}n.parse=function(e,t){return new n(t).parse(e)};var e=n.prototype;return e.parse=function(e){this.tokens=e.reverse();for(var t="";this.next();)t+=this.tok();return t},e.next=function(){return this.token=this.tokens.pop(),this.token},e.peek=function(){return this.tokens[this.tokens.length-1]||0},e.parseText=function(){for(var e=this.token.tokens?this.parseInline(this.token.tokens):this.token.text;"text"===this.peek().type;)this.next(),e+="\n"+(this.token.tokens?this.parseInline(this.token.tokens):this.token.text);return e},e.tok=function(){var e="";switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.parseInline(this.token.tokens),this.token.depth,H(this.parseInline(this.token.tokens,this.textRenderer)),this.slugger);case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var t,n,r,s,i,l,a="";for(r="",i=this.token.header.length,t=0;t/i.test(a[0])&&(this.inLink=!1),!this.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(a[0])?this.inRawBlock=!0:this.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(a[0])&&(this.inRawBlock=!1),e=e.substring(a[0].length),h=a[0],r=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(a[0]):Y(a[0]):a[0],t.push({type:this.options.sanitize?"text":"html",raw:h,text:r}),c+=r;else if(a=this.rules.link.exec(e)){var u=W(a[2],"()");if(-1$/,"$1"),c+=this.outputLink(a,{href:f.escapes(i),title:f.escapes(l)},t,h),this.inLink=!1}else if((a=this.rules.reflink.exec(e))||(a=this.rules.nolink.exec(e))){if(e=e.substring(a[0].length),h=a[0],n=(a[2]||a[1]).replace(/\s+/g," "),!(n=this.links[n.toLowerCase()])||!n.href){c+=r=a[0].charAt(0),t.push({type:"text",raw:r,text:r}),e=a[0].substring(1)+e;continue}this.inLink=!0,c+=this.outputLink(a,n,t,h),this.inLink=!1}else if(a=this.rules.strong.exec(e))e=e.substring(a[0].length),h=a[0],s=t?[]:null,r=this.output(a[4]||a[3]||a[2]||a[1],s),t.push({type:"strong",raw:h,text:r,tokens:s}),c+=r;else if(a=this.rules.em.exec(e))e=e.substring(a[0].length),h=a[0],s=t?[]:null,r=this.output(a[6]||a[5]||a[4]||a[3]||a[2]||a[1],s),t.push({type:"em",raw:h,text:r,tokens:s}),c+=r;else if(a=this.rules.code.exec(e))e=e.substring(a[0].length),h=a[0],r=Y(a[2].trim(),!0),t.push({type:"codespan",raw:h,text:r}),c+=r;else if(a=this.rules.br.exec(e))e=e.substring(a[0].length),h=a[0],t.push({type:"br",raw:h}),c+="\n";else if(a=this.rules.del.exec(e))e=e.substring(a[0].length),h=a[0],s=t?[]:null,r=this.output(a[1],s),t.push({type:"del",raw:h,text:r,tokens:s}),c+=r;else if(a=this.rules.autolink.exec(e))e=e.substring(a[0].length),h=a[0],i="@"===a[2]?"mailto:"+(r=Y(this.options.mangle?this.mangle(a[1]):a[1])):r=Y(a[1]),t.push({type:"link",raw:h,text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}),c+=r;else if(this.inLink||!(a=this.rules.url.exec(e))){if(a=this.rules.text.exec(e))e=e.substring(a[0].length),h=a[0],r=this.inRawBlock?this.options.sanitize?this.options.sanitizer?this.options.sanitizer(a[0]):Y(a[0]):a[0]:Y(this.options.smartypants?this.smartypants(a[0]):a[0]),t.push({type:"text",raw:h,text:r}),c+=r;else if(e){var g="Infinite loop on byte: "+e.charCodeAt(0);if(!this.options.silent)throw new Error(g);console.error(g)}}else{if("@"===a[2])i="mailto:"+(r=Y(this.options.mangle?this.mangle(a[0]):a[0]));else{for(;o=a[0],a[0]=this.rules._backpedal.exec(a[0])[0],o!==a[0];);r=Y(a[0]),i="www."===a[1]?"http://"+r:r}e=e.substring(a[0].length),h=a[0],t.push({type:"link",raw:h,text:r,href:i,tokens:[{type:"text",raw:r,text:r}]}),c+=r}return c},f.escapes=function(e){return e?e.replace(f.rules._escapes,"$1"):e},e.outputLink=function(e,t,n,r){var s=t.href,i=t.title?Y(t.title):null,l=n?[]:null;if("!"!==e[0].charAt(0)){var a=this.output(e[1],l);return n.push({type:"link",raw:r,text:a,href:s,title:i,tokens:l}),a}var o=Y(e[1]);return n.push({type:"image",raw:r,text:o,href:s,title:i}),o},e.smartypants=function(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")},e.mangle=function(e){var t,n,r="",s=e.length;for(t=0;tAn error occurred:

    "+re(e.message+"",!0)+"
    ";throw e}}return ae.options=ae.setOptions=function(e){return te(ae.defaults,e),ie(ae.defaults),ae},ae.getDefaults=se,ae.defaults=le,ae.Parser=J,ae.parser=J.parse,ae.Renderer=X,ae.TextRenderer=G,ae.Lexer=B,ae.lexer=B.lex,ae.InlineLexer=ee,ae.inlineLexer=ee.lex,ae.Slugger=M,ae.parse=ae}); \ No newline at end of file