From 4daf8d2266a2b80a6fee6be1179f346beed3be73 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 1 May 2018 16:29:02 -0700 Subject: [PATCH] Pick up newer marked version --- src/vs/base/common/marked/marked.js | 523 +++++++++++++++++----------- 1 file changed, 312 insertions(+), 211 deletions(-) diff --git a/src/vs/base/common/marked/marked.js b/src/vs/base/common/marked/marked.js index ca72ea8d6dc..b20380f19b7 100644 --- a/src/vs/base/common/marked/marked.js +++ b/src/vs/base/common/marked/marked.js @@ -6,7 +6,7 @@ var __marked_exports; -;(function(root) { +; (function (root) { 'use strict'; /** @@ -18,20 +18,29 @@ var block = { code: /^( {4}[^\n]+\n*)+/, fences: noop, hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, - heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, nptable: noop, blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, - html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, + html: '^ {0,3}(?:' // optional indentation + + '<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)' // (1) + + '|comment[^\\n]*(\\n+|$)' // (2) + + '|<\\?[\\s\\S]*?\\?>\\n*' // (3) + + '|\\n*' // (4) + + '|\\n*' // (5) + + '|)[\\s\\S]*?(?:\\n{2,}|$)' // (6) + + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=\\h*\\n)[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + + '|(?=\\h*\\n)[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + + ')', def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, table: noop, lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, - paragraph: /^([^\n]+(?:\n?(?!hr|heading|lheading| {0,3}>|tag)[^\n]+)+)/, + paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)+)/, text: /^[^\n]+/ }; -block._label = /(?:\\[\[\]]|[^\[\]])+/; -block._title = /(?:"(?:\\"|[^"]|"[^"\n]*")*"|'\n?(?:[^'\n]+\n?)*'|\([^()]*\))/; +block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; +block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; block.def = edit(block.def) .replace('label', block._label) .replace('title', block._title) @@ -49,23 +58,24 @@ block.list = edit(block.list) .replace('def', '\\n+(?=' + block.def.source + ')') .getRegex(); -block._tag = '(?!(?:' - + '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'; - -block.html = edit(block.html) - .replace('comment', //) - .replace('closed', /<(tag)[\s\S]+?<\/\1>/) - .replace('closing', /\s]*)*?\/?>/) - .replace(/tag/g, block._tag) +block._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'; +block._comment = //; +block.html = edit(block.html, 'i') + .replace('comment', block._comment) + .replace('tag', block._tag) + .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/) .getRegex(); block.paragraph = edit(block.paragraph) .replace('hr', block.hr) .replace('heading', block.heading) .replace('lheading', block.lheading) - .replace('tag', '<' + block._tag) + .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks .getRegex(); block.blockquote = edit(block.blockquote) @@ -99,8 +109,26 @@ block.gfm.paragraph = edit(block.paragraph) */ block.tables = merge({}, block.gfm, { - nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, - table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ + nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ +}); + +/** + * Pedantic grammar + */ + +block.pedantic = merge({}, block.normal, { + html: edit( + '^ *(?:comment *(?:\\n|\\s*$)' + + '|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)' // closed tag + + '|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))') + .replace('comment', block._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+|$)/ }); /** @@ -113,7 +141,9 @@ function Lexer(options) { this.options = options || marked.defaults; this.rules = block.normal; - if (this.options.gfm) { + if (this.options.pedantic) { + this.rules = block.pedantic; + } else if (this.options.gfm) { if (this.options.tables) { this.rules = block.tables; } else { @@ -132,7 +162,7 @@ Lexer.rules = block; * Static Lex Method */ -Lexer.lex = function(src, options) { +Lexer.lex = function (src, options) { var lexer = new Lexer(options); return lexer.lex(src); }; @@ -141,7 +171,7 @@ Lexer.lex = function(src, options) { * Preprocessing */ -Lexer.prototype.lex = function(src) { +Lexer.prototype.lex = function (src) { src = src .replace(/\r\n|\r/g, '\n') .replace(/\t/g, ' ') @@ -155,19 +185,19 @@ Lexer.prototype.lex = function(src) { * Lexing */ -Lexer.prototype.token = function(src, top) { +Lexer.prototype.token = function (src, top) { src = src.replace(/^ +$/gm, ''); var next, - loose, - cap, - bull, - b, - item, - space, - i, - tag, - l, - isordered; + loose, + cap, + bull, + b, + item, + space, + i, + tag, + l, + isordered; while (src) { // newline @@ -217,34 +247,36 @@ Lexer.prototype.token = function(src, top) { // table no leading pipe (gfm) if (top && (cap = this.rules.nptable.exec(src))) { - src = src.substring(cap[0].length); - item = { type: 'table', - header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3].replace(/\n$/, '').split('\n') + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] }; - for (i = 0; i < item.align.length; i++) { - if (/^ *-+: *$/.test(item.align[i])) { - item.align[i] = 'right'; - } else if (/^ *:-+: *$/.test(item.align[i])) { - item.align[i] = 'center'; - } else if (/^ *:-+ *$/.test(item.align[i])) { - item.align[i] = 'left'; - } else { - item.align[i] = null; + if (item.header.length === item.align.length) { + src = src.substring(cap[0].length); + + for (i = 0; i < item.align.length; i++) { + if (/^ *-+: *$/.test(item.align[i])) { + item.align[i] = 'right'; + } else if (/^ *:-+: *$/.test(item.align[i])) { + item.align[i] = 'center'; + } else if (/^ *:-+ *$/.test(item.align[i])) { + item.align[i] = 'left'; + } else { + item.align[i] = null; + } } - } - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = item.cells[i].split(/ *\| */); - } + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = splitCells(item.cells[i], item.header.length); + } - this.tokens.push(item); + this.tokens.push(item); - continue; + continue; + } } // hr @@ -372,7 +404,7 @@ Lexer.prototype.token = function(src, top) { if (top && (cap = this.rules.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(); + tag = cap[1].toLowerCase().replace(/\s+/g, ' '); if (!this.tokens.links[tag]) { this.tokens.links[tag] = { href: cap[2], @@ -384,36 +416,38 @@ Lexer.prototype.token = function(src, top) { // table (gfm) if (top && (cap = this.rules.table.exec(src))) { - src = src.substring(cap[0].length); - item = { type: 'table', - header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n') + cells: cap[3] ? cap[3].replace(/(?: *\| *)?\n$/, '').split('\n') : [] }; - for (i = 0; i < item.align.length; i++) { - if (/^ *-+: *$/.test(item.align[i])) { - item.align[i] = 'right'; - } else if (/^ *:-+: *$/.test(item.align[i])) { - item.align[i] = 'center'; - } else if (/^ *:-+ *$/.test(item.align[i])) { - item.align[i] = 'left'; - } else { - item.align[i] = null; + if (item.header.length === item.align.length) { + src = src.substring(cap[0].length); + + for (i = 0; i < item.align.length; i++) { + if (/^ *-+: *$/.test(item.align[i])) { + item.align[i] = 'right'; + } else if (/^ *:-+: *$/.test(item.align[i])) { + item.align[i] = 'center'; + } else if (/^ *:-+ *$/.test(item.align[i])) { + item.align[i] = 'left'; + } else { + item.align[i] = null; + } } - } - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = item.cells[i] - .replace(/^ *\| *| *\| *$/g, '') - .split(/ *\| */); - } + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = splitCells( + item.cells[i].replace(/^ *\| *| *\| *$/g, ''), + item.header.length); + } - this.tokens.push(item); + this.tokens.push(item); - continue; + continue; + } } // lheading @@ -463,39 +497,54 @@ Lexer.prototype.token = function(src, top) { */ var inline = { - escape: /^\\([\\`*{}\[\]()#+\-.!_>])/, + escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, url: noop, - tag: /^|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/\s]*)*?\/?>/, - link: /^!?\[(inside)\]\(href\)/, - reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, - nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/, - strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, - em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/, + tag: '^comment' + + '|^' // self-closing tag + + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag + + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. + + '|^' // declaration, e.g. + + '|^', // CDATA section + link: /^!?\[(label)\]\(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\S]*?[^\s])_(?!_)|^\*([^\s][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*][\s\S]*?[^\s])\*(?!\*)|^_([^\s_])_(?!_)|^\*([^\s*])\*(?!\*)/, code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: noop, text: /^[\s\S]+?(?=[\\?@\[\]\\^_`{|}~])/g; + inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/; inline._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])?)+(?![-_])/; - inline.autolink = edit(inline.autolink) .replace('scheme', inline._scheme) .replace('email', inline._email) - .getRegex() + .getRegex(); + +inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/; + +inline.tag = edit(inline.tag) + .replace('comment', block._comment) + .replace('attribute', inline._attribute) + .getRegex(); -inline._inside = /(?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/; -inline._href = /\s*?(?:\s+['"]([\s\S]*?)['"])?\s*/; +inline._label = /(?:\[[^\[\]]*\]|\\[\[\]]?|`[^`]*`|[^\[\]\\])*?/; +inline._href = /\s*(<(?:\\[<>]?|[^\s<>\\])*>|(?:\\[()]?|\([^\s\x00-\x1f()\\]*\)|[^\s\x00-\x1f()\\])*?)/; +inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; inline.link = edit(inline.link) - .replace('inside', inline._inside) + .replace('label', inline._label) .replace('href', inline._href) + .replace('title', inline._title) .getRegex(); inline.reflink = edit(inline.reflink) - .replace('inside', inline._inside) + .replace('label', inline._label) .getRegex(); /** @@ -510,7 +559,13 @@ inline.normal = merge({}, inline); inline.pedantic = merge({}, inline.normal, { strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, - em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/ + em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/, + link: edit(/^!?\[(label)\]\((.*?)\)/) + .replace('label', inline._label) + .getRegex(), + reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/) + .replace('label', inline._label) + .getRegex() }); /** @@ -554,14 +609,14 @@ function InlineLexer(links, options) { throw new Error('Tokens array requires a `links` property.'); } - if (this.options.gfm) { + if (this.options.pedantic) { + this.rules = inline.pedantic; + } else if (this.options.gfm) { if (this.options.breaks) { this.rules = inline.breaks; } else { this.rules = inline.gfm; } - } else if (this.options.pedantic) { - this.rules = inline.pedantic; } } @@ -575,7 +630,7 @@ InlineLexer.rules = inline; * Static Lexing/Compiling Method */ -InlineLexer.output = function(src, links, options) { +InlineLexer.output = function (src, links, options) { var inline = new InlineLexer(links, options); return inline.output(src); }; @@ -584,12 +639,13 @@ InlineLexer.output = function(src, links, options) { * Lexing/Compiling */ -InlineLexer.prototype.output = function(src) { +InlineLexer.prototype.output = function (src) { var out = '', - link, - text, - href, - cap; + link, + text, + href, + title, + cap; while (src) { // escape @@ -652,9 +708,23 @@ InlineLexer.prototype.output = function(src) { if (cap = this.rules.link.exec(src)) { 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: cap[2], - title: cap[3] + href: InlineLexer.escapes(href), + title: InlineLexer.escapes(title) }); this.inLink = false; continue; @@ -662,7 +732,7 @@ InlineLexer.prototype.output = function(src) { // reflink, nolink if ((cap = this.rules.reflink.exec(src)) - || (cap = this.rules.nolink.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()]; @@ -680,14 +750,14 @@ InlineLexer.prototype.output = function(src) { // strong if (cap = this.rules.strong.exec(src)) { src = src.substring(cap[0].length); - out += this.renderer.strong(this.output(cap[2] || cap[1])); + 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[2] || cap[1])); + out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1])); continue; } @@ -727,13 +797,17 @@ InlineLexer.prototype.output = function(src) { return out; }; +InlineLexer.escapes = function (text) { + return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; +} + /** * Compile Link */ -InlineLexer.prototype.outputLink = function(cap, link) { - var href = escape(link.href), - title = link.title ? escape(link.title) : null; +InlineLexer.prototype.outputLink = function (cap, link) { + var href = link.href, + title = link.title ? escape(link.title) : null; return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) @@ -744,7 +818,7 @@ InlineLexer.prototype.outputLink = function(cap, link) { * Smartypants Transformations */ -InlineLexer.prototype.smartypants = function(text) { +InlineLexer.prototype.smartypants = function (text) { if (!this.options.smartypants) return text; return text // em-dashes @@ -767,12 +841,12 @@ InlineLexer.prototype.smartypants = function(text) { * Mangle Links */ -InlineLexer.prototype.mangle = function(text) { +InlineLexer.prototype.mangle = function (text) { if (!this.options.mangle) return text; var out = '', - l = text.length, - i = 0, - ch; + l = text.length, + i = 0, + ch; for (; i < l; i++) { ch = text.charCodeAt(i); @@ -790,10 +864,10 @@ InlineLexer.prototype.mangle = function(text) { */ function Renderer(options) { - this.options = options || {}; + this.options = options || marked.defaults; } -Renderer.prototype.code = function(code, lang, escaped) { +Renderer.prototype.code = function (code, lang, escaped) { if (this.options.highlight) { var out = this.options.highlight(code, lang); if (out != null && out !== code) { @@ -816,90 +890,94 @@ Renderer.prototype.code = function(code, lang, escaped) { + '\n\n'; }; -Renderer.prototype.blockquote = function(quote) { +Renderer.prototype.blockquote = function (quote) { return '
\n' + quote + '
\n'; }; -Renderer.prototype.html = function(html) { +Renderer.prototype.html = function (html) { return html; }; -Renderer.prototype.heading = function(text, level, raw) { - return '' - + text - + '\n'; +Renderer.prototype.heading = function (text, level, raw) { + if (this.options.headerIds) { + return '' + + text + + '\n'; + } + // ignore IDs + return '' + text + '\n'; }; -Renderer.prototype.hr = function() { +Renderer.prototype.hr = function () { return this.options.xhtml ? '
\n' : '
\n'; }; -Renderer.prototype.list = function(body, ordered, start) { +Renderer.prototype.list = function (body, ordered, start) { var type = ordered ? 'ol' : 'ul', - startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; + startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; return '<' + type + startatt + '>\n' + body + '\n'; }; -Renderer.prototype.listitem = function(text) { +Renderer.prototype.listitem = function (text) { return '
  • ' + text + '
  • \n'; }; -Renderer.prototype.paragraph = function(text) { +Renderer.prototype.paragraph = function (text) { return '

    ' + text + '

    \n'; }; -Renderer.prototype.table = function(header, body) { +Renderer.prototype.table = function (header, body) { + if (body) body = '' + body + ''; + return '\n' + '\n' + header + '\n' - + '\n' + body - + '\n' + '
    \n'; }; -Renderer.prototype.tablerow = function(content) { +Renderer.prototype.tablerow = function (content) { return '\n' + content + '\n'; }; -Renderer.prototype.tablecell = function(content, flags) { +Renderer.prototype.tablecell = function (content, flags) { var type = flags.header ? 'th' : 'td'; var tag = flags.align - ? '<' + type + ' style="text-align:' + flags.align + '">' + ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; return tag + content + '\n'; }; // span level renderer -Renderer.prototype.strong = function(text) { +Renderer.prototype.strong = function (text) { return '' + text + ''; }; -Renderer.prototype.em = function(text) { +Renderer.prototype.em = function (text) { return '' + text + ''; }; -Renderer.prototype.codespan = function(text) { +Renderer.prototype.codespan = function (text) { return '' + text + ''; }; -Renderer.prototype.br = function() { +Renderer.prototype.br = function () { return this.options.xhtml ? '
    ' : '
    '; }; -Renderer.prototype.del = function(text) { +Renderer.prototype.del = function (text) { return '' + text + ''; }; -Renderer.prototype.link = function(href, title, text) { +Renderer.prototype.link = function (href, title, text) { if (this.options.sanitize) { try { var prot = decodeURIComponent(unescape(href)) @@ -915,7 +993,12 @@ Renderer.prototype.link = function(href, title, text) { if (this.options.baseUrl && !originIndependentUrl.test(href)) { href = resolveUrl(this.options.baseUrl, href); } - var out = ' count) { + cells.splice(count); + } else { + while (cells.length < count) cells.push(''); + } + + for (; i < cells.length; i++) { + cells[i] = cells[i].replace(/\\\|/g, '|'); + } + return cells; +} + /** * Marked */ @@ -1259,9 +1356,9 @@ function marked(src, opt, callback) { opt = merge({}, marked.defaults, opt || {}); var highlight = opt.highlight, - tokens, - pending, - i = 0; + tokens, + pending, + i = 0; try { tokens = Lexer.lex(src, opt) @@ -1271,7 +1368,7 @@ function marked(src, opt, callback) { pending = tokens.length; - var done = function(err) { + var done = function (err) { if (err) { opt.highlight = highlight; return callback(err); @@ -1301,11 +1398,11 @@ function marked(src, opt, callback) { if (!pending) return done(); for (; i < tokens.length; i++) { - (function(token) { + (function (token) { if (token.type !== 'code') { return --pending || done(); } - return highlight(token.text, token.lang, function(err, code) { + return highlight(token.text, token.lang, function (err, code) { if (err) return done(err); if (code == null || code === token.text) { return --pending || done(); @@ -1338,30 +1435,35 @@ function marked(src, opt, callback) { */ marked.options = -marked.setOptions = function(opt) { - merge(marked.defaults, opt); - return marked; -}; + marked.setOptions = function (opt) { + merge(marked.defaults, opt); + return marked; + }; -marked.defaults = { - gfm: true, - tables: true, - breaks: false, - pedantic: false, - sanitize: false, - sanitizer: null, - mangle: true, - smartLists: false, - silent: false, - highlight: null, - langPrefix: 'lang-', - smartypants: false, - headerPrefix: '', - renderer: new Renderer(), - xhtml: false, - baseUrl: null +marked.getDefaults = function () { + return { + baseUrl: null, + breaks: false, + gfm: true, + headerIds: true, + headerPrefix: '', + highlight: null, + langPrefix: 'lang-', + mangle: true, + pedantic: false, + renderer: new Renderer(), + sanitize: false, + sanitizer: null, + silent: false, + smartLists: false, + smartypants: false, + tables: true, + xhtml: false + }; }; +marked.defaults = marked.getDefaults(); + /** * Expose */ @@ -1379,16 +1481,15 @@ marked.InlineLexer = InlineLexer; marked.inlineLexer = InlineLexer.output; marked.parse = marked; - __marked_exports = marked; }).call(this); // ESM-comment-begin define([], function() { - return { - marked: __marked_exports - }; +return { + marked: __marked_exports +}; }); // ESM-comment-end -- GitLab