From ff30ee29b4895ac72c8416ee4b8792020d724d2d Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 5 Nov 2019 15:29:42 -0600 Subject: [PATCH 01/33] move marked to es modules in ./src folder --- src/InlineLexer.js | 300 ++++++++++++++++++++++++++++++++ src/Lexer.js | 409 ++++++++++++++++++++++++++++++++++++++++++++ src/Parser.js | 217 +++++++++++++++++++++++ src/Renderer.js | 169 ++++++++++++++++++ src/Slugger.js | 36 ++++ src/TextRenderer.js | 31 ++++ src/defaults.js | 26 +++ src/helpers.js | 226 ++++++++++++++++++++++++ src/marked.js | 164 ++++++++++++++++++ src/regexp.js | 243 ++++++++++++++++++++++++++ 10 files changed, 1821 insertions(+) create mode 100644 src/InlineLexer.js create mode 100644 src/Lexer.js create mode 100644 src/Parser.js create mode 100644 src/Renderer.js create mode 100644 src/Slugger.js create mode 100644 src/TextRenderer.js create mode 100644 src/defaults.js create mode 100644 src/helpers.js create mode 100644 src/marked.js create mode 100644 src/regexp.js diff --git a/src/InlineLexer.js b/src/InlineLexer.js new file mode 100644 index 0000000000..64e3a5019c --- /dev/null +++ b/src/InlineLexer.js @@ -0,0 +1,300 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +import Renderer from './Renderer.js'; +import { defaults } from './defaults.js'; +import { inline } from './regexp.js'; +import { + findClosingBracket, + escape +} from './helpers.js'; + +/** + * Inline Lexer & Compiler + */ + +export default function InlineLexer(links, options) { + this.options = options || defaults; + this.links = links; + this.rules = inline.normal; + this.renderer = this.options.renderer || new 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.pedantic; + } else if (this.options.gfm) { + if (this.options.breaks) { + this.rules = inline.breaks; + } else { + this.rules = inline.gfm; + } + } +} + +/** + * Expose Inline Rules + */ + +InlineLexer.rules = inline; + +/** + * Static Lexing/Compiling Method + */ + +InlineLexer.output = function(src, links, options) { + const inline = new InlineLexer(links, options); + return inline.output(src); +}; + +/** + * Lexing/Compiling + */ + +InlineLexer.prototype.output = function(src) { + let out = ''; + let link; + let text; + let href; + let title; + let cap; + let prevCapZero; + + while (src) { + // escape + if (cap = this.rules.escape.exec(src)) { + src = src.substring(cap[0].length); + out += escape(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.options.sanitize + ? this.options.sanitizer + ? this.options.sanitizer(cap[0]) + : escape(cap[0]) + : cap[0]; + continue; + } + + // link + if (cap = this.rules.link.exec(src)) { + const lastParenIndex = findClosingBracket(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(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(this.mangle(cap[1])); + href = 'mailto:' + text; + } else { + text = escape(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(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(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(cap[0])) : cap[0]); + } else { + out += this.renderer.text(escape(this.smartypants(cap[0]))); + } + continue; + } + + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return out; +}; + +InlineLexer.escapes = function(text) { + return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; +}; + +/** + * Compile Link + */ + +InlineLexer.prototype.outputLink = function(cap, link) { + const href = link.href, + title = link.title ? escape(link.title) : null; + + return cap[0].charAt(0) !== '!' + ? this.renderer.link(href, title, this.output(cap[1])) + : this.renderer.image(href, title, escape(cap[1])); +}; + +/** + * Smartypants Transformations + */ + +InlineLexer.prototype.smartypants = function(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 + */ + +InlineLexer.prototype.mangle = function(text) { + if (!this.options.mangle) return text; + let out = ''; + const l = text.length; + let ch; + + for (let i = 0; i < l; i++) { + ch = text.charCodeAt(i); + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } + out += '&#' + ch + ';'; + } + + return out; +}; diff --git a/src/Lexer.js b/src/Lexer.js new file mode 100644 index 0000000000..84df76f192 --- /dev/null +++ b/src/Lexer.js @@ -0,0 +1,409 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +import { defaults } from './defaults.js'; +import { block } from './regexp.js'; +import { + rtrim, + splitCells, + escape +} from './helpers.js'; + +/** + * Block Lexer + */ + +export default function Lexer(options) { + this.tokens = []; + this.tokens.links = Object.create(null); + this.options = options || defaults; + this.rules = block.normal; + + if (this.options.pedantic) { + this.rules = block.pedantic; + } else if (this.options.gfm) { + this.rules = block.gfm; + } +} + +/** + * Expose Block Rules + */ + +Lexer.rules = block; + +/** + * Static Lex Method + */ + +Lexer.lex = function(src, options) { + const lexer = new Lexer(options); + return lexer.lex(src); +}; + +/** + * Preprocessing + */ + +Lexer.prototype.lex = function(src) { + src = src + .replace(/\r\n|\r/g, '\n') + .replace(/\t/g, ' '); + + return this.token(src, true); +}; + +/** + * Lexing + */ + +Lexer.prototype.token = function(src, top) { + src = src.replace(/^ +$/gm, ''); + let next, + loose, + cap, + bull, + b, + item, + listStart, + listItems, + t, + space, + i, + tag, + l, + isordered, + istask, + ischecked; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } + + // code + if (cap = this.rules.code.exec(src)) { + const lastToken = this.tokens[this.tokens.length - 1]; + src = src.substring(cap[0].length); + // An indented code block cannot interrupt a paragraph. + if (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); + } else { + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic + ? rtrim(cap, '\n') + : cap + }); + } + continue; + } + + // fences + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' + }); + continue; + } + + // heading + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } + + // table no leading pipe (gfm) + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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] = splitCells(item.cells[i], item.header.length); + } + + this.tokens.push(item); + + continue; + } + } + + // hr + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } + + // blockquote + if (cap = this.rules.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' + }); + + continue; + } + + // list + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; + + this.tokens.push(listStart); + + // Get each top-level item. + cap = cap[0].match(this.rules.item); + + listItems = []; + next = false; + l = cap.length; + i = 0; + + for (; i < l; i++) { + item = cap[i]; + + // Remove the list item's bullet + // so it is seen as the next token. + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); + + // Outdent whatever the + // list item contains. Hacky. + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic + ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') + : item.replace(/^ {1,4}/gm, ''); + } + + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (i !== l - 1) { + b = block.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; + i = l - 1; + } + } + + // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + loose = next || /\n\n(?!\s*$)/.test(item); + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } + + if (loose) { + listStart.loose = true; + } + + // Check for task list items + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); + } + + t = { + type: 'list_item_start', + 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' + }); + } + + 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)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize + ? 'paragraph' + : 'html', + 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(cap[0])) : cap[0] + }); + continue; + } + + // def + 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().replace(/\s+/g, ' '); + if (!this.tokens.links[tag]) { + this.tokens.links[tag] = { + href: cap[2], + title: cap[3] + }; + } + continue; + } + + // table (gfm) + if (cap = this.rules.table.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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] = splitCells( + item.cells[i].replace(/^ *\| *| *\| *$/g, ''), + item.header.length); + } + + this.tokens.push(item); + + continue; + } + } + + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2].charAt(0) === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } + + // top-level paragraph + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + 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)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; + } + + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return this.tokens; +}; diff --git a/src/Parser.js b/src/Parser.js new file mode 100644 index 0000000000..18ef56c724 --- /dev/null +++ b/src/Parser.js @@ -0,0 +1,217 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +import Renderer from './Renderer.js'; +import Slugger from './Slugger.js'; +import InlineLexer from './InlineLexer.js'; +import TextRenderer from './TextRenderer.js'; +import { defaults } from './defaults.js'; +import { + merge, + unescape +} from './helpers.js'; + +/** + * Parsing & Compiling + */ + +export default function Parser(options) { + this.tokens = []; + this.token = null; + this.options = options || defaults; + this.options.renderer = this.options.renderer || new Renderer(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger(); +} + +/** + * Static Parse Method + */ + +Parser.parse = function(src, options) { + const parser = new Parser(options); + return parser.parse(src); +}; + +/** + * Parse Loop + */ + +Parser.prototype.parse = function(src) { + this.inline = new InlineLexer(src.links, this.options); + // use an InlineLexer with a TextRenderer to extract pure text + this.inlineText = new InlineLexer( + src.links, + merge({}, this.options, { renderer: new TextRenderer() }) + ); + this.tokens = src.reverse(); + + let out = ''; + while (this.next()) { + out += this.tok(); + } + + return out; +}; + +/** + * Next Token + */ + +Parser.prototype.next = function() { + this.token = this.tokens.pop(); + return this.token; +}; + +/** + * Preview Next Token + */ + +Parser.prototype.peek = function() { + return this.tokens[this.tokens.length - 1] || 0; +}; + +/** + * Parse Text Tokens + */ + +Parser.prototype.parseText = function() { + let body = this.token.text; + + while (this.peek().type === 'text') { + body += '\n' + this.next().text; + } + + return this.inline.output(body); +}; + +/** + * Parse Current Token + */ + +Parser.prototype.tok = function() { + 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(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 = ''; + let body = ''; + let i; + let row; + let cell; + let 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': { + let body = ''; + + while (this.next().type !== 'blockquote_end') { + body += this.tok(); + } + + return this.renderer.blockquote(body); + } + case 'list_start': { + let body = ''; + const 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': { + let 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) + }); + } + } 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: { + const errMsg = 'Token with "' + this.token.type + '" type was not found.'; + if (this.options.silent) { + console.log(errMsg); + } else { + throw new Error(errMsg); + } + } + } +}; diff --git a/src/Renderer.js b/src/Renderer.js new file mode 100644 index 0000000000..a73fa3e2eb --- /dev/null +++ b/src/Renderer.js @@ -0,0 +1,169 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +import { defaults } from './defaults.js'; +import { + cleanUrl, + escape +} from './helpers.js'; + +/** + * Renderer + */ + +export default function Renderer(options) { + this.options = options || defaults; +} + +Renderer.prototype.code = function(code, infostring, escaped) { + const lang = (infostring || '').match(/\S*/)[0]; + if (this.options.highlight) { + const out = this.options.highlight(code, lang); + if (out != null && out !== code) { + escaped = true; + code = out; + } + } + + if (!lang) { + return '
'
+      + (escaped ? code : escape(code, true))
+      + '
'; + } + + return '
'
+    + (escaped ? code : escape(code, true))
+    + '
\n'; +}; + +Renderer.prototype.blockquote = function(quote) { + return '
\n' + quote + '
\n'; +}; + +Renderer.prototype.html = function(html) { + return html; +}; + +Renderer.prototype.heading = function(text, level, raw, slugger) { + if (this.options.headerIds) { + return '' + + text + + '\n'; + } + // ignore IDs + return '' + text + '\n'; +}; + +Renderer.prototype.hr = function() { + return this.options.xhtml ? '
\n' : '
\n'; +}; + +Renderer.prototype.list = function(body, ordered, start) { + const type = ordered ? 'ol' : 'ul', + startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; + return '<' + type + startatt + '>\n' + body + '\n'; +}; + +Renderer.prototype.listitem = function(text) { + return '
  • ' + text + '
  • \n'; +}; + +Renderer.prototype.checkbox = function(checked) { + return ' '; +}; + +Renderer.prototype.paragraph = function(text) { + return '

    ' + text + '

    \n'; +}; + +Renderer.prototype.table = function(header, body) { + if (body) body = '' + body + ''; + + return '\n' + + '\n' + + header + + '\n' + + body + + '
    \n'; +}; + +Renderer.prototype.tablerow = function(content) { + return '\n' + content + '\n'; +}; + +Renderer.prototype.tablecell = function(content, flags) { + const type = flags.header ? 'th' : 'td'; + const tag = flags.align + ? '<' + type + ' align="' + flags.align + '">' + : '<' + type + '>'; + return tag + content + '\n'; +}; + +// span level renderer +Renderer.prototype.strong = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.em = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.codespan = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.br = function() { + return this.options.xhtml ? '
    ' : '
    '; +}; + +Renderer.prototype.del = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.link = function(href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } + let out = '
    '; + return out; +}; + +Renderer.prototype.image = function(href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } + + let out = '' + text + '' : '>'; + return out; +}; + +Renderer.prototype.text = function(text) { + return text; +}; diff --git a/src/Slugger.js b/src/Slugger.js new file mode 100644 index 0000000000..726e2b492c --- /dev/null +++ b/src/Slugger.js @@ -0,0 +1,36 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +/** + * Slugger generates header id + */ + +export default function Slugger() { + this.seen = {}; +} + +/** + * Convert string to unique id + */ + +Slugger.prototype.slug = function(value) { + let slug = value + .toLowerCase() + .trim() + .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; +}; diff --git a/src/TextRenderer.js b/src/TextRenderer.js new file mode 100644 index 0000000000..ca48bf76ce --- /dev/null +++ b/src/TextRenderer.js @@ -0,0 +1,31 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +/** + * TextRenderer + * returns only the textual part of the token + */ + +export default function TextRenderer() {} + +// no need for block level renderers + +TextRenderer.prototype.strong = +TextRenderer.prototype.em = +TextRenderer.prototype.codespan = +TextRenderer.prototype.del = +TextRenderer.prototype.text = function(text) { + return text; +}; + +TextRenderer.prototype.link = +TextRenderer.prototype.image = function(href, title, text) { + return '' + text; +}; + +TextRenderer.prototype.br = function() { + return ''; +}; diff --git a/src/defaults.js b/src/defaults.js new file mode 100644 index 0000000000..5e1cca053f --- /dev/null +++ b/src/defaults.js @@ -0,0 +1,26 @@ +export let defaults = getDefaults(); + +export function getDefaults() { + return { + baseUrl: null, + breaks: false, + gfm: true, + headerIds: true, + headerPrefix: '', + highlight: null, + langPrefix: 'language-', + mangle: true, + pedantic: false, + renderer: null, + sanitize: false, + sanitizer: null, + silent: false, + smartLists: false, + smartypants: false, + xhtml: false + }; +} + +export function changeDefaults(newDefaults) { + defaults = newDefaults; +} diff --git a/src/helpers.js b/src/helpers.js new file mode 100644 index 0000000000..715899406c --- /dev/null +++ b/src/helpers.js @@ -0,0 +1,226 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +/** + * Helpers + */ + +export function escape(html, encode) { + const escapeTest = /[&<>"']/; + const escapeReplace = /[&<>"']/g; + const replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; + const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; + + if (encode) { + if (escapeTest.test(html)) { + return html.replace(escapeReplace, function(ch) { return replacements[ch]; }); + } + } else { + if (escapeTestNoEncode.test(html)) { + return html.replace(escapeReplaceNoEncode, function(ch) { return replacements[ch]; }); + } + } + + return html; +} + +export function unescape(html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { + n = n.toLowerCase(); + if (n === 'colon') return ':'; + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' + ? String.fromCharCode(parseInt(n.substring(2), 16)) + : String.fromCharCode(+n.substring(1)); + } + return ''; + }); +} + +export function edit(regex, opt) { + regex = regex.source || regex; + opt = opt || ''; + return { + replace: function(name, val) { + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return this; + }, + getRegex: function() { + return new RegExp(regex, opt); + } + }; +} + +export function cleanUrl(sanitize, base, href) { + if (sanitize) { + let prot; + try { + prot = decodeURIComponent(unescape(href)) + .replace(/[^\w:]/g, '') + .toLowerCase(); + } catch (e) { + return null; + } + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { + return null; + } + } + const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; + if (base && !originIndependentUrl.test(href)) { + href = resolveUrl(base, href); + } + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch (e) { + return null; + } + return href; +} + +export function resolveUrl(base, href) { + if (!resolveUrl.baseUrls[' ' + base]) { + // we can ignore everything in base after the last slash of its path component, + // but we might need to add _that_ + // https://tools.ietf.org/html/rfc3986#section-3 + if (/^[^:]+:\/*[^/]*$/.test(base)) { + resolveUrl.baseUrls[' ' + base] = base + '/'; + } else { + resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); + } + } + base = resolveUrl.baseUrls[' ' + base]; + const relativeBase = base.indexOf(':') === -1; + + if (href.slice(0, 2) === '//') { + if (relativeBase) { + return href; + } + return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; + } else if (href.charAt(0) === '/') { + if (relativeBase) { + return href; + } + return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; + } else { + return base + href; + } +} +resolveUrl.baseUrls = {}; + +export function noop() {} +noop.exec = noop; + +export function merge(obj) { + let i = 1; + let target; + let key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } + + return obj; +} + +export function splitCells(tableRow, count) { + // ensure that every cell-delimiting pipe has a space + // before it to distinguish it from an escaped pipe + const row = tableRow.replace(/\|/g, function(match, offset, str) { + let escaped = false; + let curr = offset; + while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }); + const cells = row.split(/ \|/); + let i = 0; + + if (cells.length > count) { + cells.splice(count); + } else { + while (cells.length < count) cells.push(''); + } + + for (; i < cells.length; i++) { + // leading or trailing whitespace is ignored per the gfm spec + cells[i] = cells[i].trim().replace(/\\\|/g, '|'); + } + return cells; +} + +// Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). +// /c*$/ is vulnerable to REDOS. +// invert: Remove suffix of non-c chars instead. Default falsey. +export function rtrim(str, c, invert) { + if (str.length === 0) { + return ''; + } + + // Length of suffix matching the invert condition. + let suffLen = 0; + + // Step left until we fail to match the invert condition. + while (suffLen < str.length) { + const currChar = str.charAt(str.length - suffLen - 1); + if (currChar === c && !invert) { + suffLen++; + } else if (currChar !== c && invert) { + suffLen++; + } else { + break; + } + } + + return str.substr(0, str.length - suffLen); +} + +export function findClosingBracket(str, b) { + if (str.indexOf(b[1]) === -1) { + return -1; + } + let level = 0; + for (let i = 0; i < str.length; i++) { + if (str[i] === '\\') { + i++; + } else if (str[i] === b[0]) { + level++; + } else if (str[i] === b[1]) { + level--; + if (level < 0) { + return i; + } + } + } + return -1; +} + +export function checkSanitizeDeprecation(opt) { + if (opt && opt.sanitize && !opt.silent) { + console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); + } +} diff --git a/src/marked.js b/src/marked.js new file mode 100644 index 0000000000..b97c5577e7 --- /dev/null +++ b/src/marked.js @@ -0,0 +1,164 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +import Lexer from './Lexer.js'; +import Parser from './Parser.js'; +import Renderer from './Renderer.js'; +import TextRenderer from './TextRenderer.js'; +import InlineLexer from './InlineLexer.js'; +import Slugger from './Slugger.js'; +import { + merge, + checkSanitizeDeprecation, + escape +} from './helpers.js'; +import { + getDefaults, + changeDefaults, + defaults +} from './defaults.js'; + +/** + * Marked + */ + +export default function marked(src, opt, callback) { + // throw error in case of non string input + if (typeof src === 'undefined' || src === null) { + throw new Error('marked(): input parameter is undefined or null'); + } + if (typeof src !== 'string') { + throw new Error('marked(): input parameter is of type ' + + Object.prototype.toString.call(src) + ', string expected'); + } + + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } + + opt = merge({}, marked.defaults, opt || {}); + checkSanitizeDeprecation(opt); + + const highlight = opt.highlight; + let tokens; + let pending; + let i = 0; + + try { + tokens = Lexer.lex(src, opt); + } catch (e) { + return callback(e); + } + + pending = tokens.length; + + const done = function(err) { + if (err) { + opt.highlight = highlight; + return callback(err); + } + + let out; + + try { + out = Parser.parse(tokens, opt); + } catch (e) { + err = e; + } + + opt.highlight = highlight; + + return err + ? callback(err) + : callback(null, out); + }; + + if (!highlight || highlight.length < 3) { + return done(); + } + + delete opt.highlight; + + if (!pending) return done(); + + for (; i < tokens.length; i++) { + (function(token) { + if (token.type !== 'code') { + return --pending || done(); + } + return highlight(token.text, token.lang, function(err, code) { + if (err) return done(err); + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } + + return; + } + try { + opt = merge({}, marked.defaults, opt || {}); + checkSanitizeDeprecation(opt); + const t = Lexer.lex(src, opt); + return Parser.parse(t, opt); + } catch (e) { + e.message += '\nPlease report this to https://github.com/markedjs/marked.'; + if ((opt || marked.defaults).silent) { + return '

    An error occurred:

    '
    +        + escape(e.message + '', true)
    +        + '
    '; + } + throw e; + } +} + +/** + * Options + */ + +marked.options = +marked.setOptions = function(opt) { + merge(marked.defaults, opt); + return marked; +}; + +marked.getDefaults = getDefaults; + +Object.defineProperty(marked, 'defaults', { + get() { + return defaults; + }, + + set(value) { + changeDefaults(value); + } +}); + +/** + * Expose + */ + +marked.Parser = Parser; +marked.parser = Parser.parse; + +marked.Renderer = Renderer; +marked.TextRenderer = TextRenderer; + +marked.Lexer = Lexer; +marked.lexer = Lexer.lex; + +marked.InlineLexer = InlineLexer; +marked.inlineLexer = InlineLexer.output; + +marked.Slugger = Slugger; + +marked.parse = marked; diff --git a/src/regexp.js b/src/regexp.js new file mode 100644 index 0000000000..99ba02f65e --- /dev/null +++ b/src/regexp.js @@ -0,0 +1,243 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +import { + noop, + edit, + merge +} from './helpers.js'; + +/** + * Block-Level Grammar + */ + +export const block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, + hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, + heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, + blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, + list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\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)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + + ')', + def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, + nptable: noop, + table: noop, + lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, + // regex template, placeholders will be replaced according to different paragraph + // interruption rules of commonmark and the original markdown spec: + _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, + text: /^[^\n]+/ +}; + +block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; +block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; +block.def = edit(block.def) + .replace('label', block._label) + .replace('title', block._title) + .getRegex(); + +block.bullet = /(?:[*+-]|\d{1,9}\.)/; +block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; +block.item = edit(block.item, 'gm') + .replace(/bull/g, block.bullet) + .getRegex(); + +block.list = edit(block.list) + .replace(/bull/g, block.bullet) + .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))') + .replace('def', '\\n+(?=' + block.def.source + ')') + .getRegex(); + +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', ' {0,3}#{1,6} +') + .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('blockquote', ' {0,3}>') + .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') + .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt + .replace('html', ')|<(?:script|pre|style|!--)') + .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks + .getRegex(); + +block.blockquote = edit(block.blockquote) + .replace('paragraph', block.paragraph) + .getRegex(); + +/** + * Normal Block Grammar + */ + +block.normal = merge({}, block); + +/** + * GFM Block Grammar + */ + +block.gfm = merge({}, block.normal, { + nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ +}); + +/** + * Pedantic grammar (original John Gruber's loose markdown specification) + */ + +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+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, + fences: noop, // fences not supported + paragraph: edit(block.normal._paragraph) + .replace('hr', block.hr) + .replace('heading', ' *#{1,6} *[^\n]') + .replace('lheading', block.lheading) + .replace('blockquote', ' {0,3}>') + .replace('|fences', '') + .replace('|list', '') + .replace('|html', '') + .getRegex() +}); + +/** + * Inline-Level Grammar + */ + +export const inline = { + escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, + autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, + url: noop, + 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)\]\(\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: noop, + text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; +inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); + +inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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(); + +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._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; +inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; +inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; + +inline.link = edit(inline.link) + .replace('label', inline._label) + .replace('href', inline._href) + .replace('title', inline._title) + .getRegex(); + +inline.reflink = edit(inline.reflink) + .replace('label', inline._label) + .getRegex(); + +/** + * Normal Inline Grammar + */ + +inline.normal = merge({}, inline); + +/** + * Pedantic Inline Grammar + */ + +inline.pedantic = merge({}, inline.normal, { + strong: /^__(?=\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() +}); + +/** + * GFM Inline Grammar + */ + +inline.gfm = merge({}, inline.normal, { + escape: edit(inline.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]*?(?:(?=[\\ Date: Tue, 5 Nov 2019 15:30:38 -0600 Subject: [PATCH 02/33] update deps and add rollup and babel --- package-lock.json | 1282 +++++++++++++++++++++++++++++++++++++++++---- package.json | 20 +- rollup.config.js | 11 + 3 files changed, 1212 insertions(+), 101 deletions(-) create mode 100644 rollup.config.js diff --git a/package-lock.json b/package-lock.json index 924d43e9cd..2b7be30342 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,275 @@ "@babel/highlight": "^7.0.0" } }, + "@babel/core": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.7.0.tgz", + "integrity": "sha512-Bb1NjZCaiwTQC/ARL+MwDpgocdnwWDCaugvkGt6cxfBzQa8Whv1JybBoUEiBDKl8Ni3H3c7Fykwk7QChUsHRlg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.5.5", + "@babel/generator": "^7.7.0", + "@babel/helpers": "^7.7.0", + "@babel/parser": "^7.7.0", + "@babel/template": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0", + "convert-source-map": "^1.1.0", + "debug": "^4.1.0", + "json5": "^2.1.0", + "lodash": "^4.17.13", + "resolve": "^1.3.2", + "semver": "^5.4.1", + "source-map": "^0.5.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + } + } + }, + "@babel/generator": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.7.0.tgz", + "integrity": "sha512-1wdJ6UxHyL1XoJQ119JmvuRX27LRih7iYStMPZOWAjQqeAabFg3dYXKMpgihma+to+0ADsTVVt6oRyUxWZw6Mw==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0", + "jsesc": "^2.5.1", + "lodash": "^4.17.13", + "source-map": "^0.5.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true + } + } + }, + "@babel/helper-annotate-as-pure": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.7.0.tgz", + "integrity": "sha512-k50CQxMlYTYo+GGyUGFwpxKVtxVJi9yh61sXZji3zYHccK9RYliZGSTOgci85T+r+0VFN2nWbGM04PIqwfrpMg==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-builder-binary-assignment-operator-visitor": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.7.0.tgz", + "integrity": "sha512-Cd8r8zs4RKDwMG/92lpZcnn5WPQ3LAMQbCw42oqUh4s7vsSN5ANUZjMel0OOnxDLq57hoDDbai+ryygYfCTOsw==", + "dev": true, + "requires": { + "@babel/helper-explode-assignable-expression": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-call-delegate": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-call-delegate/-/helper-call-delegate-7.7.0.tgz", + "integrity": "sha512-Su0Mdq7uSSWGZayGMMQ+z6lnL00mMCnGAbO/R0ZO9odIdB/WNU/VfQKqMQU0fdIsxQYbRjDM4BixIa93SQIpvw==", + "dev": true, + "requires": { + "@babel/helper-hoist-variables": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-create-regexp-features-plugin": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.7.0.tgz", + "integrity": "sha512-ZhagAAVGD3L6MPM9/zZi7RRteonfBFLVUz3kjsnYsMAtr9hOJCKI9BAKIMpqn3NyWicPieoX779UL+7/3BEAOA==", + "dev": true, + "requires": { + "@babel/helper-regex": "^7.4.4", + "regexpu-core": "^4.6.0" + } + }, + "@babel/helper-define-map": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-define-map/-/helper-define-map-7.7.0.tgz", + "integrity": "sha512-kPKWPb0dMpZi+ov1hJiwse9dWweZsz3V9rP4KdytnX1E7z3cTNmFGglwklzFPuqIcHLIY3bgKSs4vkwXXdflQA==", + "dev": true, + "requires": { + "@babel/helper-function-name": "^7.7.0", + "@babel/types": "^7.7.0", + "lodash": "^4.17.13" + } + }, + "@babel/helper-explode-assignable-expression": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.7.0.tgz", + "integrity": "sha512-CDs26w2shdD1urNUAji2RJXyBFCaR+iBEGnFz3l7maizMkQe3saVw9WtjG1tz8CwbjvlFnaSLVhgnu1SWaherg==", + "dev": true, + "requires": { + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-function-name": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.7.0.tgz", + "integrity": "sha512-tDsJgMUAP00Ugv8O2aGEua5I2apkaQO7lBGUq1ocwN3G23JE5Dcq0uh3GvFTChPa4b40AWiAsLvCZOA2rdnQ7Q==", + "dev": true, + "requires": { + "@babel/helper-get-function-arity": "^7.7.0", + "@babel/template": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-get-function-arity": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.7.0.tgz", + "integrity": "sha512-tLdojOTz4vWcEnHWHCuPN5P85JLZWbm5Fx5ZsMEMPhF3Uoe3O7awrbM2nQ04bDOUToH/2tH/ezKEOR8zEYzqyw==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-hoist-variables": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.7.0.tgz", + "integrity": "sha512-LUe/92NqsDAkJjjCEWkNe+/PcpnisvnqdlRe19FahVapa4jndeuJ+FBiTX1rcAKWKcJGE+C3Q3tuEuxkSmCEiQ==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-member-expression-to-functions": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.7.0.tgz", + "integrity": "sha512-QaCZLO2RtBcmvO/ekOLp8p7R5X2JriKRizeDpm5ChATAFWrrYDcDxPuCIBXKyBjY+i1vYSdcUTMIb8psfxHDPA==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-module-imports": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.7.0.tgz", + "integrity": "sha512-Dv3hLKIC1jyfTkClvyEkYP2OlkzNvWs5+Q8WgPbxM5LMeorons7iPP91JM+DU7tRbhqA1ZeooPaMFvQrn23RHw==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-module-transforms": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.7.0.tgz", + "integrity": "sha512-rXEefBuheUYQyX4WjV19tuknrJFwyKw0HgzRwbkyTbB+Dshlq7eqkWbyjzToLrMZk/5wKVKdWFluiAsVkHXvuQ==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.7.0", + "@babel/helper-simple-access": "^7.7.0", + "@babel/helper-split-export-declaration": "^7.7.0", + "@babel/template": "^7.7.0", + "@babel/types": "^7.7.0", + "lodash": "^4.17.13" + } + }, + "@babel/helper-optimise-call-expression": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.7.0.tgz", + "integrity": "sha512-48TeqmbazjNU/65niiiJIJRc5JozB8acui1OS7bSd6PgxfuovWsvjfWSzlgx+gPFdVveNzUdpdIg5l56Pl5jqg==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-plugin-utils": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz", + "integrity": "sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==", + "dev": true + }, + "@babel/helper-regex": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-regex/-/helper-regex-7.5.5.tgz", + "integrity": "sha512-CkCYQLkfkiugbRDO8eZn6lRuR8kzZoGXCg3149iTk5se7g6qykSpy3+hELSwquhu+TgHn8nkLiBwHvNX8Hofcw==", + "dev": true, + "requires": { + "lodash": "^4.17.13" + } + }, + "@babel/helper-remap-async-to-generator": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.7.0.tgz", + "integrity": "sha512-pHx7RN8X0UNHPB/fnuDnRXVZ316ZigkO8y8D835JlZ2SSdFKb6yH9MIYRU4fy/KPe5sPHDFOPvf8QLdbAGGiyw==", + "dev": true, + "requires": { + "@babel/helper-annotate-as-pure": "^7.7.0", + "@babel/helper-wrap-function": "^7.7.0", + "@babel/template": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-replace-supers": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.7.0.tgz", + "integrity": "sha512-5ALYEul5V8xNdxEeWvRsBzLMxQksT7MaStpxjJf9KsnLxpAKBtfw5NeMKZJSYDa0lKdOcy0g+JT/f5mPSulUgg==", + "dev": true, + "requires": { + "@babel/helper-member-expression-to-functions": "^7.7.0", + "@babel/helper-optimise-call-expression": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-simple-access": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.7.0.tgz", + "integrity": "sha512-AJ7IZD7Eem3zZRuj5JtzFAptBw7pMlS3y8Qv09vaBWoFsle0d1kAn5Wq6Q9MyBXITPOKnxwkZKoAm4bopmv26g==", + "dev": true, + "requires": { + "@babel/template": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.7.0.tgz", + "integrity": "sha512-HgYSI8rH08neWlAH3CcdkFg9qX9YsZysZI5GD8LjhQib/mM0jGOZOVkoUiiV2Hu978fRtjtsGsW6w0pKHUWtqA==", + "dev": true, + "requires": { + "@babel/types": "^7.7.0" + } + }, + "@babel/helper-wrap-function": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.7.0.tgz", + "integrity": "sha512-sd4QjeMgQqzshSjecZjOp8uKfUtnpmCyQhKQrVJBBgeHAB/0FPi33h3AbVlVp07qQtMD4QgYSzaMI7VwncNK/w==", + "dev": true, + "requires": { + "@babel/helper-function-name": "^7.7.0", + "@babel/template": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/helpers": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.7.0.tgz", + "integrity": "sha512-VnNwL4YOhbejHb7x/b5F39Zdg5vIQpUUNzJwx0ww1EcVRt41bbGRZWhAURrfY32T5zTT3qwNOQFWpn+P0i0a2g==", + "dev": true, + "requires": { + "@babel/template": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, "@babel/highlight": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz", @@ -24,6 +293,539 @@ "js-tokens": "^4.0.0" } }, + "@babel/parser": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.7.0.tgz", + "integrity": "sha512-GqL+Z0d7B7ADlQBMXlJgvXEbtt5qlqd1YQ5fr12hTSfh7O/vgrEIvJxU2e7aSVrEUn75zTZ6Nd0s8tthrlZnrQ==", + "dev": true + }, + "@babel/plugin-proposal-async-generator-functions": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.7.0.tgz", + "integrity": "sha512-ot/EZVvf3mXtZq0Pd0+tSOfGWMizqmOohXmNZg6LNFjHOV+wOPv7BvVYh8oPR8LhpIP3ye8nNooKL50YRWxpYA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-remap-async-to-generator": "^7.7.0", + "@babel/plugin-syntax-async-generators": "^7.2.0" + } + }, + "@babel/plugin-proposal-dynamic-import": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.7.0.tgz", + "integrity": "sha512-7poL3Xi+QFPC7sGAzEIbXUyYzGJwbc2+gSD0AkiC5k52kH2cqHdqxm5hNFfLW3cRSTcx9bN0Fl7/6zWcLLnKAQ==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-dynamic-import": "^7.2.0" + } + }, + "@babel/plugin-proposal-json-strings": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz", + "integrity": "sha512-MAFV1CA/YVmYwZG0fBQyXhmj0BHCB5egZHCKWIFVv/XCxAeVGIHfos3SwDck4LvCllENIAg7xMKOG5kH0dzyUg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-json-strings": "^7.2.0" + } + }, + "@babel/plugin-proposal-object-rest-spread": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.6.2.tgz", + "integrity": "sha512-LDBXlmADCsMZV1Y9OQwMc0MyGZ8Ta/zlD9N67BfQT8uYwkRswiu2hU6nJKrjrt/58aH/vqfQlR/9yId/7A2gWw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-object-rest-spread": "^7.2.0" + } + }, + "@babel/plugin-proposal-optional-catch-binding": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.2.0.tgz", + "integrity": "sha512-mgYj3jCcxug6KUcX4OBoOJz3CMrwRfQELPQ5560F70YQUBZB7uac9fqaWamKR1iWUzGiK2t0ygzjTScZnVz75g==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-optional-catch-binding": "^7.2.0" + } + }, + "@babel/plugin-proposal-unicode-property-regex": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.7.0.tgz", + "integrity": "sha512-mk34H+hp7kRBWJOOAR0ZMGCydgKMD4iN9TpDRp3IIcbunltxEY89XSimc6WbtSLCDrwcdy/EEw7h5CFCzxTchw==", + "dev": true, + "requires": { + "@babel/helper-create-regexp-features-plugin": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-syntax-async-generators": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.2.0.tgz", + "integrity": "sha512-1ZrIRBv2t0GSlcwVoQ6VgSLpLgiN/FVQUzt9znxo7v2Ov4jJrs8RY8tv0wvDmFN3qIdMKWrmMMW6yZ0G19MfGg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-syntax-dynamic-import": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.2.0.tgz", + "integrity": "sha512-mVxuJ0YroI/h/tbFTPGZR8cv6ai+STMKNBq0f8hFxsxWjl94qqhsb+wXbpNMDPU3cfR1TIsVFzU3nXyZMqyK4w==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-syntax-json-strings": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz", + "integrity": "sha512-5UGYnMSLRE1dqqZwug+1LISpA403HzlSfsg6P9VXU6TBjcSHeNlw4DxDx7LgpF+iKZoOG/+uzqoRHTdcUpiZNg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-syntax-object-rest-spread": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz", + "integrity": "sha512-t0JKGgqk2We+9may3t0xDdmneaXmyxq0xieYcKHxIsrJO64n1OiMWNUtc5gQK1PA0NpdCRrtZp4z+IUaKugrSA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-syntax-optional-catch-binding": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.2.0.tgz", + "integrity": "sha512-bDe4xKNhb0LI7IvZHiA13kff0KEfaGX/Hv4lMA9+7TEc63hMNvfKo6ZFpXhKuEp+II/q35Gc4NoMeDZyaUbj9w==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-syntax-top-level-await": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.7.0.tgz", + "integrity": "sha512-hi8FUNiFIY1fnUI2n1ViB1DR0R4QeK4iHcTlW6aJkrPoTdb8Rf1EMQ6GT3f67DDkYyWgew9DFoOZ6gOoEsdzTA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-arrow-functions": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz", + "integrity": "sha512-ER77Cax1+8/8jCB9fo4Ud161OZzWN5qawi4GusDuRLcDbDG+bIGYY20zb2dfAFdTRGzrfq2xZPvF0R64EHnimg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-async-to-generator": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.7.0.tgz", + "integrity": "sha512-vLI2EFLVvRBL3d8roAMqtVY0Bm9C1QzLkdS57hiKrjUBSqsQYrBsMCeOg/0KK7B0eK9V71J5mWcha9yyoI2tZw==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-remap-async-to-generator": "^7.7.0" + } + }, + "@babel/plugin-transform-block-scoped-functions": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.2.0.tgz", + "integrity": "sha512-ntQPR6q1/NKuphly49+QiQiTN0O63uOwjdD6dhIjSWBI5xlrbUFh720TIpzBhpnrLfv2tNH/BXvLIab1+BAI0w==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-block-scoping": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.6.3.tgz", + "integrity": "sha512-7hvrg75dubcO3ZI2rjYTzUrEuh1E9IyDEhhB6qfcooxhDA33xx2MasuLVgdxzcP6R/lipAC6n9ub9maNW6RKdw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "lodash": "^4.17.13" + } + }, + "@babel/plugin-transform-classes": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-classes/-/plugin-transform-classes-7.7.0.tgz", + "integrity": "sha512-/b3cKIZwGeUesZheU9jNYcwrEA7f/Bo4IdPmvp7oHgvks2majB5BoT5byAql44fiNQYOPzhk2w8DbgfuafkMoA==", + "dev": true, + "requires": { + "@babel/helper-annotate-as-pure": "^7.7.0", + "@babel/helper-define-map": "^7.7.0", + "@babel/helper-function-name": "^7.7.0", + "@babel/helper-optimise-call-expression": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-replace-supers": "^7.7.0", + "@babel/helper-split-export-declaration": "^7.7.0", + "globals": "^11.1.0" + } + }, + "@babel/plugin-transform-computed-properties": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.2.0.tgz", + "integrity": "sha512-kP/drqTxY6Xt3NNpKiMomfgkNn4o7+vKxK2DDKcBG9sHj51vHqMBGy8wbDS/J4lMxnqs153/T3+DmCEAkC5cpA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-destructuring": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.6.0.tgz", + "integrity": "sha512-2bGIS5P1v4+sWTCnKNDZDxbGvEqi0ijeqM/YqHtVGrvG2y0ySgnEEhXErvE9dA0bnIzY9bIzdFK0jFA46ASIIQ==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-dotall-regex": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.7.0.tgz", + "integrity": "sha512-3QQlF7hSBnSuM1hQ0pS3pmAbWLax/uGNCbPBND9y+oJ4Y776jsyujG2k0Sn2Aj2a0QwVOiOFL5QVPA7spjvzSA==", + "dev": true, + "requires": { + "@babel/helper-create-regexp-features-plugin": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-duplicate-keys": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.5.0.tgz", + "integrity": "sha512-igcziksHizyQPlX9gfSjHkE2wmoCH3evvD2qR5w29/Dk0SMKE/eOI7f1HhBdNhR/zxJDqrgpoDTq5YSLH/XMsQ==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-exponentiation-operator": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.2.0.tgz", + "integrity": "sha512-umh4hR6N7mu4Elq9GG8TOu9M0bakvlsREEC+ialrQN6ABS4oDQ69qJv1VtR3uxlKMCQMCvzk7vr17RHKcjx68A==", + "dev": true, + "requires": { + "@babel/helper-builder-binary-assignment-operator-visitor": "^7.1.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-for-of": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.4.4.tgz", + "integrity": "sha512-9T/5Dlr14Z9TIEXLXkt8T1DU7F24cbhwhMNUziN3hB1AXoZcdzPcTiKGRn/6iOymDqtTKWnr/BtRKN9JwbKtdQ==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-function-name": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.7.0.tgz", + "integrity": "sha512-P5HKu0d9+CzZxP5jcrWdpe7ZlFDe24bmqP6a6X8BHEBl/eizAsY8K6LX8LASZL0Jxdjm5eEfzp+FIrxCm/p8bA==", + "dev": true, + "requires": { + "@babel/helper-function-name": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-literals": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-literals/-/plugin-transform-literals-7.2.0.tgz", + "integrity": "sha512-2ThDhm4lI4oV7fVQ6pNNK+sx+c/GM5/SaML0w/r4ZB7sAneD/piDJtwdKlNckXeyGK7wlwg2E2w33C/Hh+VFCg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-member-expression-literals": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-member-expression-literals/-/plugin-transform-member-expression-literals-7.2.0.tgz", + "integrity": "sha512-HiU3zKkSU6scTidmnFJ0bMX8hz5ixC93b4MHMiYebmk2lUVNGOboPsqQvx5LzooihijUoLR/v7Nc1rbBtnc7FA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-modules-amd": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.5.0.tgz", + "integrity": "sha512-n20UsQMKnWrltocZZm24cRURxQnWIvsABPJlw/fvoy9c6AgHZzoelAIzajDHAQrDpuKFFPPcFGd7ChsYuIUMpg==", + "dev": true, + "requires": { + "@babel/helper-module-transforms": "^7.1.0", + "@babel/helper-plugin-utils": "^7.0.0", + "babel-plugin-dynamic-import-node": "^2.3.0" + } + }, + "@babel/plugin-transform-modules-commonjs": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.7.0.tgz", + "integrity": "sha512-KEMyWNNWnjOom8vR/1+d+Ocz/mILZG/eyHHO06OuBQ2aNhxT62fr4y6fGOplRx+CxCSp3IFwesL8WdINfY/3kg==", + "dev": true, + "requires": { + "@babel/helper-module-transforms": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-simple-access": "^7.7.0", + "babel-plugin-dynamic-import-node": "^2.3.0" + } + }, + "@babel/plugin-transform-modules-systemjs": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.7.0.tgz", + "integrity": "sha512-ZAuFgYjJzDNv77AjXRqzQGlQl4HdUM6j296ee4fwKVZfhDR9LAGxfvXjBkb06gNETPnN0sLqRm9Gxg4wZH6dXg==", + "dev": true, + "requires": { + "@babel/helper-hoist-variables": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0", + "babel-plugin-dynamic-import-node": "^2.3.0" + } + }, + "@babel/plugin-transform-modules-umd": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.7.0.tgz", + "integrity": "sha512-u7eBA03zmUswQ9LQ7Qw0/ieC1pcAkbp5OQatbWUzY1PaBccvuJXUkYzoN1g7cqp7dbTu6Dp9bXyalBvD04AANA==", + "dev": true, + "requires": { + "@babel/helper-module-transforms": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-named-capturing-groups-regex": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.7.0.tgz", + "integrity": "sha512-+SicSJoKouPctL+j1pqktRVCgy+xAch1hWWTMy13j0IflnyNjaoskj+DwRQFimHbLqO3sq2oN2CXMvXq3Bgapg==", + "dev": true, + "requires": { + "@babel/helper-create-regexp-features-plugin": "^7.7.0" + } + }, + "@babel/plugin-transform-new-target": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.4.4.tgz", + "integrity": "sha512-r1z3T2DNGQwwe2vPGZMBNjioT2scgWzK9BCnDEh+46z8EEwXBq24uRzd65I7pjtugzPSj921aM15RpESgzsSuA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-object-super": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.5.5.tgz", + "integrity": "sha512-un1zJQAhSosGFBduPgN/YFNvWVpRuHKU7IHBglLoLZsGmruJPOo6pbInneflUdmq7YvSVqhpPs5zdBvLnteltQ==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-replace-supers": "^7.5.5" + } + }, + "@babel/plugin-transform-parameters": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.4.4.tgz", + "integrity": "sha512-oMh5DUO1V63nZcu/ZVLQFqiihBGo4OpxJxR1otF50GMeCLiRx5nUdtokd+u9SuVJrvvuIh9OosRFPP4pIPnwmw==", + "dev": true, + "requires": { + "@babel/helper-call-delegate": "^7.4.4", + "@babel/helper-get-function-arity": "^7.0.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-property-literals": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-property-literals/-/plugin-transform-property-literals-7.2.0.tgz", + "integrity": "sha512-9q7Dbk4RhgcLp8ebduOpCbtjh7C0itoLYHXd9ueASKAG/is5PQtMR5VJGka9NKqGhYEGn5ITahd4h9QeBMylWQ==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-regenerator": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.7.0.tgz", + "integrity": "sha512-AXmvnC+0wuj/cFkkS/HFHIojxH3ffSXE+ttulrqWjZZRaUOonfJc60e1wSNT4rV8tIunvu/R3wCp71/tLAa9xg==", + "dev": true, + "requires": { + "regenerator-transform": "^0.14.0" + } + }, + "@babel/plugin-transform-reserved-words": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-reserved-words/-/plugin-transform-reserved-words-7.2.0.tgz", + "integrity": "sha512-fz43fqW8E1tAB3DKF19/vxbpib1fuyCwSPE418ge5ZxILnBhWyhtPgz8eh1RCGGJlwvksHkyxMxh0eenFi+kFw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-shorthand-properties": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.2.0.tgz", + "integrity": "sha512-QP4eUM83ha9zmYtpbnyjTLAGKQritA5XW/iG9cjtuOI8s1RuL/3V6a3DeSHfKutJQ+ayUfeZJPcnCYEQzaPQqg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-spread": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.6.2.tgz", + "integrity": "sha512-DpSvPFryKdK1x+EDJYCy28nmAaIMdxmhot62jAXF/o99iA33Zj2Lmcp3vDmz+MUh0LNYVPvfj5iC3feb3/+PFg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-sticky-regex": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.2.0.tgz", + "integrity": "sha512-KKYCoGaRAf+ckH8gEL3JHUaFVyNHKe3ASNsZ+AlktgHevvxGigoIttrEJb8iKN03Q7Eazlv1s6cx2B2cQ3Jabw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-regex": "^7.0.0" + } + }, + "@babel/plugin-transform-template-literals": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.4.4.tgz", + "integrity": "sha512-mQrEC4TWkhLN0z8ygIvEL9ZEToPhG5K7KDW3pzGqOfIGZ28Jb0POUkeWcoz8HnHvhFy6dwAT1j8OzqN8s804+g==", + "dev": true, + "requires": { + "@babel/helper-annotate-as-pure": "^7.0.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-typeof-symbol": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.2.0.tgz", + "integrity": "sha512-2LNhETWYxiYysBtrBTqL8+La0jIoQQnIScUJc74OYvUGRmkskNY4EzLCnjHBzdmb38wqtTaixpo1NctEcvMDZw==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/plugin-transform-unicode-regex": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.7.0.tgz", + "integrity": "sha512-RrThb0gdrNwFAqEAAx9OWgtx6ICK69x7i9tCnMdVrxQwSDp/Abu9DXFU5Hh16VP33Rmxh04+NGW28NsIkFvFKA==", + "dev": true, + "requires": { + "@babel/helper-create-regexp-features-plugin": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, + "@babel/preset-env": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.7.1.tgz", + "integrity": "sha512-/93SWhi3PxcVTDpSqC+Dp4YxUu3qZ4m7I76k0w73wYfn7bGVuRIO4QUz95aJksbS+AD1/mT1Ie7rbkT0wSplaA==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.7.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-proposal-async-generator-functions": "^7.7.0", + "@babel/plugin-proposal-dynamic-import": "^7.7.0", + "@babel/plugin-proposal-json-strings": "^7.2.0", + "@babel/plugin-proposal-object-rest-spread": "^7.6.2", + "@babel/plugin-proposal-optional-catch-binding": "^7.2.0", + "@babel/plugin-proposal-unicode-property-regex": "^7.7.0", + "@babel/plugin-syntax-async-generators": "^7.2.0", + "@babel/plugin-syntax-dynamic-import": "^7.2.0", + "@babel/plugin-syntax-json-strings": "^7.2.0", + "@babel/plugin-syntax-object-rest-spread": "^7.2.0", + "@babel/plugin-syntax-optional-catch-binding": "^7.2.0", + "@babel/plugin-syntax-top-level-await": "^7.7.0", + "@babel/plugin-transform-arrow-functions": "^7.2.0", + "@babel/plugin-transform-async-to-generator": "^7.7.0", + "@babel/plugin-transform-block-scoped-functions": "^7.2.0", + "@babel/plugin-transform-block-scoping": "^7.6.3", + "@babel/plugin-transform-classes": "^7.7.0", + "@babel/plugin-transform-computed-properties": "^7.2.0", + "@babel/plugin-transform-destructuring": "^7.6.0", + "@babel/plugin-transform-dotall-regex": "^7.7.0", + "@babel/plugin-transform-duplicate-keys": "^7.5.0", + "@babel/plugin-transform-exponentiation-operator": "^7.2.0", + "@babel/plugin-transform-for-of": "^7.4.4", + "@babel/plugin-transform-function-name": "^7.7.0", + "@babel/plugin-transform-literals": "^7.2.0", + "@babel/plugin-transform-member-expression-literals": "^7.2.0", + "@babel/plugin-transform-modules-amd": "^7.5.0", + "@babel/plugin-transform-modules-commonjs": "^7.7.0", + "@babel/plugin-transform-modules-systemjs": "^7.7.0", + "@babel/plugin-transform-modules-umd": "^7.7.0", + "@babel/plugin-transform-named-capturing-groups-regex": "^7.7.0", + "@babel/plugin-transform-new-target": "^7.4.4", + "@babel/plugin-transform-object-super": "^7.5.5", + "@babel/plugin-transform-parameters": "^7.4.4", + "@babel/plugin-transform-property-literals": "^7.2.0", + "@babel/plugin-transform-regenerator": "^7.7.0", + "@babel/plugin-transform-reserved-words": "^7.2.0", + "@babel/plugin-transform-shorthand-properties": "^7.2.0", + "@babel/plugin-transform-spread": "^7.6.2", + "@babel/plugin-transform-sticky-regex": "^7.2.0", + "@babel/plugin-transform-template-literals": "^7.4.4", + "@babel/plugin-transform-typeof-symbol": "^7.2.0", + "@babel/plugin-transform-unicode-regex": "^7.7.0", + "@babel/types": "^7.7.1", + "browserslist": "^4.6.0", + "core-js-compat": "^3.1.1", + "invariant": "^2.2.2", + "js-levenshtein": "^1.1.3", + "semver": "^5.5.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } + } + }, + "@babel/template": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.7.0.tgz", + "integrity": "sha512-OKcwSYOW1mhWbnTBgQY5lvg1Fxg+VyfQGjcBduZFljfc044J5iDlnDSfhQ867O17XHiSCxYHUxHg2b7ryitbUQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/parser": "^7.7.0", + "@babel/types": "^7.7.0" + } + }, + "@babel/traverse": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.7.0.tgz", + "integrity": "sha512-ea/3wRZc//e/uwCpuBX2itrhI0U9l7+FsrKWyKGNyvWbuMcCG7ATKY2VI4wlg2b2TA39HHwIxnvmXvtiKsyn7w==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.5.5", + "@babel/generator": "^7.7.0", + "@babel/helper-function-name": "^7.7.0", + "@babel/helper-split-export-declaration": "^7.7.0", + "@babel/parser": "^7.7.0", + "@babel/types": "^7.7.0", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.13" + } + }, + "@babel/types": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.7.1.tgz", + "integrity": "sha512-kN/XdANDab9x1z5gcjDc9ePpxexkt+1EQ2MQUiM4XnMvQfvp87/+6kY4Ko2maLXH+tei/DgJ/ybFITeqqRwDiA==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.13", + "to-fast-properties": "^2.0.0" + } + }, "@markedjs/html-differ": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@markedjs/html-differ/-/html-differ-3.0.0.tgz", @@ -45,6 +847,12 @@ "@types/node": "*" } }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/form-data": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-0.0.33.tgz", @@ -79,15 +887,15 @@ "dev": true }, "acorn": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz", - "integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", + "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", "dev": true }, "acorn-jsx": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.2.tgz", - "integrity": "sha512-tiNTrP1MP0QrChmD2DdupCr6HWSFeKVw5d/dHTu4Y7rkAkRhU/Dt7dphAfIUyxtHpl/eBVip5uTNSpQJHylpAw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.1.0.tgz", + "integrity": "sha512-tMUqwBWfLFbJbizRmEcWSLw6HnFzfdJs2sOJEOwwtVPMoH/0Ay+E703oZz78VSXZiiDcZrQ5XKjPIUQixhmgVw==", "dev": true }, "ajv": { @@ -103,15 +911,18 @@ } }, "ansi-escapes": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", - "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", - "dev": true + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.2.1.tgz", + "integrity": "sha512-Cg3ymMAdN10wOk/VYfLV7KCQyv7EDirJ64500sU7n9UlmioEtDuU5Gd+hj73hXSU/ex7tHJSssmyftDdkMLO8Q==", + "dev": true, + "requires": { + "type-fest": "^0.5.2" + } }, "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, "ansi-styles": { @@ -160,6 +971,15 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", "dev": true }, + "babel-plugin-dynamic-import-node": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz", + "integrity": "sha512-o6qFkpeQEBxcqt0XYlWzAVxNCSCZdUgcR8IRlhD/8DylxjjO4foPcvTW0GGKa/cVt3rvxZ7o5ippJ+/0nvLhlQ==", + "dev": true, + "requires": { + "object.assign": "^4.1.0" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -182,12 +1002,29 @@ "concat-map": "0.0.1" } }, + "browserslist": { + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.7.2.tgz", + "integrity": "sha512-uZavT/gZXJd2UTi9Ov7/Z340WOSQ3+m1iBVRUknf+okKxonL9P83S3ctiBDtuRmRu8PiCHjqyueqQ9HYlJhxiw==", + "dev": true, + "requires": { + "caniuse-lite": "^1.0.30001004", + "electron-to-chromium": "^1.3.295", + "node-releases": "^1.1.38" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true }, + "caniuse-lite": { + "version": "1.0.30001008", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001008.tgz", + "integrity": "sha512-b8DJyb+VVXZGRgJUa30cbk8gKHZ3LOZTBLaUEEVr2P4xpmFigOCc62CO4uzquW641Ouq1Rm9N+rWLWdSYDaDIw==", + "dev": true + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -237,12 +1074,12 @@ } }, "cli-cursor": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", - "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", "dev": true, "requires": { - "restore-cursor": "^2.0.0" + "restore-cursor": "^3.1.0" } }, "cli-width": { @@ -287,9 +1124,9 @@ } }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, "commonmark": { @@ -359,6 +1196,25 @@ "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", "dev": true }, + "convert-source-map": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", + "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.1" + } + }, + "core-js-compat": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.3.6.tgz", + "integrity": "sha512-YnwZG/+0/f7Pf6Lr3jxtVAFjtGBW9lsLYcqrxhYJai1GfvrP8DEyEpnNzj/FRQfIkOOfk1j5tTBvPBLWVVJm4A==", + "dev": true, + "requires": { + "browserslist": "^4.7.2", + "semver": "^6.3.0" + } + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -484,10 +1340,16 @@ "domelementtype": "1" } }, + "electron-to-chromium": { + "version": "1.3.303", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.303.tgz", + "integrity": "sha512-xDFPmMjJ0gQBsVwspB0bjcbFn3MVcvU0sxXYmh1UMbZ6rDogQVM3vSyOvTO4rym1KlnJIU6nqzK3qs0yKudmjw==", + "dev": true + }, "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, "entities": { @@ -537,9 +1399,9 @@ "dev": true }, "eslint": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.4.0.tgz", - "integrity": "sha512-WTVEzK3lSFoXUovDHEbkJqCVPEPwbhCq4trDktNI6ygs7aO41d4cDT0JFAT5MivzZeVLWlg7vHL+bgrQv/t3vA==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.6.0.tgz", + "integrity": "sha512-PpEBq7b6qY/qrOmpYQ/jTMDYfuQMELR4g4WI1M/NaSDDD/bdcMb+dj4Hgks7p41kW2caXsPsEZAEAyAgjVVC0g==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -549,9 +1411,9 @@ "debug": "^4.0.1", "doctrine": "^3.0.0", "eslint-scope": "^5.0.0", - "eslint-utils": "^1.4.2", + "eslint-utils": "^1.4.3", "eslint-visitor-keys": "^1.1.0", - "espree": "^6.1.1", + "espree": "^6.1.2", "esquery": "^1.0.1", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", @@ -561,7 +1423,7 @@ "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", - "inquirer": "^6.4.1", + "inquirer": "^7.0.0", "is-glob": "^4.0.0", "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", @@ -579,6 +1441,17 @@ "table": "^5.2.3", "text-table": "^0.2.0", "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "eslint-utils": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.3.tgz", + "integrity": "sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + } } }, "eslint-config-standard": { @@ -775,13 +1648,13 @@ "dev": true }, "espree": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.1.tgz", - "integrity": "sha512-EYbr8XZUhWbYCqQRW0duU5LxzL5bETN6AjKBGy1302qqzPaCH10QbRg3Wvco79Z8x9WbiE8HYB4e75xl6qUYvQ==", + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.2.tgz", + "integrity": "sha512-2iUPuuPP+yW1PZaMSDM9eyVf8D5P0Hi8h83YtZ5bPc/zHYjII5khoixIUTMO794NOY8F/ThF1Bo8ncZILarUTA==", "dev": true, "requires": { - "acorn": "^7.0.0", - "acorn-jsx": "^5.0.2", + "acorn": "^7.1.0", + "acorn-jsx": "^5.1.0", "eslint-visitor-keys": "^1.1.0" } }, @@ -815,6 +1688,12 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -851,9 +1730,9 @@ "dev": true }, "figures": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", - "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.1.0.tgz", + "integrity": "sha512-ravh8VRXqHuMvZt/d8GblBeqDMkdJMBdv/2KntFH+ra5MXkO7nxNKpzQ3n6QD/2da1kH0aWmNISdvhM7gl2gVg==", "dev": true, "requires": { "escape-string-regexp": "^1.0.5" @@ -953,9 +1832,9 @@ } }, "glob-parent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.0.0.tgz", - "integrity": "sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.0.tgz", + "integrity": "sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw==", "dev": true, "requires": { "is-glob": "^4.0.1" @@ -1088,24 +1967,41 @@ "dev": true }, "inquirer": { - "version": "6.5.2", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.5.2.tgz", - "integrity": "sha512-cntlB5ghuB0iuO65Ovoi8ogLHiWGs/5yNrtUcKjFhSSiVeAIVpD7koaSU9RM8mpXw5YDi9RdYXGQMaOURB7ycQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.0.0.tgz", + "integrity": "sha512-rSdC7zelHdRQFkWnhsMu2+2SO41mpv2oF2zy4tMhmiLWkcKbOAs87fWAJhVXttKVwhdZvymvnuM95EyEXg2/tQ==", "dev": true, "requires": { - "ansi-escapes": "^3.2.0", + "ansi-escapes": "^4.2.1", "chalk": "^2.4.2", - "cli-cursor": "^2.1.0", + "cli-cursor": "^3.1.0", "cli-width": "^2.0.0", "external-editor": "^3.0.3", - "figures": "^2.0.0", - "lodash": "^4.17.12", - "mute-stream": "0.0.7", + "figures": "^3.0.0", + "lodash": "^4.17.15", + "mute-stream": "0.0.8", "run-async": "^2.2.0", "rxjs": "^6.4.0", - "string-width": "^2.1.0", + "string-width": "^4.1.0", "strip-ansi": "^5.1.0", "through": "^2.3.6" + }, + "dependencies": { + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + } + } + }, + "invariant": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", + "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", + "dev": true, + "requires": { + "loose-envify": "^1.0.0" } }, "is-arrayish": { @@ -1133,9 +2029,9 @@ "dev": true }, "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, "is-glob": { @@ -1199,6 +2095,12 @@ "integrity": "sha512-nCeAiw37MIMA9w9IXso7bRaLl+c/ef3wnxsoSAlYrzS+Ot0zTG6nU8G/cIfGkqpkjX2wNaIW9RFG0TwIFnG6bA==", "dev": true }, + "js-levenshtein": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", + "integrity": "sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==", + "dev": true + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1215,6 +2117,12 @@ "esprima": "^4.0.0" } }, + "jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "dev": true + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -1227,6 +2135,15 @@ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, + "json5": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.1.tgz", + "integrity": "sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -1274,6 +2191,15 @@ "integrity": "sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==", "dev": true }, + "loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dev": true, + "requires": { + "js-tokens": "^3.0.0 || ^4.0.0" + } + }, "lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -1335,9 +2261,9 @@ } }, "mimic-fn": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", - "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, "minimatch": { @@ -1379,9 +2305,9 @@ "dev": true }, "mute-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", - "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, "natural-compare": { @@ -1402,6 +2328,15 @@ "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==", "dev": true }, + "node-releases": { + "version": "1.1.39", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.39.tgz", + "integrity": "sha512-8MRC/ErwNCHOlAFycy9OPca46fQYUjbJRDcZTHVWIGXIjYLM73k70vv3WkYutVnM4cCo4hE0MqBVVZjP6vjISA==", + "dev": true, + "requires": { + "semver": "^6.3.0" + } + }, "nopt": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/nopt/-/nopt-2.1.2.tgz", @@ -1446,6 +2381,18 @@ "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, "object.values": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.0.tgz", @@ -1468,12 +2415,12 @@ } }, "onetime": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", - "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz", + "integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==", "dev": true, "requires": { - "mimic-fn": "^1.0.0" + "mimic-fn": "^2.1.0" } }, "optionator": { @@ -1613,6 +2560,12 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "private": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", + "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==", + "dev": true + }, "process-nextick-args": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", @@ -1684,12 +2637,73 @@ "util-deprecate": "^1.0.1" } }, + "regenerate": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", + "integrity": "sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==", + "dev": true + }, + "regenerate-unicode-properties": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz", + "integrity": "sha512-LGZzkgtLY79GeXLm8Dp0BVLdQlWICzBnJz/ipWUgo59qBaZ+BHtq51P2q1uVZlppMuUAT37SDk39qUbjTWB7bA==", + "dev": true, + "requires": { + "regenerate": "^1.4.0" + } + }, + "regenerator-transform": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.14.1.tgz", + "integrity": "sha512-flVuee02C3FKRISbxhXl9mGzdbWUVHubl1SMaknjxkFB1/iqpJhArQUvRxOOPEc/9tAiX0BaQ28FJH10E4isSQ==", + "dev": true, + "requires": { + "private": "^0.1.6" + } + }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, + "regexpu-core": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.6.0.tgz", + "integrity": "sha512-YlVaefl8P5BnFYOITTNzDvan1ulLOiXJzCNZxduTIosN17b87h3bvG9yHMoHaRuo88H4mQ06Aodj5VtYGGGiTg==", + "dev": true, + "requires": { + "regenerate": "^1.4.0", + "regenerate-unicode-properties": "^8.1.0", + "regjsgen": "^0.5.0", + "regjsparser": "^0.6.0", + "unicode-match-property-ecmascript": "^1.0.4", + "unicode-match-property-value-ecmascript": "^1.1.0" + } + }, + "regjsgen": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.5.1.tgz", + "integrity": "sha512-5qxzGZjDs9w4tzT3TPhCJqWdCc3RLYwy9J2NB0nm5Lz+S273lvWcpjaTGHsT1dc6Hhfq41uSEOw8wBmxrKOuyg==", + "dev": true + }, + "regjsparser": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.6.0.tgz", + "integrity": "sha512-RQ7YyokLiQBomUJuUG8iGVvkgOLxwyZM8k6d3q5SAXpg4r5TZJZigKFvC6PpD+qQ98bCDC5YelPeA3EucDoNeQ==", + "dev": true, + "requires": { + "jsesc": "~0.5.0" + }, + "dependencies": { + "jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", + "dev": true + } + } + }, "requireindex": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.1.0.tgz", @@ -1712,12 +2726,12 @@ "dev": true }, "restore-cursor": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", - "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", "dev": true, "requires": { - "onetime": "^2.0.0", + "onetime": "^5.1.0", "signal-exit": "^3.0.2" } }, @@ -1730,6 +2744,44 @@ "glob": "^7.1.3" } }, + "rollup": { + "version": "1.26.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.26.3.tgz", + "integrity": "sha512-8MhY/M8gnv3Q/pQQSWYWzbeJ5J1C5anCNY5BK1kV8Yzw9RFS0FF4lbLt+uyPO3wLKWXSXrhAL5pWL85TZAh+Sw==", + "dev": true, + "requires": { + "@types/estree": "*", + "@types/node": "*", + "acorn": "^7.1.0" + }, + "dependencies": { + "acorn": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", + "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", + "dev": true + } + } + }, + "rollup-plugin-babel": { + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.3.3.tgz", + "integrity": "sha512-tKzWOCmIJD/6aKNz0H1GMM+lW1q9KyFubbWzGiOG540zxPPifnEAHTZwjo0g991Y+DyOZcLqBgqOdqazYE5fkw==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.0.0", + "rollup-pluginutils": "^2.8.1" + } + }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + } + }, "run-async": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", @@ -1796,6 +2848,14 @@ "ansi-styles": "^3.2.0", "astral-regex": "^1.0.0", "is-fullwidth-code-point": "^2.0.0" + }, + "dependencies": { + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + } } }, "source-map": { @@ -1843,24 +2903,14 @@ "dev": true }, "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.1.0.tgz", + "integrity": "sha512-NrX+1dVVh+6Y9dnQ19pR0pP4FiEIlUvdTGn8pw6CKTNq5sgib2nIhmUNT5TAmhWmvKr3WcxBcP3E8nWezuipuQ==", "dev": true, "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - }, - "dependencies": { - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "dev": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^5.2.0" } }, "string.prototype.repeat": { @@ -1885,14 +2935,6 @@ "dev": true, "requires": { "ansi-regex": "^4.1.0" - }, - "dependencies": { - "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", - "dev": true - } } }, "strip-bom": { @@ -1948,6 +2990,18 @@ "string-width": "^3.0.0" }, "dependencies": { + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, "string-width": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", @@ -2009,6 +3063,12 @@ "os-tmpdir": "~1.0.2" } }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true + }, "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", @@ -2024,6 +3084,12 @@ "prelude-ls": "~1.1.2" } }, + "type-fest": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz", + "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==", + "dev": true + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", @@ -2037,15 +3103,43 @@ "dev": true }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.7", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.7.tgz", + "integrity": "sha512-4sXQDzmdnoXiO+xvmTzQsfIiwrjUCSA95rSP4SEd8tDb51W2TiDOlL76Hl+Kw0Ie42PSItCW8/t6pBNCF2R48A==", "dev": true, "requires": { - "commander": "~2.20.0", + "commander": "~2.20.3", "source-map": "~0.6.1" } }, + "unicode-canonical-property-names-ecmascript": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", + "integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==", + "dev": true + }, + "unicode-match-property-ecmascript": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz", + "integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==", + "dev": true, + "requires": { + "unicode-canonical-property-names-ecmascript": "^1.0.4", + "unicode-property-aliases-ecmascript": "^1.0.4" + } + }, + "unicode-match-property-value-ecmascript": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.1.0.tgz", + "integrity": "sha512-hDTHvaBk3RmFzvSl0UVrUmC3PuW9wKVnpoUDYH0JDkSIovzw+J5viQmeYHxVSBptubnr7PbH2e0fnpDRQnQl5g==", + "dev": true + }, + "unicode-property-aliases-ecmascript": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.5.tgz", + "integrity": "sha512-L5RAqCfXqAwR3RriF8pM0lU0w4Ryf/GgzONwi6KnL1taJQa7x1TCxdJnILX59WIGOwR57IVxn7Nej0fz1Ny6fw==", + "dev": true + }, "uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", diff --git a/package.json b/package.json index ffa8085b89..443d285ed6 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "author": "Christopher Jeffrey", "version": "0.7.0", "main": "./lib/marked.js", + "module": "./src/marked.js", "bin": "./bin/marked", "man": "./man/marked.1", "files": [ @@ -29,10 +30,12 @@ "html" ], "devDependencies": { + "@babel/core": "^7.7.0", + "@babel/preset-env": "^7.7.1", "@markedjs/html-differ": "^3.0.0", "cheerio": "^1.0.0-rc.3", "commonmark": "0.29.x", - "eslint": "^6.4.0", + "eslint": "^6.6.0", "eslint-config-standard": "^14.1.0", "eslint-plugin-import": "^2.18.2", "eslint-plugin-node": "^10.0.0", @@ -44,21 +47,24 @@ "markdown": "0.5.x", "markdown-it": "10.x", "node-fetch": "^2.6.0", - "uglify-js": "^3.6.0" + "rollup": "^1.26.3", + "rollup-plugin-babel": "^4.3.3", + "uglify-js": "^3.6.7" }, "scripts": { - "test": "jasmine --config=jasmine.json", - "test:all": "npm test && npm run test:node4 && npm run test:lint", + "test": "npm run build && jasmine --config=jasmine.json", + "test:all": "npm test && npm run test:lint", "test:unit": "npm test -- test/unit/**/*-spec.js", "test:specs": "npm test -- test/specs/**/*-spec.js", "test:lint": "eslint bin/marked .", "test:redos": "eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' lib/marked.js", - "test:node4": "npx node@4 ./node_modules/jasmine/bin/jasmine.js --config=jasmine.json", "test:update": "node test/update-specs.js", "bench": "node test/bench.js", "lint": "eslint --fix bin/marked .", - "build": "uglifyjs lib/marked.js -cm --comments /Copyright/ -o marked.min.js", - "preversion": "npm run build && (git diff --quiet || git commit -am 'minify')" + "build": "npm run rollup && npm run minify", + "rollup": "rollup -c rollup.config.js", + "minify": "uglifyjs lib/marked.js -cm --comments /Copyright/ -o marked.min.js", + "preversion": "npm run build && (git diff --quiet || git commit -am 'build')" }, "engines": { "node": ">=0.10.0" diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000000..2cbe749fe3 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,11 @@ +module.exports = { + input: 'src/marked.js', + output: { + file: 'lib/marked.js', + format: 'umd', + name: 'marked' + }, + plugins: [require('rollup-plugin-babel')({ + presets: ['@babel/preset-env'] + })] +}; From 2d4f668320003a3fa3a2d1b1c2a3316ff7abcf20 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 5 Nov 2019 15:31:11 -0600 Subject: [PATCH 03/33] fix eslint config --- .eslintignore | 1 + .eslintrc.json | 13 +++++-------- bin/.eslintrc.json | 33 +++++++++++++++++++++++++++++++++ docs/.eslintrc.json | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 bin/.eslintrc.json create mode 100644 docs/.eslintrc.json diff --git a/.eslintignore b/.eslintignore index 121531af84..f09ec93e09 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ +lib *.min.js diff --git a/.eslintrc.json b/.eslintrc.json index 4285bbc7d8..7915ab9bd9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,10 +3,6 @@ "plugins": [ "standard" ], - "parserOptions": { - "ecmaVersion": 5, - "sourceType": "script" - }, "rules": { "semi": ["error", "always"], "indent": ["error", 2, { @@ -20,11 +16,12 @@ "no-useless-escape": "off", "one-var": "off", "no-control-regex": "off", - "no-prototype-builtins": "off" + "no-prototype-builtins": "off", + + "prefer-const": "error", + "no-var": "error" }, "env": { - "node": true, - "browser": true, - "amd": true + "node": true } } diff --git a/bin/.eslintrc.json b/bin/.eslintrc.json new file mode 100644 index 0000000000..6ee10878c6 --- /dev/null +++ b/bin/.eslintrc.json @@ -0,0 +1,33 @@ +{ + "extends": "standard", + "plugins": [ + "standard" + ], + "parserOptions": { + "ecmaVersion": 5, + "sourceType": "script" + }, + "rules": { + "semi": ["error", "always"], + "indent": ["error", 2, { + "SwitchCase": 1, + "VariableDeclarator": { "var": 2 }, + "outerIIFEBody": 0 + }], + "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], + "space-before-function-paren": ["error", "never"], + "no-cond-assign": "off", + "no-useless-escape": "off", + "one-var": "off", + "no-control-regex": "off", + "no-prototype-builtins": "off", + + "prefer-const": "off", + "no-var": "off" + }, + "env": { + "node": true, + "browser": true, + "amd": true + } +} diff --git a/docs/.eslintrc.json b/docs/.eslintrc.json new file mode 100644 index 0000000000..6ee10878c6 --- /dev/null +++ b/docs/.eslintrc.json @@ -0,0 +1,33 @@ +{ + "extends": "standard", + "plugins": [ + "standard" + ], + "parserOptions": { + "ecmaVersion": 5, + "sourceType": "script" + }, + "rules": { + "semi": ["error", "always"], + "indent": ["error", 2, { + "SwitchCase": 1, + "VariableDeclarator": { "var": 2 }, + "outerIIFEBody": 0 + }], + "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], + "space-before-function-paren": ["error", "never"], + "no-cond-assign": "off", + "no-useless-escape": "off", + "one-var": "off", + "no-control-regex": "off", + "no-prototype-builtins": "off", + + "prefer-const": "off", + "no-var": "off" + }, + "env": { + "node": true, + "browser": true, + "amd": true + } +} From f75bb8fa8325ab214c68a45a268368f35a566c59 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 5 Nov 2019 15:31:51 -0600 Subject: [PATCH 04/33] run build --- lib/marked.js | 3002 ++++++++++++++++++++++++------------------------- marked.min.js | 52 +- 2 files changed, 1516 insertions(+), 1538 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 773341f48a..ae9ee3ead0 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1,25 +1,304 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - -;(function(root) { -'use strict'; - -/** - * Block-Level Grammar - */ - -var block = { - newline: /^\n+/, - code: /^( {4}[^\n]+\n*)+/, - fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, - hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, - heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, - blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, - list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, - html: '^ {0,3}(?:' // optional indentation +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.marked = factory()); +}(this, (function () { 'use strict'; + + function _typeof(obj) { + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); + } + + var defaults = getDefaults(); + function getDefaults() { + return { + baseUrl: null, + breaks: false, + gfm: true, + headerIds: true, + headerPrefix: '', + highlight: null, + langPrefix: 'language-', + mangle: true, + pedantic: false, + renderer: null, + sanitize: false, + sanitizer: null, + silent: false, + smartLists: false, + smartypants: false, + xhtml: false + }; + } + function changeDefaults(newDefaults) { + defaults = newDefaults; + } + + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + + /** + * Helpers + */ + function escape(html, encode) { + var escapeTest = /[&<>"']/; + var escapeReplace = /[&<>"']/g; + var replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; + var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; + + if (encode) { + if (escapeTest.test(html)) { + return html.replace(escapeReplace, function (ch) { + return replacements[ch]; + }); + } + } else { + if (escapeTestNoEncode.test(html)) { + return html.replace(escapeReplaceNoEncode, function (ch) { + return replacements[ch]; + }); + } + } + + return html; + } + function unescape(html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function (_, n) { + n = n.toLowerCase(); + if (n === 'colon') return ':'; + + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1)); + } + + return ''; + }); + } + function edit(regex, opt) { + regex = regex.source || regex; + opt = opt || ''; + return { + replace: function replace(name, val) { + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return this; + }, + getRegex: function getRegex() { + return new RegExp(regex, opt); + } + }; + } + function cleanUrl(sanitize, base, href) { + if (sanitize) { + var prot; + + try { + prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, '').toLowerCase(); + } catch (e) { + return null; + } + + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { + return null; + } + } + + var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; + + if (base && !originIndependentUrl.test(href)) { + href = resolveUrl(base, href); + } + + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch (e) { + return null; + } + + return href; + } + function resolveUrl(base, href) { + if (!resolveUrl.baseUrls[' ' + base]) { + // we can ignore everything in base after the last slash of its path component, + // but we might need to add _that_ + // https://tools.ietf.org/html/rfc3986#section-3 + if (/^[^:]+:\/*[^/]*$/.test(base)) { + resolveUrl.baseUrls[' ' + base] = base + '/'; + } else { + resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); + } + } + + base = resolveUrl.baseUrls[' ' + base]; + var relativeBase = base.indexOf(':') === -1; + + if (href.slice(0, 2) === '//') { + if (relativeBase) { + return href; + } + + return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; + } else if (href.charAt(0) === '/') { + if (relativeBase) { + return href; + } + + return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; + } else { + return base + href; + } + } + resolveUrl.baseUrls = {}; + function noop() {} + noop.exec = noop; + function merge(obj) { + var i = 1; + var target; + var key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } + + return obj; + } + function splitCells(tableRow, count) { + // ensure that every cell-delimiting pipe has a space + // before it to distinguish it from an escaped pipe + var row = tableRow.replace(/\|/g, function (match, offset, str) { + var escaped = false; + var curr = offset; + + while (--curr >= 0 && str[curr] === '\\') { + escaped = !escaped; + } + + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }); + var cells = row.split(/ \|/); + var i = 0; + + if (cells.length > count) { + cells.splice(count); + } else { + while (cells.length < count) { + cells.push(''); + } + } + + for (; i < cells.length; i++) { + // leading or trailing whitespace is ignored per the gfm spec + cells[i] = cells[i].trim().replace(/\\\|/g, '|'); + } + + return cells; + } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). + // /c*$/ is vulnerable to REDOS. + // invert: Remove suffix of non-c chars instead. Default falsey. + + function rtrim(str, c, invert) { + if (str.length === 0) { + return ''; + } // Length of suffix matching the invert condition. + + + var suffLen = 0; // Step left until we fail to match the invert condition. + + while (suffLen < str.length) { + var currChar = str.charAt(str.length - suffLen - 1); + + if (currChar === c && !invert) { + suffLen++; + } else if (currChar !== c && invert) { + suffLen++; + } else { + break; + } + } + + return str.substr(0, str.length - suffLen); + } + function findClosingBracket(str, b) { + if (str.indexOf(b[1]) === -1) { + return -1; + } + + var level = 0; + + for (var i = 0; i < str.length; i++) { + if (str[i] === '\\') { + i++; + } else if (str[i] === b[0]) { + level++; + } else if (str[i] === b[1]) { + level--; + + if (level < 0) { + return i; + } + } + } + + return -1; + } + function checkSanitizeDeprecation(opt) { + if (opt && opt.sanitize && !opt.silent) { + console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); + } + } + + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + /** + * Block-Level Grammar + */ + + var block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, + hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, + heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, + blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, + list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, + html: '^ {0,3}(?:' // optional indentation + '<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)' // (1) + '|comment[^\\n]*(\\n+|$)' // (2) + '|<\\?[\\s\\S]*?\\?>\\n*' // (3) @@ -29,1694 +308,1351 @@ var block = { + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + ')', - def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, - nptable: noop, - table: noop, - lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, - // regex template, placeholders will be replaced according to different paragraph - // interruption rules of commonmark and the original markdown spec: - _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, - text: /^[^\n]+/ -}; - -block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; -block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; -block.def = edit(block.def) - .replace('label', block._label) - .replace('title', block._title) + def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, + nptable: noop, + table: noop, + lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, + // regex template, placeholders will be replaced according to different paragraph + // interruption rules of commonmark and the original markdown spec: + _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, + text: /^[^\n]+/ + }; + block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; + block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; + block.def = edit(block.def).replace('label', block._label).replace('title', block._title).getRegex(); + block.bullet = /(?:[*+-]|\d{1,9}\.)/; + block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; + block.item = edit(block.item, 'gm').replace(/bull/g, block.bullet).getRegex(); + block.list = edit(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex(); + 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', ' {0,3}#{1,6} +').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt + .replace('html', ')|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks .getRegex(); + block.blockquote = edit(block.blockquote).replace('paragraph', block.paragraph).getRegex(); + /** + * Normal Block Grammar + */ + + block.normal = merge({}, block); + /** + * GFM Block Grammar + */ + + block.gfm = merge({}, block.normal, { + nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ + }); + /** + * Pedantic grammar (original John Gruber's loose markdown specification) + */ + + 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+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, + fences: noop, + // fences not supported + paragraph: edit(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex() + }); + /** + * Inline-Level Grammar + */ + + var inline = { + escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, + autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, + url: noop, + 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)\]\(\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: noop, + text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; + inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); + inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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(); + 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._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; + inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; + inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; + inline.link = edit(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex(); + inline.reflink = edit(inline.reflink).replace('label', inline._label).getRegex(); + /** + * Normal Inline Grammar + */ + + inline.normal = merge({}, inline); + /** + * Pedantic Inline Grammar + */ + + inline.pedantic = merge({}, inline.normal, { + strong: /^__(?=\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() + }); + /** + * GFM Inline Grammar + */ + + inline.gfm = merge({}, inline.normal, { + escape: edit(inline.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]*?(?:(?=[\\)[\s\S]*?-->/; -block.html = edit(block.html, 'i') - .replace('comment', block._comment) - .replace('tag', block._tag) - .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/) - .getRegex(); + Lexer.prototype.lex = function (src) { + src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' '); + return this.token(src, true); + }; + /** + * Lexing + */ -block.paragraph = edit(block._paragraph) - .replace('hr', block.hr) - .replace('heading', ' {0,3}#{1,6} +') - .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs - .replace('blockquote', ' {0,3}>') - .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') - .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt - .replace('html', ')|<(?:script|pre|style|!--)') - .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks - .getRegex(); -block.blockquote = edit(block.blockquote) - .replace('paragraph', block.paragraph) - .getRegex(); + Lexer.prototype.token = function (src, top) { + src = src.replace(/^ +$/gm, ''); + var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked; -/** - * Normal Block Grammar - */ - -block.normal = merge({}, block); - -/** - * GFM Block Grammar - */ - -block.gfm = merge({}, block.normal, { - nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, - table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ -}); - -/** - * Pedantic grammar (original John Gruber's loose markdown specification) - */ - -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+|$)/, - heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, - fences: noop, // fences not supported - paragraph: edit(block.normal._paragraph) - .replace('hr', block.hr) - .replace('heading', ' *#{1,6} *[^\n]') - .replace('lheading', block.lheading) - .replace('blockquote', ' {0,3}>') - .replace('|fences', '') - .replace('|list', '') - .replace('|html', '') - .getRegex() -}); - -/** - * Block Lexer - */ - -function Lexer(options) { - this.tokens = []; - this.tokens.links = Object.create(null); - this.options = options || marked.defaults; - this.rules = block.normal; - - if (this.options.pedantic) { - this.rules = block.pedantic; - } else if (this.options.gfm) { - this.rules = block.gfm; - } -} - -/** - * Expose Block Rules - */ - -Lexer.rules = block; - -/** - * Static Lex Method - */ - -Lexer.lex = function(src, options) { - var lexer = new Lexer(options); - return lexer.lex(src); -}; - -/** - * Preprocessing - */ - -Lexer.prototype.lex = function(src) { - src = src - .replace(/\r\n|\r/g, '\n') - .replace(/\t/g, ' '); - - return this.token(src, true); -}; - -/** - * Lexing - */ - -Lexer.prototype.token = function(src, top) { - src = src.replace(/^ +$/gm, ''); - var next, - loose, - cap, - bull, - b, - item, - listStart, - listItems, - t, - space, - i, - tag, - l, - isordered, - istask, - ischecked; - - while (src) { - // newline - if (cap = this.rules.newline.exec(src)) { - src = src.substring(cap[0].length); - if (cap[0].length > 1) { - this.tokens.push({ - type: 'space' - }); - } - } + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); - // 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 (lastToken && lastToken.type === 'paragraph') { - lastToken.text += '\n' + cap[0].trimRight(); - } else { - cap = cap[0].replace(/^ {4}/gm, ''); + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } // 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 (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); + } else { + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic ? rtrim(cap, '\n') : cap + }); + } + + continue; + } // fences + + + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); this.tokens.push({ type: 'code', - codeBlockStyle: 'indented', - text: !this.options.pedantic - ? rtrim(cap, '\n') - : cap + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' }); - } - continue; - } + continue; + } // heading - // fences - if (cap = this.rules.fences.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'code', - lang: cap[2] ? cap[2].trim() : cap[2], - text: cap[3] || '' - }); - continue; - } - // heading - if (cap = this.rules.heading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[1].length, - text: cap[2] - }); - continue; - } + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } // table no leading pipe (gfm) - // table no leading pipe (gfm) - if (cap = this.rules.nptable.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; - if (item.header.length === item.align.length) { - src = src.substring(cap[0].length); + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + 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] = splitCells(item.cells[i], item.header.length); } - } - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells(item.cells[i], item.header.length); + this.tokens.push(item); + continue; } + } // hr + + + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } // blockquote - this.tokens.push(item); + if (cap = this.rules.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' + }); continue; - } - } + } // list - // hr - if (cap = this.rules.hr.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' - }); - continue; - } - // blockquote - if (cap = this.rules.blockquote.exec(src)) { - src = src.substring(cap[0].length); + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; + this.tokens.push(listStart); // Get each top-level item. - this.tokens.push({ - type: 'blockquote_start' - }); + cap = cap[0].match(this.rules.item); + listItems = []; + next = false; + l = cap.length; + i = 0; - cap = cap[0].replace(/^ *> ?/gm, ''); + for (; i < l; i++) { + item = cap[i]; // Remove the list item's bullet + // so it is seen as the next token. - // Pass `top` to keep the current - // "toplevel" state. This is exactly - // how markdown.pl works. - this.token(cap, top); + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the + // list item contains. Hacky. - this.tokens.push({ - type: 'blockquote_end' - }); + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, ''); + } // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. - continue; - } - // list - if (cap = this.rules.list.exec(src)) { - src = src.substring(cap[0].length); - bull = cap[2]; - isordered = bull.length > 1; - - listStart = { - type: 'list_start', - ordered: isordered, - start: isordered ? +bull : '', - loose: false - }; + if (i !== l - 1) { + b = block.bullet.exec(cap[i + 1])[0]; - this.tokens.push(listStart); + if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) { + src = cap.slice(i + 1).join('\n') + src; + i = l - 1; + } + } // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. - // Get each top-level item. - cap = cap[0].match(this.rules.item); - listItems = []; - next = false; - l = cap.length; - i = 0; + loose = next || /\n\n(?!\s*$)/.test(item); - for (; i < l; i++) { - item = cap[i]; + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } - // Remove the list item's bullet - // so it is seen as the next token. - space = item.length; - item = item.replace(/^ *([*+-]|\d+\.) */, ''); + if (loose) { + listStart.loose = true; + } // Check for task list items - // Outdent whatever the - // list item contains. Hacky. - if (~item.indexOf('\n ')) { - space -= item.length; - item = !this.options.pedantic - ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') - : item.replace(/^ {1,4}/gm, ''); - } - // Determine whether the next list item belongs here. - // Backpedal if it does not belong in this list. - if (i !== l - 1) { - b = block.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; - i = l - 1; + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); } - } - // Determine whether item is loose or not. - // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ - // for discount behavior. - loose = next || /\n\n(?!\s*$)/.test(item); - if (i !== l - 1) { - next = item.charAt(item.length - 1) === '\n'; - if (!loose) loose = next; + t = { + type: 'list_item_start', + 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' + }); } - if (loose) { - listStart.loose = true; + if (listStart.loose) { + l = listItems.length; + i = 0; + + for (; i < l; i++) { + listItems[i].loose = true; + } } - // Check for task list items - istask = /^\[[ xX]\] /.test(item); - ischecked = undefined; - if (istask) { - ischecked = item[1] !== ' '; - item = item.replace(/^\[[ xX]\] +/, ''); + this.tokens.push({ + type: 'list_end' + }); + continue; + } // html + + + if (cap = this.rules.html.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize ? 'paragraph' : 'html', + 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(cap[0]) : cap[0] + }); + continue; + } // def + + + 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().replace(/\s+/g, ' '); + + if (!this.tokens.links[tag]) { + this.tokens.links[tag] = { + href: cap[2], + title: cap[3] + }; } - t = { - type: 'list_item_start', - task: istask, - checked: ischecked, - loose: loose + continue; + } // table (gfm) + + + if (cap = this.rules.table.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] }; - listItems.push(t); - this.tokens.push(t); + 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] = splitCells(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length); + } + + this.tokens.push(item); + continue; + } + } // lheading - // Recurse. - this.token(item, false); + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); this.tokens.push({ - type: 'list_item_end' + type: 'heading', + depth: cap[2].charAt(0) === '=' ? 1 : 2, + text: cap[1] }); + continue; + } // top-level paragraph + + + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + 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)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; } - if (listStart.loose) { - l = listItems.length; - i = 0; - for (; i < l; i++) { - listItems[i].loose = true; + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return this.tokens; + }; + + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + /** + * Renderer + */ + + function Renderer(options) { + this.options = options || defaults; + } + + Renderer.prototype.code = function (code, infostring, escaped) { + var lang = (infostring || '').match(/\S*/)[0]; + + if (this.options.highlight) { + var out = this.options.highlight(code, lang); + + if (out != null && out !== code) { + escaped = true; + code = out; + } + } + + if (!lang) { + return '
    ' + (escaped ? code : escape(code, true)) + '
    '; + } + + return '
    ' + (escaped ? code : escape(code, true)) + '
    \n'; + }; + + Renderer.prototype.blockquote = function (quote) { + return '
    \n' + quote + '
    \n'; + }; + + Renderer.prototype.html = function (html) { + return html; + }; + + Renderer.prototype.heading = function (text, level, raw, slugger) { + if (this.options.headerIds) { + return '' + text + '\n'; + } // ignore IDs + + + return '' + text + '\n'; + }; + + Renderer.prototype.hr = function () { + return this.options.xhtml ? '
    \n' : '
    \n'; + }; + + Renderer.prototype.list = function (body, ordered, start) { + var type = ordered ? 'ol' : 'ul', + startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; + return '<' + type + startatt + '>\n' + body + '\n'; + }; + + Renderer.prototype.listitem = function (text) { + return '
  • ' + text + '
  • \n'; + }; + + Renderer.prototype.checkbox = function (checked) { + return ' '; + }; + + Renderer.prototype.paragraph = function (text) { + return '

    ' + text + '

    \n'; + }; + + Renderer.prototype.table = function (header, body) { + if (body) body = '' + body + ''; + return '\n' + '\n' + header + '\n' + body + '
    \n'; + }; + + Renderer.prototype.tablerow = function (content) { + return '\n' + content + '\n'; + }; + + Renderer.prototype.tablecell = function (content, flags) { + var type = flags.header ? 'th' : 'td'; + var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; + return tag + content + '\n'; + }; // span level renderer + + + Renderer.prototype.strong = function (text) { + return '' + text + ''; + }; + + Renderer.prototype.em = function (text) { + return '' + text + ''; + }; + + Renderer.prototype.codespan = function (text) { + return '' + text + ''; + }; + + Renderer.prototype.br = function () { + return this.options.xhtml ? '
    ' : '
    '; + }; + + Renderer.prototype.del = function (text) { + return '' + text + ''; + }; + + Renderer.prototype.link = function (href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + + if (href === null) { + return text; + } + + var out = '
    '; + return out; + }; + + Renderer.prototype.image = function (href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + + if (href === null) { + return text; + } + + var out = '' + text + '' : '>'; + return out; + }; + + Renderer.prototype.text = function (text) { + return text; + }; + + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + + /** + * Slugger generates header id + */ + function Slugger() { + this.seen = {}; + } + /** + * Convert string to unique id + */ + + Slugger.prototype.slug = function (value) { + var slug = value.toLowerCase().trim().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; + }; + + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + /** + * Inline Lexer & Compiler + */ + + function InlineLexer(links, options) { + this.options = options || defaults; + this.links = links; + this.rules = inline.normal; + this.renderer = this.options.renderer || new 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.pedantic; + } else if (this.options.gfm) { + if (this.options.breaks) { + this.rules = inline.breaks; + } else { + this.rules = inline.gfm; + } + } + } + /** + * Expose Inline Rules + */ + + InlineLexer.rules = inline; + /** + * Static Lexing/Compiling Method + */ + + InlineLexer.output = function (src, links, options) { + var inline = new InlineLexer(links, options); + return inline.output(src); + }; + /** + * Lexing/Compiling + */ + + + InlineLexer.prototype.output = function (src) { + var out = ''; + var link; + var text; + var href; + var title; + var cap; + var prevCapZero; + + while (src) { + // escape + if (cap = this.rules.escape.exec(src)) { + src = src.substring(cap[0].length); + out += escape(cap[1]); + continue; + } // tag + + + if (cap = this.rules.tag.exec(src)) { + if (!this.inLink && /^/i.test(cap[0])) { + this.inLink = false; } - } - this.tokens.push({ - type: 'list_end' - }); + 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; + } - continue; - } + src = src.substring(cap[0].length); + out += this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0]; + continue; + } // link - // html - if (cap = this.rules.html.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: this.options.sanitize - ? 'paragraph' - : 'html', - 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(cap[0])) : cap[0] - }); - continue; - } - // def - 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().replace(/\s+/g, ' '); - if (!this.tokens.links[tag]) { - this.tokens.links[tag] = { - href: cap[2], - title: cap[3] - }; - } - continue; - } + if (cap = this.rules.link.exec(src)) { + var lastParenIndex = findClosingBracket(cap[2], '()'); - // table (gfm) - if (cap = this.rules.table.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; + 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] = ''; + } - if (item.header.length === item.align.length) { src = src.substring(cap[0].length); + this.inLink = true; + href = cap[2]; - 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'; + if (this.options.pedantic) { + link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); + + if (link) { + href = link[1]; + title = link[3]; } else { - item.align[i] = null; + title = ''; } + } else { + title = cap[3] ? cap[3].slice(1, -1) : ''; } - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells( - item.cells[i].replace(/^ *\| *| *\| *$/g, ''), - item.header.length); - } - - this.tokens.push(item); - + 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 - // lheading - if (cap = this.rules.lheading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[2].charAt(0) === '=' ? 1 : 2, - text: cap[1] - }); - continue; - } - // top-level paragraph - if (top && (cap = this.rules.paragraph.exec(src))) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'paragraph', - text: cap[1].charAt(cap[1].length - 1) === '\n' - ? cap[1].slice(0, -1) - : cap[1] - }); - continue; - } + 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()]; - // text - if (cap = this.rules.text.exec(src)) { - // Top-level should never reach here. - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'text', - text: cap[0] - }); - continue; - } + if (!link || !link.href) { + out += cap[0].charAt(0); + src = cap[0].substring(1) + src; + continue; + } - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } - } + this.inLink = true; + out += this.outputLink(cap, link); + this.inLink = false; + continue; + } // strong - return this.tokens; -}; -/** - * Inline-Level Grammar - */ + 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 -var inline = { - escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, - autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, - url: noop, - 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)\]\(\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: noop, - text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; -inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); - -inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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(); -inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/; + 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 -inline.tag = edit(inline.tag) - .replace('comment', block._comment) - .replace('attribute', inline._attribute) - .getRegex(); -inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; -inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; -inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; + if (cap = this.rules.code.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.codespan(escape(cap[2].trim(), true)); + continue; + } // br -inline.link = edit(inline.link) - .replace('label', inline._label) - .replace('href', inline._href) - .replace('title', inline._title) - .getRegex(); -inline.reflink = edit(inline.reflink) - .replace('label', inline._label) - .getRegex(); + if (cap = this.rules.br.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.br(); + continue; + } // del (gfm) -/** - * Normal Inline Grammar - */ - -inline.normal = merge({}, inline); - -/** - * Pedantic Inline Grammar - */ - -inline.pedantic = merge({}, inline.normal, { - strong: /^__(?=\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() -}); - -/** - * GFM Inline Grammar - */ - -inline.gfm = merge({}, inline.normal, { - escape: edit(inline.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]*?(?:(?=[\\/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.options.sanitize - ? this.options.sanitizer - ? this.options.sanitizer(cap[0]) - : escape(cap[0]) - : cap[0]; - continue; - } + if (cap = this.rules.autolink.exec(src)) { + src = src.substring(cap[0].length); - // link - if (cap = this.rules.link.exec(src)) { - var lastParenIndex = findClosingBracket(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]; + if (cap[2] === '@') { + text = escape(this.mangle(cap[1])); + href = 'mailto:' + text; } else { - title = ''; + text = escape(cap[1]); + href = text; } - } 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; + out += this.renderer.link(href, null, text); continue; - } - this.inLink = true; - out += this.outputLink(cap, link); - this.inLink = false; - continue; - } + } // url (gfm) - // 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; - } + if (!this.inLink && (cap = this.rules.url.exec(src))) { + if (cap[2] === '@') { + text = escape(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]); - // code - if (cap = this.rules.code.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.codespan(escape(cap[2].trim(), true)); - continue; - } + text = escape(cap[0]); - // br - if (cap = this.rules.br.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.br(); - continue; - } + if (cap[1] === 'www.') { + href = 'http://' + text; + } else { + href = text; + } + } - // del (gfm) - if (cap = this.rules.del.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.del(this.output(cap[1])); - continue; - } + src = src.substring(cap[0].length); + out += this.renderer.link(href, null, text); + continue; + } // text - // autolink - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); - if (cap[2] === '@') { - text = escape(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape(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(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(cap[0]); - if (cap[1] === 'www.') { - href = 'http://' + 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(cap[0]) : cap[0]); } else { - href = text; + out += this.renderer.text(escape(this.smartypants(cap[0]))); } + + continue; } - 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(cap[0])) : cap[0]); - } else { - out += this.renderer.text(escape(this.smartypants(cap[0]))); + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); } - continue; } - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } - } + return out; + }; + + InlineLexer.escapes = function (text) { + return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; + }; + /** + * Compile Link + */ - 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 = link.href, - title = link.title ? escape(link.title) : null; - - return cap[0].charAt(0) !== '!' - ? this.renderer.link(href, title, this.output(cap[1])) - : this.renderer.image(href, title, escape(cap[1])); -}; - -/** - * Smartypants Transformations - */ - -InlineLexer.prototype.smartypants = function(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 - */ - -InlineLexer.prototype.mangle = function(text) { - if (!this.options.mangle) return text; - var out = '', - l = text.length, - 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; -}; + 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])) : this.renderer.image(href, title, escape(cap[1])); + }; + /** + * Smartypants Transformations + */ + + + InlineLexer.prototype.smartypants = function (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 + */ + + + InlineLexer.prototype.mangle = function (text) { + if (!this.options.mangle) return text; + var out = ''; + var l = text.length; + var ch; -/** - * Renderer - */ + for (var i = 0; i < l; i++) { + ch = text.charCodeAt(i); -function Renderer(options) { - this.options = options || marked.defaults; -} + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } -Renderer.prototype.code = function(code, infostring, escaped) { - var lang = (infostring || '').match(/\S*/)[0]; - if (this.options.highlight) { - var out = this.options.highlight(code, lang); - if (out != null && out !== code) { - escaped = true; - code = out; + out += '&#' + ch + ';'; } - } - if (!lang) { - return '
    '
    -      + (escaped ? code : escape(code, true))
    -      + '
    '; - } + return out; + }; - return '
    '
    -    + (escaped ? code : escape(code, true))
    -    + '
    \n'; -}; - -Renderer.prototype.blockquote = function(quote) { - return '
    \n' + quote + '
    \n'; -}; - -Renderer.prototype.html = function(html) { - return html; -}; - -Renderer.prototype.heading = function(text, level, raw, slugger) { - if (this.options.headerIds) { - return '' - + text - + '\n'; - } - // ignore IDs - return '' + text + '\n'; -}; - -Renderer.prototype.hr = function() { - return this.options.xhtml ? '
    \n' : '
    \n'; -}; - -Renderer.prototype.list = function(body, ordered, start) { - var type = ordered ? 'ol' : 'ul', - startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; - return '<' + type + startatt + '>\n' + body + '\n'; -}; - -Renderer.prototype.listitem = function(text) { - return '
  • ' + text + '
  • \n'; -}; - -Renderer.prototype.checkbox = function(checked) { - return ' '; -}; - -Renderer.prototype.paragraph = function(text) { - return '

    ' + text + '

    \n'; -}; - -Renderer.prototype.table = function(header, body) { - if (body) body = '' + body + ''; - - return '\n' - + '\n' - + header - + '\n' - + body - + '
    \n'; -}; - -Renderer.prototype.tablerow = function(content) { - return '\n' + content + '\n'; -}; - -Renderer.prototype.tablecell = function(content, flags) { - var type = flags.header ? 'th' : 'td'; - var tag = flags.align - ? '<' + type + ' align="' + flags.align + '">' - : '<' + type + '>'; - return tag + content + '\n'; -}; - -// span level renderer -Renderer.prototype.strong = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.em = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.codespan = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.br = function() { - return this.options.xhtml ? '
    ' : '
    '; -}; - -Renderer.prototype.del = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.link = function(href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { - return text; - } - var out = '
    '; - return out; -}; + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ -Renderer.prototype.image = function(href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { + /** + * TextRenderer + * returns only the textual part of the token + */ + function TextRenderer() {} // no need for block level renderers + + TextRenderer.prototype.strong = TextRenderer.prototype.em = TextRenderer.prototype.codespan = TextRenderer.prototype.del = TextRenderer.prototype.text = function (text) { return text; - } + }; - var out = '' + text + '' : '>'; - return out; -}; - -Renderer.prototype.text = function(text) { - return text; -}; - -/** - * TextRenderer - * returns only the textual part of the token - */ - -function TextRenderer() {} - -// no need for block level renderers - -TextRenderer.prototype.strong = -TextRenderer.prototype.em = -TextRenderer.prototype.codespan = -TextRenderer.prototype.del = -TextRenderer.prototype.text = function(text) { - return text; -}; - -TextRenderer.prototype.link = -TextRenderer.prototype.image = function(href, title, text) { - return '' + text; -}; - -TextRenderer.prototype.br = function() { - return ''; -}; - -/** - * Parsing & Compiling - */ - -function Parser(options) { - this.tokens = []; - this.token = null; - this.options = options || marked.defaults; - this.options.renderer = this.options.renderer || new Renderer(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - this.slugger = new Slugger(); -} - -/** - * Static Parse Method - */ - -Parser.parse = function(src, options) { - var parser = new Parser(options); - return parser.parse(src); -}; - -/** - * Parse Loop - */ - -Parser.prototype.parse = function(src) { - this.inline = new InlineLexer(src.links, this.options); - // use an InlineLexer with a TextRenderer to extract pure text - this.inlineText = new InlineLexer( - src.links, - merge({}, this.options, { renderer: new TextRenderer() }) - ); - this.tokens = src.reverse(); - - var out = ''; - while (this.next()) { - out += this.tok(); + TextRenderer.prototype.link = TextRenderer.prototype.image = function (href, title, text) { + return '' + text; + }; + + TextRenderer.prototype.br = function () { + return ''; + }; + + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + /** + * Parsing & Compiling + */ + + function Parser(options) { + this.tokens = []; + this.token = null; + this.options = options || defaults; + this.options.renderer = this.options.renderer || new Renderer(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger(); } + /** + * Static Parse Method + */ + + Parser.parse = function (src, options) { + var parser = new Parser(options); + return parser.parse(src); + }; + /** + * Parse Loop + */ - return out; -}; -/** - * Next Token - */ + Parser.prototype.parse = function (src) { + this.inline = new InlineLexer(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text -Parser.prototype.next = function() { - this.token = this.tokens.pop(); - return this.token; -}; + this.inlineText = new InlineLexer(src.links, merge({}, this.options, { + renderer: new TextRenderer() + })); + this.tokens = src.reverse(); + var out = ''; -/** - * Preview Next Token - */ + while (this.next()) { + out += this.tok(); + } -Parser.prototype.peek = function() { - return this.tokens[this.tokens.length - 1] || 0; -}; + return out; + }; + /** + * Next Token + */ -/** - * Parse Text Tokens - */ -Parser.prototype.parseText = function() { - var body = this.token.text; + Parser.prototype.next = function () { + this.token = this.tokens.pop(); + return this.token; + }; + /** + * Preview Next Token + */ - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } - return this.inline.output(body); -}; + Parser.prototype.peek = function () { + return this.tokens[this.tokens.length - 1] || 0; + }; + /** + * Parse Text Tokens + */ -/** - * Parse Current Token - */ -Parser.prototype.tok = function() { - 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(this.inlineText.output(this.token.text)), - this.slugger); - } - case 'code': { - return this.renderer.code(this.token.text, - this.token.lang, - this.token.escaped); + Parser.prototype.parseText = function () { + var body = this.token.text; + + while (this.peek().type === 'text') { + body += '\n' + this.next().text; } - case 'table': { - var header = '', - body = '', - 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]; + return this.inline.output(body); + }; + /** + * Parse Current Token + */ - 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 = ''; + Parser.prototype.tok = function () { + switch (this.token.type) { + case 'space': + { + return ''; + } - while (this.next().type !== 'blockquote_end') { - body += this.tok(); - } + case 'hr': + { + return this.renderer.hr(); + } - return this.renderer.blockquote(body); - } - case 'list_start': { - body = ''; - var ordered = this.token.ordered, - start = this.token.start; + case 'heading': + { + return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, unescape(this.inlineText.output(this.token.text)), this.slugger); + } - while (this.next().type !== 'list_end') { - body += this.tok(); - } + case 'code': + { + return this.renderer.code(this.token.text, this.token.lang, this.token.escaped); + } - 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) + case 'table': + { + var header = ''; + var body = ''; + var i; + var row; + var cell; + var 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] }); } - } 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); - } - } - } -}; - -/** - * Slugger generates header id - */ - -function Slugger() { - this.seen = {}; -} - -/** - * Convert string to unique id - */ - -Slugger.prototype.slug = function(value) { - var slug = value - .toLowerCase() - .trim() - .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; + header += this.renderer.tablerow(cell); - return slug; -}; + for (i = 0; i < this.token.cells.length; i++) { + row = this.token.cells[i]; + cell = ''; -/** - * Helpers - */ + for (j = 0; j < row.length; j++) { + cell += this.renderer.tablecell(this.inline.output(row[j]), { + header: false, + align: this.token.align[j] + }); + } -function escape(html, encode) { - if (encode) { - if (escape.escapeTest.test(html)) { - return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; }); - } - } else { - if (escape.escapeTestNoEncode.test(html)) { - return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; }); - } - } + body += this.renderer.tablerow(cell); + } - return html; -} - -escape.escapeTest = /[&<>"']/; -escape.escapeReplace = /[&<>"']/g; -escape.replacements = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' -}; - -escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; -escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; - -function unescape(html) { - // explicitly match decimal, hex, and named HTML entities - return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { - n = n.toLowerCase(); - if (n === 'colon') return ':'; - if (n.charAt(0) === '#') { - return n.charAt(1) === 'x' - ? String.fromCharCode(parseInt(n.substring(2), 16)) - : String.fromCharCode(+n.substring(1)); - } - return ''; - }); -} - -function edit(regex, opt) { - regex = regex.source || regex; - opt = opt || ''; - return { - replace: function(name, val) { - val = val.source || val; - val = val.replace(/(^|[^\[])\^/g, '$1'); - regex = regex.replace(name, val); - return this; - }, - getRegex: function() { - return new RegExp(regex, opt); - } - }; -} + return this.renderer.table(header, body); + } -function cleanUrl(sanitize, base, href) { - if (sanitize) { - try { - var prot = decodeURIComponent(unescape(href)) - .replace(/[^\w:]/g, '') - .toLowerCase(); - } catch (e) { - return null; - } - if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { - return null; - } - } - if (base && !originIndependentUrl.test(href)) { - href = resolveUrl(base, href); - } - try { - href = encodeURI(href).replace(/%25/g, '%'); - } catch (e) { - return null; - } - return href; -} - -function resolveUrl(base, href) { - if (!baseUrls[' ' + base]) { - // we can ignore everything in base after the last slash of its path component, - // but we might need to add _that_ - // https://tools.ietf.org/html/rfc3986#section-3 - if (/^[^:]+:\/*[^/]*$/.test(base)) { - baseUrls[' ' + base] = base + '/'; - } else { - baseUrls[' ' + base] = rtrim(base, '/', true); - } - } - base = baseUrls[' ' + base]; - var relativeBase = base.indexOf(':') === -1; + case 'blockquote_start': + { + var _body = ''; - if (href.slice(0, 2) === '//') { - if (relativeBase) { - return href; - } - return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; - } else if (href.charAt(0) === '/') { - if (relativeBase) { - return href; - } - return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; - } else { - return base + href; - } -} -var baseUrls = {}; -var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; - -function noop() {} -noop.exec = noop; - -function merge(obj) { - var i = 1, - target, - key; - - for (; i < arguments.length; i++) { - target = arguments[i]; - for (key in target) { - if (Object.prototype.hasOwnProperty.call(target, key)) { - obj[key] = target[key]; - } - } - } + while (this.next().type !== 'blockquote_end') { + _body += this.tok(); + } - return obj; -} - -function splitCells(tableRow, count) { - // ensure that every cell-delimiting pipe has a space - // before it to distinguish it from an escaped pipe - var row = tableRow.replace(/\|/g, function(match, offset, str) { - var escaped = false, - curr = offset; - while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; - if (escaped) { - // odd number of slashes means | is escaped - // so we leave it alone - return '|'; - } else { - // add space before unescaped | - return ' |'; + return this.renderer.blockquote(_body); } - }), - cells = row.split(/ \|/), - i = 0; - - if (cells.length > count) { - cells.splice(count); - } else { - while (cells.length < count) cells.push(''); - } - for (; i < cells.length; i++) { - // leading or trailing whitespace is ignored per the gfm spec - cells[i] = cells[i].trim().replace(/\\\|/g, '|'); - } - return cells; -} - -// Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). -// /c*$/ is vulnerable to REDOS. -// invert: Remove suffix of non-c chars instead. Default falsey. -function rtrim(str, c, invert) { - if (str.length === 0) { - return ''; - } + case 'list_start': + { + var _body2 = ''; + var ordered = this.token.ordered, + start = this.token.start; + + while (this.next().type !== 'list_end') { + _body2 += this.tok(); + } - // Length of suffix matching the invert condition. - var suffLen = 0; + return this.renderer.list(_body2, ordered, start); + } - // Step left until we fail to match the invert condition. - while (suffLen < str.length) { - var currChar = str.charAt(str.length - suffLen - 1); - if (currChar === c && !invert) { - suffLen++; - } else if (currChar !== c && invert) { - suffLen++; - } else { - break; - } - } + case 'list_item_start': + { + var _body3 = ''; + 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 { + _body3 += this.renderer.checkbox(checked); + } + } - return str.substr(0, str.length - suffLen); -} + while (this.next().type !== 'list_item_end') { + _body3 += !loose && this.token.type === 'text' ? this.parseText() : this.tok(); + } -function findClosingBracket(str, b) { - if (str.indexOf(b[1]) === -1) { - return -1; - } - var level = 0; - for (var i = 0; i < str.length; i++) { - if (str[i] === '\\') { - i++; - } else if (str[i] === b[0]) { - level++; - } else if (str[i] === b[1]) { - level--; - if (level < 0) { - return i; - } - } - } - return -1; -} + return this.renderer.listitem(_body3, task, checked); + } -function checkSanitizeDeprecation(opt) { - if (opt && opt.sanitize && !opt.silent) { - console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); - } -} + 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)); + } -/** - * Marked - */ + case 'text': + { + return this.renderer.paragraph(this.parseText()); + } -function marked(src, opt, callback) { - // throw error in case of non string input - if (typeof src === 'undefined' || src === null) { - throw new Error('marked(): input parameter is undefined or null'); - } - if (typeof src !== 'string') { - throw new Error('marked(): input parameter is of type ' - + Object.prototype.toString.call(src) + ', string expected'); - } + default: + { + var errMsg = 'Token with "' + this.token.type + '" type was not found.'; - if (callback || typeof opt === 'function') { - if (!callback) { - callback = opt; - opt = null; + if (this.options.silent) { + console.log(errMsg); + } else { + throw new Error(errMsg); + } + } } + }; - opt = merge({}, marked.defaults, opt || {}); - checkSanitizeDeprecation(opt); + /** + * Marked + */ - var highlight = opt.highlight, - tokens, - pending, - i = 0; + function marked(src, opt, callback) { + // throw error in case of non string input + if (typeof src === 'undefined' || src === null) { + throw new Error('marked(): input parameter is undefined or null'); + } - try { - tokens = Lexer.lex(src, opt); - } catch (e) { - return callback(e); + if (typeof src !== 'string') { + throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected'); } - pending = tokens.length; + if (callback || typeof opt === 'function') { + var _ret = function () { + if (!callback) { + callback = opt; + opt = null; + } - var done = function(err) { - if (err) { - opt.highlight = highlight; - return callback(err); - } + opt = merge({}, marked.defaults, opt || {}); + checkSanitizeDeprecation(opt); + var highlight = opt.highlight; + var tokens; + var pending; + var i = 0; + + try { + tokens = Lexer.lex(src, opt); + } catch (e) { + return { + v: callback(e) + }; + } - var out; + pending = tokens.length; - try { - out = Parser.parse(tokens, opt); - } catch (e) { - err = e; - } + var done = function done(err) { + if (err) { + opt.highlight = highlight; + return callback(err); + } - opt.highlight = highlight; + var out; - return err - ? callback(err) - : callback(null, out); - }; + try { + out = Parser.parse(tokens, opt); + } catch (e) { + err = e; + } - if (!highlight || highlight.length < 3) { - return done(); - } + opt.highlight = highlight; + return err ? callback(err) : callback(null, out); + }; - delete opt.highlight; + if (!highlight || highlight.length < 3) { + return { + v: done() + }; + } - if (!pending) return done(); + delete opt.highlight; + if (!pending) return { + v: done() + }; - for (; i < tokens.length; i++) { - (function(token) { - if (token.type !== 'code') { - return --pending || done(); - } - return highlight(token.text, token.lang, function(err, code) { - if (err) return done(err); - if (code == null || code === token.text) { - return --pending || done(); - } - token.text = code; - token.escaped = true; - --pending || done(); - }); - })(tokens[i]); - } + for (; i < tokens.length; i++) { + (function (token) { + if (token.type !== 'code') { + return --pending || done(); + } - return; - } - try { - if (opt) opt = merge({}, marked.defaults, opt); - checkSanitizeDeprecation(opt); - return Parser.parse(Lexer.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(e.message + '', true)
    -        + '
    '; - } - throw e; - } -} + return highlight(token.text, token.lang, function (err, code) { + if (err) return done(err); -/** - * Options - */ + if (code == null || code === token.text) { + return --pending || done(); + } -marked.options = -marked.setOptions = function(opt) { - merge(marked.defaults, opt); - return marked; -}; - -marked.getDefaults = function() { - return { - baseUrl: null, - breaks: false, - gfm: true, - headerIds: true, - headerPrefix: '', - highlight: null, - langPrefix: 'language-', - mangle: true, - pedantic: false, - renderer: new Renderer(), - sanitize: false, - sanitizer: null, - silent: false, - smartLists: false, - smartypants: false, - xhtml: false - }; -}; + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } -marked.defaults = marked.getDefaults(); + return { + v: void 0 + }; + }(); -/** - * Expose - */ + if (_typeof(_ret) === "object") return _ret.v; + } -marked.Parser = Parser; -marked.parser = Parser.parse; + try { + opt = merge({}, marked.defaults, opt || {}); + checkSanitizeDeprecation(opt); + var t = Lexer.lex(src, opt); + return Parser.parse(t, opt); + } catch (e) { + e.message += '\nPlease report this to https://github.com/markedjs/marked.'; -marked.Renderer = Renderer; -marked.TextRenderer = TextRenderer; + if ((opt || marked.defaults).silent) { + return '

    An error occurred:

    ' + escape(e.message + '', true) + '
    '; + } -marked.Lexer = Lexer; -marked.lexer = Lexer.lex; + throw e; + } + } + /** + * Options + */ -marked.InlineLexer = InlineLexer; -marked.inlineLexer = InlineLexer.output; + marked.options = marked.setOptions = function (opt) { + merge(marked.defaults, opt); + return marked; + }; -marked.Slugger = Slugger; + marked.getDefaults = getDefaults; + Object.defineProperty(marked, 'defaults', { + get: function get() { + return defaults; + }, + set: function set(value) { + changeDefaults(value); + } + }); + /** + * Expose + */ + + marked.Parser = Parser; + marked.parser = Parser.parse; + marked.Renderer = Renderer; + marked.TextRenderer = TextRenderer; + marked.Lexer = Lexer; + marked.lexer = Lexer.lex; + marked.InlineLexer = InlineLexer; + marked.inlineLexer = InlineLexer.output; + marked.Slugger = Slugger; + marked.parse = marked; -marked.parse = marked; + return marked; -if (typeof module !== 'undefined' && typeof exports === 'object') { - module.exports = marked; -} else if (typeof define === 'function' && define.amd) { - define(function() { return marked; }); -} else { - root.marked = marked; -} -})(this || (typeof window !== 'undefined' ? window : global)); +}))); diff --git a/marked.min.js b/marked.min.js index c19df528a4..2475b9ab30 100644 --- a/marked.min.js +++ b/marked.min.js @@ -1,6 +1,48 @@ +!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 n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var r={baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,xhtml:!1};function e(){return{baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,xhtml:!1}}function t(n,e){return n=n.source||n,e=e||"",{replace:function(e,t){return t=(t=t.source||t).replace(/(^|[^\[])\^/g,"$1"),n=n.replace(e,t),this},getRegex:function(){return new RegExp(n,e)}}}function s(e,t,n){if(e){var r;try{r=decodeURIComponent( /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ -!function(e){"use strict";var x={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:/^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,hr:/^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,blockquote:/^( {0,3}> ?(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:u,table:u,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/};function a(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||k.defaults,this.rules=x.normal,this.options.pedantic?this.rules=x.pedantic:this.options.gfm&&(this.rules=x.gfm)}x._label=/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,x._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,x.def=i(x.def).replace("label",x._label).replace("title",x._title).getRegex(),x.bullet=/(?:[*+-]|\d{1,9}\.)/,x.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,x.item=i(x.item,"gm").replace(/bull/g,x.bullet).getRegex(),x.list=i(x.list).replace(/bull/g,x.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+x.def.source+")").getRegex(),x._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",x._comment=//,x.html=i(x.html,"i").replace("comment",x._comment).replace("tag",x._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),x.paragraph=i(x._paragraph).replace("hr",x.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",x._tag).getRegex(),x.blockquote=i(x.blockquote).replace("paragraph",x.paragraph).getRegex(),x.normal=f({},x),x.gfm=f({},x.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),x.pedantic=f({},x.normal,{html:i("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",x._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:u,paragraph:i(x.normal._paragraph).replace("hr",x.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",x.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()}),a.rules=x,a.lex=function(e,t){return new a(t).lex(e)},a.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," "),this.token(e,!0)},a.prototype.token=function(e,t){var n,r,s,i,l,o,a,h,p,c,u,g,f,d,m,k;for(e=e.replace(/^ +$/gm,"");e;)if((s=this.rules.newline.exec(e))&&(e=e.substring(s[0].length),1 ?/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),a={type:"list_start",ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(a),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,u=0;u?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:u,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:u,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~",n.em=i(n.em).replace(/punctuation/g,n._punctuation).getRegex(),n._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,n._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,n._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])?)+(?![-_])/,n.autolink=i(n.autolink).replace("scheme",n._scheme).replace("email",n._email).getRegex(),n._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,n.tag=i(n.tag).replace("comment",x._comment).replace("attribute",n._attribute).getRegex(),n._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,n._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,n._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,n.link=i(n.link).replace("label",n._label).replace("href",n._href).replace("title",n._title).getRegex(),n.reflink=i(n.reflink).replace("label",n._label).getRegex(),n.normal=f({},n),n.pedantic=f({},n.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:i(/^!?\[(label)\]\((.*?)\)/).replace("label",n._label).getRegex(),reflink:i(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",n._label).getRegex()}),n.gfm=f({},n.normal,{escape:i(n.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]*?(?:(?=[\\/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),o+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):_(i[0]):i[0];else if(i=this.rules.link.exec(e)){var a=d(i[2],"()");if(-1$/,"$1"),o+=this.outputLink(i,{href:p.escapes(r),title:p.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){o+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,o+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),o+=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),o+=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),o+=this.renderer.codespan(_(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),o+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),o+=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=_(this.mangle(i[1]))):n=_(i[1]),o+=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?o+=this.renderer.text(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):_(i[0]):i[0]):o+=this.renderer.text(_(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=_(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=_(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),o+=this.renderer.link(r,null,n)}return o},p.escapes=function(e){return e?e.replace(p.rules._escapes,"$1"):e},p.prototype.outputLink=function(e,t){var n=t.href,r=t.title?_(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,_(e[1]))},p.prototype.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},p.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=e.length,s=0;s'+(n?e:_(e,!0))+"\n":"
    "+(n?e:_(e,!0))+"
    "},r.prototype.blockquote=function(e){return"
    \n"+e+"
    \n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"},r.prototype.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},r.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},r.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},r.prototype.checkbox=function(e){return" "},r.prototype.paragraph=function(e){return"

    "+e+"

    \n"},r.prototype.table=function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"},r.prototype.tablerow=function(e){return"\n"+e+"\n"},r.prototype.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},r.prototype.strong=function(e){return""+e+""},r.prototype.em=function(e){return""+e+""},r.prototype.codespan=function(e){return""+e+""},r.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},r.prototype.del=function(e){return""+e+""},r.prototype.link=function(e,t,n){if(null===(e=l(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "},r.prototype.image=function(e,t,n){if(null===(e=l(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"},r.prototype.text=function(e){return e},s.prototype.strong=s.prototype.em=s.prototype.codespan=s.prototype.del=s.prototype.text=function(e){return e},s.prototype.link=s.prototype.image=function(e,t,n){return""+n},s.prototype.br=function(){return""},h.parse=function(e,t){return new h(t).parse(e)},h.prototype.parse=function(e){this.inline=new p(e.links,this.options),this.inlineText=new p(e.links,f({},this.options,{renderer:new s})),this.tokens=e.reverse();for(var t="";this.next();)t+=this.tok();return t},h.prototype.next=function(){return this.token=this.tokens.pop(),this.token},h.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},h.prototype.parseText=function(){for(var e=this.token.text;"text"===this.peek().type;)e+="\n"+this.next().text;return this.inline.output(e)},h.prototype.tok=function(){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,g(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 e,t,n,r,s="",i="";for(n="",e=0;e?@[\]^`{|}~]/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},_.escapeTest=/[&<>"']/,_.escapeReplace=/[&<>"']/g,_.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},_.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,_.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var o={},c=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function u(){}function f(e){for(var t,n,r=1;rt)n.splice(t);else for(;n.lengthAn error occurred:

    "+_(e.message+"",!0)+"
    ";throw e}}u.exec=u,k.options=k.setOptions=function(e){return f(k.defaults,e),k},k.getDefaults=function(){return{baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:new r,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,xhtml:!1}},k.defaults=k.getDefaults(),k.Parser=h,k.parser=h.parse,k.Renderer=r,k.TextRenderer=s,k.Lexer=a,k.lexer=a.lex,k.InlineLexer=p,k.inlineLexer=p.output,k.Slugger=t,k.parse=k,"undefined"!=typeof module&&"object"==typeof exports?module.exports=k:"function"==typeof define&&define.amd?define(function(){return k}):e.marked=k}(this||("undefined"!=typeof window?window:global)); \ No newline at end of file + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ +function(e){return e.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,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)):""})}(n)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return null}if(0===r.indexOf("javascript:")||0===r.indexOf("vbscript:")||0===r.indexOf("data:"))return null}t&&!/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i.test(n)&&(n=i(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch(e){return null}return n}function i(e,t){i.baseUrls[" "+e]||(/^[^:]+:\/*[^/]*$/.test(e)?i.baseUrls[" "+e]=e+"/":i.baseUrls[" "+e]=y(e,"/",!0));var n=-1===(e=i.baseUrls[" "+e]).indexOf(":");return"//"===t.slice(0,2)?n?t:e.replace(/^([^:]+:)[\s\S]*$/,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/,"$1")+t:e+t}function l(){}function a(e){for(var t,n,r=1;rt)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:l.exec=l,table:l,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?'|\([^()]*\))/};_.def=t(_.def).replace("label",_._label).replace("title",_._title).getRegex(),_.bullet=/(?:[*+-]|\d{1,9}\.)/,_.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,_.item=t(_.item,"gm").replace(/bull/g,_.bullet).getRegex(),_.list=t(_.list).replace(/bull/g,_.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+_.def.source+")").getRegex(),_._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",_._comment=//,_.html=t(_.html,"i").replace("comment",_._comment).replace("tag",_._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),_.paragraph=t(_._paragraph).replace("hr",_.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",_._tag).getRegex(),_.blockquote=t(_.blockquote).replace("paragraph",_.paragraph).getRegex(),_.normal=a({},_),_.gfm=a({},_.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),_.pedantic=a({},_.normal,{html:t("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",_._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:l,paragraph:t(_.normal._paragraph).replace("hr",_.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",_.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var o={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:l,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:l,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\An error occurred:

    "+escape(e.message+"",!0)+"
    ";throw e}}return o._punctuation="!\"#$%&'()*+,\\-./:;<=>?@\\[^_{|}~",o.em=t(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=t(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=t(o.tag).replace("comment",_._comment).replace("attribute",o._attribute).getRegex(),o._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,o._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,o._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,o.link=t(o.link).replace("label",o._label).replace("href",o._href).replace("title",o._title).getRegex(),o.reflink=t(o.reflink).replace("label",o._label).getRegex(),o.normal=a({},o),o.pedantic=a({},o.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:t(/^!?\[(label)\]\((.*?)\)/).replace("label",o._label).getRegex(),reflink:t(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",o._label).getRegex()}),o.gfm=a({},o.normal,{escape:t(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),a={type:"list_start",ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(a),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,u=0;u'+(n?e:escape(e,!0))+"\n":"
    "+(n?e:escape(e,!0))+"
    "},u.prototype.blockquote=function(e){return"
    \n"+e+"
    \n"},u.prototype.html=function(e){return e},u.prototype.heading=function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"},u.prototype.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},u.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},u.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},u.prototype.checkbox=function(e){return" "},u.prototype.paragraph=function(e){return"

    "+e+"

    \n"},u.prototype.table=function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"},u.prototype.tablerow=function(e){return"\n"+e+"\n"},u.prototype.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},u.prototype.strong=function(e){return""+e+""},u.prototype.em=function(e){return""+e+""},u.prototype.codespan=function(e){return""+e+""},u.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},u.prototype.del=function(e){return""+e+""},u.prototype.link=function(e,t,n){if(null===(e=s(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "},u.prototype.image=function(e,t,n){if(null===(e=s(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"},u.prototype.text=function(e){return e},g.prototype.slug=function(e){var t=e.toLowerCase().trim().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},f.rules=o,f.output=function(e,t,n){return new f(t,n).output(e)},f.prototype.output=function(e){for(var t,n,r,s,i,l,o="";e;)if(i=this.rules.escape.exec(e))e=e.substring(i[0].length),o+=escape(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),o+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):escape(i[0]):i[0];else if(i=this.rules.link.exec(e)){var a=p(i[2],"()");if(-1$/,"$1"),o+=this.outputLink(i,{href:f.escapes(r),title:f.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){o+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,o+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),o+=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),o+=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),o+=this.renderer.codespan(escape(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),o+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),o+=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=escape(this.mangle(i[1]))):n=escape(i[1]),o+=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?o+=this.renderer.text(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):escape(i[0]):i[0]):o+=this.renderer.text(escape(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=escape(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=escape(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),o+=this.renderer.link(r,null,n)}return o},f.escapes=function(e){return e?e.replace(f.rules._escapes,"$1"):e},f.prototype.outputLink=function(e,t){var n=t.href,r=t.title?escape(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,escape(e[1]))},f.prototype.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},f.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=e.length,s=0;s Date: Tue, 5 Nov 2019 15:48:01 -0600 Subject: [PATCH 05/33] no-ignore test:redos --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 443d285ed6..a6ef530f10 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "test:unit": "npm test -- test/unit/**/*-spec.js", "test:specs": "npm test -- test/specs/**/*-spec.js", "test:lint": "eslint bin/marked .", - "test:redos": "eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' lib/marked.js", + "test:redos": "eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' --no-ignore lib/marked.js", "test:update": "node test/update-specs.js", "bench": "node test/bench.js", "lint": "eslint --fix bin/marked .", From ce03223be0b4094ca2767b302d4e52928726ea17 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 11:11:06 -0600 Subject: [PATCH 06/33] use commonjs and es6 classes --- package-lock.json | 43 ++- package.json | 10 +- rollup.config.js | 12 +- src/InlineLexer.js | 487 ++++++++++++++++---------------- src/Lexer.js | 662 ++++++++++++++++++++++---------------------- src/Parser.js | 356 ++++++++++++------------ src/Renderer.js | 296 ++++++++++---------- src/Slugger.js | 45 +-- src/TextRenderer.js | 44 ++- src/defaults.js | 12 +- src/helpers.js | 129 +++++---- src/marked.js | 47 ++-- src/regexp.js | 13 +- test/bench.js | 57 +++- 14 files changed, 1169 insertions(+), 1044 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2b7be30342..212e5914e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2049,6 +2049,15 @@ "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", "dev": true }, + "is-reference": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", + "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", + "dev": true, + "requires": { + "@types/estree": "0.0.39" + } + }, "is-regex": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", @@ -2209,6 +2218,15 @@ "yallist": "^3.0.2" } }, + "magic-string": { + "version": "0.25.4", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.4.tgz", + "integrity": "sha512-oycWO9nEVAP2RVPbIoDoA4Y7LFIJ3xRYov93gAyJhZkET1tNuB0u7uWkZS2LpBWTJUWnmau/To8ECWRC+jKNfw==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, "markdown": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/markdown/-/markdown-0.5.0.tgz", @@ -2773,6 +2791,19 @@ "rollup-pluginutils": "^2.8.1" } }, + "rollup-plugin-commonjs": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz", + "integrity": "sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1", + "is-reference": "^1.1.2", + "magic-string": "^0.25.2", + "resolve": "^1.11.0", + "rollup-pluginutils": "^2.8.1" + } + }, "rollup-pluginutils": { "version": "2.8.2", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", @@ -2864,6 +2895,12 @@ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, + "sourcemap-codec": { + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz", + "integrity": "sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg==", + "dev": true + }, "spdx-correct": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz", @@ -3103,9 +3140,9 @@ "dev": true }, "uglify-js": { - "version": "3.6.7", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.7.tgz", - "integrity": "sha512-4sXQDzmdnoXiO+xvmTzQsfIiwrjUCSA95rSP4SEd8tDb51W2TiDOlL76Hl+Kw0Ie42PSItCW8/t6pBNCF2R48A==", + "version": "3.6.8", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.8.tgz", + "integrity": "sha512-XhHJ3S3ZyMwP8kY1Gkugqx3CJh2C3O0y8NPiSxtm1tyD/pktLAkFZsFGpuNfTZddKDQ/bbDBLAd2YyA1pbi8HQ==", "dev": true, "requires": { "commander": "~2.20.3", diff --git a/package.json b/package.json index a6ef530f10..ab5c9a15a2 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,7 @@ "description": "A markdown parser built for speed", "author": "Christopher Jeffrey", "version": "0.7.0", - "main": "./lib/marked.js", - "module": "./src/marked.js", + "main": "./src/marked.js", "bin": "./bin/marked", "man": "./man/marked.1", "files": [ @@ -49,7 +48,8 @@ "node-fetch": "^2.6.0", "rollup": "^1.26.3", "rollup-plugin-babel": "^4.3.3", - "uglify-js": "^3.6.7" + "rollup-plugin-commonjs": "^10.1.0", + "uglify-js": "^3.6.8" }, "scripts": { "test": "npm run build && jasmine --config=jasmine.json", @@ -57,9 +57,9 @@ "test:unit": "npm test -- test/unit/**/*-spec.js", "test:specs": "npm test -- test/specs/**/*-spec.js", "test:lint": "eslint bin/marked .", - "test:redos": "eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' --no-ignore lib/marked.js", + "test:redos": "npm run rollup && eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' --no-ignore lib/marked.js", "test:update": "node test/update-specs.js", - "bench": "node test/bench.js", + "bench": "npm run rollup && node test/bench.js", "lint": "eslint --fix bin/marked .", "build": "npm run rollup && npm run minify", "rollup": "rollup -c rollup.config.js", diff --git a/rollup.config.js b/rollup.config.js index 2cbe749fe3..8373372865 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,3 +1,6 @@ +const commonjs = require('rollup-plugin-commonjs'); +const babel = require('rollup-plugin-babel'); + module.exports = { input: 'src/marked.js', output: { @@ -5,7 +8,10 @@ module.exports = { format: 'umd', name: 'marked' }, - plugins: [require('rollup-plugin-babel')({ - presets: ['@babel/preset-env'] - })] + plugins: [ + commonjs(), + babel({ + presets: ['@babel/preset-env'] + }) + ] }; diff --git a/src/InlineLexer.js b/src/InlineLexer.js index 64e3a5019c..f4fa9ad20c 100644 --- a/src/InlineLexer.js +++ b/src/InlineLexer.js @@ -4,297 +4,296 @@ * https://github.com/markedjs/marked */ -import Renderer from './Renderer.js'; -import { defaults } from './defaults.js'; -import { inline } from './regexp.js'; -import { +const Renderer = require('./Renderer.js'); +const { defaults } = require('./defaults.js'); +const { inline } = require('./regexp.js'); +const { findClosingBracket, escape -} from './helpers.js'; +} = require('./helpers.js'); /** * Inline Lexer & Compiler */ -export default function InlineLexer(links, options) { - this.options = options || defaults; - this.links = links; - this.rules = inline.normal; - this.renderer = this.options.renderer || new Renderer(); - this.renderer.options = this.options; +module.exports = class InlineLexer { + constructor(links, options) { + this.options = options || defaults; + this.links = links; + this.rules = inline.normal; + this.renderer = this.options.renderer || new Renderer(); + this.renderer.options = this.options; - if (!this.links) { - throw new Error('Tokens array requires a `links` property.'); - } + if (!this.links) { + throw new Error('Tokens array requires a `links` property.'); + } - 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; + 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; + } } } -} -/** - * Expose Inline Rules - */ - -InlineLexer.rules = inline; - -/** - * Static Lexing/Compiling Method - */ + /** + * Expose Inline Rules + */ + static get rules() { + return inline; + } -InlineLexer.output = function(src, links, options) { - const inline = new InlineLexer(links, options); - return inline.output(src); -}; + /** + * Static Lexing/Compiling Method + */ + static output(src, links, options) { + const inline = new InlineLexer(links, options); + return inline.output(src); + } -/** - * Lexing/Compiling - */ + /** + * 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(cap[1]); + continue; + } -InlineLexer.prototype.output = function(src) { - let out = ''; - let link; - let text; - let href; - let title; - let cap; - let prevCapZero; + // 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; + } - while (src) { - // escape - if (cap = this.rules.escape.exec(src)) { - src = src.substring(cap[0].length); - out += escape(cap[1]); - continue; - } + src = src.substring(cap[0].length); + out += this.options.sanitize + ? this.options.sanitizer + ? this.options.sanitizer(cap[0]) + : escape(cap[0]) + : cap[0]; + continue; + } - // tag - if (cap = this.rules.tag.exec(src)) { - if (!this.inLink && /^ -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; - } else if (this.inLink && /^<\/a>/i.test(cap[0])) { + 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; } - 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.options.sanitize - ? this.options.sanitizer - ? this.options.sanitizer(cap[0]) - : escape(cap[0]) - : cap[0]; - continue; - } - - // link - if (cap = this.rules.link.exec(src)) { - const lastParenIndex = findClosingBracket(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 = ''; + // 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; } - } else { - title = cap[3] ? cap[3].slice(1, -1) : ''; + this.inLink = true; + out += this.outputLink(cap, link); + this.inLink = false; + continue; } - 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; + // 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; } - 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; + } - // 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(cap[2].trim(), true)); + continue; + } - // code - if (cap = this.rules.code.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.codespan(escape(cap[2].trim(), true)); - continue; - } + // br + if (cap = this.rules.br.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.br(); + 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; + } - // 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(this.mangle(cap[1])); + href = 'mailto:' + text; + } else { + text = escape(cap[1]); + href = text; + } + out += this.renderer.link(href, null, text); + continue; + } - // autolink - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); - if (cap[2] === '@') { - text = escape(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape(cap[1]); - href = text; + // url (gfm) + if (!this.inLink && (cap = this.rules.url.exec(src))) { + if (cap[2] === '@') { + text = escape(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(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; } - out += this.renderer.link(href, null, text); - continue; - } - // url (gfm) - if (!this.inLink && (cap = this.rules.url.exec(src))) { - if (cap[2] === '@') { - text = escape(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(cap[0]); - if (cap[1] === 'www.') { - href = 'http://' + text; + // 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(cap[0])) : cap[0]); } else { - href = text; + out += this.renderer.text(escape(this.smartypants(cap[0]))); } + continue; } - 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(cap[0])) : cap[0]); - } else { - out += this.renderer.text(escape(this.smartypants(cap[0]))); + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); } - continue; } - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } + return out; } - return out; -}; - -InlineLexer.escapes = function(text) { - return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; -}; - -/** - * Compile Link - */ - -InlineLexer.prototype.outputLink = function(cap, link) { - const href = link.href, - title = link.title ? escape(link.title) : null; - - return cap[0].charAt(0) !== '!' - ? this.renderer.link(href, title, this.output(cap[1])) - : this.renderer.image(href, title, escape(cap[1])); -}; - -/** - * Smartypants Transformations - */ + static escapes(text) { + return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; + } -InlineLexer.prototype.smartypants = function(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'); -}; + /** + * Compile Link + */ + outputLink(cap, link) { + const href = link.href, + title = link.title ? escape(link.title) : null; -/** - * Mangle Links - */ + return cap[0].charAt(0) !== '!' + ? this.renderer.link(href, title, this.output(cap[1])) + : this.renderer.image(href, title, escape(cap[1])); + } -InlineLexer.prototype.mangle = function(text) { - if (!this.options.mangle) return text; - let out = ''; - const l = text.length; - let ch; + /** + * 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'); + } - for (let i = 0; i < l; i++) { - ch = text.charCodeAt(i); - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); + /** + * 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 + ';'; } - out += '&#' + ch + ';'; - } - return out; + return out; + } }; diff --git a/src/Lexer.js b/src/Lexer.js index 84df76f192..eb104fa918 100644 --- a/src/Lexer.js +++ b/src/Lexer.js @@ -4,406 +4,406 @@ * https://github.com/markedjs/marked */ -import { defaults } from './defaults.js'; -import { block } from './regexp.js'; -import { +const { defaults } = require('./defaults.js'); +const { block } = require('./regexp.js'); +const { rtrim, splitCells, escape -} from './helpers.js'; +} = require('./helpers.js'); /** * Block Lexer */ -export default function Lexer(options) { - this.tokens = []; - this.tokens.links = Object.create(null); - this.options = options || defaults; - this.rules = block.normal; +module.exports = class Lexer { + constructor(options) { + this.tokens = []; + this.tokens.links = Object.create(null); + this.options = options || defaults; + this.rules = block.normal; + + if (this.options.pedantic) { + this.rules = block.pedantic; + } else if (this.options.gfm) { + this.rules = block.gfm; + } + } - if (this.options.pedantic) { - this.rules = block.pedantic; - } else if (this.options.gfm) { - this.rules = block.gfm; + /** + * Expose Block Rules + */ + static get rules() { + return block; } -} -/** - * Expose Block Rules - */ + /** + * Static Lex Method + */ + static lex(src, options) { + const lexer = new Lexer(options); + return lexer.lex(src); + }; + + /** + * Preprocessing + */ + lex(src) { + src = src + .replace(/\r\n|\r/g, '\n') + .replace(/\t/g, ' '); + + return this.token(src, true); + }; + + /** + * Lexing + */ + token(src, top) { + src = src.replace(/^ +$/gm, ''); + let next, + loose, + cap, + bull, + b, + item, + listStart, + listItems, + t, + space, + i, + tag, + l, + isordered, + istask, + ischecked; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } -Lexer.rules = block; + // code + if (cap = this.rules.code.exec(src)) { + const lastToken = this.tokens[this.tokens.length - 1]; + src = src.substring(cap[0].length); + // An indented code block cannot interrupt a paragraph. + if (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); + } else { + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic + ? rtrim(cap, '\n') + : cap + }); + } + continue; + } -/** - * Static Lex Method - */ + // fences + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' + }); + continue; + } -Lexer.lex = function(src, options) { - const lexer = new Lexer(options); - return lexer.lex(src); -}; + // heading + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } -/** - * Preprocessing - */ + // table no leading pipe (gfm) + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; -Lexer.prototype.lex = function(src) { - src = src - .replace(/\r\n|\r/g, '\n') - .replace(/\t/g, ' '); + 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; + } + } - return this.token(src, true); -}; + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = splitCells(item.cells[i], item.header.length); + } -/** - * Lexing - */ + this.tokens.push(item); -Lexer.prototype.token = function(src, top) { - src = src.replace(/^ +$/gm, ''); - let next, - loose, - cap, - bull, - b, - item, - listStart, - listItems, - t, - space, - i, - tag, - l, - isordered, - istask, - ischecked; - - while (src) { - // newline - if (cap = this.rules.newline.exec(src)) { - src = src.substring(cap[0].length); - if (cap[0].length > 1) { - this.tokens.push({ - type: 'space' - }); + continue; + } } - } - // code - if (cap = this.rules.code.exec(src)) { - const lastToken = this.tokens[this.tokens.length - 1]; - src = src.substring(cap[0].length); - // An indented code block cannot interrupt a paragraph. - if (lastToken && lastToken.type === 'paragraph') { - lastToken.text += '\n' + cap[0].trimRight(); - } else { - cap = cap[0].replace(/^ {4}/gm, ''); + // hr + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); this.tokens.push({ - type: 'code', - codeBlockStyle: 'indented', - text: !this.options.pedantic - ? rtrim(cap, '\n') - : cap + type: 'hr' }); + continue; } - continue; - } - - // fences - if (cap = this.rules.fences.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'code', - lang: cap[2] ? cap[2].trim() : cap[2], - text: cap[3] || '' - }); - continue; - } - - // heading - if (cap = this.rules.heading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[1].length, - text: cap[2] - }); - continue; - } - // table no leading pipe (gfm) - if (cap = this.rules.nptable.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; - - if (item.header.length === item.align.length) { + // blockquote + if (cap = this.rules.blockquote.exec(src)) { 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; - } - } + this.tokens.push({ + type: 'blockquote_start' + }); - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells(item.cells[i], item.header.length); - } + 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(item); + this.tokens.push({ + type: 'blockquote_end' + }); continue; } - } - // hr - if (cap = this.rules.hr.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' - }); - continue; - } + // list + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; - // blockquote - if (cap = this.rules.blockquote.exec(src)) { - src = src.substring(cap[0].length); + this.tokens.push(listStart); - this.tokens.push({ - type: 'blockquote_start' - }); + // Get each top-level item. + cap = cap[0].match(this.rules.item); - cap = cap[0].replace(/^ *> ?/gm, ''); + listItems = []; + next = false; + l = cap.length; + i = 0; - // Pass `top` to keep the current - // "toplevel" state. This is exactly - // how markdown.pl works. - this.token(cap, top); + for (; i < l; i++) { + item = cap[i]; + + // Remove the list item's bullet + // so it is seen as the next token. + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); + + // Outdent whatever the + // list item contains. Hacky. + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic + ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') + : item.replace(/^ {1,4}/gm, ''); + } - this.tokens.push({ - type: 'blockquote_end' - }); + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (i !== l - 1) { + b = block.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; + i = l - 1; + } + } - continue; - } + // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + loose = next || /\n\n(?!\s*$)/.test(item); + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } - // list - if (cap = this.rules.list.exec(src)) { - src = src.substring(cap[0].length); - bull = cap[2]; - isordered = bull.length > 1; - - listStart = { - type: 'list_start', - ordered: isordered, - start: isordered ? +bull : '', - loose: false - }; - - this.tokens.push(listStart); - - // Get each top-level item. - cap = cap[0].match(this.rules.item); - - listItems = []; - next = false; - l = cap.length; - i = 0; - - for (; i < l; i++) { - item = cap[i]; - - // Remove the list item's bullet - // so it is seen as the next token. - space = item.length; - item = item.replace(/^ *([*+-]|\d+\.) */, ''); - - // Outdent whatever the - // list item contains. Hacky. - if (~item.indexOf('\n ')) { - space -= item.length; - item = !this.options.pedantic - ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') - : item.replace(/^ {1,4}/gm, ''); - } + if (loose) { + listStart.loose = true; + } - // Determine whether the next list item belongs here. - // Backpedal if it does not belong in this list. - if (i !== l - 1) { - b = block.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; - i = l - 1; + // Check for task list items + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); } - } - // Determine whether item is loose or not. - // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ - // for discount behavior. - loose = next || /\n\n(?!\s*$)/.test(item); - if (i !== l - 1) { - next = item.charAt(item.length - 1) === '\n'; - if (!loose) loose = next; - } + t = { + type: 'list_item_start', + task: istask, + checked: ischecked, + loose: loose + }; - if (loose) { - listStart.loose = true; - } + listItems.push(t); + this.tokens.push(t); - // Check for task list items - istask = /^\[[ xX]\] /.test(item); - ischecked = undefined; - if (istask) { - ischecked = item[1] !== ' '; - item = item.replace(/^\[[ xX]\] +/, ''); + // Recurse. + this.token(item, false); + + this.tokens.push({ + type: 'list_item_end' + }); } - t = { - type: 'list_item_start', - task: istask, - checked: ischecked, - loose: loose - }; + if (listStart.loose) { + l = listItems.length; + i = 0; + for (; i < l; i++) { + listItems[i].loose = true; + } + } - listItems.push(t); - this.tokens.push(t); + this.tokens.push({ + type: 'list_end' + }); - // Recurse. - this.token(item, false); + continue; + } + // html + if (cap = this.rules.html.exec(src)) { + src = src.substring(cap[0].length); this.tokens.push({ - type: 'list_item_end' + type: this.options.sanitize + ? 'paragraph' + : 'html', + 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(cap[0])) : cap[0] }); + continue; } - if (listStart.loose) { - l = listItems.length; - i = 0; - for (; i < l; i++) { - listItems[i].loose = true; + // def + 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().replace(/\s+/g, ' '); + if (!this.tokens.links[tag]) { + this.tokens.links[tag] = { + href: cap[2], + title: cap[3] + }; } + continue; } - this.tokens.push({ - type: 'list_end' - }); - - continue; - } - - // html - if (cap = this.rules.html.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: this.options.sanitize - ? 'paragraph' - : 'html', - 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(cap[0])) : cap[0] - }); - continue; - } - - // def - 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().replace(/\s+/g, ' '); - if (!this.tokens.links[tag]) { - this.tokens.links[tag] = { - href: cap[2], - title: cap[3] + // table (gfm) + if (cap = this.rules.table.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] }; - } - continue; - } - // table (gfm) - if (cap = this.rules.table.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; - - if (item.header.length === item.align.length) { - src = src.substring(cap[0].length); + 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.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] = splitCells( + item.cells[i].replace(/^ *\| *| *\| *$/g, ''), + item.header.length); } - } - 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; + } + } + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2].charAt(0) === '=' ? 1 : 2, + text: cap[1] + }); continue; } - } - - // lheading - if (cap = this.rules.lheading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[2].charAt(0) === '=' ? 1 : 2, - text: cap[1] - }); - continue; - } - // top-level paragraph - if (top && (cap = this.rules.paragraph.exec(src))) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'paragraph', - text: cap[1].charAt(cap[1].length - 1) === '\n' - ? cap[1].slice(0, -1) - : cap[1] - }); - continue; - } + // top-level paragraph + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + 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)) { - // Top-level should never reach here. - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'text', - text: cap[0] - }); - continue; - } + // text + if (cap = this.rules.text.exec(src)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; + } - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } } - } - return this.tokens; + return this.tokens; + }; }; diff --git a/src/Parser.js b/src/Parser.js index 18ef56c724..2a43dbf8b9 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -4,214 +4,210 @@ * https://github.com/markedjs/marked */ -import Renderer from './Renderer.js'; -import Slugger from './Slugger.js'; -import InlineLexer from './InlineLexer.js'; -import TextRenderer from './TextRenderer.js'; -import { defaults } from './defaults.js'; -import { +const Renderer = require('./Renderer.js'); +const Slugger = require('./Slugger.js'); +const InlineLexer = require('./InlineLexer.js'); +const TextRenderer = require('./TextRenderer.js'); +const { defaults } = require('./defaults.js'); +const { merge, unescape -} from './helpers.js'; +} = require('./helpers.js'); /** * Parsing & Compiling */ -export default function Parser(options) { - this.tokens = []; - this.token = null; - this.options = options || defaults; - this.options.renderer = this.options.renderer || new Renderer(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - this.slugger = new Slugger(); -} - -/** - * Static Parse Method - */ - -Parser.parse = function(src, options) { - const parser = new Parser(options); - return parser.parse(src); -}; - -/** - * Parse Loop - */ - -Parser.prototype.parse = function(src) { - this.inline = new InlineLexer(src.links, this.options); - // use an InlineLexer with a TextRenderer to extract pure text - this.inlineText = new InlineLexer( - src.links, - merge({}, this.options, { renderer: new TextRenderer() }) - ); - this.tokens = src.reverse(); - - let out = ''; - while (this.next()) { - out += this.tok(); +module.exports = class Parser { + constructor(options) { + this.tokens = []; + this.token = null; + this.options = options || defaults; + this.options.renderer = this.options.renderer || new Renderer(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger(); } - return out; -}; - -/** - * Next Token - */ - -Parser.prototype.next = function() { - this.token = this.tokens.pop(); - return this.token; -}; - -/** - * Preview Next Token - */ - -Parser.prototype.peek = function() { - return this.tokens[this.tokens.length - 1] || 0; -}; - -/** - * Parse Text Tokens - */ - -Parser.prototype.parseText = function() { - let body = this.token.text; - - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } - - return this.inline.output(body); -}; - -/** - * Parse Current Token - */ - -Parser.prototype.tok = function() { - switch (this.token.type) { - case 'space': { - return ''; - } - case 'hr': { - return this.renderer.hr(); + /** + * Static Parse Method + */ + static parse(src, options) { + const parser = new Parser(options); + return parser.parse(src); + }; + + /** + * Parse Loop + */ + parse(src) { + this.inline = new InlineLexer(src.links, this.options); + // use an InlineLexer with a TextRenderer to extract pure text + this.inlineText = new InlineLexer( + src.links, + merge({}, this.options, { renderer: new TextRenderer() }) + ); + this.tokens = src.reverse(); + + let out = ''; + while (this.next()) { + out += this.tok(); } - case 'heading': { - return this.renderer.heading( - this.inline.output(this.token.text), - this.token.depth, - unescape(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 = ''; - let body = ''; - let i; - let row; - let cell; - let 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]; + return out; + }; + + /** + * Next Token + */ + next() { + this.token = this.tokens.pop(); + return this.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(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 (j = 0; j < row.length; j++) { + for (i = 0; i < this.token.header.length; i++) { cell += this.renderer.tablecell( - this.inline.output(row[j]), - { header: false, align: this.token.align[j] } + this.inline.output(this.token.header[i]), + { header: true, align: this.token.align[i] } ); } + header += this.renderer.tablerow(cell); - body += this.renderer.tablerow(cell); - } - return this.renderer.table(header, body); - } - case 'blockquote_start': { - let body = ''; + 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] } + ); + } - while (this.next().type !== 'blockquote_end') { - body += this.tok(); + body += this.renderer.tablerow(cell); + } + return this.renderer.table(header, body); } + case 'blockquote_start': { + body = ''; - return this.renderer.blockquote(body); - } - case 'list_start': { - let body = ''; - const ordered = this.token.ordered, - start = this.token.start; + while (this.next().type !== 'blockquote_end') { + body += this.tok(); + } - while (this.next().type !== 'list_end') { - body += this.tok(); + return this.renderer.blockquote(body); } + case 'list_start': { + body = ''; + const ordered = this.token.ordered, + start = this.token.start; - return this.renderer.list(body, ordered, start); - } - case 'list_item_start': { - let 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; + while (this.next().type !== 'list_end') { + body += this.tok(); + } + + 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) + }); + } } else { - this.tokens.push({ - type: 'text', - text: this.renderer.checkbox(checked) - }); + body += 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(); + while (this.next().type !== 'list_item_end') { + body += !loose && this.token.type === 'text' + ? this.parseText() + : this.tok(); + } + return this.renderer.listitem(body, task, checked); } - 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); + 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); + } } } - } + }; }; diff --git a/src/Renderer.js b/src/Renderer.js index a73fa3e2eb..86f9af2bc2 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -4,166 +4,168 @@ * https://github.com/markedjs/marked */ -import { defaults } from './defaults.js'; -import { +const { defaults } = require('./defaults.js'); +const { cleanUrl, escape -} from './helpers.js'; +} = require('./helpers.js'); /** * Renderer */ -export default function Renderer(options) { - this.options = options || defaults; -} - -Renderer.prototype.code = function(code, infostring, escaped) { - const lang = (infostring || '').match(/\S*/)[0]; - if (this.options.highlight) { - const out = this.options.highlight(code, lang); - if (out != null && out !== code) { - escaped = true; - code = out; - } - } - - if (!lang) { - return '
    '
    -      + (escaped ? code : escape(code, true))
    -      + '
    '; +module.exports = class Renderer { + constructor(options) { + this.options = options || defaults; } - return '
    '
    -    + (escaped ? code : escape(code, true))
    -    + '
    \n'; -}; - -Renderer.prototype.blockquote = function(quote) { - return '
    \n' + quote + '
    \n'; -}; + code(code, infostring, escaped) { + const lang = (infostring || '').match(/\S*/)[0]; + if (this.options.highlight) { + const out = this.options.highlight(code, lang); + if (out != null && out !== code) { + escaped = true; + code = out; + } + } -Renderer.prototype.html = function(html) { - return html; -}; + if (!lang) { + return '
    '
    +        + (escaped ? code : escape(code, true))
    +        + '
    '; + } -Renderer.prototype.heading = function(text, level, raw, slugger) { - if (this.options.headerIds) { - return '' - + text - + '\n'; - } - // ignore IDs - return '' + text + '\n'; -}; - -Renderer.prototype.hr = function() { - return this.options.xhtml ? '
    \n' : '
    \n'; -}; - -Renderer.prototype.list = function(body, ordered, start) { - const type = ordered ? 'ol' : 'ul', - startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; - return '<' + type + startatt + '>\n' + body + '\n'; -}; - -Renderer.prototype.listitem = function(text) { - return '
  • ' + text + '
  • \n'; -}; - -Renderer.prototype.checkbox = function(checked) { - return ' '; -}; - -Renderer.prototype.paragraph = function(text) { - return '

    ' + text + '

    \n'; -}; - -Renderer.prototype.table = function(header, body) { - if (body) body = '' + body + ''; - - return '\n' - + '\n' - + header - + '\n' - + body - + '
    \n'; -}; - -Renderer.prototype.tablerow = function(content) { - return '\n' + content + '\n'; -}; - -Renderer.prototype.tablecell = function(content, flags) { - const type = flags.header ? 'th' : 'td'; - const tag = flags.align - ? '<' + type + ' align="' + flags.align + '">' - : '<' + type + '>'; - return tag + content + '\n'; -}; - -// span level renderer -Renderer.prototype.strong = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.em = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.codespan = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.br = function() { - return this.options.xhtml ? '
    ' : '
    '; -}; - -Renderer.prototype.del = function(text) { - return '' + text + ''; -}; + + (escaped ? code : escape(code, true)) + + '\n'; + }; + + blockquote(quote) { + return '
    \n' + quote + '
    \n'; + }; + + html(html) { + return html; + }; + + heading(text, level, raw, slugger) { + if (this.options.headerIds) { + return '' + + text + + '\n'; + } + // 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 + ''; + + return '\n' + + '\n' + + header + + '\n' + + body + + '
    \n'; + }; + + tablerow(content) { + return '\n' + content + '\n'; + }; + + tablecell(content, flags) { + const type = flags.header ? 'th' : 'td'; + const tag = flags.align + ? '<' + 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(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } + let out = '
    '; + return out; + }; + + image(href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } -Renderer.prototype.link = function(href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { - return text; - } - let out = ''; - return out; -}; + let out = '' + text + '' : '>'; + return out; + }; -Renderer.prototype.image = function(href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { + text(text) { return text; - } - - let out = '' + text + '' : '>'; - return out; -}; - -Renderer.prototype.text = function(text) { - return text; + }; }; diff --git a/src/Slugger.js b/src/Slugger.js index 726e2b492c..ab8781b681 100644 --- a/src/Slugger.js +++ b/src/Slugger.js @@ -8,29 +8,30 @@ * Slugger generates header id */ -export default function Slugger() { - this.seen = {}; -} - -/** - * Convert string to unique id - */ +module.exports = class Slugger { + constructor() { + this.seen = {}; + } -Slugger.prototype.slug = function(value) { - let slug = value - .toLowerCase() - .trim() - .replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '') - .replace(/\s/g, '-'); + /** + * Convert string to unique id + */ + slug(value) { + let slug = value + .toLowerCase() + .trim() + .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; + 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; + return slug; + }; }; diff --git a/src/TextRenderer.js b/src/TextRenderer.js index ca48bf76ce..b54c7724df 100644 --- a/src/TextRenderer.js +++ b/src/TextRenderer.js @@ -9,23 +9,37 @@ * returns only the textual part of the token */ -export default function TextRenderer() {} +module.exports = class TextRenderer { + // no need for block level renderers + strong(text) { + return text; + } -// no need for block level renderers + em(text) { + return text; + } -TextRenderer.prototype.strong = -TextRenderer.prototype.em = -TextRenderer.prototype.codespan = -TextRenderer.prototype.del = -TextRenderer.prototype.text = function(text) { - return text; -}; + codespan(text) { + return text; + } -TextRenderer.prototype.link = -TextRenderer.prototype.image = function(href, title, text) { - return '' + text; -}; + del(text) { + return text; + } + + text(text) { + return text; + } + + link(href, title, text) { + return '' + text; + } + + image(href, title, text) { + return '' + text; + } -TextRenderer.prototype.br = function() { - return ''; + br() { + return ''; + } }; diff --git a/src/defaults.js b/src/defaults.js index 5e1cca053f..4ff3e5a9b3 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -1,6 +1,6 @@ -export let defaults = getDefaults(); +let defaults = getDefaults(); -export function getDefaults() { +function getDefaults() { return { baseUrl: null, breaks: false, @@ -21,6 +21,12 @@ export function getDefaults() { }; } -export function changeDefaults(newDefaults) { +function changeDefaults(newDefaults) { defaults = newDefaults; } + +module.exports = { + defaults, + getDefaults, + changeDefaults +}; diff --git a/src/helpers.js b/src/helpers.js index 715899406c..497434303e 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -8,34 +8,34 @@ * Helpers */ -export function escape(html, encode) { - const escapeTest = /[&<>"']/; - const escapeReplace = /[&<>"']/g; - const replacements = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - - const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; - const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; - +function escape(html, encode) { if (encode) { - if (escapeTest.test(html)) { - return html.replace(escapeReplace, function(ch) { return replacements[ch]; }); + if (escape.escapeTest.test(html)) { + return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; }); } } else { - if (escapeTestNoEncode.test(html)) { - return html.replace(escapeReplaceNoEncode, function(ch) { return replacements[ch]; }); + if (escape.escapeTestNoEncode.test(html)) { + return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; }); } } return html; } -export function unescape(html) { +escape.escapeTest = /[&<>"']/; +escape.escapeReplace = /[&<>"']/g; +escape.replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' +}; + +escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; +escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; + +function unescape(html) { // explicitly match decimal, hex, and named HTML entities return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { n = n.toLowerCase(); @@ -49,7 +49,7 @@ export function unescape(html) { }); } -export function edit(regex, opt) { +function edit(regex, opt) { regex = regex.source || regex; opt = opt || ''; return { @@ -65,7 +65,7 @@ export function edit(regex, opt) { }; } -export function cleanUrl(sanitize, base, href) { +function cleanUrl(sanitize, base, href) { if (sanitize) { let prot; try { @@ -79,7 +79,6 @@ export function cleanUrl(sanitize, base, href) { return null; } } - const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; if (base && !originIndependentUrl.test(href)) { href = resolveUrl(base, href); } @@ -91,18 +90,18 @@ export function cleanUrl(sanitize, base, href) { return href; } -export function resolveUrl(base, href) { - if (!resolveUrl.baseUrls[' ' + base]) { +function resolveUrl(base, href) { + if (!baseUrls[' ' + base]) { // we can ignore everything in base after the last slash of its path component, // but we might need to add _that_ // https://tools.ietf.org/html/rfc3986#section-3 if (/^[^:]+:\/*[^/]*$/.test(base)) { - resolveUrl.baseUrls[' ' + base] = base + '/'; + baseUrls[' ' + base] = base + '/'; } else { - resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); + baseUrls[' ' + base] = rtrim(base, '/', true); } } - base = resolveUrl.baseUrls[' ' + base]; + base = baseUrls[' ' + base]; const relativeBase = base.indexOf(':') === -1; if (href.slice(0, 2) === '//') { @@ -119,15 +118,16 @@ export function resolveUrl(base, href) { return base + href; } } -resolveUrl.baseUrls = {}; +const baseUrls = {}; +const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; -export function noop() {} +function noop() {} noop.exec = noop; -export function merge(obj) { - let i = 1; - let target; - let key; +function merge(obj) { + let i = 1, + target, + key; for (; i < arguments.length; i++) { target = arguments[i]; @@ -141,23 +141,23 @@ export function merge(obj) { return obj; } -export function splitCells(tableRow, count) { +function splitCells(tableRow, count) { // ensure that every cell-delimiting pipe has a space // before it to distinguish it from an escaped pipe const row = tableRow.replace(/\|/g, function(match, offset, str) { - let escaped = false; - let curr = offset; - while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; - if (escaped) { - // odd number of slashes means | is escaped - // so we leave it alone - return '|'; - } else { - // add space before unescaped | - return ' |'; - } - }); - const cells = row.split(/ \|/); + let escaped = false, + curr = offset; + while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }), + cells = row.split(/ \|/); let i = 0; if (cells.length > count) { @@ -176,8 +176,9 @@ export function splitCells(tableRow, count) { // Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). // /c*$/ is vulnerable to REDOS. // invert: Remove suffix of non-c chars instead. Default falsey. -export function rtrim(str, c, invert) { - if (str.length === 0) { +function rtrim(str, c, invert) { + const l = str.length; + if (l === 0) { return ''; } @@ -185,8 +186,8 @@ export function rtrim(str, c, invert) { let suffLen = 0; // Step left until we fail to match the invert condition. - while (suffLen < str.length) { - const currChar = str.charAt(str.length - suffLen - 1); + while (suffLen < l) { + const currChar = str.charAt(l - suffLen - 1); if (currChar === c && !invert) { suffLen++; } else if (currChar !== c && invert) { @@ -196,15 +197,17 @@ export function rtrim(str, c, invert) { } } - return str.substr(0, str.length - suffLen); + return str.substr(0, l - suffLen); } -export function findClosingBracket(str, b) { +function findClosingBracket(str, b) { if (str.indexOf(b[1]) === -1) { return -1; } - let level = 0; - for (let i = 0; i < str.length; i++) { + const l = str.length; + let level = 0, + i = 0; + for (; i < l; i++) { if (str[i] === '\\') { i++; } else if (str[i] === b[0]) { @@ -219,8 +222,22 @@ export function findClosingBracket(str, b) { return -1; } -export function checkSanitizeDeprecation(opt) { +function checkSanitizeDeprecation(opt) { if (opt && opt.sanitize && !opt.silent) { console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); } } + +module.exports = { + escape, + unescape, + edit, + cleanUrl, + resolveUrl, + noop, + merge, + splitCells, + rtrim, + findClosingBracket, + checkSanitizeDeprecation +}; diff --git a/src/marked.js b/src/marked.js index b97c5577e7..e9eb161079 100644 --- a/src/marked.js +++ b/src/marked.js @@ -4,28 +4,28 @@ * https://github.com/markedjs/marked */ -import Lexer from './Lexer.js'; -import Parser from './Parser.js'; -import Renderer from './Renderer.js'; -import TextRenderer from './TextRenderer.js'; -import InlineLexer from './InlineLexer.js'; -import Slugger from './Slugger.js'; -import { +const Lexer = require('./Lexer.js'); +const Parser = require('./Parser.js'); +const Renderer = require('./Renderer.js'); +const TextRenderer = require('./TextRenderer.js'); +const InlineLexer = require('./InlineLexer.js'); +const Slugger = require('./Slugger.js'); +const { merge, checkSanitizeDeprecation, escape -} from './helpers.js'; -import { +} = require('./helpers.js'); +const { getDefaults, changeDefaults, defaults -} from './defaults.js'; +} = require('./defaults.js'); /** * Marked */ -export default function marked(src, opt, callback) { +function marked(src, opt, callback) { // throw error in case of non string input if (typeof src === 'undefined' || src === null) { throw new Error('marked(): input parameter is undefined or null'); @@ -43,11 +43,10 @@ export default function marked(src, opt, callback) { opt = merge({}, marked.defaults, opt || {}); checkSanitizeDeprecation(opt); - const highlight = opt.highlight; - let tokens; - let pending; - let i = 0; + let tokens, + pending, + i = 0; try { tokens = Lexer.lex(src, opt); @@ -106,10 +105,9 @@ export default function marked(src, opt, callback) { return; } try { - opt = merge({}, marked.defaults, opt || {}); + if (opt) opt = merge({}, marked.defaults, opt); checkSanitizeDeprecation(opt); - const t = Lexer.lex(src, opt); - return Parser.parse(t, opt); + return Parser.parse(Lexer.lex(src, opt), opt); } catch (e) { e.message += '\nPlease report this to https://github.com/markedjs/marked.'; if ((opt || marked.defaults).silent) { @@ -128,20 +126,13 @@ export default function marked(src, opt, callback) { marked.options = marked.setOptions = function(opt) { merge(marked.defaults, opt); + changeDefaults(marked.defaults); return marked; }; marked.getDefaults = getDefaults; -Object.defineProperty(marked, 'defaults', { - get() { - return defaults; - }, - - set(value) { - changeDefaults(value); - } -}); +marked.defaults = defaults; /** * Expose @@ -162,3 +153,5 @@ marked.inlineLexer = InlineLexer.output; marked.Slugger = Slugger; marked.parse = marked; + +module.exports = marked; diff --git a/src/regexp.js b/src/regexp.js index 99ba02f65e..ba3517365d 100644 --- a/src/regexp.js +++ b/src/regexp.js @@ -4,17 +4,17 @@ * https://github.com/markedjs/marked */ -import { +const { noop, edit, merge -} from './helpers.js'; +} = require('./helpers.js'); /** * Block-Level Grammar */ -export const block = { +const block = { newline: /^\n+/, code: /^( {4}[^\n]+\n*)+/, fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, @@ -137,7 +137,7 @@ block.pedantic = merge({}, block.normal, { * Inline-Level Grammar */ -export const inline = { +const inline = { escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, url: noop, @@ -241,3 +241,8 @@ inline.breaks = merge({}, inline.gfm, { .replace(/\{2,\}/g, '*') .getRegex() }); + +module.exports = { + block, + inline +}; diff --git a/test/bench.js b/test/bench.js index 247728c5d4..3932453529 100644 --- a/test/bench.js +++ b/test/bench.js @@ -2,7 +2,8 @@ const path = require('path'); const htmlDiffer = require('./helpers/html-differ.js'); const { loadFiles } = require('./helpers/load.js'); -let marked = require('../'); +let marked = require('../lib/marked.js'); +const es6marked = require('../src/marked.js'); /** * Load specs @@ -26,6 +27,18 @@ function runBench(options) { options = options || {}; const specs = load(); + marked.setOptions({ + gfm: false, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: false + }); + if (options.marked) { + marked.setOptions(options.marked); + } + bench('non marked', specs, marked); + // Non-GFM, Non-pedantic marked.setOptions({ gfm: false, @@ -37,7 +50,19 @@ function runBench(options) { if (options.marked) { marked.setOptions(options.marked); } - bench('marked', specs, marked); + bench('es5 marked', specs, marked); + + es6marked.setOptions({ + gfm: false, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: false + }); + if (options.marked) { + es6marked.setOptions(options.marked); + } + bench('es6 marked', specs, es6marked); // GFM marked.setOptions({ @@ -50,7 +75,19 @@ function runBench(options) { if (options.marked) { marked.setOptions(options.marked); } - bench('marked (gfm)', specs, marked); + bench('es5 marked (gfm)', specs, marked); + + es6marked.setOptions({ + gfm: true, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: false + }); + if (options.marked) { + es6marked.setOptions(options.marked); + } + bench('es6 marked (gfm)', specs, es6marked); // Pedantic marked.setOptions({ @@ -63,7 +100,19 @@ function runBench(options) { if (options.marked) { marked.setOptions(options.marked); } - bench('marked (pedantic)', specs, marked); + bench('es5 marked (pedantic)', specs, marked); + + es6marked.setOptions({ + gfm: false, + breaks: false, + pedantic: true, + sanitize: false, + smartLists: false + }); + if (options.marked) { + es6marked.setOptions(options.marked); + } + bench('es6 marked (pedantic)', specs, es6marked); try { bench('commonmark', specs, (() => { From 507c136309eb2b84de272cfef7b38ad260443255 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 11:11:39 -0600 Subject: [PATCH 07/33] run build --- lib/marked.js | 2134 +++++++++++++++++++++++++++---------------------- marked.min.js | 40 +- 2 files changed, 1187 insertions(+), 987 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index ae9ee3ead0..2570f1d254 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -18,7 +18,30 @@ return _typeof(obj); } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + var defaults = getDefaults(); + function getDefaults() { return { baseUrl: null, @@ -39,10 +62,17 @@ xhtml: false }; } + function changeDefaults(newDefaults) { defaults = newDefaults; } + var defaults_1 = { + defaults: defaults, + getDefaults: getDefaults, + changeDefaults: changeDefaults + }; + /** * marked - a markdown parser * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) @@ -53,34 +83,35 @@ * Helpers */ function escape(html, encode) { - var escapeTest = /[&<>"']/; - var escapeReplace = /[&<>"']/g; - var replacements = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; - var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; - if (encode) { - if (escapeTest.test(html)) { - return html.replace(escapeReplace, function (ch) { - return replacements[ch]; + if (escape.escapeTest.test(html)) { + return html.replace(escape.escapeReplace, function (ch) { + return escape.replacements[ch]; }); } } else { - if (escapeTestNoEncode.test(html)) { - return html.replace(escapeReplaceNoEncode, function (ch) { - return replacements[ch]; + if (escape.escapeTestNoEncode.test(html)) { + return html.replace(escape.escapeReplaceNoEncode, function (ch) { + return escape.replacements[ch]; }); } } return html; } + + escape.escapeTest = /[&<>"']/; + escape.escapeReplace = /[&<>"']/g; + escape.replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; + escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; + function unescape(html) { // explicitly match decimal, hex, and named HTML entities return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function (_, n) { @@ -94,6 +125,7 @@ return ''; }); } + function edit(regex, opt) { regex = regex.source || regex; opt = opt || ''; @@ -109,6 +141,7 @@ } }; } + function cleanUrl(sanitize, base, href) { if (sanitize) { var prot; @@ -124,8 +157,6 @@ } } - var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; - if (base && !originIndependentUrl.test(href)) { href = resolveUrl(base, href); } @@ -138,19 +169,20 @@ return href; } + function resolveUrl(base, href) { - if (!resolveUrl.baseUrls[' ' + base]) { + if (!baseUrls[' ' + base]) { // we can ignore everything in base after the last slash of its path component, // but we might need to add _that_ // https://tools.ietf.org/html/rfc3986#section-3 if (/^[^:]+:\/*[^/]*$/.test(base)) { - resolveUrl.baseUrls[' ' + base] = base + '/'; + baseUrls[' ' + base] = base + '/'; } else { - resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); + baseUrls[' ' + base] = rtrim(base, '/', true); } } - base = resolveUrl.baseUrls[' ' + base]; + base = baseUrls[' ' + base]; var relativeBase = base.indexOf(':') === -1; if (href.slice(0, 2) === '//') { @@ -169,13 +201,18 @@ return base + href; } } - resolveUrl.baseUrls = {}; + + var baseUrls = {}; + var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; + function noop() {} + noop.exec = noop; + function merge(obj) { - var i = 1; - var target; - var key; + var i = 1, + target, + key; for (; i < arguments.length; i++) { target = arguments[i]; @@ -189,12 +226,13 @@ return obj; } + function splitCells(tableRow, count) { // ensure that every cell-delimiting pipe has a space // before it to distinguish it from an escaped pipe var row = tableRow.replace(/\|/g, function (match, offset, str) { - var escaped = false; - var curr = offset; + var escaped = false, + curr = offset; while (--curr >= 0 && str[curr] === '\\') { escaped = !escaped; @@ -208,8 +246,8 @@ // add space before unescaped | return ' |'; } - }); - var cells = row.split(/ \|/); + }), + cells = row.split(/ \|/); var i = 0; if (cells.length > count) { @@ -230,16 +268,19 @@ // /c*$/ is vulnerable to REDOS. // invert: Remove suffix of non-c chars instead. Default falsey. + function rtrim(str, c, invert) { - if (str.length === 0) { + var l = str.length; + + if (l === 0) { return ''; } // Length of suffix matching the invert condition. var suffLen = 0; // Step left until we fail to match the invert condition. - while (suffLen < str.length) { - var currChar = str.charAt(str.length - suffLen - 1); + while (suffLen < l) { + var currChar = str.charAt(l - suffLen - 1); if (currChar === c && !invert) { suffLen++; @@ -250,16 +291,19 @@ } } - return str.substr(0, str.length - suffLen); + return str.substr(0, l - suffLen); } + function findClosingBracket(str, b) { if (str.indexOf(b[1]) === -1) { return -1; } - var level = 0; + var l = str.length; + var level = 0, + i = 0; - for (var i = 0; i < str.length; i++) { + for (; i < l; i++) { if (str[i] === '\\') { i++; } else if (str[i] === b[0]) { @@ -275,17 +319,36 @@ return -1; } + function checkSanitizeDeprecation(opt) { if (opt && opt.sanitize && !opt.silent) { console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); } } + var helpers = { + escape: escape, + unescape: unescape, + edit: edit, + cleanUrl: cleanUrl, + resolveUrl: resolveUrl, + noop: noop, + merge: merge, + splitCells: splitCells, + rtrim: rtrim, + findClosingBracket: findClosingBracket, + checkSanitizeDeprecation: checkSanitizeDeprecation + }; + /** * marked - a markdown parser * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ + + var noop$1 = helpers.noop, + edit$1 = helpers.edit, + merge$1 = helpers.merge; /** * Block-Level Grammar */ @@ -309,8 +372,8 @@ + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + ')', def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, - nptable: noop, - table: noop, + nptable: noop$1, + table: noop$1, lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, // regex template, placeholders will be replaced according to different paragraph // interruption rules of commonmark and the original markdown spec: @@ -319,29 +382,29 @@ }; block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; - block.def = edit(block.def).replace('label', block._label).replace('title', block._title).getRegex(); + block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex(); block.bullet = /(?:[*+-]|\d{1,9}\.)/; block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; - block.item = edit(block.item, 'gm').replace(/bull/g, block.bullet).getRegex(); - block.list = edit(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex(); + block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex(); + block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex(); 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', ' {0,3}#{1,6} +').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + block.html = edit$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(); + block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} +').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt .replace('html', ')|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks .getRegex(); - block.blockquote = edit(block.blockquote).replace('paragraph', block.paragraph).getRegex(); + block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex(); /** * Normal Block Grammar */ - block.normal = merge({}, block); + block.normal = merge$1({}, block); /** * GFM Block Grammar */ - block.gfm = merge({}, block.normal, { + block.gfm = merge$1({}, block.normal, { nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ }); @@ -349,14 +412,14 @@ * Pedantic grammar (original John Gruber's loose markdown specification) */ - block.pedantic = merge({}, block.normal, { - html: edit('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)' // closed tag + block.pedantic = merge$1({}, block.normal, { + html: edit$1('^ *(?: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+|$)/, heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, - fences: noop, + fences: noop$1, // fences not supported - paragraph: edit(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex() + paragraph: edit$1(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex() }); /** * Inline-Level Grammar @@ -365,7 +428,7 @@ var inline = { escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, - url: noop, + url: noop$1, tag: '^comment' + '|^' // self-closing tag + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. @@ -379,565 +442,627 @@ 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: noop, + del: noop$1, text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; - inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); + inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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(); + inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).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.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex(); inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; - inline.link = edit(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex(); - inline.reflink = edit(inline.reflink).replace('label', inline._label).getRegex(); + inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex(); + inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex(); /** * Normal Inline Grammar */ - inline.normal = merge({}, inline); + inline.normal = merge$1({}, inline); /** * Pedantic Inline Grammar */ - inline.pedantic = merge({}, inline.normal, { + inline.pedantic = merge$1({}, inline.normal, { strong: /^__(?=\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() + link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(), + reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex() }); /** * GFM Inline Grammar */ - inline.gfm = merge({}, inline.normal, { - escape: edit(inline.escape).replace('])', '~|])').getRegex(), + inline.gfm = merge$1({}, inline.normal, { + escape: edit$1(inline.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]*?(?:(?=[\\ 1) { - this.tokens.push({ - type: 'space' - }); - } - } // 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 (lastToken && lastToken.type === 'paragraph') { - lastToken.text += '\n' + cap[0].trimRight(); - } else { - cap = cap[0].replace(/^ {4}/gm, ''); - this.tokens.push({ - type: 'code', - codeBlockStyle: 'indented', - text: !this.options.pedantic ? rtrim(cap, '\n') : cap - }); - } - continue; - } // fences - - - if (cap = this.rules.fences.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'code', - lang: cap[2] ? cap[2].trim() : cap[2], - text: cap[3] || '' - }); - continue; - } // heading - - - if (cap = this.rules.heading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[1].length, - text: cap[2] - }); - continue; - } // table no leading pipe (gfm) + _createClass(Lexer, [{ + key: "lex", + /** + * Preprocessing + */ + value: function lex(src) { + src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' '); + return this.token(src, true); + } + }, { + key: "token", + + /** + * Lexing + */ + value: function token(src, top) { + src = src.replace(/^ +$/gm, ''); + var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } // code - if (cap = this.rules.nptable.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; - if (item.header.length === item.align.length) { - src = src.substring(cap[0].length); + 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. - 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'; + if (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); } else { - item.align[i] = null; + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic ? rtrim$1(cap, '\n') : cap + }); } - } - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells(item.cells[i], item.header.length); - } - - this.tokens.push(item); - continue; - } - } // hr + continue; + } // fences - if (cap = this.rules.hr.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' - }); - continue; - } // blockquote - + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' + }); + continue; + } // heading - if (cap = this.rules.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' - }); - continue; - } // list - - - if (cap = this.rules.list.exec(src)) { - src = src.substring(cap[0].length); - bull = cap[2]; - isordered = bull.length > 1; - listStart = { - type: 'list_start', - ordered: isordered, - start: isordered ? +bull : '', - loose: false - }; - this.tokens.push(listStart); // Get each top-level item. + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } // table no leading pipe (gfm) + + + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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; + } + } - cap = cap[0].match(this.rules.item); - listItems = []; - next = false; - l = cap.length; - i = 0; + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = splitCells$1(item.cells[i], item.header.length); + } - for (; i < l; i++) { - item = cap[i]; // Remove the list item's bullet - // so it is seen as the next token. + this.tokens.push(item); + continue; + } + } // hr - space = item.length; - item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the - // list item contains. Hacky. - if (~item.indexOf('\n ')) { - space -= item.length; - item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, ''); - } // Determine whether the next list item belongs here. - // Backpedal if it does not belong in this list. + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } // blockquote - if (i !== l - 1) { - b = block.bullet.exec(cap[i + 1])[0]; + if (cap = this.rules.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. - if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) { - src = cap.slice(i + 1).join('\n') + src; - i = l - 1; - } - } // Determine whether item is loose or not. - // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ - // for discount behavior. + this.token(cap, top); + this.tokens.push({ + type: 'blockquote_end' + }); + continue; + } // list + + + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; + this.tokens.push(listStart); // Get each top-level item. + + cap = cap[0].match(this.rules.item); + listItems = []; + next = false; + l = cap.length; + i = 0; + + for (; i < l; i++) { + item = cap[i]; // Remove the list item's bullet + // so it is seen as the next token. + + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the + // list item contains. Hacky. + + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, ''); + } // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + + + if (i !== l - 1) { + 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; + i = l - 1; + } + } // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + + + loose = next || /\n\n(?!\s*$)/.test(item); + + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } + if (loose) { + listStart.loose = true; + } // Check for task list items - loose = next || /\n\n(?!\s*$)/.test(item); - if (i !== l - 1) { - next = item.charAt(item.length - 1) === '\n'; - if (!loose) loose = next; - } + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; - if (loose) { - listStart.loose = true; - } // Check for task list items + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); + } + t = { + type: 'list_item_start', + 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' + }); + } - istask = /^\[[ xX]\] /.test(item); - ischecked = undefined; + if (listStart.loose) { + l = listItems.length; + i = 0; - if (istask) { - ischecked = item[1] !== ' '; - item = item.replace(/^\[[ xX]\] +/, ''); - } + for (; i < l; i++) { + listItems[i].loose = true; + } + } - t = { - type: 'list_item_start', - task: istask, - checked: ischecked, - loose: loose - }; - listItems.push(t); - this.tokens.push(t); // Recurse. + this.tokens.push({ + type: 'list_end' + }); + continue; + } // html - this.token(item, false); - this.tokens.push({ - type: 'list_item_end' - }); - } - if (listStart.loose) { - l = listItems.length; - i = 0; + if (cap = this.rules.html.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize ? 'paragraph' : 'html', + 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] + }); + continue; + } // def - for (; i < l; i++) { - listItems[i].loose = true; - } - } - this.tokens.push({ - type: 'list_end' - }); - continue; - } // html + 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().replace(/\s+/g, ' '); + if (!this.tokens.links[tag]) { + this.tokens.links[tag] = { + href: cap[2], + title: cap[3] + }; + } - if (cap = this.rules.html.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: this.options.sanitize ? 'paragraph' : 'html', - 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(cap[0]) : cap[0] - }); - continue; - } // def + continue; + } // table (gfm) + + + if (cap = this.rules.table.exec(src)) { + item = { + type: 'table', + header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length); + } - 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().replace(/\s+/g, ' '); + this.tokens.push(item); + continue; + } + } // lheading - if (!this.tokens.links[tag]) { - this.tokens.links[tag] = { - href: cap[2], - title: cap[3] - }; - } - continue; - } // table (gfm) + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2].charAt(0) === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } // top-level paragraph - if (cap = this.rules.table.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1] + }); + continue; + } // text - 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; - } + if (cap = this.rules.text.exec(src)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; } - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length); + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); } - - this.tokens.push(item); - continue; } - } // lheading - - - if (cap = this.rules.lheading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[2].charAt(0) === '=' ? 1 : 2, - text: cap[1] - }); - continue; - } // top-level paragraph - - - if (top && (cap = this.rules.paragraph.exec(src))) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'paragraph', - 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)) { - // Top-level should never reach here. - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'text', - text: cap[0] - }); - continue; + return this.tokens; } - - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + }], [{ + key: "lex", + + /** + * Static Lex Method + */ + value: function lex(src, options) { + var lexer = new Lexer(options); + return lexer.lex(src); } - } + }, { + key: "rules", + get: function get() { + return block$1; + } + }]); - return this.tokens; - }; + return Lexer; + }(); /** * marked - a markdown parser * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ + + var defaults$2 = defaults_1.defaults; + var cleanUrl$1 = helpers.cleanUrl, + escape$2 = helpers.escape; /** * Renderer */ - function Renderer(options) { - this.options = options || defaults; - } - - Renderer.prototype.code = function (code, infostring, escaped) { - var lang = (infostring || '').match(/\S*/)[0]; + var Renderer_1 = + /*#__PURE__*/ + function () { + function Renderer(options) { + _classCallCheck(this, Renderer); - if (this.options.highlight) { - var out = this.options.highlight(code, lang); - - if (out != null && out !== code) { - escaped = true; - code = out; - } - } - - if (!lang) { - return '
    ' + (escaped ? code : escape(code, true)) + '
    '; + this.options = options || defaults$2; } - return '
    ' + (escaped ? code : escape(code, true)) + '
    \n'; - }; - - Renderer.prototype.blockquote = function (quote) { - return '
    \n' + quote + '
    \n'; - }; - - Renderer.prototype.html = function (html) { - return html; - }; - - Renderer.prototype.heading = function (text, level, raw, slugger) { - if (this.options.headerIds) { - return '' + text + '\n'; - } // ignore IDs + _createClass(Renderer, [{ + key: "code", + value: function code(_code, infostring, escaped) { + var lang = (infostring || '').match(/\S*/)[0]; + if (this.options.highlight) { + var out = this.options.highlight(_code, lang); - return '' + text + '\n'; - }; - - Renderer.prototype.hr = function () { - return this.options.xhtml ? '
    \n' : '
    \n'; - }; - - Renderer.prototype.list = function (body, ordered, start) { - var type = ordered ? 'ol' : 'ul', - startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; - return '<' + type + startatt + '>\n' + body + '\n'; - }; - - Renderer.prototype.listitem = function (text) { - return '
  • ' + text + '
  • \n'; - }; - - Renderer.prototype.checkbox = function (checked) { - return ' '; - }; - - Renderer.prototype.paragraph = function (text) { - return '

    ' + text + '

    \n'; - }; - - Renderer.prototype.table = function (header, body) { - if (body) body = '' + body + ''; - return '\n' + '\n' + header + '\n' + body + '
    \n'; - }; - - Renderer.prototype.tablerow = function (content) { - return '\n' + content + '\n'; - }; - - Renderer.prototype.tablecell = function (content, flags) { - var type = flags.header ? 'th' : 'td'; - var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; - return tag + content + '\n'; - }; // span level renderer - - - Renderer.prototype.strong = function (text) { - return '' + text + ''; - }; - - Renderer.prototype.em = function (text) { - return '' + text + ''; - }; - - Renderer.prototype.codespan = function (text) { - return '' + text + ''; - }; + if (out != null && out !== _code) { + escaped = true; + _code = out; + } + } - Renderer.prototype.br = function () { - return this.options.xhtml ? '
    ' : '
    '; - }; + if (!lang) { + return '
    ' + (escaped ? _code : escape$2(_code, true)) + '
    '; + } - Renderer.prototype.del = function (text) { - return '' + text + ''; - }; + return '
    ' + (escaped ? _code : escape$2(_code, true)) + '
    \n'; + } + }, { + key: "blockquote", + value: function blockquote(quote) { + return '
    \n' + quote + '
    \n'; + } + }, { + key: "html", + value: function html(_html) { + return _html; + } + }, { + key: "heading", + value: function heading(text, level, raw, slugger) { + if (this.options.headerIds) { + return '' + text + '\n'; + } // ignore IDs - Renderer.prototype.link = function (href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { - return text; - } + return '' + text + '\n'; + } + }, { + key: "hr", + value: function hr() { + return this.options.xhtml ? '
    \n' : '
    \n'; + } + }, { + key: "list", + value: function list(body, ordered, start) { + var type = ordered ? 'ol' : 'ul', + startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; + return '<' + type + startatt + '>\n' + body + '\n'; + } + }, { + key: "listitem", + value: function listitem(text) { + return '
  • ' + text + '
  • \n'; + } + }, { + key: "checkbox", + value: function checkbox(checked) { + return ' '; + } + }, { + key: "paragraph", + value: function paragraph(text) { + return '

    ' + text + '

    \n'; + } + }, { + key: "table", + value: function table(header, body) { + if (body) body = '' + body + ''; + return '\n' + '\n' + header + '\n' + body + '
    \n'; + } + }, { + key: "tablerow", + value: function tablerow(content) { + return '\n' + content + '\n'; + } + }, { + key: "tablecell", + value: function tablecell(content, flags) { + var type = flags.header ? 'th' : 'td'; + var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; + return tag + content + '\n'; + } + }, { + key: "strong", + // span level renderer + value: function strong(text) { + return '' + text + ''; + } + }, { + key: "em", + value: function em(text) { + return '' + text + ''; + } + }, { + key: "codespan", + value: function codespan(text) { + return '' + text + ''; + } + }, { + key: "br", + value: function br() { + return this.options.xhtml ? '
    ' : '
    '; + } + }, { + key: "del", + value: function del(text) { + return '' + text + ''; + } + }, { + key: "link", + value: function link(href, title, text) { + href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); - var out = '
    '; - return out; - }; + if (title) { + out += ' title="' + title + '"'; + } - Renderer.prototype.image = function (href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + out += '>' + text + ''; + return out; + } + }, { + key: "image", + value: function image(href, title, text) { + href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { - return text; - } + if (href === null) { + return text; + } - var out = '' + text + '' : '>'; - return out; - }; + out += this.options.xhtml ? '/>' : '>'; + return out; + } + }, { + key: "text", + value: function text(_text) { + return _text; + } + }]); - Renderer.prototype.text = function (text) { - return text; - }; + return Renderer; + }(); /** * marked - a markdown parser @@ -948,319 +1073,358 @@ /** * Slugger generates header id */ - function Slugger() { - this.seen = {}; - } - /** - * Convert string to unique id - */ + var Slugger_1 = + /*#__PURE__*/ + function () { + function Slugger() { + _classCallCheck(this, Slugger); - Slugger.prototype.slug = function (value) { - var slug = value.toLowerCase().trim().replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-'); + this.seen = {}; + } + /** + * Convert string to unique id + */ - if (this.seen.hasOwnProperty(slug)) { - var originalSlug = slug; - do { - this.seen[originalSlug]++; - slug = originalSlug + '-' + this.seen[originalSlug]; - } while (this.seen.hasOwnProperty(slug)); - } + _createClass(Slugger, [{ + key: "slug", + value: function slug(value) { + var slug = value.toLowerCase().trim().replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-'); - this.seen[slug] = 0; - return slug; - }; + 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; + }(); /** * marked - a markdown parser * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ + + var defaults$3 = defaults_1.defaults; + var inline$1 = regexp.inline; + var findClosingBracket$1 = helpers.findClosingBracket, + escape$3 = helpers.escape; /** * Inline Lexer & Compiler */ - function InlineLexer(links, options) { - this.options = options || defaults; - this.links = links; - this.rules = inline.normal; - this.renderer = this.options.renderer || new Renderer(); - this.renderer.options = this.options; + var InlineLexer_1 = + /*#__PURE__*/ + function () { + function InlineLexer(links, options) { + _classCallCheck(this, InlineLexer); - if (!this.links) { - throw new Error('Tokens array requires a `links` property.'); - } + this.options = options || defaults$3; + this.links = links; + this.rules = inline$1.normal; + this.renderer = this.options.renderer || new Renderer_1(); + this.renderer.options = this.options; - 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; + if (!this.links) { + throw new Error('Tokens array requires a `links` property.'); } - } - } - /** - * Expose Inline Rules - */ - InlineLexer.rules = inline; - /** - * Static Lexing/Compiling Method - */ - - InlineLexer.output = function (src, links, options) { - var inline = new InlineLexer(links, options); - return inline.output(src); - }; - /** - * Lexing/Compiling - */ + 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 + */ + + + _createClass(InlineLexer, [{ + key: "output", + + /** + * Lexing/Compiling + */ + value: 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; + } - InlineLexer.prototype.output = function (src) { - var out = ''; - var link; - var text; - var href; - var title; - var cap; - var prevCapZero; - - while (src) { - // escape - if (cap = this.rules.escape.exec(src)) { - src = src.substring(cap[0].length); - out += escape(cap[1]); - continue; - } // tag - - - if (cap = this.rules.tag.exec(src)) { - if (!this.inLink && /^/i.test(cap[0])) { - this.inLink = false; - } + src = src.substring(cap[0].length); + out += this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]; + continue; + } // link - 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.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(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] = ''; + } - if (cap = this.rules.link.exec(src)) { - var lastParenIndex = findClosingBracket(cap[2], '()'); + src = src.substring(cap[0].length); + this.inLink = true; + href = 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] = ''; - } + if (this.options.pedantic) { + link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); - src = src.substring(cap[0].length); - this.inLink = true; - href = cap[2]; + if (link) { + href = link[1]; + title = link[3]; + } else { + title = ''; + } + } else { + title = cap[3] ? cap[3].slice(1, -1) : ''; + } - if (this.options.pedantic) { - link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href); + 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 (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; + } - 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()]; + this.inLink = true; + out += this.outputLink(cap, link); + this.inLink = false; + continue; + } // strong - 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.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.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.code.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.codespan(escape(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.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.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; + } - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); + out += this.renderer.link(href, null, text); + continue; + } // url (gfm) - if (cap[2] === '@') { - text = escape(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape(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 (!this.inLink && (cap = this.rules.url.exec(src))) { - if (cap[2] === '@') { - text = escape(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]); + if (cap[1] === 'www.') { + href = 'http://' + text; + } else { + href = text; + } + } - text = escape(cap[0]); + src = src.substring(cap[0].length); + out += this.renderer.link(href, null, text); + continue; + } // text - 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]))); + } - if (cap = this.rules.text.exec(src)) { - src = src.substring(cap[0].length); + continue; + } - if (this.inRawBlock) { - out += this.renderer.text(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0]); - } else { - out += this.renderer.text(escape(this.smartypants(cap[0]))); + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } } - continue; + return out; } - - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + }, { + key: "outputLink", + + /** + * Compile Link + */ + value: 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])); } - } - - 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 = link.href, - title = link.title ? escape(link.title) : null; - return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) : this.renderer.image(href, title, escape(cap[1])); - }; - /** - * Smartypants Transformations - */ - - - InlineLexer.prototype.smartypants = function (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 - */ + /** + * Smartypants Transformations + */ + + }, { + key: "smartypants", + value: 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 + */ + + }, { + key: "mangle", + value: 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); - InlineLexer.prototype.mangle = function (text) { - if (!this.options.mangle) return text; - var out = ''; - var l = text.length; - var ch; + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } - for (var i = 0; i < l; i++) { - ch = text.charCodeAt(i); + out += '&#' + ch + ';'; + } - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); + return out; } + }], [{ + key: "output", + + /** + * Static Lexing/Compiling Method + */ + value: function output(src, links, options) { + var inline = new InlineLexer(links, options); + return inline.output(src); + } + }, { + key: "escapes", + value: function escapes(text) { + return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; + } + }, { + key: "rules", + get: function get() { + return inline$1; + } + }]); - out += '&#' + ch + ';'; - } - - return out; - }; + return InlineLexer; + }(); /** * marked - a markdown parser @@ -1272,244 +1436,317 @@ * TextRenderer * returns only the textual part of the token */ - function TextRenderer() {} // no need for block level renderers - - TextRenderer.prototype.strong = TextRenderer.prototype.em = TextRenderer.prototype.codespan = TextRenderer.prototype.del = TextRenderer.prototype.text = function (text) { - return text; - }; + var TextRenderer_1 = + /*#__PURE__*/ + function () { + function TextRenderer() { + _classCallCheck(this, TextRenderer); + } - TextRenderer.prototype.link = TextRenderer.prototype.image = function (href, title, text) { - return '' + text; - }; + _createClass(TextRenderer, [{ + key: "strong", + // no need for block level renderers + value: function strong(text) { + return text; + } + }, { + key: "em", + value: function em(text) { + return text; + } + }, { + key: "codespan", + value: function codespan(text) { + return text; + } + }, { + key: "del", + value: function del(text) { + return text; + } + }, { + key: "text", + value: function text(_text) { + return _text; + } + }, { + key: "link", + value: function link(href, title, text) { + return '' + text; + } + }, { + key: "image", + value: function image(href, title, text) { + return '' + text; + } + }, { + key: "br", + value: function br() { + return ''; + } + }]); - TextRenderer.prototype.br = function () { - return ''; - }; + return TextRenderer; + }(); /** * marked - a markdown parser * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ - /** - * Parsing & Compiling - */ - - function Parser(options) { - this.tokens = []; - this.token = null; - this.options = options || defaults; - this.options.renderer = this.options.renderer || new Renderer(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - this.slugger = new Slugger(); - } - /** - * Static Parse Method - */ - Parser.parse = function (src, options) { - var parser = new Parser(options); - return parser.parse(src); - }; + var defaults$4 = defaults_1.defaults; + var merge$2 = helpers.merge, + unescape$1 = helpers.unescape; /** - * Parse Loop + * Parsing & Compiling */ + var Parser_1 = + /*#__PURE__*/ + function () { + function Parser(options) { + _classCallCheck(this, Parser); + + this.tokens = []; + this.token = null; + this.options = options || defaults$4; + this.options.renderer = this.options.renderer || new Renderer_1(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger_1(); + } + /** + * Static Parse Method + */ - Parser.prototype.parse = function (src) { - this.inline = new InlineLexer(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text - - this.inlineText = new InlineLexer(src.links, merge({}, this.options, { - renderer: new TextRenderer() - })); - this.tokens = src.reverse(); - var out = ''; - while (this.next()) { - out += this.tok(); - } + _createClass(Parser, [{ + key: "parse", - return out; - }; - /** - * Next Token - */ + /** + * Parse Loop + */ + value: function parse(src) { + this.inline = new InlineLexer_1(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text + this.inlineText = new InlineLexer_1(src.links, merge$2({}, this.options, { + renderer: new TextRenderer_1() + })); + this.tokens = src.reverse(); + var out = ''; - Parser.prototype.next = function () { - this.token = this.tokens.pop(); - return this.token; - }; - /** - * Preview Next Token - */ + while (this.next()) { + out += this.tok(); + } + return out; + } + }, { + key: "next", + + /** + * Next Token + */ + value: function next() { + this.token = this.tokens.pop(); + return this.token; + } + }, { + key: "peek", + + /** + * Preview Next Token + */ + value: function peek() { + return this.tokens[this.tokens.length - 1] || 0; + } + }, { + key: "parseText", - Parser.prototype.peek = function () { - return this.tokens[this.tokens.length - 1] || 0; - }; - /** - * Parse Text Tokens - */ + /** + * Parse Text Tokens + */ + value: function parseText() { + var body = this.token.text; + while (this.peek().type === 'text') { + body += '\n' + this.next().text; + } - Parser.prototype.parseText = function () { - var body = this.token.text; + return this.inline.output(body); + } + }, { + key: "tok", + + /** + * Parse Current Token + */ + value: function tok() { + var body = ''; + + switch (this.token.type) { + case 'space': + { + return ''; + } - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } + case 'hr': + { + return this.renderer.hr(); + } - return this.inline.output(body); - }; - /** - * Parse Current Token - */ + 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); + } - Parser.prototype.tok = function () { - switch (this.token.type) { - case 'space': - { - return ''; - } + case 'table': + { + var header = '', + i, + row, + cell, + j; // header - case 'hr': - { - return this.renderer.hr(); - } + cell = ''; - case 'heading': - { - return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, unescape(this.inlineText.output(this.token.text)), this.slugger); - } + 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] + }); + } - case 'code': - { - return this.renderer.code(this.token.text, this.token.lang, this.token.escaped); - } + header += this.renderer.tablerow(cell); - case 'table': - { - var header = ''; - var body = ''; - var i; - var row; - var cell; - var 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] - }); - } + for (i = 0; i < this.token.cells.length; i++) { + row = this.token.cells[i]; + cell = ''; - header += this.renderer.tablerow(cell); + for (j = 0; j < row.length; j++) { + cell += this.renderer.tablecell(this.inline.output(row[j]), { + header: false, + align: this.token.align[j] + }); + } - for (i = 0; i < this.token.cells.length; i++) { - row = this.token.cells[i]; - cell = ''; + body += this.renderer.tablerow(cell); + } - for (j = 0; j < row.length; j++) { - cell += this.renderer.tablecell(this.inline.output(row[j]), { - header: false, - align: this.token.align[j] - }); + return this.renderer.table(header, body); } - body += this.renderer.tablerow(cell); - } - - return this.renderer.table(header, body); - } + case 'blockquote_start': + { + body = ''; - case 'blockquote_start': - { - var _body = ''; + while (this.next().type !== 'blockquote_end') { + body += this.tok(); + } - while (this.next().type !== 'blockquote_end') { - _body += this.tok(); - } + return this.renderer.blockquote(body); + } - return this.renderer.blockquote(_body); - } + case 'list_start': + { + body = ''; + var ordered = this.token.ordered, + start = this.token.start; - case 'list_start': - { - var _body2 = ''; - var ordered = this.token.ordered, - start = this.token.start; + while (this.next().type !== 'list_end') { + body += this.tok(); + } - while (this.next().type !== 'list_end') { - _body2 += this.tok(); - } + return this.renderer.list(body, ordered, start); + } - return this.renderer.list(_body2, 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); + } + } - case 'list_item_start': - { - var _body3 = ''; - 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) - }); + while (this.next().type !== 'list_item_end') { + body += !loose && this.token.type === 'text' ? this.parseText() : this.tok(); } - } else { - _body3 += this.renderer.checkbox(checked); + + return this.renderer.listitem(body, task, checked); } - } - while (this.next().type !== 'list_item_end') { - _body3 += !loose && this.token.type === 'text' ? this.parseText() : this.tok(); - } + case 'html': + { + // TODO parse inline content if parameter markdown=1 + return this.renderer.html(this.token.text); + } - return this.renderer.listitem(_body3, task, checked); - } + case 'paragraph': + { + return this.renderer.paragraph(this.inline.output(this.token.text)); + } - case 'html': - { - // TODO parse inline content if parameter markdown=1 - return this.renderer.html(this.token.text); - } + case 'text': + { + return this.renderer.paragraph(this.parseText()); + } - case 'paragraph': - { - return this.renderer.paragraph(this.inline.output(this.token.text)); - } + default: + { + var errMsg = 'Token with "' + this.token.type + '" type was not found.'; - case 'text': - { - return this.renderer.paragraph(this.parseText()); + if (this.options.silent) { + console.log(errMsg); + } else { + throw new Error(errMsg); + } + } } + } + }], [{ + key: "parse", + value: function parse(src, options) { + var parser = new Parser(options); + return parser.parse(src); + } + }]); - default: - { - var errMsg = 'Token with "' + this.token.type + '" type was not found.'; + return Parser; + }(); - if (this.options.silent) { - console.log(errMsg); - } else { - throw new Error(errMsg); - } - } - } - }; + /** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + var merge$3 = helpers.merge, + checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation, + escape$4 = helpers.escape; + var getDefaults$1 = defaults_1.getDefaults, + changeDefaults$1 = defaults_1.changeDefaults, + defaults$5 = defaults_1.defaults; /** * Marked */ @@ -1531,15 +1768,15 @@ opt = null; } - opt = merge({}, marked.defaults, opt || {}); - checkSanitizeDeprecation(opt); + opt = merge$3({}, marked.defaults, opt || {}); + checkSanitizeDeprecation$1(opt); var highlight = opt.highlight; - var tokens; - var pending; - var i = 0; + var tokens, + pending, + i = 0; try { - tokens = Lexer.lex(src, opt); + tokens = Lexer_1.lex(src, opt); } catch (e) { return { v: callback(e) @@ -1557,7 +1794,7 @@ var out; try { - out = Parser.parse(tokens, opt); + out = Parser_1.parse(tokens, opt); } catch (e) { err = e; } @@ -1606,15 +1843,14 @@ } try { - opt = merge({}, marked.defaults, opt || {}); - checkSanitizeDeprecation(opt); - var t = Lexer.lex(src, opt); - return Parser.parse(t, opt); + if (opt) opt = merge$3({}, 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(e.message + '', true) + '
    '; + return '

    An error occurred:

    ' + escape$4(e.message + '', true) + '
    '; } throw e; @@ -1624,35 +1860,31 @@ * Options */ + marked.options = marked.setOptions = function (opt) { - merge(marked.defaults, opt); + merge$3(marked.defaults, opt); + changeDefaults$1(marked.defaults); return marked; }; - marked.getDefaults = getDefaults; - Object.defineProperty(marked, 'defaults', { - get: function get() { - return defaults; - }, - set: function set(value) { - changeDefaults(value); - } - }); + marked.getDefaults = getDefaults$1; + marked.defaults = defaults$5; /** * Expose */ - marked.Parser = Parser; - marked.parser = Parser.parse; - marked.Renderer = Renderer; - marked.TextRenderer = TextRenderer; - marked.Lexer = Lexer; - marked.lexer = Lexer.lex; - marked.InlineLexer = InlineLexer; - marked.inlineLexer = InlineLexer.output; - marked.Slugger = Slugger; + marked.Parser = Parser_1; + marked.parser = Parser_1.parse; + marked.Renderer = Renderer_1; + 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; - return marked; + return marked_1; }))); diff --git a/marked.min.js b/marked.min.js index 2475b9ab30..cbe608d87b 100644 --- a/marked.min.js +++ b/marked.min.js @@ -1,48 +1,16 @@ -!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 n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var r={baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,xhtml:!1};function e(){return{baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,xhtml:!1}}function t(n,e){return n=n.source||n,e=e||"",{replace:function(e,t){return t=(t=t.source||t).replace(/(^|[^\[])\^/g,"$1"),n=n.replace(e,t),this},getRegex:function(){return new RegExp(n,e)}}}function s(e,t,n){if(e){var r;try{r=decodeURIComponent( +!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 n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;nt)n.splice(t);else for(;n.length"']/,a.escapeReplace=/[&<>"']/g,a.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},a.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,a.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var h={},c=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function p(){}function g(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:v,table:v,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?'|\([^()]*\))/}; /** * marked - a markdown parser * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked - */i.baseUrls={};var _={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:/^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,hr:/^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,blockquote:/^( {0,3}> ?(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:l.exec=l,table:l,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?'|\([^()]*\))/};_.def=t(_.def).replace("label",_._label).replace("title",_._title).getRegex(),_.bullet=/(?:[*+-]|\d{1,9}\.)/,_.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,_.item=t(_.item,"gm").replace(/bull/g,_.bullet).getRegex(),_.list=t(_.list).replace(/bull/g,_.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+_.def.source+")").getRegex(),_._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",_._comment=//,_.html=t(_.html,"i").replace("comment",_._comment).replace("tag",_._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),_.paragraph=t(_._paragraph).replace("hr",_.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",_._tag).getRegex(),_.blockquote=t(_.blockquote).replace("paragraph",_.paragraph).getRegex(),_.normal=a({},_),_.gfm=a({},_.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),_.pedantic=a({},_.normal,{html:t("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",_._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:l,paragraph:t(_.normal._paragraph).replace("hr",_.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",_.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var o={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:l,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:l,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\)[\s\S]*?-->/,S.html=w(S.html,"i").replace("comment",S._comment).replace("tag",S._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),S.paragraph=w(S._paragraph).replace("hr",S.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",S._tag).getRegex(),S.blockquote=w(S.blockquote).replace("paragraph",S.paragraph).getRegex(),S.normal=$({},S),S.gfm=$({},S.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),S.pedantic=$({},S.normal,{html:w("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",S._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:v,paragraph:w(S.normal._paragraph).replace("hr",S.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",S.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var z={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:v,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:v,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};z.em=w(z.em).replace(/punctuation/g,z._punctuation).getRegex(),z._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,z._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,z._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])?)+(?![-_])/,z.autolink=w(z.autolink).replace("scheme",z._scheme).replace("email",z._email).getRegex(),z._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,z.tag=w(z.tag).replace("comment",S._comment).replace("attribute",z._attribute).getRegex(),z._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,z._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,z._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,z.link=w(z.link).replace("label",z._label).replace("href",z._href).replace("title",z._title).getRegex(),z.reflink=w(z.reflink).replace("label",z._label).getRegex(),z.normal=$({},z),z.pedantic=$({},z.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",z._label).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",z._label).getRegex()}),z.gfm=$({},z.normal,{escape:w(z.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=!(u=[]),f=(s=s[0].match(this.rules.item)).length,p=0;p'+(n?e:P(e,!0))+"\n":"
    "+(n?e:P(e,!0))+"
    "}},{key:"blockquote",value:function(e){return"
    \n"+e+"
    \n"}},{key:"html",value:function(e){return e}},{key:"heading",value:function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"}},{key:"hr",value:function(){return this.options.xhtml?"
    \n":"
    \n"}},{key:"list",value:function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"}},{key:"listitem",value:function(e){return"
  • "+e+"
  • \n"}},{key:"checkbox",value:function(e){return" "}},{key:"paragraph",value:function(e){return"

    "+e+"

    \n"}},{key:"table",value:function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"}},{key:"tablerow",value:function(e){return"\n"+e+"\n"}},{key:"tablecell",value:function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"}},{key:"strong",value:function(e){return""+e+""}},{key:"em",value:function(e){return""+e+""}},{key:"codespan",value:function(e){return""+e+""}},{key:"br",value:function(){return this.options.xhtml?"
    ":"
    "}},{key:"del",value:function(e){return""+e+""}},{key:"link",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "}},{key:"image",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"}},{key:"text",value:function(e){return e}}]),t}(),I=function(){function e(){r(this,e),this.seen={}}return i(e,[{key:"slug",value:function(e){var t=e.toLowerCase().trim().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}(),D=l.defaults,U=A.inline,B=y,N=f,F=function(){function h(e,t){if(r(this,h),this.options=t||D,this.links=e,this.rules=U.normal,this.renderer=this.options.renderer||new j,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.pedantic?this.rules=U.pedantic:this.options.gfm&&(this.options.breaks?this.rules=U.breaks:this.rules=U.gfm)}return i(h,[{key:"output",value: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+=N(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.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):N(i[0]):i[0];else if(i=this.rules.link.exec(e)){var o=B(i[2],"()");if(-1$/,"$1"),a+=this.outputLink(i,{href:h.escapes(r),title:h.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(N(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=N(this.mangle(i[1]))):n=N(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]):N(i[0]):i[0]):a+=this.renderer.text(N(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=N(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=N(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),a+=this.renderer.link(r,null,n)}return a}},{key:"outputLink",value:function(e,t){var n=t.href,r=t.title?N(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,N(e[1]))}},{key:"smartypants",value: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}},{key:"mangle",value:function(e){if(!this.options.mangle)return e;for(var t,n=e.length,r="",s=0;sAn error occurred:

    "+escape(e.message+"",!0)+"
    ";throw e}}return o._punctuation="!\"#$%&'()*+,\\-./:;<=>?@\\[^_{|}~",o.em=t(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=t(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=t(o.tag).replace("comment",_._comment).replace("attribute",o._attribute).getRegex(),o._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,o._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,o._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,o.link=t(o.link).replace("label",o._label).replace("href",o._href).replace("title",o._title).getRegex(),o.reflink=t(o.reflink).replace("label",o._label).getRegex(),o.normal=a({},o),o.pedantic=a({},o.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:t(/^!?\[(label)\]\((.*?)\)/).replace("label",o._label).getRegex(),reflink:t(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",o._label).getRegex()}),o.gfm=a({},o.normal,{escape:t(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),a={type:"list_start",ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(a),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,u=0;u'+(n?e:escape(e,!0))+"\n":"
    "+(n?e:escape(e,!0))+"
    "},u.prototype.blockquote=function(e){return"
    \n"+e+"
    \n"},u.prototype.html=function(e){return e},u.prototype.heading=function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"},u.prototype.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},u.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},u.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},u.prototype.checkbox=function(e){return" "},u.prototype.paragraph=function(e){return"

    "+e+"

    \n"},u.prototype.table=function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"},u.prototype.tablerow=function(e){return"\n"+e+"\n"},u.prototype.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},u.prototype.strong=function(e){return""+e+""},u.prototype.em=function(e){return""+e+""},u.prototype.codespan=function(e){return""+e+""},u.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},u.prototype.del=function(e){return""+e+""},u.prototype.link=function(e,t,n){if(null===(e=s(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "},u.prototype.image=function(e,t,n){if(null===(e=s(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"},u.prototype.text=function(e){return e},g.prototype.slug=function(e){var t=e.toLowerCase().trim().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},f.rules=o,f.output=function(e,t,n){return new f(t,n).output(e)},f.prototype.output=function(e){for(var t,n,r,s,i,l,o="";e;)if(i=this.rules.escape.exec(e))e=e.substring(i[0].length),o+=escape(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),o+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):escape(i[0]):i[0];else if(i=this.rules.link.exec(e)){var a=p(i[2],"()");if(-1$/,"$1"),o+=this.outputLink(i,{href:f.escapes(r),title:f.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){o+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,o+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),o+=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),o+=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),o+=this.renderer.codespan(escape(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),o+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),o+=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=escape(this.mangle(i[1]))):n=escape(i[1]),o+=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?o+=this.renderer.text(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):escape(i[0]):i[0]):o+=this.renderer.text(escape(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=escape(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=escape(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),o+=this.renderer.link(r,null,n)}return o},f.escapes=function(e){return e?e.replace(f.rules._escapes,"$1"):e},f.prototype.outputLink=function(e,t){var n=t.href,r=t.title?escape(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,escape(e[1]))},f.prototype.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},f.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=e.length,s=0;sAn error occurred:

    "+Q(e.message+"",!0)+"
    ";throw e}}return te.options=te.setOptions=function(e){return J(te.defaults,e),Y(te.defaults),te},te.getDefaults=W,te.defaults=ee,te.Parser=H,te.parser=H.parse,te.Renderer=j,te.TextRenderer=X,te.Lexer=E,te.lexer=E.lex,te.InlineLexer=F,te.inlineLexer=F.output,te.Slugger=I,te.parse=te}); \ No newline at end of file From 5dfbd30ae3ce8dea47015c63244781b8d025b85e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 11:54:31 -0600 Subject: [PATCH 08/33] add license in rollup --- lib/marked.js | 60 +++++---------------------------------------- marked.min.js | 20 ++++----------- package-lock.json | 43 ++++++++++++++++++++++++++++++++ package.json | 1 + rollup.config.js | 8 ++++++ src/InlineLexer.js | 7 ------ src/Lexer.js | 7 ------ src/Parser.js | 7 ------ src/Renderer.js | 7 ------ src/Slugger.js | 7 ------ src/TextRenderer.js | 7 ------ src/helpers.js | 7 ------ src/marked.js | 7 ------ src/regexp.js | 8 ------ 14 files changed, 63 insertions(+), 133 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 2570f1d254..8f1edb2a92 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1,3 +1,9 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : @@ -73,12 +79,6 @@ changeDefaults: changeDefaults }; - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - /** * Helpers */ @@ -340,12 +340,6 @@ checkSanitizeDeprecation: checkSanitizeDeprecation }; - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - var noop$1 = helpers.noop, edit$1 = helpers.edit, merge$1 = helpers.merge; @@ -501,12 +495,6 @@ inline: inline }; - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - var defaults$1 = defaults_1.defaults; var block$1 = regexp.block; var rtrim$1 = helpers.rtrim, @@ -885,12 +873,6 @@ return Lexer; }(); - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - var defaults$2 = defaults_1.defaults; var cleanUrl$1 = helpers.cleanUrl, escape$2 = helpers.escape; @@ -1064,12 +1046,6 @@ return Renderer; }(); - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - /** * Slugger generates header id */ @@ -1108,12 +1084,6 @@ return Slugger; }(); - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - var defaults$3 = defaults_1.defaults; var inline$1 = regexp.inline; var findClosingBracket$1 = helpers.findClosingBracket, @@ -1426,12 +1396,6 @@ return InlineLexer; }(); - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - /** * TextRenderer * returns only the textual part of the token @@ -1489,12 +1453,6 @@ return TextRenderer; }(); - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - var defaults$4 = defaults_1.defaults; var merge$2 = helpers.merge, unescape$1 = helpers.unescape; @@ -1735,12 +1693,6 @@ return Parser; }(); - /** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - var merge$3 = helpers.merge, checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation, escape$4 = helpers.escape; diff --git a/marked.min.js b/marked.min.js index cbe608d87b..8d5e08d729 100644 --- a/marked.min.js +++ b/marked.min.js @@ -1,16 +1,6 @@ -!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 n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n"']/,a.escapeReplace=/[&<>"']/g,a.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},a.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,a.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var h={},c=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function p(){}function g(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:v,table:v,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?'|\([^()]*\))/}; -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */S.def=w(S.def).replace("label",S._label).replace("title",S._title).getRegex(),S.bullet=/(?:[*+-]|\d{1,9}\.)/,S.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,S.item=w(S.item,"gm").replace(/bull/g,S.bullet).getRegex(),S.list=w(S.list).replace(/bull/g,S.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+S.def.source+")").getRegex(),S._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",S._comment=//,S.html=w(S.html,"i").replace("comment",S._comment).replace("tag",S._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),S.paragraph=w(S._paragraph).replace("hr",S.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",S._tag).getRegex(),S.blockquote=w(S.blockquote).replace("paragraph",S.paragraph).getRegex(),S.normal=$({},S),S.gfm=$({},S.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),S.pedantic=$({},S.normal,{html:w("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",S._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:v,paragraph:w(S.normal._paragraph).replace("hr",S.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",S.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var z={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:v,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:v,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};z.em=w(z.em).replace(/punctuation/g,z._punctuation).getRegex(),z._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,z._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,z._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])?)+(?![-_])/,z.autolink=w(z.autolink).replace("scheme",z._scheme).replace("email",z._email).getRegex(),z._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,z.tag=w(z.tag).replace("comment",S._comment).replace("attribute",z._attribute).getRegex(),z._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,z._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,z._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,z.link=w(z.link).replace("label",z._label).replace("href",z._href).replace("title",z._title).getRegex(),z.reflink=w(z.reflink).replace("label",z._label).getRegex(),z.normal=$({},z),z.pedantic=$({},z.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",z._label).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",z._label).getRegex()}),z.gfm=$({},z.normal,{escape:w(z.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=!(u=[]),f=(s=s[0].match(this.rules.item)).length,p=0;p'+(n?e:P(e,!0))+"\n":"
    "+(n?e:P(e,!0))+"
    "}},{key:"blockquote",value:function(e){return"
    \n"+e+"
    \n"}},{key:"html",value:function(e){return e}},{key:"heading",value:function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"}},{key:"hr",value:function(){return this.options.xhtml?"
    \n":"
    \n"}},{key:"list",value:function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"}},{key:"listitem",value:function(e){return"
  • "+e+"
  • \n"}},{key:"checkbox",value:function(e){return" "}},{key:"paragraph",value:function(e){return"

    "+e+"

    \n"}},{key:"table",value:function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"}},{key:"tablerow",value:function(e){return"\n"+e+"\n"}},{key:"tablecell",value:function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"}},{key:"strong",value:function(e){return""+e+""}},{key:"em",value:function(e){return""+e+""}},{key:"codespan",value:function(e){return""+e+""}},{key:"br",value:function(){return this.options.xhtml?"
    ":"
    "}},{key:"del",value:function(e){return""+e+""}},{key:"link",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "}},{key:"image",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"}},{key:"text",value:function(e){return e}}]),t}(),I=function(){function e(){r(this,e),this.seen={}}return i(e,[{key:"slug",value:function(e){var t=e.toLowerCase().trim().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}(),D=l.defaults,U=A.inline,B=y,N=f,F=function(){function h(e,t){if(r(this,h),this.options=t||D,this.links=e,this.rules=U.normal,this.renderer=this.options.renderer||new j,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.pedantic?this.rules=U.pedantic:this.options.gfm&&(this.options.breaks?this.rules=U.breaks:this.rules=U.gfm)}return i(h,[{key:"output",value: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+=N(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.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):N(i[0]):i[0];else if(i=this.rules.link.exec(e)){var o=B(i[2],"()");if(-1$/,"$1"),a+=this.outputLink(i,{href:h.escapes(r),title:h.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(N(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=N(this.mangle(i[1]))):n=N(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]):N(i[0]):i[0]):a+=this.renderer.text(N(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=N(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=N(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),a+=this.renderer.link(r,null,n)}return a}},{key:"outputLink",value:function(e,t){var n=t.href,r=t.title?N(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,N(e[1]))}},{key:"smartypants",value: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}},{key:"mangle",value:function(e){if(!this.options.mangle)return e;for(var t,n=e.length,r="",s=0;sAn error occurred:

    "+Q(e.message+"",!0)+"
    ";throw e}}return te.options=te.setOptions=function(e){return J(te.defaults,e),Y(te.defaults),te},te.getDefaults=W,te.defaults=ee,te.Parser=H,te.parser=H.parse,te.Renderer=j,te.TextRenderer=X,te.Lexer=E,te.lexer=E.lex,te.InlineLexer=F,te.inlineLexer=F.output,te.Slugger=I,te.parse=te}); \ No newline at end of file + * marked - a markdown parser + * Copyright (c) 2011-2018, 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 n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n"']/,a.escapeReplace=/[&<>"']/g,a.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},a.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,a.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var h={},c=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function p(){}function g(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:v,table:v,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?'|\([^()]*\))/};S.def=w(S.def).replace("label",S._label).replace("title",S._title).getRegex(),S.bullet=/(?:[*+-]|\d{1,9}\.)/,S.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,S.item=w(S.item,"gm").replace(/bull/g,S.bullet).getRegex(),S.list=w(S.list).replace(/bull/g,S.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+S.def.source+")").getRegex(),S._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",S._comment=//,S.html=w(S.html,"i").replace("comment",S._comment).replace("tag",S._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),S.paragraph=w(S._paragraph).replace("hr",S.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",S._tag).getRegex(),S.blockquote=w(S.blockquote).replace("paragraph",S.paragraph).getRegex(),S.normal=$({},S),S.gfm=$({},S.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),S.pedantic=$({},S.normal,{html:w("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",S._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:v,paragraph:w(S.normal._paragraph).replace("hr",S.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",S.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var z={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:v,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:v,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};z.em=w(z.em).replace(/punctuation/g,z._punctuation).getRegex(),z._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,z._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,z._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])?)+(?![-_])/,z.autolink=w(z.autolink).replace("scheme",z._scheme).replace("email",z._email).getRegex(),z._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,z.tag=w(z.tag).replace("comment",S._comment).replace("attribute",z._attribute).getRegex(),z._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,z._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,z._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,z.link=w(z.link).replace("label",z._label).replace("href",z._href).replace("title",z._title).getRegex(),z.reflink=w(z.reflink).replace("label",z._label).getRegex(),z.normal=$({},z),z.pedantic=$({},z.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",z._label).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",z._label).getRegex()}),z.gfm=$({},z.normal,{escape:w(z.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=!(u=[]),f=(s=s[0].match(this.rules.item)).length,p=0;p'+(n?e:P(e,!0))+"\n":"
    "+(n?e:P(e,!0))+"
    "}},{key:"blockquote",value:function(e){return"
    \n"+e+"
    \n"}},{key:"html",value:function(e){return e}},{key:"heading",value:function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"}},{key:"hr",value:function(){return this.options.xhtml?"
    \n":"
    \n"}},{key:"list",value:function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"}},{key:"listitem",value:function(e){return"
  • "+e+"
  • \n"}},{key:"checkbox",value:function(e){return" "}},{key:"paragraph",value:function(e){return"

    "+e+"

    \n"}},{key:"table",value:function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"}},{key:"tablerow",value:function(e){return"\n"+e+"\n"}},{key:"tablecell",value:function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"}},{key:"strong",value:function(e){return""+e+""}},{key:"em",value:function(e){return""+e+""}},{key:"codespan",value:function(e){return""+e+""}},{key:"br",value:function(){return this.options.xhtml?"
    ":"
    "}},{key:"del",value:function(e){return""+e+""}},{key:"link",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "}},{key:"image",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"}},{key:"text",value:function(e){return e}}]),t}(),I=function(){function e(){r(this,e),this.seen={}}return i(e,[{key:"slug",value:function(e){var t=e.toLowerCase().trim().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}(),D=l.defaults,U=A.inline,B=y,N=f,F=function(){function h(e,t){if(r(this,h),this.options=t||D,this.links=e,this.rules=U.normal,this.renderer=this.options.renderer||new j,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.pedantic?this.rules=U.pedantic:this.options.gfm&&(this.options.breaks?this.rules=U.breaks:this.rules=U.gfm)}return i(h,[{key:"output",value: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+=N(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.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):N(i[0]):i[0];else if(i=this.rules.link.exec(e)){var o=B(i[2],"()");if(-1$/,"$1"),a+=this.outputLink(i,{href:h.escapes(r),title:h.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(N(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=N(this.mangle(i[1]))):n=N(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]):N(i[0]):i[0]):a+=this.renderer.text(N(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=N(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=N(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),a+=this.renderer.link(r,null,n)}return a}},{key:"outputLink",value:function(e,t){var n=t.href,r=t.title?N(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,N(e[1]))}},{key:"smartypants",value: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}},{key:"mangle",value:function(e){if(!this.options.mangle)return e;for(var t,n=e.length,r="",s=0;sAn error occurred:

    "+Q(e.message+"",!0)+"
    ";throw e}}return te.options=te.setOptions=function(e){return J(te.defaults,e),Y(te.defaults),te},te.getDefaults=W,te.defaults=ee,te.Parser=H,te.parser=H.parse,te.Renderer=j,te.TextRenderer=X,te.Lexer=E,te.lexer=E.lex,te.InlineLexer=F,te.inlineLexer=F.output,te.Slugger=I,te.parse=te}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 212e5914e4..22955f55e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1129,6 +1129,12 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, + "commenting": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/commenting/-/commenting-1.1.0.tgz", + "integrity": "sha512-YeNK4tavZwtH7jEgK1ZINXzLKm6DZdEMfsaaieOsCAN0S8vsY7UeuO3Q7d/M018EFgE+IeUAuBOKkFccBZsUZA==", + "dev": true + }, "commonmark": { "version": "0.29.0", "resolved": "https://registry.npmjs.org/commonmark/-/commonmark-0.29.0.tgz", @@ -2316,6 +2322,12 @@ } } }, + "moment": { + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==", + "dev": true + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -2804,6 +2816,37 @@ "rollup-pluginutils": "^2.8.1" } }, + "rollup-plugin-license": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-license/-/rollup-plugin-license-0.12.1.tgz", + "integrity": "sha512-zT8UO+Tc+DAVQHM5qeX4jnuHzTtDUYJ/8AHzUgVgqYrx5Wj5kHlvoZNaQqg7hOQbjSuHuJFlQGZmxxSQq2WMqA==", + "dev": true, + "requires": { + "commenting": "1.1.0", + "glob": "7.1.4", + "lodash": "4.17.15", + "magic-string": "0.25.3", + "mkdirp": "0.5.1", + "moment": "2.24.0" + }, + "dependencies": { + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + }, + "magic-string": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", + "integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + } + } + }, "rollup-pluginutils": { "version": "2.8.2", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", diff --git a/package.json b/package.json index ab5c9a15a2..115c86e037 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "rollup": "^1.26.3", "rollup-plugin-babel": "^4.3.3", "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-license": "^0.12.1", "uglify-js": "^3.6.8" }, "scripts": { diff --git a/rollup.config.js b/rollup.config.js index 8373372865..4a529c571a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,6 @@ const commonjs = require('rollup-plugin-commonjs'); const babel = require('rollup-plugin-babel'); +const license = require('rollup-plugin-license'); module.exports = { input: 'src/marked.js', @@ -9,6 +10,13 @@ module.exports = { name: 'marked' }, plugins: [ + license({ + banner: ` +marked - a markdown parser +Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) +https://github.com/markedjs/marked +` + }), commonjs(), babel({ presets: ['@babel/preset-env'] diff --git a/src/InlineLexer.js b/src/InlineLexer.js index f4fa9ad20c..e790e9e8d8 100644 --- a/src/InlineLexer.js +++ b/src/InlineLexer.js @@ -1,9 +1,3 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - const Renderer = require('./Renderer.js'); const { defaults } = require('./defaults.js'); const { inline } = require('./regexp.js'); @@ -15,7 +9,6 @@ const { /** * Inline Lexer & Compiler */ - module.exports = class InlineLexer { constructor(links, options) { this.options = options || defaults; diff --git a/src/Lexer.js b/src/Lexer.js index eb104fa918..7c2789b25d 100644 --- a/src/Lexer.js +++ b/src/Lexer.js @@ -1,9 +1,3 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - const { defaults } = require('./defaults.js'); const { block } = require('./regexp.js'); const { @@ -15,7 +9,6 @@ const { /** * Block Lexer */ - module.exports = class Lexer { constructor(options) { this.tokens = []; diff --git a/src/Parser.js b/src/Parser.js index 2a43dbf8b9..ce7a95a654 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -1,9 +1,3 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - const Renderer = require('./Renderer.js'); const Slugger = require('./Slugger.js'); const InlineLexer = require('./InlineLexer.js'); @@ -17,7 +11,6 @@ const { /** * Parsing & Compiling */ - module.exports = class Parser { constructor(options) { this.tokens = []; diff --git a/src/Renderer.js b/src/Renderer.js index 86f9af2bc2..d86341a810 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -1,9 +1,3 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - const { defaults } = require('./defaults.js'); const { cleanUrl, @@ -13,7 +7,6 @@ const { /** * Renderer */ - module.exports = class Renderer { constructor(options) { this.options = options || defaults; diff --git a/src/Slugger.js b/src/Slugger.js index ab8781b681..51064211c1 100644 --- a/src/Slugger.js +++ b/src/Slugger.js @@ -1,13 +1,6 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - /** * Slugger generates header id */ - module.exports = class Slugger { constructor() { this.seen = {}; diff --git a/src/TextRenderer.js b/src/TextRenderer.js index b54c7724df..652004d50c 100644 --- a/src/TextRenderer.js +++ b/src/TextRenderer.js @@ -1,14 +1,7 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - /** * TextRenderer * returns only the textual part of the token */ - module.exports = class TextRenderer { // no need for block level renderers strong(text) { diff --git a/src/helpers.js b/src/helpers.js index 497434303e..89414546c6 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,13 +1,6 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - /** * Helpers */ - function escape(html, encode) { if (encode) { if (escape.escapeTest.test(html)) { diff --git a/src/marked.js b/src/marked.js index e9eb161079..32acf4d136 100644 --- a/src/marked.js +++ b/src/marked.js @@ -1,9 +1,3 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - const Lexer = require('./Lexer.js'); const Parser = require('./Parser.js'); const Renderer = require('./Renderer.js'); @@ -24,7 +18,6 @@ const { /** * Marked */ - function marked(src, opt, callback) { // throw error in case of non string input if (typeof src === 'undefined' || src === null) { diff --git a/src/regexp.js b/src/regexp.js index ba3517365d..c50ff67663 100644 --- a/src/regexp.js +++ b/src/regexp.js @@ -1,9 +1,3 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) - * https://github.com/markedjs/marked - */ - const { noop, edit, @@ -13,7 +7,6 @@ const { /** * Block-Level Grammar */ - const block = { newline: /^\n+/, code: /^( {4}[^\n]+\n*)+/, @@ -136,7 +129,6 @@ block.pedantic = merge({}, block.normal, { /** * Inline-Level Grammar */ - const inline = { escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, From 24212184b8f2bf7ccbef5880f0e75bb0297c072b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 12:05:09 -0600 Subject: [PATCH 09/33] add npm run build:reset To prevent changes to compiled files in pull requests the user can just run `npm run build:reset` --- lib/marked.js | 3144 ++++++++++++++++++++++++------------------------- marked.min.js | 2 +- package.json | 1 + 3 files changed, 1514 insertions(+), 1633 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 8f1edb2a92..773341f48a 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -4,1839 +4,1719 @@ * https://github.com/markedjs/marked */ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global = global || self, global.marked = factory()); -}(this, (function () { 'use strict'; - - function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } +;(function(root) { +'use strict'; - return _typeof(obj); - } +/** + * Block-Level Grammar + */ - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } +var block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, + hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, + heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, + blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, + list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\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)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + + ')', + def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, + nptable: noop, + table: noop, + lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, + // regex template, placeholders will be replaced according to different paragraph + // interruption rules of commonmark and the original markdown spec: + _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, + text: /^[^\n]+/ +}; + +block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; +block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; +block.def = edit(block.def) + .replace('label', block._label) + .replace('title', block._title) + .getRegex(); - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } +block.bullet = /(?:[*+-]|\d{1,9}\.)/; +block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; +block.item = edit(block.item, 'gm') + .replace(/bull/g, block.bullet) + .getRegex(); - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } +block.list = edit(block.list) + .replace(/bull/g, block.bullet) + .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))') + .replace('def', '\\n+(?=' + block.def.source + ')') + .getRegex(); - var defaults = getDefaults(); - - function getDefaults() { - return { - baseUrl: null, - breaks: false, - gfm: true, - headerIds: true, - headerPrefix: '', - highlight: null, - langPrefix: 'language-', - mangle: true, - pedantic: false, - renderer: null, - sanitize: false, - sanitizer: null, - silent: false, - smartLists: false, - smartypants: false, - xhtml: false - }; - } +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(); - function changeDefaults(newDefaults) { - defaults = newDefaults; - } +block.paragraph = edit(block._paragraph) + .replace('hr', block.hr) + .replace('heading', ' {0,3}#{1,6} +') + .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('blockquote', ' {0,3}>') + .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') + .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt + .replace('html', ')|<(?:script|pre|style|!--)') + .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks + .getRegex(); - var defaults_1 = { - defaults: defaults, - getDefaults: getDefaults, - changeDefaults: changeDefaults - }; +block.blockquote = edit(block.blockquote) + .replace('paragraph', block.paragraph) + .getRegex(); - /** - * Helpers - */ - function escape(html, encode) { - if (encode) { - if (escape.escapeTest.test(html)) { - return html.replace(escape.escapeReplace, function (ch) { - return escape.replacements[ch]; - }); - } - } else { - if (escape.escapeTestNoEncode.test(html)) { - return html.replace(escape.escapeReplaceNoEncode, function (ch) { - return escape.replacements[ch]; - }); - } - } +/** + * Normal Block Grammar + */ - return html; - } +block.normal = merge({}, block); - escape.escapeTest = /[&<>"']/; - escape.escapeReplace = /[&<>"']/g; - escape.replacements = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; - escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; +/** + * GFM Block Grammar + */ - function unescape(html) { - // explicitly match decimal, hex, and named HTML entities - return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function (_, n) { - n = n.toLowerCase(); - if (n === 'colon') return ':'; +block.gfm = merge({}, block.normal, { + nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ +}); - if (n.charAt(0) === '#') { - return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1)); - } +/** + * Pedantic grammar (original John Gruber's loose markdown specification) + */ - return ''; - }); - } +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+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, + fences: noop, // fences not supported + paragraph: edit(block.normal._paragraph) + .replace('hr', block.hr) + .replace('heading', ' *#{1,6} *[^\n]') + .replace('lheading', block.lheading) + .replace('blockquote', ' {0,3}>') + .replace('|fences', '') + .replace('|list', '') + .replace('|html', '') + .getRegex() +}); - function edit(regex, opt) { - regex = regex.source || regex; - opt = opt || ''; - return { - replace: function replace(name, val) { - val = val.source || val; - val = val.replace(/(^|[^\[])\^/g, '$1'); - regex = regex.replace(name, val); - return this; - }, - getRegex: function getRegex() { - return new RegExp(regex, opt); - } - }; +/** + * Block Lexer + */ + +function Lexer(options) { + this.tokens = []; + this.tokens.links = Object.create(null); + this.options = options || marked.defaults; + this.rules = block.normal; + + if (this.options.pedantic) { + this.rules = block.pedantic; + } else if (this.options.gfm) { + this.rules = block.gfm; } +} + +/** + * Expose Block Rules + */ - function cleanUrl(sanitize, base, href) { - if (sanitize) { - var prot; +Lexer.rules = block; - try { - prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, '').toLowerCase(); - } catch (e) { - return null; +/** + * Static Lex Method + */ + +Lexer.lex = function(src, options) { + var lexer = new Lexer(options); + return lexer.lex(src); +}; + +/** + * Preprocessing + */ + +Lexer.prototype.lex = function(src) { + src = src + .replace(/\r\n|\r/g, '\n') + .replace(/\t/g, ' '); + + return this.token(src, true); +}; + +/** + * Lexing + */ + +Lexer.prototype.token = function(src, top) { + src = src.replace(/^ +$/gm, ''); + var next, + loose, + cap, + bull, + b, + item, + listStart, + listItems, + t, + space, + i, + tag, + l, + isordered, + istask, + ischecked; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); } + } - if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { - return null; + // 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 (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); + } else { + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic + ? rtrim(cap, '\n') + : cap + }); } + continue; } - if (base && !originIndependentUrl.test(href)) { - href = resolveUrl(base, href); + // fences + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' + }); + continue; } - try { - href = encodeURI(href).replace(/%25/g, '%'); - } catch (e) { - return null; + // heading + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; } - return href; - } + // table no leading pipe (gfm) + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; - function resolveUrl(base, href) { - if (!baseUrls[' ' + base]) { - // we can ignore everything in base after the last slash of its path component, - // but we might need to add _that_ - // https://tools.ietf.org/html/rfc3986#section-3 - if (/^[^:]+:\/*[^/]*$/.test(base)) { - baseUrls[' ' + base] = base + '/'; - } else { - baseUrls[' ' + base] = rtrim(base, '/', true); - } - } + 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; + } + } - base = baseUrls[' ' + base]; - var relativeBase = base.indexOf(':') === -1; + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = splitCells(item.cells[i], item.header.length); + } - if (href.slice(0, 2) === '//') { - if (relativeBase) { - return href; - } + this.tokens.push(item); - return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; - } else if (href.charAt(0) === '/') { - if (relativeBase) { - return href; + continue; } + } - return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; - } else { - return base + href; + // hr + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; } - } - var baseUrls = {}; - var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; + // blockquote + if (cap = this.rules.blockquote.exec(src)) { + src = src.substring(cap[0].length); - function noop() {} + this.tokens.push({ + type: 'blockquote_start' + }); - noop.exec = noop; + cap = cap[0].replace(/^ *> ?/gm, ''); - function merge(obj) { - var i = 1, - target, - key; + // Pass `top` to keep the current + // "toplevel" state. This is exactly + // how markdown.pl works. + this.token(cap, top); - for (; i < arguments.length; i++) { - target = arguments[i]; + this.tokens.push({ + type: 'blockquote_end' + }); - for (key in target) { - if (Object.prototype.hasOwnProperty.call(target, key)) { - obj[key] = target[key]; - } - } + continue; } - return obj; - } + // list + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; - function splitCells(tableRow, count) { - // ensure that every cell-delimiting pipe has a space - // before it to distinguish it from an escaped pipe - var row = tableRow.replace(/\|/g, function (match, offset, str) { - var escaped = false, - curr = offset; + this.tokens.push(listStart); - while (--curr >= 0 && str[curr] === '\\') { - escaped = !escaped; - } + // Get each top-level item. + cap = cap[0].match(this.rules.item); - if (escaped) { - // odd number of slashes means | is escaped - // so we leave it alone - return '|'; - } else { - // add space before unescaped | - return ' |'; - } - }), - cells = row.split(/ \|/); - var i = 0; + listItems = []; + next = false; + l = cap.length; + i = 0; - if (cells.length > count) { - cells.splice(count); - } else { - while (cells.length < count) { - cells.push(''); - } - } + for (; i < l; i++) { + item = cap[i]; - for (; i < cells.length; i++) { - // leading or trailing whitespace is ignored per the gfm spec - cells[i] = cells[i].trim().replace(/\\\|/g, '|'); - } + // Remove the list item's bullet + // so it is seen as the next token. + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); - return cells; - } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). - // /c*$/ is vulnerable to REDOS. - // invert: Remove suffix of non-c chars instead. Default falsey. + // Outdent whatever the + // list item contains. Hacky. + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic + ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') + : item.replace(/^ {1,4}/gm, ''); + } + + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (i !== l - 1) { + b = block.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; + i = l - 1; + } + } + // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + loose = next || /\n\n(?!\s*$)/.test(item); + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } - function rtrim(str, c, invert) { - var l = str.length; + if (loose) { + listStart.loose = true; + } - if (l === 0) { - return ''; - } // Length of suffix matching the invert condition. + // Check for task list items + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); + } + t = { + type: 'list_item_start', + task: istask, + checked: ischecked, + loose: loose + }; - var suffLen = 0; // Step left until we fail to match the invert condition. + listItems.push(t); + this.tokens.push(t); - while (suffLen < l) { - var currChar = str.charAt(l - suffLen - 1); + // Recurse. + this.token(item, false); - if (currChar === c && !invert) { - suffLen++; - } else if (currChar !== c && invert) { - suffLen++; - } else { - break; + this.tokens.push({ + type: 'list_item_end' + }); } + + if (listStart.loose) { + l = listItems.length; + i = 0; + for (; i < l; i++) { + listItems[i].loose = true; + } + } + + this.tokens.push({ + type: 'list_end' + }); + + continue; } - return str.substr(0, l - suffLen); - } + // html + if (cap = this.rules.html.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize + ? 'paragraph' + : 'html', + 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(cap[0])) : cap[0] + }); + continue; + } - function findClosingBracket(str, b) { - if (str.indexOf(b[1]) === -1) { - return -1; + // def + 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().replace(/\s+/g, ' '); + if (!this.tokens.links[tag]) { + this.tokens.links[tag] = { + href: cap[2], + title: cap[3] + }; + } + continue; } - var l = str.length; - var level = 0, - i = 0; + // table (gfm) + if (cap = this.rules.table.exec(src)) { + item = { + type: 'table', + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; - for (; i < l; i++) { - if (str[i] === '\\') { - i++; - } else if (str[i] === b[0]) { - level++; - } else if (str[i] === b[1]) { - level--; + 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; + } + } - if (level < 0) { - return i; + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = splitCells( + item.cells[i].replace(/^ *\| *| *\| *$/g, ''), + item.header.length); } + + this.tokens.push(item); + + continue; } } - return -1; - } + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2].charAt(0) === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } + + // top-level paragraph + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + 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)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; + } - function checkSanitizeDeprecation(opt) { - if (opt && opt.sanitize && !opt.silent) { - console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); } } - var helpers = { - escape: escape, - unescape: unescape, - edit: edit, - cleanUrl: cleanUrl, - resolveUrl: resolveUrl, - noop: noop, - merge: merge, - splitCells: splitCells, - rtrim: rtrim, - findClosingBracket: findClosingBracket, - checkSanitizeDeprecation: checkSanitizeDeprecation - }; + return this.tokens; +}; - var noop$1 = helpers.noop, - edit$1 = helpers.edit, - merge$1 = helpers.merge; - /** - * Block-Level Grammar - */ - - var block = { - newline: /^\n+/, - code: /^( {4}[^\n]+\n*)+/, - fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, - hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, - heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, - blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, - list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\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)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag - + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag - + ')', - def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, - nptable: noop$1, - table: noop$1, - lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, - // regex template, placeholders will be replaced according to different paragraph - // interruption rules of commonmark and the original markdown spec: - _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, - text: /^[^\n]+/ - }; - block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; - block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; - block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex(); - block.bullet = /(?:[*+-]|\d{1,9}\.)/; - block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; - block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex(); - block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex(); - 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$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(); - block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} +').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs - .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt - .replace('html', ')|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks - .getRegex(); - block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex(); - /** - * Normal Block Grammar - */ - - block.normal = merge$1({}, block); - /** - * GFM Block Grammar - */ - - block.gfm = merge$1({}, block.normal, { - nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, - table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ - }); - /** - * Pedantic grammar (original John Gruber's loose markdown specification) - */ - - block.pedantic = merge$1({}, block.normal, { - html: edit$1('^ *(?: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+|$)/, - heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, - fences: noop$1, - // fences not supported - paragraph: edit$1(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex() - }); - /** - * Inline-Level Grammar - */ - - var inline = { - escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, - autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, - url: noop$1, - tag: '^comment' + '|^' // self-closing tag +/** + * Inline-Level Grammar + */ + +var inline = { + escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, + autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, + url: noop, + 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)\]\(\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: noop$1, - text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; - inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); - inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex(); - inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/; - inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex(); - inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; - inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; - inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; - inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex(); - inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex(); - /** - * Normal Inline Grammar - */ - - inline.normal = merge$1({}, inline); - /** - * Pedantic Inline Grammar - */ - - inline.pedantic = merge$1({}, inline.normal, { - strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, - em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/, - link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(), - reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex() - }); - /** - * GFM Inline Grammar - */ - - inline.gfm = merge$1({}, inline.normal, { - escape: edit$1(inline.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]*?(?:(?=[\\', // CDATA section + 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: noop, + text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; +inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); + +inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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(); - if (this.options.pedantic) { - this.rules = block$1.pedantic; - } else if (this.options.gfm) { - this.rules = block$1.gfm; - } - } - /** - * Expose Block Rules - */ +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(); - _createClass(Lexer, [{ - key: "lex", +inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; +inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; +inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; - /** - * Preprocessing - */ - value: function lex(src) { - src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' '); - return this.token(src, true); - } - }, { - key: "token", - - /** - * Lexing - */ - value: function token(src, top) { - src = src.replace(/^ +$/gm, ''); - var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked; - - while (src) { - // newline - if (cap = this.rules.newline.exec(src)) { - src = src.substring(cap[0].length); - - if (cap[0].length > 1) { - this.tokens.push({ - type: 'space' - }); - } - } // 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 (lastToken && lastToken.type === 'paragraph') { - lastToken.text += '\n' + cap[0].trimRight(); - } else { - cap = cap[0].replace(/^ {4}/gm, ''); - this.tokens.push({ - type: 'code', - codeBlockStyle: 'indented', - text: !this.options.pedantic ? rtrim$1(cap, '\n') : cap - }); - } - - continue; - } // fences - - - if (cap = this.rules.fences.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'code', - lang: cap[2] ? cap[2].trim() : cap[2], - text: cap[3] || '' - }); - continue; - } // heading +inline.link = edit(inline.link) + .replace('label', inline._label) + .replace('href', inline._href) + .replace('title', inline._title) + .getRegex(); +inline.reflink = edit(inline.reflink) + .replace('label', inline._label) + .getRegex(); - if (cap = this.rules.heading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[1].length, - text: cap[2] - }); - continue; - } // table no leading pipe (gfm) - - - if (cap = this.rules.nptable.exec(src)) { - item = { - type: 'table', - header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; - - 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] = splitCells$1(item.cells[i], item.header.length); - } - - this.tokens.push(item); - continue; - } - } // hr - - - if (cap = this.rules.hr.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' - }); - continue; - } // blockquote +/** + * Normal Inline Grammar + */ +inline.normal = merge({}, inline); - if (cap = this.rules.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. +/** + * Pedantic Inline Grammar + */ - this.token(cap, top); - this.tokens.push({ - type: 'blockquote_end' - }); - continue; - } // list - - - if (cap = this.rules.list.exec(src)) { - src = src.substring(cap[0].length); - bull = cap[2]; - isordered = bull.length > 1; - listStart = { - type: 'list_start', - ordered: isordered, - start: isordered ? +bull : '', - loose: false - }; - this.tokens.push(listStart); // Get each top-level item. - - cap = cap[0].match(this.rules.item); - listItems = []; - next = false; - l = cap.length; - i = 0; - - for (; i < l; i++) { - item = cap[i]; // Remove the list item's bullet - // so it is seen as the next token. - - space = item.length; - item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the - // list item contains. Hacky. - - if (~item.indexOf('\n ')) { - space -= item.length; - item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, ''); - } // Determine whether the next list item belongs here. - // Backpedal if it does not belong in this list. - - - if (i !== l - 1) { - 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; - i = l - 1; - } - } // Determine whether item is loose or not. - // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ - // for discount behavior. - - - loose = next || /\n\n(?!\s*$)/.test(item); - - if (i !== l - 1) { - next = item.charAt(item.length - 1) === '\n'; - if (!loose) loose = next; - } - - if (loose) { - listStart.loose = true; - } // Check for task list items - - - istask = /^\[[ xX]\] /.test(item); - ischecked = undefined; - - if (istask) { - ischecked = item[1] !== ' '; - item = item.replace(/^\[[ xX]\] +/, ''); - } - - t = { - type: 'list_item_start', - 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' - }); - } - - if (listStart.loose) { - l = listItems.length; - i = 0; - - for (; i < l; i++) { - listItems[i].loose = true; - } - } +inline.pedantic = merge({}, inline.normal, { + strong: /^__(?=\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() +}); - this.tokens.push({ - type: 'list_end' - }); - continue; - } // html +/** + * GFM Inline Grammar + */ +inline.gfm = merge({}, inline.normal, { + escape: edit(inline.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]*?(?:(?=[\\/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.options.sanitize + ? this.options.sanitizer + ? this.options.sanitizer(cap[0]) + : escape(cap[0]) + : cap[0]; + continue; + } - if (this.options.highlight) { - var out = this.options.highlight(_code, lang); + // link + if (cap = this.rules.link.exec(src)) { + var lastParenIndex = findClosingBracket(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 (out != null && out !== _code) { - escaped = true; - _code = out; - } + 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; + } - if (!lang) { - return '
    ' + (escaped ? _code : escape$2(_code, true)) + '
    '; - } + // 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; + } - return '
    ' + (escaped ? _code : escape$2(_code, true)) + '
    \n'; - } - }, { - key: "blockquote", - value: function blockquote(quote) { - return '
    \n' + quote + '
    \n'; - } - }, { - key: "html", - value: function html(_html) { - return _html; - } - }, { - key: "heading", - value: function heading(text, level, raw, slugger) { - if (this.options.headerIds) { - return '' + text + '\n'; - } // ignore IDs + // 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; + } - return '' + text + '\n'; - } - }, { - key: "hr", - value: function hr() { - return this.options.xhtml ? '
    \n' : '
    \n'; - } - }, { - key: "list", - value: function list(body, ordered, start) { - var type = ordered ? 'ol' : 'ul', - startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; - return '<' + type + startatt + '>\n' + body + '\n'; - } - }, { - key: "listitem", - value: function listitem(text) { - return '
  • ' + text + '
  • \n'; - } - }, { - key: "checkbox", - value: function checkbox(checked) { - return ' '; - } - }, { - key: "paragraph", - value: function paragraph(text) { - return '

    ' + text + '

    \n'; - } - }, { - key: "table", - value: function table(header, body) { - if (body) body = '' + body + ''; - return '\n' + '\n' + header + '\n' + body + '
    \n'; - } - }, { - key: "tablerow", - value: function tablerow(content) { - return '\n' + content + '\n'; - } - }, { - key: "tablecell", - value: function tablecell(content, flags) { - var type = flags.header ? 'th' : 'td'; - var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; - return tag + content + '\n'; - } - }, { - key: "strong", - // span level renderer - value: function strong(text) { - return '' + text + ''; - } - }, { - key: "em", - value: function em(text) { - return '' + text + ''; - } - }, { - key: "codespan", - value: function codespan(text) { - return '' + text + ''; - } - }, { - key: "br", - value: function br() { - return this.options.xhtml ? '
    ' : '
    '; - } - }, { - key: "del", - value: function del(text) { - return '' + text + ''; - } - }, { - key: "link", - value: function link(href, title, text) { - href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); + // code + if (cap = this.rules.code.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.codespan(escape(cap[2].trim(), true)); + continue; + } - if (href === null) { - return text; - } + // br + if (cap = this.rules.br.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.br(); + continue; + } - var out = '
    '; - return out; + // 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(cap[0])) : cap[0]); + } else { + out += this.renderer.text(escape(this.smartypants(cap[0]))); } - }, { - key: "image", - value: function image(href, title, text) { - href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); + continue; + } - if (href === null) { - return text; - } + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } - var out = '' + text + '' : '>'; - return out; - } - }, { - key: "text", - value: function text(_text) { - return _text; - } - }]); +/** + * Compile Link + */ - return Renderer; - }(); +InlineLexer.prototype.outputLink = function(cap, link) { + var href = link.href, + title = link.title ? escape(link.title) : null; - /** - * Slugger generates header id - */ - var Slugger_1 = - /*#__PURE__*/ - function () { - function Slugger() { - _classCallCheck(this, Slugger); + return cap[0].charAt(0) !== '!' + ? this.renderer.link(href, title, this.output(cap[1])) + : this.renderer.image(href, title, escape(cap[1])); +}; - this.seen = {}; - } - /** - * Convert string to unique id - */ +/** + * Smartypants Transformations + */ +InlineLexer.prototype.smartypants = function(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'); +}; - _createClass(Slugger, [{ - key: "slug", - value: function slug(value) { - var slug = value.toLowerCase().trim().replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-'); +/** + * Mangle Links + */ - if (this.seen.hasOwnProperty(slug)) { - var originalSlug = slug; +InlineLexer.prototype.mangle = function(text) { + if (!this.options.mangle) return text; + var out = '', + l = text.length, + i = 0, + ch; + + for (; i < l; i++) { + ch = text.charCodeAt(i); + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } + out += '&#' + ch + ';'; + } - do { - this.seen[originalSlug]++; - slug = originalSlug + '-' + this.seen[originalSlug]; - } while (this.seen.hasOwnProperty(slug)); - } + return out; +}; - this.seen[slug] = 0; - return slug; - } - }]); - - return Slugger; - }(); - - var defaults$3 = defaults_1.defaults; - var inline$1 = regexp.inline; - var findClosingBracket$1 = helpers.findClosingBracket, - escape$3 = helpers.escape; - /** - * Inline Lexer & Compiler - */ - - var InlineLexer_1 = - /*#__PURE__*/ - function () { - function InlineLexer(links, options) { - _classCallCheck(this, InlineLexer); - - this.options = options || defaults$3; - this.links = links; - this.rules = inline$1.normal; - this.renderer = this.options.renderer || new Renderer_1(); - this.renderer.options = this.options; - - if (!this.links) { - throw new Error('Tokens array requires a `links` property.'); - } +/** + * Renderer + */ - 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; - } - } +function Renderer(options) { + this.options = options || marked.defaults; +} + +Renderer.prototype.code = function(code, infostring, escaped) { + var lang = (infostring || '').match(/\S*/)[0]; + if (this.options.highlight) { + var out = this.options.highlight(code, lang); + if (out != null && out !== code) { + escaped = true; + code = out; } - /** - * Expose Inline Rules - */ - - - _createClass(InlineLexer, [{ - key: "output", - - /** - * Lexing/Compiling - */ - value: 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.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 (!lang) { + return '
    '
    +      + (escaped ? code : escape(code, true))
    +      + '
    '; + } - if (!link || !link.href) { - out += cap[0].charAt(0); - src = cap[0].substring(1) + src; - continue; - } + return '
    '
    +    + (escaped ? code : escape(code, true))
    +    + '
    \n'; +}; + +Renderer.prototype.blockquote = function(quote) { + return '
    \n' + quote + '
    \n'; +}; + +Renderer.prototype.html = function(html) { + return html; +}; + +Renderer.prototype.heading = function(text, level, raw, slugger) { + if (this.options.headerIds) { + return '' + + text + + '\n'; + } + // ignore IDs + return '' + text + '\n'; +}; + +Renderer.prototype.hr = function() { + return this.options.xhtml ? '
    \n' : '
    \n'; +}; + +Renderer.prototype.list = function(body, ordered, start) { + var type = ordered ? 'ol' : 'ul', + startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; + return '<' + type + startatt + '>\n' + body + '\n'; +}; + +Renderer.prototype.listitem = function(text) { + return '
  • ' + text + '
  • \n'; +}; + +Renderer.prototype.checkbox = function(checked) { + return ' '; +}; + +Renderer.prototype.paragraph = function(text) { + return '

    ' + text + '

    \n'; +}; + +Renderer.prototype.table = function(header, body) { + if (body) body = '' + body + ''; + + return '\n' + + '\n' + + header + + '\n' + + body + + '
    \n'; +}; + +Renderer.prototype.tablerow = function(content) { + return '\n' + content + '\n'; +}; + +Renderer.prototype.tablecell = function(content, flags) { + var type = flags.header ? 'th' : 'td'; + var tag = flags.align + ? '<' + type + ' align="' + flags.align + '">' + : '<' + type + '>'; + return tag + content + '\n'; +}; + +// span level renderer +Renderer.prototype.strong = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.em = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.codespan = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.br = function() { + return this.options.xhtml ? '
    ' : '
    '; +}; + +Renderer.prototype.del = function(text) { + return '' + text + ''; +}; + +Renderer.prototype.link = function(href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } + var out = '
    '; + return out; +}; + +Renderer.prototype.image = function(href, title, text) { + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } - this.inLink = true; - out += this.outputLink(cap, link); - this.inLink = false; - continue; - } // strong + var out = '' + text + '' : '>'; + return out; +}; +Renderer.prototype.text = function(text) { + return text; +}; - 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 +/** + * TextRenderer + * returns only the textual part of the token + */ +function TextRenderer() {} - 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 +// no need for block level renderers +TextRenderer.prototype.strong = +TextRenderer.prototype.em = +TextRenderer.prototype.codespan = +TextRenderer.prototype.del = +TextRenderer.prototype.text = function(text) { + return text; +}; - 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 +TextRenderer.prototype.link = +TextRenderer.prototype.image = function(href, title, text) { + return '' + text; +}; +TextRenderer.prototype.br = function() { + return ''; +}; - if (cap = this.rules.br.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.br(); - continue; - } // del (gfm) +/** + * Parsing & Compiling + */ +function Parser(options) { + this.tokens = []; + this.token = null; + this.options = options || marked.defaults; + this.options.renderer = this.options.renderer || new Renderer(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger(); +} - if (cap = this.rules.del.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.del(this.output(cap[1])); - continue; - } // autolink +/** + * Static Parse Method + */ +Parser.parse = function(src, options) { + var parser = new Parser(options); + return parser.parse(src); +}; - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); +/** + * Parse Loop + */ - if (cap[2] === '@') { - text = escape$3(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape$3(cap[1]); - href = text; - } +Parser.prototype.parse = function(src) { + this.inline = new InlineLexer(src.links, this.options); + // use an InlineLexer with a TextRenderer to extract pure text + this.inlineText = new InlineLexer( + src.links, + merge({}, this.options, { renderer: new TextRenderer() }) + ); + this.tokens = src.reverse(); + + var out = ''; + while (this.next()) { + out += this.tok(); + } - out += this.renderer.link(href, null, text); - continue; - } // url (gfm) + return out; +}; +/** + * Next Token + */ - 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]); +Parser.prototype.next = function() { + this.token = this.tokens.pop(); + return this.token; +}; - text = escape$3(cap[0]); +/** + * Preview Next Token + */ - if (cap[1] === 'www.') { - href = 'http://' + text; - } else { - href = text; - } - } +Parser.prototype.peek = function() { + return this.tokens[this.tokens.length - 1] || 0; +}; - src = src.substring(cap[0].length); - out += this.renderer.link(href, null, text); - continue; - } // text +/** + * Parse Text Tokens + */ +Parser.prototype.parseText = function() { + var body = this.token.text; - if (cap = this.rules.text.exec(src)) { - src = src.substring(cap[0].length); + while (this.peek().type === 'text') { + body += '\n' + this.next().text; + } - 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]))); - } + return this.inline.output(body); +}; - continue; - } +/** + * Parse Current Token + */ - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } +Parser.prototype.tok = function() { + 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(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 = '', + body = '', + 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] } + ); } - return out; - } - }, { - key: "outputLink", - - /** - * Compile Link - */ - value: 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])); + body += this.renderer.tablerow(cell); } - /** - * Smartypants Transformations - */ - - }, { - key: "smartypants", - value: 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"); + return this.renderer.table(header, body); + } + case 'blockquote_start': { + body = ''; + + while (this.next().type !== 'blockquote_end') { + body += this.tok(); } - /** - * Mangle Links - */ - - }, { - key: "mangle", - value: 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); + return this.renderer.blockquote(body); + } + case 'list_start': { + body = ''; + var ordered = this.token.ordered, + start = this.token.start; - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); - } + while (this.next().type !== 'list_end') { + body += this.tok(); + } - out += '&#' + ch + ';'; + 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); } - - return out; - } - }], [{ - key: "output", - - /** - * Static Lexing/Compiling Method - */ - value: function output(src, links, options) { - var inline = new InlineLexer(links, options); - return inline.output(src); } - }, { - key: "escapes", - value: function escapes(text) { - return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; - } - }, { - key: "rules", - get: function get() { - return inline$1; - } - }]); - - return InlineLexer; - }(); - - /** - * TextRenderer - * returns only the textual part of the token - */ - var TextRenderer_1 = - /*#__PURE__*/ - function () { - function TextRenderer() { - _classCallCheck(this, TextRenderer); - } - _createClass(TextRenderer, [{ - key: "strong", - // no need for block level renderers - value: function strong(text) { - return text; - } - }, { - key: "em", - value: function em(text) { - return text; - } - }, { - key: "codespan", - value: function codespan(text) { - return text; - } - }, { - key: "del", - value: function del(text) { - return text; + while (this.next().type !== 'list_item_end') { + body += !loose && this.token.type === 'text' + ? this.parseText() + : this.tok(); } - }, { - key: "text", - value: function text(_text) { - return _text; - } - }, { - key: "link", - value: function link(href, title, text) { - return '' + text; - } - }, { - key: "image", - value: function image(href, title, text) { - return '' + text; - } - }, { - key: "br", - value: function br() { - return ''; + 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 TextRenderer; - }(); - - var defaults$4 = defaults_1.defaults; - var merge$2 = helpers.merge, - unescape$1 = helpers.unescape; - /** - * Parsing & Compiling - */ - - var Parser_1 = - /*#__PURE__*/ - function () { - function Parser(options) { - _classCallCheck(this, Parser); - - this.tokens = []; - this.token = null; - this.options = options || defaults$4; - this.options.renderer = this.options.renderer || new Renderer_1(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - this.slugger = new Slugger_1(); } - /** - * Static Parse Method - */ + } +}; +/** + * Slugger generates header id + */ - _createClass(Parser, [{ - key: "parse", +function Slugger() { + this.seen = {}; +} - /** - * Parse Loop - */ - value: function parse(src) { - this.inline = new InlineLexer_1(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text +/** + * Convert string to unique id + */ - this.inlineText = new InlineLexer_1(src.links, merge$2({}, this.options, { - renderer: new TextRenderer_1() - })); - this.tokens = src.reverse(); - var out = ''; +Slugger.prototype.slug = function(value) { + var slug = value + .toLowerCase() + .trim() + .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; - while (this.next()) { - out += this.tok(); - } + return slug; +}; - return out; - } - }, { - key: "next", - - /** - * Next Token - */ - value: function next() { - this.token = this.tokens.pop(); - return this.token; - } - }, { - key: "peek", - - /** - * Preview Next Token - */ - value: function peek() { - return this.tokens[this.tokens.length - 1] || 0; - } - }, { - key: "parseText", +/** + * Helpers + */ - /** - * Parse Text Tokens - */ - value: function parseText() { - var body = this.token.text; +function escape(html, encode) { + if (encode) { + if (escape.escapeTest.test(html)) { + return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; }); + } + } else { + if (escape.escapeTestNoEncode.test(html)) { + return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; }); + } + } - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } + return html; +} + +escape.escapeTest = /[&<>"']/; +escape.escapeReplace = /[&<>"']/g; +escape.replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' +}; + +escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; +escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; + +function unescape(html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { + n = n.toLowerCase(); + if (n === 'colon') return ':'; + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' + ? String.fromCharCode(parseInt(n.substring(2), 16)) + : String.fromCharCode(+n.substring(1)); + } + return ''; + }); +} + +function edit(regex, opt) { + regex = regex.source || regex; + opt = opt || ''; + return { + replace: function(name, val) { + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return this; + }, + getRegex: function() { + return new RegExp(regex, opt); + } + }; +} - return this.inline.output(body); - } - }, { - key: "tok", - - /** - * Parse Current Token - */ - value: 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); - } - } - } - } - }], [{ - key: "parse", - value: function parse(src, options) { - var parser = new Parser(options); - return parser.parse(src); - } - }]); - - return Parser; - }(); - - var merge$3 = helpers.merge, - checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation, - escape$4 = helpers.escape; - var getDefaults$1 = defaults_1.getDefaults, - changeDefaults$1 = defaults_1.changeDefaults, - defaults$5 = defaults_1.defaults; - /** - * Marked - */ - - function marked(src, opt, callback) { - // throw error in case of non string input - if (typeof src === 'undefined' || src === null) { - throw new Error('marked(): input parameter is undefined or null'); +function cleanUrl(sanitize, base, href) { + if (sanitize) { + try { + var prot = decodeURIComponent(unescape(href)) + .replace(/[^\w:]/g, '') + .toLowerCase(); + } catch (e) { + return null; + } + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { + return null; + } + } + if (base && !originIndependentUrl.test(href)) { + href = resolveUrl(base, href); + } + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch (e) { + return null; + } + return href; +} + +function resolveUrl(base, href) { + if (!baseUrls[' ' + base]) { + // we can ignore everything in base after the last slash of its path component, + // but we might need to add _that_ + // https://tools.ietf.org/html/rfc3986#section-3 + if (/^[^:]+:\/*[^/]*$/.test(base)) { + baseUrls[' ' + base] = base + '/'; + } else { + baseUrls[' ' + base] = rtrim(base, '/', true); } + } + base = baseUrls[' ' + base]; + var relativeBase = base.indexOf(':') === -1; - if (typeof src !== 'string') { - throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected'); + if (href.slice(0, 2) === '//') { + if (relativeBase) { + return href; + } + return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; + } else if (href.charAt(0) === '/') { + if (relativeBase) { + return href; } + return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; + } else { + return base + href; + } +} +var baseUrls = {}; +var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; - if (callback || typeof opt === 'function') { - var _ret = function () { - if (!callback) { - callback = opt; - opt = null; - } +function noop() {} +noop.exec = noop; - opt = merge$3({}, marked.defaults, opt || {}); - checkSanitizeDeprecation$1(opt); - var highlight = opt.highlight; - var tokens, - pending, - i = 0; - - try { - tokens = Lexer_1.lex(src, opt); - } catch (e) { - return { - v: callback(e) - }; - } +function merge(obj) { + var i = 1, + target, + key; - pending = tokens.length; + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } - var done = function done(err) { - if (err) { - opt.highlight = highlight; - return callback(err); - } + return obj; +} + +function splitCells(tableRow, count) { + // ensure that every cell-delimiting pipe has a space + // before it to distinguish it from an escaped pipe + var row = tableRow.replace(/\|/g, function(match, offset, str) { + var escaped = false, + curr = offset; + while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }), + cells = row.split(/ \|/), + i = 0; + + if (cells.length > count) { + cells.splice(count); + } else { + while (cells.length < count) cells.push(''); + } - var out; + for (; i < cells.length; i++) { + // leading or trailing whitespace is ignored per the gfm spec + cells[i] = cells[i].trim().replace(/\\\|/g, '|'); + } + return cells; +} + +// Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). +// /c*$/ is vulnerable to REDOS. +// invert: Remove suffix of non-c chars instead. Default falsey. +function rtrim(str, c, invert) { + if (str.length === 0) { + return ''; + } - try { - out = Parser_1.parse(tokens, opt); - } catch (e) { - err = e; - } + // Length of suffix matching the invert condition. + var suffLen = 0; - opt.highlight = highlight; - return err ? callback(err) : callback(null, out); - }; + // Step left until we fail to match the invert condition. + while (suffLen < str.length) { + var currChar = str.charAt(str.length - suffLen - 1); + if (currChar === c && !invert) { + suffLen++; + } else if (currChar !== c && invert) { + suffLen++; + } else { + break; + } + } - if (!highlight || highlight.length < 3) { - return { - v: done() - }; - } + return str.substr(0, str.length - suffLen); +} - delete opt.highlight; - if (!pending) return { - v: done() - }; +function findClosingBracket(str, b) { + if (str.indexOf(b[1]) === -1) { + return -1; + } + var level = 0; + for (var i = 0; i < str.length; i++) { + if (str[i] === '\\') { + i++; + } else if (str[i] === b[0]) { + level++; + } else if (str[i] === b[1]) { + level--; + if (level < 0) { + return i; + } + } + } + return -1; +} - for (; i < tokens.length; i++) { - (function (token) { - if (token.type !== 'code') { - return --pending || done(); - } +function checkSanitizeDeprecation(opt) { + if (opt && opt.sanitize && !opt.silent) { + console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); + } +} - return highlight(token.text, token.lang, function (err, code) { - if (err) return done(err); +/** + * Marked + */ - if (code == null || code === token.text) { - return --pending || done(); - } +function marked(src, opt, callback) { + // throw error in case of non string input + if (typeof src === 'undefined' || src === null) { + throw new Error('marked(): input parameter is undefined or null'); + } + if (typeof src !== 'string') { + throw new Error('marked(): input parameter is of type ' + + Object.prototype.toString.call(src) + ', string expected'); + } - token.text = code; - token.escaped = true; - --pending || done(); - }); - })(tokens[i]); - } + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } - return { - v: void 0 - }; - }(); + opt = merge({}, marked.defaults, opt || {}); + checkSanitizeDeprecation(opt); - if (_typeof(_ret) === "object") return _ret.v; - } + var highlight = opt.highlight, + tokens, + pending, + i = 0; try { - if (opt) opt = merge$3({}, marked.defaults, opt); - checkSanitizeDeprecation$1(opt); - return Parser_1.parse(Lexer_1.lex(src, opt), opt); + tokens = Lexer.lex(src, opt); } catch (e) { - e.message += '\nPlease report this to https://github.com/markedjs/marked.'; + return callback(e); + } + + pending = tokens.length; - if ((opt || marked.defaults).silent) { - return '

    An error occurred:

    ' + escape$4(e.message + '', true) + '
    '; + var done = function(err) { + if (err) { + opt.highlight = highlight; + return callback(err); } - throw e; + var out; + + try { + out = Parser.parse(tokens, opt); + } catch (e) { + err = e; + } + + opt.highlight = highlight; + + return err + ? callback(err) + : callback(null, out); + }; + + if (!highlight || highlight.length < 3) { + return done(); + } + + delete opt.highlight; + + if (!pending) return done(); + + for (; i < tokens.length; i++) { + (function(token) { + if (token.type !== 'code') { + return --pending || done(); + } + return highlight(token.text, token.lang, function(err, code) { + if (err) return done(err); + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); } + + return; } - /** - * Options - */ + try { + if (opt) opt = merge({}, marked.defaults, opt); + checkSanitizeDeprecation(opt); + return Parser.parse(Lexer.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(e.message + '', true)
    +        + '
    '; + } + throw e; + } +} +/** + * Options + */ - marked.options = marked.setOptions = function (opt) { - merge$3(marked.defaults, opt); - changeDefaults$1(marked.defaults); - return marked; +marked.options = +marked.setOptions = function(opt) { + merge(marked.defaults, opt); + return marked; +}; + +marked.getDefaults = function() { + return { + baseUrl: null, + breaks: false, + gfm: true, + headerIds: true, + headerPrefix: '', + highlight: null, + langPrefix: 'language-', + mangle: true, + pedantic: false, + renderer: new Renderer(), + sanitize: false, + sanitizer: null, + silent: false, + smartLists: false, + smartypants: false, + xhtml: false }; +}; + +marked.defaults = marked.getDefaults(); + +/** + * Expose + */ + +marked.Parser = Parser; +marked.parser = Parser.parse; + +marked.Renderer = Renderer; +marked.TextRenderer = TextRenderer; + +marked.Lexer = Lexer; +marked.lexer = Lexer.lex; + +marked.InlineLexer = InlineLexer; +marked.inlineLexer = InlineLexer.output; + +marked.Slugger = Slugger; + +marked.parse = marked; - marked.getDefaults = getDefaults$1; - marked.defaults = defaults$5; - /** - * Expose - */ - - marked.Parser = Parser_1; - marked.parser = Parser_1.parse; - marked.Renderer = Renderer_1; - 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; - - return marked_1; - -}))); +if (typeof module !== 'undefined' && typeof exports === 'object') { + module.exports = marked; +} else if (typeof define === 'function' && define.amd) { + define(function() { return marked; }); +} else { + root.marked = marked; +} +})(this || (typeof window !== 'undefined' ? window : global)); diff --git a/marked.min.js b/marked.min.js index 8d5e08d729..c19df528a4 100644 --- a/marked.min.js +++ b/marked.min.js @@ -3,4 +3,4 @@ * Copyright (c) 2011-2018, 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 n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n"']/,a.escapeReplace=/[&<>"']/g,a.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},a.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,a.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var h={},c=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function p(){}function g(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:v,table:v,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?'|\([^()]*\))/};S.def=w(S.def).replace("label",S._label).replace("title",S._title).getRegex(),S.bullet=/(?:[*+-]|\d{1,9}\.)/,S.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,S.item=w(S.item,"gm").replace(/bull/g,S.bullet).getRegex(),S.list=w(S.list).replace(/bull/g,S.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+S.def.source+")").getRegex(),S._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",S._comment=//,S.html=w(S.html,"i").replace("comment",S._comment).replace("tag",S._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),S.paragraph=w(S._paragraph).replace("hr",S.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",S._tag).getRegex(),S.blockquote=w(S.blockquote).replace("paragraph",S.paragraph).getRegex(),S.normal=$({},S),S.gfm=$({},S.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),S.pedantic=$({},S.normal,{html:w("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",S._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:v,paragraph:w(S.normal._paragraph).replace("hr",S.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",S.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()});var z={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:v,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:v,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~"};z.em=w(z.em).replace(/punctuation/g,z._punctuation).getRegex(),z._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,z._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,z._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])?)+(?![-_])/,z.autolink=w(z.autolink).replace("scheme",z._scheme).replace("email",z._email).getRegex(),z._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,z.tag=w(z.tag).replace("comment",S._comment).replace("attribute",z._attribute).getRegex(),z._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,z._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,z._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,z.link=w(z.link).replace("label",z._label).replace("href",z._href).replace("title",z._title).getRegex(),z.reflink=w(z.reflink).replace("label",z._label).getRegex(),z.normal=$({},z),z.pedantic=$({},z.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",z._label).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",z._label).getRegex()}),z.gfm=$({},z.normal,{escape:w(z.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=!(u=[]),f=(s=s[0].match(this.rules.item)).length,p=0;p'+(n?e:P(e,!0))+"\n":"
    "+(n?e:P(e,!0))+"
    "}},{key:"blockquote",value:function(e){return"
    \n"+e+"
    \n"}},{key:"html",value:function(e){return e}},{key:"heading",value:function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"}},{key:"hr",value:function(){return this.options.xhtml?"
    \n":"
    \n"}},{key:"list",value:function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"}},{key:"listitem",value:function(e){return"
  • "+e+"
  • \n"}},{key:"checkbox",value:function(e){return" "}},{key:"paragraph",value:function(e){return"

    "+e+"

    \n"}},{key:"table",value:function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"}},{key:"tablerow",value:function(e){return"\n"+e+"\n"}},{key:"tablecell",value:function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"}},{key:"strong",value:function(e){return""+e+""}},{key:"em",value:function(e){return""+e+""}},{key:"codespan",value:function(e){return""+e+""}},{key:"br",value:function(){return this.options.xhtml?"
    ":"
    "}},{key:"del",value:function(e){return""+e+""}},{key:"link",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "}},{key:"image",value:function(e,t,n){if(null===(e=T(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"}},{key:"text",value:function(e){return e}}]),t}(),I=function(){function e(){r(this,e),this.seen={}}return i(e,[{key:"slug",value:function(e){var t=e.toLowerCase().trim().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}(),D=l.defaults,U=A.inline,B=y,N=f,F=function(){function h(e,t){if(r(this,h),this.options=t||D,this.links=e,this.rules=U.normal,this.renderer=this.options.renderer||new j,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.pedantic?this.rules=U.pedantic:this.options.gfm&&(this.options.breaks?this.rules=U.breaks:this.rules=U.gfm)}return i(h,[{key:"output",value: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+=N(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.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):N(i[0]):i[0];else if(i=this.rules.link.exec(e)){var o=B(i[2],"()");if(-1$/,"$1"),a+=this.outputLink(i,{href:h.escapes(r),title:h.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(N(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=N(this.mangle(i[1]))):n=N(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]):N(i[0]):i[0]):a+=this.renderer.text(N(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=N(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=N(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),a+=this.renderer.link(r,null,n)}return a}},{key:"outputLink",value:function(e,t){var n=t.href,r=t.title?N(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,N(e[1]))}},{key:"smartypants",value: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}},{key:"mangle",value:function(e){if(!this.options.mangle)return e;for(var t,n=e.length,r="",s=0;sAn error occurred:

    "+Q(e.message+"",!0)+"
    ";throw e}}return te.options=te.setOptions=function(e){return J(te.defaults,e),Y(te.defaults),te},te.getDefaults=W,te.defaults=ee,te.Parser=H,te.parser=H.parse,te.Renderer=j,te.TextRenderer=X,te.Lexer=E,te.lexer=E.lex,te.InlineLexer=F,te.inlineLexer=F.output,te.Slugger=I,te.parse=te}); \ No newline at end of file +!function(e){"use strict";var x={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:/^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,hr:/^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,blockquote:/^( {0,3}> ?(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:u,table:u,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/};function a(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||k.defaults,this.rules=x.normal,this.options.pedantic?this.rules=x.pedantic:this.options.gfm&&(this.rules=x.gfm)}x._label=/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,x._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,x.def=i(x.def).replace("label",x._label).replace("title",x._title).getRegex(),x.bullet=/(?:[*+-]|\d{1,9}\.)/,x.item=/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,x.item=i(x.item,"gm").replace(/bull/g,x.bullet).getRegex(),x.list=i(x.list).replace(/bull/g,x.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+x.def.source+")").getRegex(),x._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",x._comment=//,x.html=i(x.html,"i").replace("comment",x._comment).replace("tag",x._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),x.paragraph=i(x._paragraph).replace("hr",x.hr).replace("heading"," {0,3}#{1,6} +").replace("|lheading","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html",")|<(?:script|pre|style|!--)").replace("tag",x._tag).getRegex(),x.blockquote=i(x.blockquote).replace("paragraph",x.paragraph).getRegex(),x.normal=f({},x),x.gfm=f({},x.normal,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),x.pedantic=f({},x.normal,{html:i("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",x._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:u,paragraph:i(x.normal._paragraph).replace("hr",x.hr).replace("heading"," *#{1,6} *[^\n]").replace("lheading",x.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()}),a.rules=x,a.lex=function(e,t){return new a(t).lex(e)},a.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," "),this.token(e,!0)},a.prototype.token=function(e,t){var n,r,s,i,l,o,a,h,p,c,u,g,f,d,m,k;for(e=e.replace(/^ +$/gm,"");e;)if((s=this.rules.newline.exec(e))&&(e=e.substring(s[0].length),1 ?/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),a={type:"list_start",ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(a),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,u=0;u?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:u,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:u,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~",n.em=i(n.em).replace(/punctuation/g,n._punctuation).getRegex(),n._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,n._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,n._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])?)+(?![-_])/,n.autolink=i(n.autolink).replace("scheme",n._scheme).replace("email",n._email).getRegex(),n._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,n.tag=i(n.tag).replace("comment",x._comment).replace("attribute",n._attribute).getRegex(),n._label=/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,n._href=/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/,n._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,n.link=i(n.link).replace("label",n._label).replace("href",n._href).replace("title",n._title).getRegex(),n.reflink=i(n.reflink).replace("label",n._label).getRegex(),n.normal=f({},n),n.pedantic=f({},n.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:i(/^!?\[(label)\]\((.*?)\)/).replace("label",n._label).getRegex(),reflink:i(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",n._label).getRegex()}),n.gfm=f({},n.normal,{escape:i(n.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]*?(?:(?=[\\/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),o+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):_(i[0]):i[0];else if(i=this.rules.link.exec(e)){var a=d(i[2],"()");if(-1$/,"$1"),o+=this.outputLink(i,{href:p.escapes(r),title:p.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){o+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,o+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),o+=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),o+=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),o+=this.renderer.codespan(_(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),o+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),o+=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=_(this.mangle(i[1]))):n=_(i[1]),o+=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?o+=this.renderer.text(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):_(i[0]):i[0]):o+=this.renderer.text(_(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=_(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=_(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),o+=this.renderer.link(r,null,n)}return o},p.escapes=function(e){return e?e.replace(p.rules._escapes,"$1"):e},p.prototype.outputLink=function(e,t){var n=t.href,r=t.title?_(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,_(e[1]))},p.prototype.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},p.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=e.length,s=0;s'+(n?e:_(e,!0))+"\n":"
    "+(n?e:_(e,!0))+"
    "},r.prototype.blockquote=function(e){return"
    \n"+e+"
    \n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,n,r){return this.options.headerIds?"'+e+"\n":""+e+"\n"},r.prototype.hr=function(){return this.options.xhtml?"
    \n":"
    \n"},r.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},r.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},r.prototype.checkbox=function(e){return" "},r.prototype.paragraph=function(e){return"

    "+e+"

    \n"},r.prototype.table=function(e,t){return"\n\n"+e+"\n"+(t=t&&""+t+"")+"
    \n"},r.prototype.tablerow=function(e){return"\n"+e+"\n"},r.prototype.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},r.prototype.strong=function(e){return""+e+""},r.prototype.em=function(e){return""+e+""},r.prototype.codespan=function(e){return""+e+""},r.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},r.prototype.del=function(e){return""+e+""},r.prototype.link=function(e,t,n){if(null===(e=l(this.options.sanitize,this.options.baseUrl,e)))return n;var r='
    "},r.prototype.image=function(e,t,n){if(null===(e=l(this.options.sanitize,this.options.baseUrl,e)))return n;var r=''+n+'":">"},r.prototype.text=function(e){return e},s.prototype.strong=s.prototype.em=s.prototype.codespan=s.prototype.del=s.prototype.text=function(e){return e},s.prototype.link=s.prototype.image=function(e,t,n){return""+n},s.prototype.br=function(){return""},h.parse=function(e,t){return new h(t).parse(e)},h.prototype.parse=function(e){this.inline=new p(e.links,this.options),this.inlineText=new p(e.links,f({},this.options,{renderer:new s})),this.tokens=e.reverse();for(var t="";this.next();)t+=this.tok();return t},h.prototype.next=function(){return this.token=this.tokens.pop(),this.token},h.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},h.prototype.parseText=function(){for(var e=this.token.text;"text"===this.peek().type;)e+="\n"+this.next().text;return this.inline.output(e)},h.prototype.tok=function(){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,g(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 e,t,n,r,s="",i="";for(n="",e=0;e?@[\]^`{|}~]/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},_.escapeTest=/[&<>"']/,_.escapeReplace=/[&<>"']/g,_.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},_.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,_.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var o={},c=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function u(){}function f(e){for(var t,n,r=1;rt)n.splice(t);else for(;n.lengthAn error occurred:

    "+_(e.message+"",!0)+"
    ";throw e}}u.exec=u,k.options=k.setOptions=function(e){return f(k.defaults,e),k},k.getDefaults=function(){return{baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:new r,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,xhtml:!1}},k.defaults=k.getDefaults(),k.Parser=h,k.parser=h.parse,k.Renderer=r,k.TextRenderer=s,k.Lexer=a,k.lexer=a.lex,k.InlineLexer=p,k.inlineLexer=p.output,k.Slugger=t,k.parse=k,"undefined"!=typeof module&&"object"==typeof exports?module.exports=k:"function"==typeof define&&define.amd?define(function(){return k}):e.marked=k}(this||("undefined"!=typeof window?window:global)); \ No newline at end of file diff --git a/package.json b/package.json index 115c86e037..c4a25314c9 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "test:update": "node test/update-specs.js", "bench": "npm run rollup && node test/bench.js", "lint": "eslint --fix bin/marked .", + "build:reset": "git checkout upstream/master lib/marked.js marked.min.js", "build": "npm run rollup && npm run minify", "rollup": "rollup -c rollup.config.js", "minify": "uglifyjs lib/marked.js -cm --comments /Copyright/ -o marked.min.js", From 1ce5c4e1fd1270ee5c5a16d855614d4ee57d2e1c Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 12:15:12 -0600 Subject: [PATCH 10/33] remove test:redos and use es6 in tests --- .travis.yml | 4 ---- package.json | 5 ++--- test/helpers/helpers.js | 2 +- test/unit/marked-spec.js | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c17ffab2b..9f1b0b81b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,10 +33,6 @@ jobs: node_js: lts/* if: branch = master AND type = push - - stage: security scan 🔐 - script: npm run test:redos - node_js: lts/* - cache: directories: - node_modules diff --git a/package.json b/package.json index c4a25314c9..42544bd1a7 100644 --- a/package.json +++ b/package.json @@ -53,17 +53,16 @@ "uglify-js": "^3.6.8" }, "scripts": { - "test": "npm run build && jasmine --config=jasmine.json", + "test": "jasmine --config=jasmine.json", "test:all": "npm test && npm run test:lint", "test:unit": "npm test -- test/unit/**/*-spec.js", "test:specs": "npm test -- test/specs/**/*-spec.js", "test:lint": "eslint bin/marked .", - "test:redos": "npm run rollup && eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' --no-ignore lib/marked.js", "test:update": "node test/update-specs.js", "bench": "npm run rollup && node test/bench.js", "lint": "eslint --fix bin/marked .", "build:reset": "git checkout upstream/master lib/marked.js marked.min.js", - "build": "npm run rollup && npm run minify", + "build": "npm run build && npm run minify", "rollup": "rollup -c rollup.config.js", "minify": "uglifyjs lib/marked.js -cm --comments /Copyright/ -o marked.min.js", "preversion": "npm run build && (git diff --quiet || git commit -am 'build')" diff --git a/test/helpers/helpers.js b/test/helpers/helpers.js index f6eb634a72..a71db73cd9 100644 --- a/test/helpers/helpers.js +++ b/test/helpers/helpers.js @@ -1,4 +1,4 @@ -const marked = require('../../'); +const marked = require('../../src/marked.js'); const htmlDiffer = require('./html-differ.js'); beforeEach(() => { diff --git a/test/unit/marked-spec.js b/test/unit/marked-spec.js index e28371aa47..4145f73807 100644 --- a/test/unit/marked-spec.js +++ b/test/unit/marked-spec.js @@ -1,4 +1,4 @@ -const marked = require('../../lib/marked.js'); +const marked = require('../../src/marked.js'); describe('Test heading ID functionality', () => { it('should add id attribute by default', () => { From 0b056bff9e17315e9fc76c9e0f44f4a77eb8b140 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 14:00:06 -0600 Subject: [PATCH 11/33] build `lib/marked.esm.js` --- package-lock.json | 281 +++---------------------------------------- package.json | 11 +- rollup.config.esm.js | 20 +++ 3 files changed, 43 insertions(+), 269 deletions(-) create mode 100644 rollup.config.esm.js diff --git a/package-lock.json b/package-lock.json index 22955f55e9..9c6879ff94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -838,30 +838,12 @@ "parse5-sax-parser": "^5.1.0" } }, - "@types/concat-stream": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@types/concat-stream/-/concat-stream-1.6.0.tgz", - "integrity": "sha1-OU2+C7X+5Gs42JZzXoto7yOQ0A0=", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, - "@types/form-data": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-0.0.33.tgz", - "integrity": "sha1-yayFsqX9GENbjIXZ7LUObWyJP/g=", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/node": { "version": "9.6.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.5.tgz", @@ -874,12 +856,6 @@ "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==", "dev": true }, - "@types/qs": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-mNhVdZHdtKHMMxbqzNK3RzkBcN1cux3AvuCYGTvjEIQT2uheH3eCAyYsbMbh2Bq8nXkeOWs1kyDiF7geWRFQ4Q==", - "dev": true - }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -953,24 +929,12 @@ "es-abstract": "^1.7.0" } }, - "asap": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=", - "dev": true - }, "astral-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "dev": true - }, "babel-plugin-dynamic-import-node": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz", @@ -1025,12 +989,6 @@ "integrity": "sha512-b8DJyb+VVXZGRgJUa30cbk8gKHZ3LOZTBLaUEEVr2P4xpmFigOCc62CO4uzquW641Ouq1Rm9N+rWLWdSYDaDIw==", "dev": true }, - "caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "dev": true - }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -1114,15 +1072,6 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, - "combined-stream": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz", - "integrity": "sha1-cj599ugBrFYTETp+RFqbactjKBg=", - "dev": true, - "requires": { - "delayed-stream": "~1.0.0" - } - }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1153,49 +1102,6 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, - "concat-stream": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", - "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", - "dev": true, - "requires": { - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - }, - "dependencies": { - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "readable-stream": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", - "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~1.0.6", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.0.3", - "util-deprecate": "~1.0.1" - } - }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - } - } - }, "contains-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", @@ -1221,12 +1127,6 @@ "semver": "^6.3.0" } }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true - }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -1290,12 +1190,6 @@ "object-keys": "^1.0.12" } }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true - }, "diff": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", @@ -1618,16 +1512,6 @@ "integrity": "sha512-v/KBnfyaOMPmZc/dmc6ozOdWqekGp7bBGq4jLAecEfPGmfKiWS4sA8sC0LqiV9w5qmXAtXVn4M3p1jSyhY85SQ==", "dev": true }, - "eslint-plugin-vuln-regex-detector": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-vuln-regex-detector/-/eslint-plugin-vuln-regex-detector-1.0.4.tgz", - "integrity": "sha512-MlGNEvfk/lmHrbp6gIXKP2NPedA+wX2+KwezolXLE6t9q0pcmohkYm2EKmgL9z5n57CAIYFJ/I4SSI3ANWyl/A==", - "dev": true, - "requires": { - "requireindex": "~1.1.0", - "vuln-regex-detector": "^1.3.0" - } - }, "eslint-scope": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", @@ -1779,17 +1663,6 @@ "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "dev": true }, - "form-data": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.2.tgz", - "integrity": "sha1-SXBJi+YEwgwAXU9cI67NIda0kJk=", - "dev": true, - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "1.0.6", - "mime-types": "^2.1.12" - } - }, "front-matter": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.0.2.tgz", @@ -1817,12 +1690,6 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, - "get-port": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-3.2.0.tgz", - "integrity": "sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw=", - "dev": true - }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", @@ -1902,29 +1769,6 @@ "readable-stream": "^3.1.1" } }, - "http-basic": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/http-basic/-/http-basic-7.0.0.tgz", - "integrity": "sha1-gvClBr6UJzLsje6+6A50bvVzbbo=", - "dev": true, - "requires": { - "@types/concat-stream": "^1.6.0", - "@types/node": "^9.4.1", - "caseless": "~0.12.0", - "concat-stream": "^1.4.6", - "http-response-object": "^3.0.1", - "parse-cache-control": "^1.0.1" - } - }, - "http-response-object": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.1.tgz", - "integrity": "sha512-6L0Fkd6TozA8kFSfh9Widst0wfza3U1Ex2RjJ6zNDK0vR1U1auUR6jY4Nn2Xl7CCy0ikFmxW1XcspVpb9RvwTg==", - "dev": true, - "requires": { - "@types/node": "^9.3.0" - } - }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -2269,21 +2113,6 @@ "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", "dev": true }, - "mime-db": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", - "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==", - "dev": true - }, - "mime-types": { - "version": "2.1.18", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz", - "integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==", - "dev": true, - "requires": { - "mime-db": "~1.33.0" - } - }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -2506,12 +2335,6 @@ "callsites": "^3.0.0" } }, - "parse-cache-control": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz", - "integrity": "sha1-juqz5U+laSD+Fro493+iGqzC104=", - "dev": true - }, "parse-json": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", @@ -2596,27 +2419,12 @@ "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==", "dev": true }, - "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=", - "dev": true - }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, - "promise": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/promise/-/promise-8.0.1.tgz", - "integrity": "sha1-5F1osAoXZHttpxG/he1u1HII9FA=", - "dev": true, - "requires": { - "asap": "~2.0.3" - } - }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -2629,12 +2437,6 @@ "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=", "dev": true }, - "qs": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==", - "dev": true - }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -2691,6 +2493,12 @@ "private": "^0.1.6" } }, + "regexp-tree": { + "version": "0.1.14", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.14.tgz", + "integrity": "sha512-59v5A90TAh4cAMyDQEOzcnsu4q7Wb10RsyTjngEnJIZsWYM4siVGu+JmLT1WsxHvOWhiu4YS20XiTuxWMeVoHQ==", + "dev": true + }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", @@ -2734,12 +2542,6 @@ } } }, - "requireindex": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.1.0.tgz", - "integrity": "sha1-5UBLgVV+91225JxacgBIk/4D4WI=", - "dev": true - }, "resolve": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", @@ -2880,6 +2682,15 @@ "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", "dev": true }, + "safe-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz", + "integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==", + "dev": true, + "requires": { + "regexp-tree": "~0.1.1" + } + }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -3038,26 +2849,6 @@ "has-flag": "^3.0.0" } }, - "sync-request": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/sync-request/-/sync-request-6.0.0.tgz", - "integrity": "sha512-jGNIAlCi9iU4X3Dm4oQnNQshDD3h0/1A7r79LyqjbjUnj69sX6mShAXlhRXgImsfVKtTcnra1jfzabdZvp+Lmw==", - "dev": true, - "requires": { - "http-response-object": "^3.0.1", - "sync-rpc": "^1.2.1", - "then-request": "^6.0.0" - } - }, - "sync-rpc": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/sync-rpc/-/sync-rpc-1.3.3.tgz", - "integrity": "sha512-xtTZUAeFaescZALim6yqjMDsVQD7mKAkdZ0/FOvVjlrr4uQqrARlWxs4P7bKV2ZPnvOyTVyHyyxqztxtBF4iIw==", - "dev": true, - "requires": { - "get-port": "^3.1.0" - } - }, "table": { "version": "5.4.6", "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", @@ -3101,33 +2892,6 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, - "then-request": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/then-request/-/then-request-6.0.0.tgz", - "integrity": "sha512-xA+7uEMc+jsQIoyySJ93Ad08Kuqnik7u6jLS5hR91Z3smAoCfL3M8/MqMlobAa9gzBfO9pA88A/AntfepkkMJQ==", - "dev": true, - "requires": { - "@types/concat-stream": "^1.6.0", - "@types/form-data": "0.0.33", - "@types/node": "^8.0.0", - "@types/qs": "^6.2.31", - "caseless": "~0.12.0", - "concat-stream": "^1.6.0", - "form-data": "^2.2.0", - "http-basic": "^7.0.0", - "http-response-object": "^3.0.1", - "promise": "^8.0.0", - "qs": "^6.4.0" - }, - "dependencies": { - "@types/node": { - "version": "8.10.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.8.tgz", - "integrity": "sha512-BvcUxNZe9JgiiUVivtiQt3NrPVu9OAQzkxR1Ko9ESftCYU7V6Np5kpDzQwxd+34lsop7SNRdL292Flv52OvCaw==", - "dev": true - } - } - }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -3170,12 +2934,6 @@ "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==", "dev": true }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "dev": true - }, "uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", @@ -3251,15 +3009,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "vuln-regex-detector": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/vuln-regex-detector/-/vuln-regex-detector-1.3.0.tgz", - "integrity": "sha512-QWm8buVznZjdcfMuFHYsiNfHd0YQ7dO41G0iEGVPlUng5eZUo8uy+QsVCmbgVZ2b96xprY1Tz9dQD7QtvbFHXw==", - "dev": true, - "requires": { - "sync-request": "^6.0.0" - } - }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 42544bd1a7..331b85e068 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,10 @@ "author": "Christopher Jeffrey", "version": "0.7.0", "main": "./src/marked.js", + "module": "./lib/marked.esm.js", + "browser": { + "./src/marked.js": "./lib/marked.js" + }, "bin": "./bin/marked", "man": "./man/marked.1", "files": [ @@ -40,7 +44,6 @@ "eslint-plugin-node": "^10.0.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", - "eslint-plugin-vuln-regex-detector": "^1.0.4", "front-matter": "^3.0.2", "jasmine": "^3.5.0", "markdown": "0.5.x", @@ -62,8 +65,10 @@ "bench": "npm run rollup && node test/bench.js", "lint": "eslint --fix bin/marked .", "build:reset": "git checkout upstream/master lib/marked.js marked.min.js", - "build": "npm run build && npm run minify", - "rollup": "rollup -c rollup.config.js", + "build": "npm run rollup && npm run minify", + "rollup": "npm run rollup:umd && npm run rollup:esm", + "rollup:umd": "rollup -c rollup.config.js", + "rollup:esm": "rollup -c rollup.config.esm.js", "minify": "uglifyjs lib/marked.js -cm --comments /Copyright/ -o marked.min.js", "preversion": "npm run build && (git diff --quiet || git commit -am 'build')" }, diff --git a/rollup.config.esm.js b/rollup.config.esm.js new file mode 100644 index 0000000000..0e1bfc3a47 --- /dev/null +++ b/rollup.config.esm.js @@ -0,0 +1,20 @@ +const commonjs = require('rollup-plugin-commonjs'); +const license = require('rollup-plugin-license'); + +module.exports = { + input: 'src/marked.js', + output: { + file: 'lib/marked.esm.js', + format: 'esm' + }, + plugins: [ + license({ + banner: ` +marked - a markdown parser +Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) +https://github.com/markedjs/marked +` + }), + commonjs() + ] +}; From 58beb5ceebdc007c4018d8a614cb8c634d503ae2 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 14:34:27 -0600 Subject: [PATCH 12/33] add vuln-regex test --- .travis.yml | 4 + package-lock.json | 272 ++++++++++++++++++++++++++++++++++++++++++--- package.json | 4 +- test/vuln-regex.js | 42 +++++++ 4 files changed, 306 insertions(+), 16 deletions(-) create mode 100644 test/vuln-regex.js diff --git a/.travis.yml b/.travis.yml index 9f1b0b81b5..1c17ffab2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,10 @@ jobs: node_js: lts/* if: branch = master AND type = push + - stage: security scan 🔐 + script: npm run test:redos + node_js: lts/* + cache: directories: - node_modules diff --git a/package-lock.json b/package-lock.json index 9c6879ff94..23fc190a71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -838,12 +838,30 @@ "parse5-sax-parser": "^5.1.0" } }, + "@types/concat-stream": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@types/concat-stream/-/concat-stream-1.6.0.tgz", + "integrity": "sha1-OU2+C7X+5Gs42JZzXoto7yOQ0A0=", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, + "@types/form-data": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-0.0.33.tgz", + "integrity": "sha1-yayFsqX9GENbjIXZ7LUObWyJP/g=", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "9.6.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.5.tgz", @@ -856,6 +874,12 @@ "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==", "dev": true }, + "@types/qs": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.5.3.tgz", + "integrity": "sha512-Jugo5V/1bS0fRhy2z8+cUAHEyWOATaz4rbyLVvcFs7+dXp5HfwpEwzF1Q11bB10ApUqHf+yTauxI0UXQDwGrbA==", + "dev": true + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -929,12 +953,24 @@ "es-abstract": "^1.7.0" } }, + "asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=", + "dev": true + }, "astral-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true + }, "babel-plugin-dynamic-import-node": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz", @@ -977,6 +1013,12 @@ "node-releases": "^1.1.38" } }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -989,6 +1031,12 @@ "integrity": "sha512-b8DJyb+VVXZGRgJUa30cbk8gKHZ3LOZTBLaUEEVr2P4xpmFigOCc62CO4uzquW641Ouq1Rm9N+rWLWdSYDaDIw==", "dev": true }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", + "dev": true + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -1072,6 +1120,15 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1102,6 +1159,44 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, "contains-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", @@ -1127,6 +1222,12 @@ "semver": "^6.3.0" } }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -1190,6 +1291,12 @@ "object-keys": "^1.0.12" } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, "diff": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", @@ -1663,6 +1770,17 @@ "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "dev": true }, + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, "front-matter": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.0.2.tgz", @@ -1690,6 +1808,12 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "get-port": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/get-port/-/get-port-3.2.0.tgz", + "integrity": "sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw=", + "dev": true + }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", @@ -1769,6 +1893,35 @@ "readable-stream": "^3.1.1" } }, + "http-basic": { + "version": "8.1.3", + "resolved": "https://registry.npmjs.org/http-basic/-/http-basic-8.1.3.tgz", + "integrity": "sha512-/EcDMwJZh3mABI2NhGfHOGOeOZITqfkEO4p/xK+l3NpyncIHUQBoMvCSF/b5GqvKtySC2srL/GGG3+EtlqlmCw==", + "dev": true, + "requires": { + "caseless": "^0.12.0", + "concat-stream": "^1.6.2", + "http-response-object": "^3.0.1", + "parse-cache-control": "^1.0.1" + } + }, + "http-response-object": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz", + "integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==", + "dev": true, + "requires": { + "@types/node": "^10.0.3" + }, + "dependencies": { + "@types/node": { + "version": "10.17.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.4.tgz", + "integrity": "sha512-F2pgg+LcIr/elguz+x+fdBX5KeZXGUOp7TV8M0TVIrDezYLFRNt8oMTyps0VQ1kj5WGGoR18RdxnRDHXrIFHMQ==", + "dev": true + } + } + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -2113,6 +2266,21 @@ "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", "dev": true }, + "mime-db": { + "version": "1.40.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", + "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA==", + "dev": true + }, + "mime-types": { + "version": "2.1.24", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz", + "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==", + "dev": true, + "requires": { + "mime-db": "1.40.0" + } + }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -2335,6 +2503,12 @@ "callsites": "^3.0.0" } }, + "parse-cache-control": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz", + "integrity": "sha1-juqz5U+laSD+Fro493+iGqzC104=", + "dev": true + }, "parse-json": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", @@ -2419,12 +2593,27 @@ "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==", "dev": true }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true + }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, + "promise": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/promise/-/promise-8.0.3.tgz", + "integrity": "sha512-HeRDUL1RJiLhyA0/grn+PTShlBAcLuh/1BJGtrvjwbvRDCTLLMEz9rOGCV+R3vHY4MixIuoMEd9Yq/XvsTPcjw==", + "dev": true, + "requires": { + "asap": "~2.0.6" + } + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -2437,6 +2626,12 @@ "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=", "dev": true }, + "qs": { + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.0.tgz", + "integrity": "sha512-27RP4UotQORTpmNQDX8BHPukOnBP3p1uUJY5UnDhaJB+rMt9iMsok724XL+UHU23bEFOHRMQ2ZhI99qOWUMGFA==", + "dev": true + }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -2493,12 +2688,6 @@ "private": "^0.1.6" } }, - "regexp-tree": { - "version": "0.1.14", - "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.14.tgz", - "integrity": "sha512-59v5A90TAh4cAMyDQEOzcnsu4q7Wb10RsyTjngEnJIZsWYM4siVGu+JmLT1WsxHvOWhiu4YS20XiTuxWMeVoHQ==", - "dev": true - }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", @@ -2682,15 +2871,6 @@ "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", "dev": true }, - "safe-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz", - "integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==", - "dev": true, - "requires": { - "regexp-tree": "~0.1.1" - } - }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -2849,6 +3029,26 @@ "has-flag": "^3.0.0" } }, + "sync-request": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/sync-request/-/sync-request-6.1.0.tgz", + "integrity": "sha512-8fjNkrNlNCrVc/av+Jn+xxqfCjYaBoHqCsDz6mt030UMxJGr+GSfCV1dQt2gRtlL63+VPidwDVLr7V2OcTSdRw==", + "dev": true, + "requires": { + "http-response-object": "^3.0.1", + "sync-rpc": "^1.2.1", + "then-request": "^6.0.0" + } + }, + "sync-rpc": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/sync-rpc/-/sync-rpc-1.3.6.tgz", + "integrity": "sha512-J8jTXuZzRlvU7HemDgHi3pGnh/rkoqR/OZSjhTyyZrEkkYQbk7Z33AXp37mkPfPpfdOuj7Ex3H/TJM1z48uPQw==", + "dev": true, + "requires": { + "get-port": "^3.1.0" + } + }, "table": { "version": "5.4.6", "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", @@ -2892,6 +3092,33 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "then-request": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/then-request/-/then-request-6.0.2.tgz", + "integrity": "sha512-3ZBiG7JvP3wbDzA9iNY5zJQcHL4jn/0BWtXIkagfz7QgOL/LqjCEOBQuJNZfu0XYnv5JhKh+cDxCPM4ILrqruA==", + "dev": true, + "requires": { + "@types/concat-stream": "^1.6.0", + "@types/form-data": "0.0.33", + "@types/node": "^8.0.0", + "@types/qs": "^6.2.31", + "caseless": "~0.12.0", + "concat-stream": "^1.6.0", + "form-data": "^2.2.0", + "http-basic": "^8.1.1", + "http-response-object": "^3.0.1", + "promise": "^8.0.0", + "qs": "^6.4.0" + }, + "dependencies": { + "@types/node": { + "version": "8.10.58", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.58.tgz", + "integrity": "sha512-NNcUk/rAdR7Pie7WiA5NHp345dTkD62qaxqscQXVIjCjog/ZXsrG8Wo7dZMZAzE7PSpA+qR2S3TYTeFCKuBFxQ==", + "dev": true + } + } + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -2934,6 +3161,12 @@ "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==", "dev": true }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, "uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", @@ -3009,6 +3242,15 @@ "spdx-expression-parse": "^3.0.0" } }, + "vuln-regex-detector": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/vuln-regex-detector/-/vuln-regex-detector-1.3.0.tgz", + "integrity": "sha512-QWm8buVznZjdcfMuFHYsiNfHd0YQ7dO41G0iEGVPlUng5eZUo8uy+QsVCmbgVZ2b96xprY1Tz9dQD7QtvbFHXw==", + "dev": true, + "requires": { + "sync-request": "^6.0.0" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 331b85e068..fa6f509d9a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "rollup-plugin-babel": "^4.3.3", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-license": "^0.12.1", - "uglify-js": "^3.6.8" + "uglify-js": "^3.6.8", + "vuln-regex-detector": "^1.3.0" }, "scripts": { "test": "jasmine --config=jasmine.json", @@ -61,6 +62,7 @@ "test:unit": "npm test -- test/unit/**/*-spec.js", "test:specs": "npm test -- test/specs/**/*-spec.js", "test:lint": "eslint bin/marked .", + "test:redos": "node test/vuln-regex.js", "test:update": "node test/update-specs.js", "bench": "npm run rollup && node test/bench.js", "lint": "eslint --fix bin/marked .", diff --git a/test/vuln-regex.js b/test/vuln-regex.js new file mode 100644 index 0000000000..e548c8038f --- /dev/null +++ b/test/vuln-regex.js @@ -0,0 +1,42 @@ +const regexp = require('../src/regexp.js'); +const vulnRegexDetector = require('vuln-regex-detector'); + +const promises = []; +function findRegexps(name, obj) { + if (typeof obj === 'string') { + promises.push(testRegexp(name, obj)); + } if (obj instanceof RegExp || obj.exec) { + if (obj.source) { + promises.push(testRegexp(name, obj.source)); + } + } else if (typeof obj === 'object') { + for (const prop in obj) { + findRegexps(name + (name ? '.' : '') + prop, obj[prop]); + } + } +} + +async function testRegexp(name, source) { + try { + const result = await vulnRegexDetector.test(source); + + if (result === vulnRegexDetector.responses.safe) { + console.log(`${name} is safe`); + return true; + } else if (result === vulnRegexDetector.responses.vulnerable) { + console.error(`${name} is vulnerable`); + } else { + console.error(`${name} might be vulnerable: ` + result.toString()); + } + } catch (ex) { + console.error(`${name} failed with error: ` + ex.toString()); + } + return false; +} + +findRegexps('', regexp); +// promises.push(testRegexp('a', /(a+)+$/.source)); +Promise.allSettled(promises).then(results => { + const code = results.every(r => r.value) ? 0 : 1; + process.exit(code); +}); From 30b41028264a903d3ea4573c3e8ec237e0817ca5 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 14:57:24 -0600 Subject: [PATCH 13/33] include src/ in npm package --- bin/.eslintrc.json | 33 --------------------------------- bin/marked | 34 +++++++++++++++++----------------- package.json | 1 + 3 files changed, 18 insertions(+), 50 deletions(-) delete mode 100644 bin/.eslintrc.json diff --git a/bin/.eslintrc.json b/bin/.eslintrc.json deleted file mode 100644 index 6ee10878c6..0000000000 --- a/bin/.eslintrc.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "extends": "standard", - "plugins": [ - "standard" - ], - "parserOptions": { - "ecmaVersion": 5, - "sourceType": "script" - }, - "rules": { - "semi": ["error", "always"], - "indent": ["error", 2, { - "SwitchCase": 1, - "VariableDeclarator": { "var": 2 }, - "outerIIFEBody": 0 - }], - "operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }], - "space-before-function-paren": ["error", "never"], - "no-cond-assign": "off", - "no-useless-escape": "off", - "one-var": "off", - "no-control-regex": "off", - "no-prototype-builtins": "off", - - "prefer-const": "off", - "no-var": "off" - }, - "env": { - "node": true, - "browser": true, - "amd": true - } -} diff --git a/bin/marked b/bin/marked index 307db173b0..4612fedf23 100755 --- a/bin/marked +++ b/bin/marked @@ -5,18 +5,18 @@ * Copyright (c) 2011-2013, Christopher Jeffrey (MIT License) */ -var fs = require('fs'), - path = require('path'), - marked = require('../'); +const fs = require('fs'), + path = require('path'), + marked = require('../'); /** * Man Page */ function help() { - var spawn = require('child_process').spawn; + const spawn = require('child_process').spawn; - var options = { + const options = { cwd: process.cwd(), env: process.env, setsid: false, @@ -33,7 +33,7 @@ function help() { } function version() { - var pkg = require('../package.json'); + const pkg = require('../package.json'); console.log(pkg.version); } @@ -42,17 +42,17 @@ function version() { */ function main(argv, callback) { - var files = [], - options = {}, - input, - output, - string, - arg, - tokens, - opt; + const files = [], + options = {}; + let input, + output, + string, + arg, + tokens, + opt; function getarg() { - var arg = argv.shift(); + let arg = argv.shift(); if (arg.indexOf('--') === 0) { // e.g. --opt @@ -162,8 +162,8 @@ function main(argv, callback) { */ function getStdin(callback) { - var stdin = process.stdin, - buff = ''; + const stdin = process.stdin; + let buff = ''; stdin.setEncoding('utf8'); diff --git a/package.json b/package.json index fa6f509d9a..fc477c70f9 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "files": [ "bin/", "lib/", + "src/", "man/", "marked.min.js" ], From faab6c7f7211bc672b82718eb2c6be2fc0313628 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 15:00:03 -0600 Subject: [PATCH 14/33] fix options not being passed --- src/marked.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/marked.js b/src/marked.js index 32acf4d136..10704b0764 100644 --- a/src/marked.js +++ b/src/marked.js @@ -98,7 +98,7 @@ function marked(src, opt, callback) { return; } try { - if (opt) opt = merge({}, marked.defaults, opt); + opt = merge({}, marked.defaults, opt || {}); checkSanitizeDeprecation(opt); return Parser.parse(Lexer.lex(src, opt), opt); } catch (e) { From 5a8a63b170854a5de9f932ad439057812298cdb2 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 15:03:28 -0600 Subject: [PATCH 15/33] reset esm.js --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fc477c70f9..0fb720a586 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "test:update": "node test/update-specs.js", "bench": "npm run rollup && node test/bench.js", "lint": "eslint --fix bin/marked .", - "build:reset": "git checkout upstream/master lib/marked.js marked.min.js", + "build:reset": "git checkout upstream/master lib/marked.js lib/marked.esm.js marked.min.js", "build": "npm run rollup && npm run minify", "rollup": "npm run rollup:umd && npm run rollup:esm", "rollup:umd": "rollup -c rollup.config.js", From c14a18fad0b7c112edb226ead3566a7e75d4f30c Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 15:22:07 -0600 Subject: [PATCH 16/33] save renderer to inlinelexer options --- src/InlineLexer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/InlineLexer.js b/src/InlineLexer.js index e790e9e8d8..a25bfea129 100644 --- a/src/InlineLexer.js +++ b/src/InlineLexer.js @@ -14,7 +14,8 @@ module.exports = class InlineLexer { this.options = options || defaults; this.links = links; this.rules = inline.normal; - this.renderer = this.options.renderer || new Renderer(); + this.options.renderer = this.options.renderer || new Renderer(); + this.renderer = this.options.renderer; this.renderer.options = this.options; if (!this.links) { From 18b311030a899adab7950af4dd972de710fdcb2e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 15:24:37 -0600 Subject: [PATCH 17/33] remove bench debugging --- test/bench.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/bench.js b/test/bench.js index 3932453529..564f74c238 100644 --- a/test/bench.js +++ b/test/bench.js @@ -27,18 +27,6 @@ function runBench(options) { options = options || {}; const specs = load(); - marked.setOptions({ - gfm: false, - breaks: false, - pedantic: false, - sanitize: false, - smartLists: false - }); - if (options.marked) { - marked.setOptions(options.marked); - } - bench('non marked', specs, marked); - // Non-GFM, Non-pedantic marked.setOptions({ gfm: false, From 6707c3d76241c8214fb2c51ca42fcf6aae7bd654 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 15:27:05 -0600 Subject: [PATCH 18/33] fix spelling --- docs/AUTHORS.md | 10 +++++----- docs/CONTRIBUTING.md | 3 +-- docs/PUBLISHING.md | 6 +++--- docs/USING_ADVANCED.md | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/AUTHORS.md b/docs/AUTHORS.md index dd91409568..87ab522f98 100644 --- a/docs/AUTHORS.md +++ b/docs/AUTHORS.md @@ -1,6 +1,6 @@ # Authors -Marked takes an encompassing approach to its community. As such, you can think of these as [concentric circles](https://medium.com/the-node-js-collection/healthy-open-source-967fa8be7951), where each group encompases the following groups. +Marked takes an encompassing approach to its community. As such, you can think of these as [concentric circles](https://medium.com/the-node-js-collection/healthy-open-source-967fa8be7951), where each group encompasses the following groups. @@ -170,7 +170,7 @@ To be removed: You can remove yourself through the [GitHub UI](https://help.gith A note on volunteering: 1. Please do not volunteer unless you believe you can demonstrate to your peers you can do the work required. -2. Please do not overcommit yourself; we count on those committed to the project to be responsive. Really consider, with all you have going on, wehther you able to really commit to it. +2. Please do not overcommit yourself; we count on those committed to the project to be responsive. Really consider, with all you have going on, whether you able to really commit to it. 3. Don't let the previous frighten you away, it can always be changed later by you or your peers. [Details on badges](#badges) @@ -227,7 +227,7 @@ Badges? If you *want* 'em, we got 'em, and here's how you get 'em (and…dr
    Dr. Docs
    -
    Someone who has contributed a great deal to the creation and maintainance of the non-code areas of marked.
    +
    Someone who has contributed a great deal to the creation and maintenance of the non-code areas of marked.
    Eye for the CLI
    At this point? Pretty much anyone who can update that `man` file to the current Marked version without regression in the CLI tool itself.
    GitHub Guru
    @@ -259,9 +259,9 @@ Badges? If you *want* 'em, we got 'em, and here's how you get 'em (and…dr
    Defibrillator
    -
    A contributor who stepped up to help bring Marked back to life by contriuting solutions to help Marked pass when compared against the CommonMark and GitHub Flavored Markdown specifications.
    +
    A contributor who stepped up to help bring Marked back to life by contributing solutions to help Marked pass when compared against the CommonMark and GitHub Flavored Markdown specifications.
    Maker of the Marked mark
    -
    This badge is given to the person or oganization credited with creating the logo (or logotype) used in Marked communications for a given period of time. **Maker of the Marked mark from 2017 to present**, for example.
    +
    This badge is given to the person or organization credited with creating the logo (or logotype) used in Marked communications for a given period of time. **Maker of the Marked mark from 2017 to present**, for example.
    Release Wrangler
    This is a badge given to all Publishers.
    Snyk's Security Saint
    diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index f5a356804a..1c1aaedabd 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -7,7 +7,7 @@ - [ ] Create a branch. - [ ] Make as small a change as possible. - [ ] Run `npm test`, fix any broken things (for linting, you can run `npm run lint` to have the linter fix them for you). -- [ ] Submit a PR. +- [ ] Submit a Pull Request. ## Design principles @@ -91,4 +91,3 @@ To build your own minified version of Marked: ```bash npm run build ``` - diff --git a/docs/PUBLISHING.md b/docs/PUBLISHING.md index 27937c2f2f..739726674a 100644 --- a/docs/PUBLISHING.md +++ b/docs/PUBLISHING.md @@ -7,7 +7,7 @@ ## Overall strategy -**Master is always shippable:** We try to merge PRs in such a way that `master` is the only branch to really be concerned about *and* `master` can always be released. This allows smoother flow between new fetures, bug fixes, and so on. (Almost a continuous deployment setup, without automation.) +**Master is always shippable:** We try to merge PRs in such a way that `master` is the only branch to really be concerned about *and* `master` can always be released. This allows smoother flow between new features, bug fixes, and so on. (Almost a continuous deployment setup, without automation.) ## Versioning @@ -20,5 +20,5 @@ We follow [semantic versioning](https://semver.org) where the following sequence What to expect while Marked is a zero-major (0.x.y): 1. The major will remain at zero; thereby, alerting consumers to the potentially volatile nature of the package. -2. The minor will tend to be more analagous to a `major` release. -3. The patch will tend to be more analagous to a `minor` release or a collection of bug fixes (patches). +2. The minor will tend to be more analogous to a `major` release. +3. The patch will tend to be more analogous to a `minor` release or a collection of bug fixes (patches). diff --git a/docs/USING_ADVANCED.md b/docs/USING_ADVANCED.md index 94e1eb007e..ee8b3126da 100644 --- a/docs/USING_ADVANCED.md +++ b/docs/USING_ADVANCED.md @@ -40,7 +40,7 @@ console.log(marked(markdownString)); |Member |Type |Default |Since |Notes | |:-----------|:---------|:--------|:--------|:-------------| -|baseUrl |`string` |`null` |0.3.9 |A prefix url for any relative link. | +|baseUrl |`string` |`null` |0.3.9 |A prefix url for any relative link. | |breaks |`boolean` |`false` |v0.2.7 |If true, add `
    ` on a single line break (copies GitHub). Requires `gfm` be `true`.| |gfm |`boolean` |`true` |v0.2.1 |If true, use approved [GitHub Flavored Markdown (GFM) specification](https://github.github.com/gfm/).| |headerIds |`boolean` |`true` |v0.4.0 |If true, include an `id` attribute when emitting headings (h1, h2, h3, etc).| From 4018c551efcf1ac777049bd54433b24ca31804d8 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 15:56:29 -0600 Subject: [PATCH 19/33] add DO NOT EDIT comment in compiled files --- rollup.config.esm.js | 6 ++++++ rollup.config.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/rollup.config.esm.js b/rollup.config.esm.js index 0e1bfc3a47..c81592ceaa 100644 --- a/rollup.config.esm.js +++ b/rollup.config.esm.js @@ -10,6 +10,12 @@ module.exports = { plugins: [ license({ banner: ` +DO NOT EDIT THIS FILE +The code in this file is generated from files in ./src/ + ` + }), + license({ + banner: ` marked - a markdown parser Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) https://github.com/markedjs/marked diff --git a/rollup.config.js b/rollup.config.js index 4a529c571a..e862a10565 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -12,6 +12,12 @@ module.exports = { plugins: [ license({ banner: ` +DO NOT EDIT THIS FILE +The code in this file is generated from files in ./src/ + ` + }), + license({ + banner: ` marked - a markdown parser Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) https://github.com/markedjs/marked From 121fe87444a916a53c1748d002185cc5b2971c6e Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 16:03:39 -0600 Subject: [PATCH 20/33] update docs --- docs/CONTRIBUTING.md | 8 +++++--- docs/USING_PRO.md | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 1c1aaedabd..f5ec82b6a9 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -5,8 +5,9 @@ - [ ] Make sure you are on the `master` branch. - [ ] Be sure to run `npm install` or `npm update`. - [ ] Create a branch. -- [ ] Make as small a change as possible. -- [ ] Run `npm test`, fix any broken things (for linting, you can run `npm run lint` to have the linter fix them for you). +- [ ] Update code in `src` folder. (`lib` folder is for auto compiled code) +- [ ] Run `npm run test:all`, fix any broken things (for linting, you can run `npm run lint` to have the linter fix them for you). +- [ ] Run `npm run build:reset` to remove changes to compiled files. - [ ] Submit a Pull Request. ## Design principles @@ -30,6 +31,7 @@ The following table lists the ticket type labels we use when there is work to be |RR - refactor and re-engineer |Results in an improvement to developers using Marked (improved readability) or end-users (faster performance) or both. | |NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](#/README.md#specifications) | |NFU - new feature (user requested) |A capability Marked does not currently provide but has been requested by users of Marked. | +|NFE - new feature (should be an extension) |A capability Marked does not currently provide and is not part of a spec. | ## Test early, often, and everything @@ -86,7 +88,7 @@ To check for (and fix) standardized syntax (lint): npm run lint ``` -To build your own minified version of Marked: +To build your own es5, esm, and minified versions of Marked: ```bash npm run build diff --git a/docs/USING_PRO.md b/docs/USING_PRO.md index d0dd0ee2e9..5e9451bee1 100644 --- a/docs/USING_PRO.md +++ b/docs/USING_PRO.md @@ -106,7 +106,7 @@ You also have direct access to the lexer and parser if you so desire. ``` js const tokens = marked.lexer(text, options); -console.log(marked.parser(tokens)); +console.log(marked.parser(tokens, options)); ``` ``` js From eb3ba33f43db24fcd92594d901b7a22e145f9de4 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 6 Nov 2019 16:12:58 -0600 Subject: [PATCH 21/33] clean up code --- rollup.config.esm.js | 2 +- rollup.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rollup.config.esm.js b/rollup.config.esm.js index c81592ceaa..0c9b5ef75b 100644 --- a/rollup.config.esm.js +++ b/rollup.config.esm.js @@ -12,7 +12,7 @@ module.exports = { banner: ` DO NOT EDIT THIS FILE The code in this file is generated from files in ./src/ - ` +` }), license({ banner: ` diff --git a/rollup.config.js b/rollup.config.js index e862a10565..7e42e11792 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,7 +14,7 @@ module.exports = { banner: ` DO NOT EDIT THIS FILE The code in this file is generated from files in ./src/ - ` +` }), license({ banner: ` From 96cf35cfb1ee1869a9eb86b10cc7036d0edb4ea6 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 7 Nov 2019 09:40:19 -0600 Subject: [PATCH 22/33] fix benchmark pass percentage --- test/bench.js | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/test/bench.js b/test/bench.js index 564f74c238..ceed4eb993 100644 --- a/test/bench.js +++ b/test/bench.js @@ -23,7 +23,7 @@ function load() { /** * Run all benchmarks */ -function runBench(options) { +async function runBench(options) { options = options || {}; const specs = load(); @@ -38,7 +38,7 @@ function runBench(options) { if (options.marked) { marked.setOptions(options.marked); } - bench('es5 marked', specs, marked); + await bench('es5 marked', specs, marked); es6marked.setOptions({ gfm: false, @@ -50,7 +50,7 @@ function runBench(options) { if (options.marked) { es6marked.setOptions(options.marked); } - bench('es6 marked', specs, es6marked); + await bench('es6 marked', specs, es6marked); // GFM marked.setOptions({ @@ -63,7 +63,7 @@ function runBench(options) { if (options.marked) { marked.setOptions(options.marked); } - bench('es5 marked (gfm)', specs, marked); + await bench('es5 marked (gfm)', specs, marked); es6marked.setOptions({ gfm: true, @@ -75,7 +75,7 @@ function runBench(options) { if (options.marked) { es6marked.setOptions(options.marked); } - bench('es6 marked (gfm)', specs, es6marked); + await bench('es6 marked (gfm)', specs, es6marked); // Pedantic marked.setOptions({ @@ -88,7 +88,7 @@ function runBench(options) { if (options.marked) { marked.setOptions(options.marked); } - bench('es5 marked (pedantic)', specs, marked); + await bench('es5 marked (pedantic)', specs, marked); es6marked.setOptions({ gfm: false, @@ -100,10 +100,10 @@ function runBench(options) { if (options.marked) { es6marked.setOptions(options.marked); } - bench('es6 marked (pedantic)', specs, es6marked); + await bench('es6 marked (pedantic)', specs, es6marked); try { - bench('commonmark', specs, (() => { + await bench('commonmark', specs, (() => { const commonmark = require('commonmark'); const parser = new commonmark.Parser(); const writer = new commonmark.HtmlRenderer(); @@ -116,7 +116,7 @@ function runBench(options) { } try { - bench('markdown-it', specs, (() => { + await bench('markdown-it', specs, (() => { const MarkdownIt = require('markdown-it'); const md = new MarkdownIt(); return md.render.bind(md); @@ -126,7 +126,7 @@ function runBench(options) { } try { - bench('markdown.js', specs, (() => { + await bench('markdown.js', specs, (() => { const md = require('markdown').markdown; return md.toHTML.bind(md); })()); @@ -135,25 +135,23 @@ function runBench(options) { } } -function bench(name, specs, engine) { +async function bench(name, specs, engine) { const before = process.hrtime(); for (let i = 0; i < 1e3; i++) { for (const spec of specs) { - engine(spec.markdown); + await engine(spec.markdown); } } const elapsed = process.hrtime(before); const ms = prettyElapsedTime(elapsed).toFixed(); - const results = []; + let correct = 0; for (const spec of specs) { - results.push({ - expected: spec.html, - actual: engine(spec.markdown) - }); + if (await htmlDiffer.isEqual(spec.html, engine(spec.markdown))) { + correct++; + } } - const correct = results.reduce((num, result) => num + (htmlDiffer.isEqual(result.expected, result.actual) ? 1 : 0), 0); - const percent = (correct / results.length * 100).toFixed(2); + const percent = (correct / specs.length * 100).toFixed(2); console.log('%s completed in %sms and passed %s%', name, ms, percent); } @@ -161,13 +159,13 @@ function bench(name, specs, engine) { /** * A simple one-time benchmark */ -function time(options) { +async function time(options) { options = options || {}; const specs = load(); if (options.marked) { marked.setOptions(options.marked); } - bench('marked', specs, marked); + await bench('marked', specs, marked); } /** @@ -263,7 +261,7 @@ function camelize(text) { /** * Main */ -function main(argv) { +async function main(argv) { const opt = parseArg(argv); if (opt.minified) { @@ -271,9 +269,9 @@ function main(argv) { } if (opt.time) { - time(opt); + await time(opt); } else { - runBench(opt); + await runBench(opt); } } From 83c467466c72d0d9a0126de0c6af023acac77f8b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 7 Nov 2019 10:40:56 -0600 Subject: [PATCH 23/33] await engine --- test/bench.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bench.js b/test/bench.js index ceed4eb993..0c1106de82 100644 --- a/test/bench.js +++ b/test/bench.js @@ -147,7 +147,7 @@ async function bench(name, specs, engine) { let correct = 0; for (const spec of specs) { - if (await htmlDiffer.isEqual(spec.html, engine(spec.markdown))) { + if (await htmlDiffer.isEqual(spec.html, await engine(spec.markdown))) { correct++; } } From 957f94655e6db630d0328158f5fd2e6b2dd03d94 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 7 Nov 2019 12:46:32 -0600 Subject: [PATCH 24/33] clean up code --- src/helpers.js | 56 ++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 89414546c6..6515dddeb3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -4,19 +4,20 @@ function escape(html, encode) { if (encode) { if (escape.escapeTest.test(html)) { - return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; }); + return html.replace(escape.escapeReplace, escape.getReplacement); } } else { if (escape.escapeTestNoEncode.test(html)) { - return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; }); + return html.replace(escape.escapeReplaceNoEncode, escape.getReplacement); } } return html; } - escape.escapeTest = /[&<>"']/; escape.escapeReplace = /[&<>"']/g; +escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; +escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; escape.replacements = { '&': '&', '<': '<', @@ -24,13 +25,11 @@ escape.replacements = { '"': '"', "'": ''' }; - -escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; -escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; +escape.getReplacement = (ch) => escape.replacements[ch]; function unescape(html) { // explicitly match decimal, hex, and named HTML entities - return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { + return html.replace(unescape.unescapeTest, (_, n) => { n = n.toLowerCase(); if (n === 'colon') return ':'; if (n.charAt(0) === '#') { @@ -41,29 +40,32 @@ function unescape(html) { return ''; }); } +unescape.unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig; function edit(regex, opt) { regex = regex.source || regex; opt = opt || ''; - return { - replace: function(name, val) { + const obj = { + replace: (name, val) => { val = val.source || val; - val = val.replace(/(^|[^\[])\^/g, '$1'); + val = val.replace(edit.caret, '$1'); regex = regex.replace(name, val); - return this; + return obj; }, - getRegex: function() { + getRegex: () => { return new RegExp(regex, opt); } }; + return obj; } +edit.caret = /(^|[^\[])\^/g; function cleanUrl(sanitize, base, href) { if (sanitize) { let prot; try { prot = decodeURIComponent(unescape(href)) - .replace(/[^\w:]/g, '') + .replace(cleanUrl.protocol, '') .toLowerCase(); } catch (e) { return null; @@ -72,7 +74,7 @@ function cleanUrl(sanitize, base, href) { return null; } } - if (base && !originIndependentUrl.test(href)) { + if (base && !cleanUrl.originIndependentUrl.test(href)) { href = resolveUrl(base, href); } try { @@ -82,37 +84,41 @@ function cleanUrl(sanitize, base, href) { } return href; } +cleanUrl.protocol = /[^\w:]/g; +cleanUrl.originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; function resolveUrl(base, href) { - if (!baseUrls[' ' + base]) { + if (!resolveUrl.baseUrls[' ' + base]) { // we can ignore everything in base after the last slash of its path component, // but we might need to add _that_ // https://tools.ietf.org/html/rfc3986#section-3 - if (/^[^:]+:\/*[^/]*$/.test(base)) { - baseUrls[' ' + base] = base + '/'; + if (resolveUrl.justDomain.test(base)) { + resolveUrl.baseUrls[' ' + base] = base + '/'; } else { - baseUrls[' ' + base] = rtrim(base, '/', true); + resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); } } - base = baseUrls[' ' + base]; + base = resolveUrl.baseUrls[' ' + base]; const relativeBase = base.indexOf(':') === -1; - if (href.slice(0, 2) === '//') { + if (href.substring(0, 2) === '//') { if (relativeBase) { return href; } - return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; + return base.replace(resolveUrl.protocol, '$1') + href; } else if (href.charAt(0) === '/') { if (relativeBase) { return href; } - return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; + return base.replace(resolveUrl.domain, '$1') + href; } else { return base + href; } } -const baseUrls = {}; -const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; +resolveUrl.baseUrls = {}; +resolveUrl.justDomain = /^[^:]+:\/*[^/]*$/; +resolveUrl.protocol = /^([^:]+:)[\s\S]*$/; +resolveUrl.domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; function noop() {} noop.exec = noop; @@ -137,7 +143,7 @@ function merge(obj) { function splitCells(tableRow, count) { // ensure that every cell-delimiting pipe has a space // before it to distinguish it from an escaped pipe - const row = tableRow.replace(/\|/g, function(match, offset, str) { + const row = tableRow.replace(/\|/g, (match, offset, str) => { let escaped = false, curr = offset; while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; From 9a3d72958e2f1aa3f18a192a2bd477aa331b946b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 7 Nov 2019 12:49:10 -0600 Subject: [PATCH 25/33] commit lib --- lib/marked.esm.js | 1808 ++++++++++++++++++++++++++ lib/marked.js | 3150 +++++++++++++++++++++++---------------------- 2 files changed, 3451 insertions(+), 1507 deletions(-) create mode 100644 lib/marked.esm.js diff --git a/lib/marked.esm.js b/lib/marked.esm.js new file mode 100644 index 0000000000..0c5213057d --- /dev/null +++ b/lib/marked.esm.js @@ -0,0 +1,1808 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ + +/** + * DO NOT EDIT THIS FILE + * The code in this file is generated from files in ./src/ + */ + +let defaults = getDefaults(); + +function getDefaults() { + return { + baseUrl: null, + breaks: false, + gfm: true, + headerIds: true, + headerPrefix: '', + highlight: null, + langPrefix: 'language-', + mangle: true, + pedantic: false, + renderer: null, + sanitize: false, + sanitizer: null, + silent: false, + smartLists: false, + smartypants: false, + xhtml: false + }; +} + +function changeDefaults(newDefaults) { + defaults = newDefaults; +} + +var defaults_1 = { + defaults, + getDefaults, + changeDefaults +}; + +/** + * Helpers + */ +function escape(html, encode) { + if (encode) { + if (escape.escapeTest.test(html)) { + return html.replace(escape.escapeReplace, escape.getReplacement); + } + } else { + if (escape.escapeTestNoEncode.test(html)) { + return html.replace(escape.escapeReplaceNoEncode, escape.getReplacement); + } + } + + return html; +} +escape.escapeTest = /[&<>"']/; +escape.escapeReplace = /[&<>"']/g; +escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; +escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; +escape.replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' +}; +escape.getReplacement = (ch) => escape.replacements[ch]; + +function unescape(html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(unescape.unescapeTest, (_, n) => { + n = n.toLowerCase(); + if (n === 'colon') return ':'; + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' + ? String.fromCharCode(parseInt(n.substring(2), 16)) + : String.fromCharCode(+n.substring(1)); + } + return ''; + }); +} +unescape.unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig; + +function edit(regex, opt) { + regex = regex.source || regex; + opt = opt || ''; + const obj = { + replace: (name, val) => { + val = val.source || val; + val = val.replace(edit.caret, '$1'); + regex = regex.replace(name, val); + return obj; + }, + getRegex: () => { + return new RegExp(regex, opt); + } + }; + return obj; +} +edit.caret = /(^|[^\[])\^/g; + +function cleanUrl(sanitize, base, href) { + if (sanitize) { + let prot; + try { + prot = decodeURIComponent(unescape(href)) + .replace(cleanUrl.protocol, '') + .toLowerCase(); + } catch (e) { + return null; + } + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { + return null; + } + } + if (base && !cleanUrl.originIndependentUrl.test(href)) { + href = resolveUrl(base, href); + } + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch (e) { + return null; + } + return href; +} +cleanUrl.protocol = /[^\w:]/g; +cleanUrl.originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; + +function resolveUrl(base, href) { + if (!resolveUrl.baseUrls[' ' + base]) { + // we can ignore everything in base after the last slash of its path component, + // but we might need to add _that_ + // https://tools.ietf.org/html/rfc3986#section-3 + if (resolveUrl.justDomain.test(base)) { + resolveUrl.baseUrls[' ' + base] = base + '/'; + } else { + resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); + } + } + base = resolveUrl.baseUrls[' ' + base]; + const relativeBase = base.indexOf(':') === -1; + + if (href.substring(0, 2) === '//') { + if (relativeBase) { + return href; + } + return base.replace(resolveUrl.protocol, '$1') + href; + } else if (href.charAt(0) === '/') { + if (relativeBase) { + return href; + } + return base.replace(resolveUrl.domain, '$1') + href; + } else { + return base + href; + } +} +resolveUrl.baseUrls = {}; +resolveUrl.justDomain = /^[^:]+:\/*[^/]*$/; +resolveUrl.protocol = /^([^:]+:)[\s\S]*$/; +resolveUrl.domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; + +function noop() {} +noop.exec = noop; + +function merge(obj) { + let i = 1, + target, + key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } + + return obj; +} + +function splitCells(tableRow, count) { + // ensure that every cell-delimiting pipe has a space + // before it to distinguish it from an escaped pipe + const row = tableRow.replace(/\|/g, (match, offset, str) => { + let escaped = false, + curr = offset; + while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }), + cells = row.split(/ \|/); + let i = 0; + + if (cells.length > count) { + cells.splice(count); + } else { + while (cells.length < count) cells.push(''); + } + + for (; i < cells.length; i++) { + // leading or trailing whitespace is ignored per the gfm spec + cells[i] = cells[i].trim().replace(/\\\|/g, '|'); + } + return cells; +} + +// Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). +// /c*$/ is vulnerable to REDOS. +// invert: Remove suffix of non-c chars instead. Default falsey. +function rtrim(str, c, invert) { + const l = str.length; + if (l === 0) { + return ''; + } + + // Length of suffix matching the invert condition. + let suffLen = 0; + + // Step left until we fail to match the invert condition. + while (suffLen < l) { + const currChar = str.charAt(l - suffLen - 1); + if (currChar === c && !invert) { + suffLen++; + } else if (currChar !== c && invert) { + suffLen++; + } else { + break; + } + } + + return str.substr(0, l - suffLen); +} + +function findClosingBracket(str, b) { + if (str.indexOf(b[1]) === -1) { + return -1; + } + const l = str.length; + let level = 0, + i = 0; + for (; i < l; i++) { + if (str[i] === '\\') { + i++; + } else if (str[i] === b[0]) { + level++; + } else if (str[i] === b[1]) { + level--; + if (level < 0) { + return i; + } + } + } + return -1; +} + +function checkSanitizeDeprecation(opt) { + if (opt && opt.sanitize && !opt.silent) { + console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); + } +} + +var helpers = { + escape, + unescape, + edit, + cleanUrl, + resolveUrl, + noop, + merge, + splitCells, + rtrim, + findClosingBracket, + checkSanitizeDeprecation +}; + +const { + noop: noop$1, + edit: edit$1, + merge: merge$1 +} = helpers; + +/** + * Block-Level Grammar + */ +const block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, + hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, + heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, + blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, + list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\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)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + + ')', + def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, + nptable: noop$1, + table: noop$1, + lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, + // regex template, placeholders will be replaced according to different paragraph + // interruption rules of commonmark and the original markdown spec: + _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, + text: /^[^\n]+/ +}; + +block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; +block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; +block.def = edit$1(block.def) + .replace('label', block._label) + .replace('title', block._title) + .getRegex(); + +block.bullet = /(?:[*+-]|\d{1,9}\.)/; +block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; +block.item = edit$1(block.item, 'gm') + .replace(/bull/g, block.bullet) + .getRegex(); + +block.list = edit$1(block.list) + .replace(/bull/g, block.bullet) + .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))') + .replace('def', '\\n+(?=' + block.def.source + ')') + .getRegex(); + +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$1(block.html, 'i') + .replace('comment', block._comment) + .replace('tag', block._tag) + .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/) + .getRegex(); + +block.paragraph = edit$1(block._paragraph) + .replace('hr', block.hr) + .replace('heading', ' {0,3}#{1,6} +') + .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('blockquote', ' {0,3}>') + .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') + .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt + .replace('html', ')|<(?:script|pre|style|!--)') + .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks + .getRegex(); + +block.blockquote = edit$1(block.blockquote) + .replace('paragraph', block.paragraph) + .getRegex(); + +/** + * Normal Block Grammar + */ + +block.normal = merge$1({}, block); + +/** + * GFM Block Grammar + */ + +block.gfm = merge$1({}, block.normal, { + nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ +}); + +/** + * Pedantic grammar (original John Gruber's loose markdown specification) + */ + +block.pedantic = merge$1({}, block.normal, { + html: edit$1( + '^ *(?: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+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, + fences: noop$1, // fences not supported + paragraph: edit$1(block.normal._paragraph) + .replace('hr', block.hr) + .replace('heading', ' *#{1,6} *[^\n]') + .replace('lheading', block.lheading) + .replace('blockquote', ' {0,3}>') + .replace('|fences', '') + .replace('|list', '') + .replace('|html', '') + .getRegex() +}); + +/** + * Inline-Level Grammar + */ +const inline = { + escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, + autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, + url: noop$1, + 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)\]\(\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: noop$1, + text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; +inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); + +inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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$1(inline.autolink) + .replace('scheme', inline._scheme) + .replace('email', inline._email) + .getRegex(); + +inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/; + +inline.tag = edit$1(inline.tag) + .replace('comment', block._comment) + .replace('attribute', inline._attribute) + .getRegex(); + +inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; +inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; +inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; + +inline.link = edit$1(inline.link) + .replace('label', inline._label) + .replace('href', inline._href) + .replace('title', inline._title) + .getRegex(); + +inline.reflink = edit$1(inline.reflink) + .replace('label', inline._label) + .getRegex(); + +/** + * Normal Inline Grammar + */ + +inline.normal = merge$1({}, inline); + +/** + * Pedantic Inline Grammar + */ + +inline.pedantic = merge$1({}, inline.normal, { + strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, + em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/, + link: edit$1(/^!?\[(label)\]\((.*?)\)/) + .replace('label', inline._label) + .getRegex(), + reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/) + .replace('label', inline._label) + .getRegex() +}); + +/** + * GFM Inline Grammar + */ + +inline.gfm = merge$1({}, inline.normal, { + escape: edit$1(inline.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]*?(?:(?=[\\ 1) { + this.tokens.push({ + type: 'space' + }); + } + } + + // code + if (cap = this.rules.code.exec(src)) { + const lastToken = this.tokens[this.tokens.length - 1]; + src = src.substring(cap[0].length); + // An indented code block cannot interrupt a paragraph. + if (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); + } else { + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic + ? rtrim$1(cap, '\n') + : cap + }); + } + continue; + } + + // fences + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' + }); + continue; + } + + // heading + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } + + // table no leading pipe (gfm) + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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] = splitCells$1(item.cells[i], item.header.length); + } + + this.tokens.push(item); + + continue; + } + } + + // hr + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } + + // blockquote + if (cap = this.rules.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' + }); + + continue; + } + + // list + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; + + this.tokens.push(listStart); + + // Get each top-level item. + cap = cap[0].match(this.rules.item); + + listItems = []; + next = false; + l = cap.length; + i = 0; + + for (; i < l; i++) { + item = cap[i]; + + // Remove the list item's bullet + // so it is seen as the next token. + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); + + // Outdent whatever the + // list item contains. Hacky. + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic + ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') + : item.replace(/^ {1,4}/gm, ''); + } + + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (i !== l - 1) { + 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; + i = l - 1; + } + } + + // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + loose = next || /\n\n(?!\s*$)/.test(item); + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } + + if (loose) { + listStart.loose = true; + } + + // Check for task list items + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); + } + + t = { + type: 'list_item_start', + 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' + }); + } + + 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)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize + ? 'paragraph' + : 'html', + 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] + }); + continue; + } + + // def + 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().replace(/\s+/g, ' '); + if (!this.tokens.links[tag]) { + this.tokens.links[tag] = { + href: cap[2], + title: cap[3] + }; + } + continue; + } + + // table (gfm) + if (cap = this.rules.table.exec(src)) { + item = { + type: 'table', + header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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] = splitCells$1( + item.cells[i].replace(/^ *\| *| *\| *$/g, ''), + item.header.length); + } + + this.tokens.push(item); + + continue; + } + } + + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2].charAt(0) === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } + + // top-level paragraph + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + 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)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; + } + + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return this.tokens; + }; +}; + +const { defaults: defaults$2 } = defaults_1; +const { + cleanUrl: cleanUrl$1, + escape: escape$2 +} = helpers; + +/** + * Renderer + */ +var Renderer_1 = class Renderer { + constructor(options) { + this.options = options || defaults$2; + } + + code(code, infostring, escaped) { + const lang = (infostring || '').match(/\S*/)[0]; + if (this.options.highlight) { + const out = this.options.highlight(code, lang); + if (out != null && out !== code) { + escaped = true; + code = out; + } + } + + if (!lang) { + return '
    '
    +        + (escaped ? code : escape$2(code, true))
    +        + '
    '; + } + + return '
    '
    +      + (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) { + return '' + + text + + '\n'; + } + // 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 + ''; + + return '
    \n' + + '\n' + + header + + '\n' + + body + + '
    \n'; + }; + + tablerow(content) { + return '\n' + content + '\n'; + }; + + tablecell(content, flags) { + const type = flags.header ? 'th' : 'td'; + const tag = flags.align + ? '<' + 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); + if (href === null) { + return text; + } + let out = '
    '; + return out; + }; + + image(href, title, text) { + href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); + if (href === null) { + return text; + } + + let out = '' + text + '' : '>'; + 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() + .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_1; +const { inline: inline$1 } = regexp; +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.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; + } +}; + +/** + * TextRenderer + * returns only the textual part of the token + */ +var TextRenderer_1 = class TextRenderer { + // no need for block level renderers + strong(text) { + return text; + } + + em(text) { + return text; + } + + codespan(text) { + return text; + } + + del(text) { + return text; + } + + text(text) { + return text; + } + + link(href, title, text) { + return '' + text; + } + + image(href, title, text) { + return '' + text; + } + + br() { + return ''; + } +}; + +const { defaults: defaults$4 } = defaults_1; +const { + merge: merge$2, + unescape: unescape$1 +} = helpers; + +/** + * Parsing & Compiling + */ +var Parser_1 = class Parser { + constructor(options) { + this.tokens = []; + this.token = null; + this.options = options || defaults$4; + this.options.renderer = this.options.renderer || new Renderer_1(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger_1(); + } + + /** + * Static Parse Method + */ + static parse(src, options) { + const parser = new Parser(options); + return parser.parse(src); + }; + + /** + * Parse Loop + */ + parse(src) { + this.inline = new InlineLexer_1(src.links, this.options); + // use an InlineLexer with a TextRenderer to extract pure text + this.inlineText = new InlineLexer_1( + src.links, + merge$2({}, this.options, { renderer: new TextRenderer_1() }) + ); + this.tokens = src.reverse(); + + let out = ''; + while (this.next()) { + out += this.tok(); + } + + return out; + }; + + /** + * Next Token + */ + next() { + this.token = this.tokens.pop(); + return this.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] } + ); + } + 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 = ''; + const 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 = ''; + 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) + }); + } + } 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: { + const errMsg = 'Token with "' + this.token.type + '" type was not found.'; + if (this.options.silent) { + console.log(errMsg); + } else { + throw new Error(errMsg); + } + } + } + }; +}; + +const { + merge: merge$3, + checkSanitizeDeprecation: checkSanitizeDeprecation$1, + escape: escape$4 +} = helpers; +const { + getDefaults: getDefaults$1, + changeDefaults: changeDefaults$1, + defaults: defaults$5 +} = defaults_1; + +/** + * Marked + */ +function marked(src, opt, callback) { + // throw error in case of non string input + if (typeof src === 'undefined' || src === null) { + throw new Error('marked(): input parameter is undefined or null'); + } + if (typeof src !== 'string') { + throw new Error('marked(): input parameter is of type ' + + Object.prototype.toString.call(src) + ', string expected'); + } + + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } + + opt = merge$3({}, marked.defaults, opt || {}); + checkSanitizeDeprecation$1(opt); + const highlight = opt.highlight; + let tokens, + pending, + i = 0; + + try { + tokens = Lexer_1.lex(src, opt); + } catch (e) { + return callback(e); + } + + pending = tokens.length; + + const done = function(err) { + if (err) { + opt.highlight = highlight; + return callback(err); + } + + let out; + + try { + out = Parser_1.parse(tokens, opt); + } catch (e) { + err = e; + } + + opt.highlight = highlight; + + return err + ? callback(err) + : callback(null, out); + }; + + if (!highlight || highlight.length < 3) { + return done(); + } + + delete opt.highlight; + + if (!pending) return done(); + + for (; i < tokens.length; i++) { + (function(token) { + if (token.type !== 'code') { + return --pending || done(); + } + return highlight(token.text, token.lang, function(err, code) { + if (err) return done(err); + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } + + return; + } + try { + opt = merge$3({}, 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)
    +        + '
    '; + } + throw e; + } +} + +/** + * Options + */ + +marked.options = +marked.setOptions = function(opt) { + merge$3(marked.defaults, opt); + changeDefaults$1(marked.defaults); + return marked; +}; + +marked.getDefaults = getDefaults$1; + +marked.defaults = defaults$5; + +/** + * Expose + */ + +marked.Parser = Parser_1; +marked.parser = Parser_1.parse; + +marked.Renderer = Renderer_1; +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; + +export default marked_1; diff --git a/lib/marked.js b/lib/marked.js index 773341f48a..8ccb660932 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -4,1719 +4,1855 @@ * https://github.com/markedjs/marked */ -;(function(root) { -'use strict'; - /** - * Block-Level Grammar + * DO NOT EDIT THIS FILE + * The code in this file is generated from files in ./src/ */ -var block = { - newline: /^\n+/, - code: /^( {4}[^\n]+\n*)+/, - fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, - hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, - heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, - blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, - list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\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)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag - + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag - + ')', - def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, - nptable: noop, - table: noop, - lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, - // regex template, placeholders will be replaced according to different paragraph - // interruption rules of commonmark and the original markdown spec: - _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, - text: /^[^\n]+/ -}; - -block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; -block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; -block.def = edit(block.def) - .replace('label', block._label) - .replace('title', block._title) - .getRegex(); - -block.bullet = /(?:[*+-]|\d{1,9}\.)/; -block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; -block.item = edit(block.item, 'gm') - .replace(/bull/g, block.bullet) - .getRegex(); - -block.list = edit(block.list) - .replace(/bull/g, block.bullet) - .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))') - .replace('def', '\\n+(?=' + block.def.source + ')') - .getRegex(); - -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(); +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.marked = factory()); +}(this, (function () { 'use strict'; -block.paragraph = edit(block._paragraph) - .replace('hr', block.hr) - .replace('heading', ' {0,3}#{1,6} +') - .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs - .replace('blockquote', ' {0,3}>') - .replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n') - .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt - .replace('html', ')|<(?:script|pre|style|!--)') - .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks - .getRegex(); - -block.blockquote = edit(block.blockquote) - .replace('paragraph', block.paragraph) - .getRegex(); + function _typeof(obj) { + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } -/** - * Normal Block Grammar - */ + return _typeof(obj); + } -block.normal = merge({}, block); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -/** - * GFM Block Grammar - */ + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } -block.gfm = merge({}, block.normal, { - nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, - table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ -}); + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } -/** - * Pedantic grammar (original John Gruber's loose markdown specification) - */ + var defaults = getDefaults(); + + function getDefaults() { + return { + baseUrl: null, + breaks: false, + gfm: true, + headerIds: true, + headerPrefix: '', + highlight: null, + langPrefix: 'language-', + mangle: true, + pedantic: false, + renderer: null, + sanitize: false, + sanitizer: null, + silent: false, + smartLists: false, + smartypants: false, + xhtml: false + }; + } -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+|$)/, - heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, - fences: noop, // fences not supported - paragraph: edit(block.normal._paragraph) - .replace('hr', block.hr) - .replace('heading', ' *#{1,6} *[^\n]') - .replace('lheading', block.lheading) - .replace('blockquote', ' {0,3}>') - .replace('|fences', '') - .replace('|list', '') - .replace('|html', '') - .getRegex() -}); + function changeDefaults(newDefaults) { + defaults = newDefaults; + } -/** - * Block Lexer - */ + var defaults_1 = { + defaults: defaults, + getDefaults: getDefaults, + changeDefaults: changeDefaults + }; -function Lexer(options) { - this.tokens = []; - this.tokens.links = Object.create(null); - this.options = options || marked.defaults; - this.rules = block.normal; + /** + * Helpers + */ + function escape(html, encode) { + if (encode) { + if (escape.escapeTest.test(html)) { + return html.replace(escape.escapeReplace, escape.getReplacement); + } + } else { + if (escape.escapeTestNoEncode.test(html)) { + return html.replace(escape.escapeReplaceNoEncode, escape.getReplacement); + } + } - if (this.options.pedantic) { - this.rules = block.pedantic; - } else if (this.options.gfm) { - this.rules = block.gfm; + return html; } -} -/** - * Expose Block Rules - */ + escape.escapeTest = /[&<>"']/; + escape.escapeReplace = /[&<>"']/g; + escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; + escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; + escape.replacements = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; -Lexer.rules = block; + escape.getReplacement = function (ch) { + return escape.replacements[ch]; + }; -/** - * Static Lex Method - */ + function unescape(html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(unescape.unescapeTest, function (_, n) { + n = n.toLowerCase(); + if (n === 'colon') return ':'; -Lexer.lex = function(src, options) { - var lexer = new Lexer(options); - return lexer.lex(src); -}; + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1)); + } -/** - * Preprocessing - */ + return ''; + }); + } -Lexer.prototype.lex = function(src) { - src = src - .replace(/\r\n|\r/g, '\n') - .replace(/\t/g, ' '); + unescape.unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig; + + function edit(regex, opt) { + regex = regex.source || regex; + opt = opt || ''; + var obj = { + replace: function replace(name, val) { + val = val.source || val; + val = val.replace(edit.caret, '$1'); + regex = regex.replace(name, val); + return obj; + }, + getRegex: function getRegex() { + return new RegExp(regex, opt); + } + }; + return obj; + } - return this.token(src, true); -}; + edit.caret = /(^|[^\[])\^/g; -/** - * Lexing - */ + function cleanUrl(sanitize, base, href) { + if (sanitize) { + var prot; -Lexer.prototype.token = function(src, top) { - src = src.replace(/^ +$/gm, ''); - var next, - loose, - cap, - bull, - b, - item, - listStart, - listItems, - t, - space, - i, - tag, - l, - isordered, - istask, - ischecked; - - while (src) { - // newline - if (cap = this.rules.newline.exec(src)) { - src = src.substring(cap[0].length); - if (cap[0].length > 1) { - this.tokens.push({ - type: 'space' - }); + try { + prot = decodeURIComponent(unescape(href)).replace(cleanUrl.protocol, '').toLowerCase(); + } catch (e) { + return null; } - } - // 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 (lastToken && lastToken.type === 'paragraph') { - lastToken.text += '\n' + cap[0].trimRight(); - } else { - cap = cap[0].replace(/^ {4}/gm, ''); - this.tokens.push({ - type: 'code', - codeBlockStyle: 'indented', - text: !this.options.pedantic - ? rtrim(cap, '\n') - : cap - }); - } - continue; + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { + return null; + } } - // fences - if (cap = this.rules.fences.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'code', - lang: cap[2] ? cap[2].trim() : cap[2], - text: cap[3] || '' - }); - continue; + if (base && !cleanUrl.originIndependentUrl.test(href)) { + href = resolveUrl(base, href); } - // heading - if (cap = this.rules.heading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[1].length, - text: cap[2] - }); - continue; + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch (e) { + return null; } - // table no leading pipe (gfm) - if (cap = this.rules.nptable.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; + return href; + } - 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; - } - } + cleanUrl.protocol = /[^\w:]/g; + cleanUrl.originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells(item.cells[i], item.header.length); - } + function resolveUrl(base, href) { + if (!resolveUrl.baseUrls[' ' + base]) { + // we can ignore everything in base after the last slash of its path component, + // but we might need to add _that_ + // https://tools.ietf.org/html/rfc3986#section-3 + if (resolveUrl.justDomain.test(base)) { + resolveUrl.baseUrls[' ' + base] = base + '/'; + } else { + resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true); + } + } - this.tokens.push(item); + base = resolveUrl.baseUrls[' ' + base]; + var relativeBase = base.indexOf(':') === -1; - continue; + if (href.substring(0, 2) === '//') { + if (relativeBase) { + return href; } - } - // hr - if (cap = this.rules.hr.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'hr' - }); - continue; + return base.replace(resolveUrl.protocol, '$1') + href; + } else if (href.charAt(0) === '/') { + if (relativeBase) { + return href; + } + + return base.replace(resolveUrl.domain, '$1') + href; + } else { + return base + href; } + } - // blockquote - if (cap = this.rules.blockquote.exec(src)) { - src = src.substring(cap[0].length); + resolveUrl.baseUrls = {}; + resolveUrl.justDomain = /^[^:]+:\/*[^/]*$/; + resolveUrl.protocol = /^([^:]+:)[\s\S]*$/; + resolveUrl.domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; - this.tokens.push({ - type: 'blockquote_start' - }); + function noop() {} - cap = cap[0].replace(/^ *> ?/gm, ''); + noop.exec = noop; - // Pass `top` to keep the current - // "toplevel" state. This is exactly - // how markdown.pl works. - this.token(cap, top); + function merge(obj) { + var i = 1, + target, + key; - this.tokens.push({ - type: 'blockquote_end' - }); + for (; i < arguments.length; i++) { + target = arguments[i]; - continue; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } } - // list - if (cap = this.rules.list.exec(src)) { - src = src.substring(cap[0].length); - bull = cap[2]; - isordered = bull.length > 1; - - listStart = { - type: 'list_start', - ordered: isordered, - start: isordered ? +bull : '', - loose: false - }; - - this.tokens.push(listStart); - - // Get each top-level item. - cap = cap[0].match(this.rules.item); + return obj; + } - listItems = []; - next = false; - l = cap.length; - i = 0; + function splitCells(tableRow, count) { + // ensure that every cell-delimiting pipe has a space + // before it to distinguish it from an escaped pipe + var row = tableRow.replace(/\|/g, function (match, offset, str) { + var escaped = false, + curr = offset; - for (; i < l; i++) { - item = cap[i]; + while (--curr >= 0 && str[curr] === '\\') { + escaped = !escaped; + } - // Remove the list item's bullet - // so it is seen as the next token. - space = item.length; - item = item.replace(/^ *([*+-]|\d+\.) */, ''); + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }), + cells = row.split(/ \|/); + var i = 0; - // Outdent whatever the - // list item contains. Hacky. - if (~item.indexOf('\n ')) { - space -= item.length; - item = !this.options.pedantic - ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') - : item.replace(/^ {1,4}/gm, ''); - } + if (cells.length > count) { + cells.splice(count); + } else { + while (cells.length < count) { + cells.push(''); + } + } - // Determine whether the next list item belongs here. - // Backpedal if it does not belong in this list. - if (i !== l - 1) { - b = block.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; - i = l - 1; - } - } + for (; i < cells.length; i++) { + // leading or trailing whitespace is ignored per the gfm spec + cells[i] = cells[i].trim().replace(/\\\|/g, '|'); + } - // Determine whether item is loose or not. - // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ - // for discount behavior. - loose = next || /\n\n(?!\s*$)/.test(item); - if (i !== l - 1) { - next = item.charAt(item.length - 1) === '\n'; - if (!loose) loose = next; - } + return cells; + } // Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). + // /c*$/ is vulnerable to REDOS. + // invert: Remove suffix of non-c chars instead. Default falsey. - if (loose) { - listStart.loose = true; - } - // Check for task list items - istask = /^\[[ xX]\] /.test(item); - ischecked = undefined; - if (istask) { - ischecked = item[1] !== ' '; - item = item.replace(/^\[[ xX]\] +/, ''); - } + function rtrim(str, c, invert) { + var l = str.length; - t = { - type: 'list_item_start', - task: istask, - checked: ischecked, - loose: loose - }; + if (l === 0) { + return ''; + } // Length of suffix matching the invert condition. - listItems.push(t); - this.tokens.push(t); - // Recurse. - this.token(item, false); + var suffLen = 0; // Step left until we fail to match the invert condition. - this.tokens.push({ - type: 'list_item_end' - }); - } + while (suffLen < l) { + var currChar = str.charAt(l - suffLen - 1); - if (listStart.loose) { - l = listItems.length; - i = 0; - for (; i < l; i++) { - listItems[i].loose = true; - } + if (currChar === c && !invert) { + suffLen++; + } else if (currChar !== c && invert) { + suffLen++; + } else { + break; } - - this.tokens.push({ - type: 'list_end' - }); - - continue; } - // html - if (cap = this.rules.html.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: this.options.sanitize - ? 'paragraph' - : 'html', - 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(cap[0])) : cap[0] - }); - continue; - } + return str.substr(0, l - suffLen); + } - // def - 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().replace(/\s+/g, ' '); - if (!this.tokens.links[tag]) { - this.tokens.links[tag] = { - href: cap[2], - title: cap[3] - }; - } - continue; + function findClosingBracket(str, b) { + if (str.indexOf(b[1]) === -1) { + return -1; } - // table (gfm) - if (cap = this.rules.table.exec(src)) { - item = { - type: 'table', - header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] - }; + var l = str.length; + var level = 0, + i = 0; - 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 < l; i++) { + if (str[i] === '\\') { + i++; + } else if (str[i] === b[0]) { + level++; + } else if (str[i] === b[1]) { + level--; - for (i = 0; i < item.cells.length; i++) { - item.cells[i] = splitCells( - item.cells[i].replace(/^ *\| *| *\| *$/g, ''), - item.header.length); + if (level < 0) { + return i; } - - this.tokens.push(item); - - continue; } } - // lheading - if (cap = this.rules.lheading.exec(src)) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'heading', - depth: cap[2].charAt(0) === '=' ? 1 : 2, - text: cap[1] - }); - continue; - } - - // top-level paragraph - if (top && (cap = this.rules.paragraph.exec(src))) { - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'paragraph', - 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)) { - // Top-level should never reach here. - src = src.substring(cap[0].length); - this.tokens.push({ - type: 'text', - text: cap[0] - }); - continue; - } + return -1; + } - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + function checkSanitizeDeprecation(opt) { + if (opt && opt.sanitize && !opt.silent) { + console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); } } - return this.tokens; -}; - -/** - * Inline-Level Grammar - */ + var helpers = { + escape: escape, + unescape: unescape, + edit: edit, + cleanUrl: cleanUrl, + resolveUrl: resolveUrl, + noop: noop, + merge: merge, + splitCells: splitCells, + rtrim: rtrim, + findClosingBracket: findClosingBracket, + checkSanitizeDeprecation: checkSanitizeDeprecation + }; -var inline = { - escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, - autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, - url: noop, - tag: '^comment' - + '|^' // self-closing tag + var noop$1 = helpers.noop, + edit$1 = helpers.edit, + merge$1 = helpers.merge; + /** + * Block-Level Grammar + */ + + var block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: /^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, + hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/, + heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/, + blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/, + list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\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)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + + '|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + + ')', + def: /^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/, + nptable: noop$1, + table: noop$1, + lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/, + // regex template, placeholders will be replaced according to different paragraph + // interruption rules of commonmark and the original markdown spec: + _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/, + text: /^[^\n]+/ + }; + block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/; + block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/; + block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex(); + block.bullet = /(?:[*+-]|\d{1,9}\.)/; + block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/; + block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex(); + block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex(); + 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$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(); + block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} +').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs + .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt + .replace('html', ')|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks + .getRegex(); + block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex(); + /** + * Normal Block Grammar + */ + + block.normal = merge$1({}, block); + /** + * GFM Block Grammar + */ + + block.gfm = merge$1({}, block.normal, { + nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/, + table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/ + }); + /** + * Pedantic grammar (original John Gruber's loose markdown specification) + */ + + block.pedantic = merge$1({}, block.normal, { + html: edit$1('^ *(?: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+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/, + fences: noop$1, + // fences not supported + paragraph: edit$1(block.normal._paragraph).replace('hr', block.hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', block.lheading).replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').getRegex() + }); + /** + * Inline-Level Grammar + */ + + var inline = { + escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/, + autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/, + url: noop$1, + 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)\]\(\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: noop, - text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; -inline.em = edit(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); - -inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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(); + + '|^', + // CDATA section + 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: noop$1, + text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\?@\\[^_{|}~'; + inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex(); + inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/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$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex(); + inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/; + inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex(); + inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; + inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; + inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; + inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex(); + inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex(); + /** + * Normal Inline Grammar + */ + + inline.normal = merge$1({}, inline); + /** + * Pedantic Inline Grammar + */ + + inline.pedantic = merge$1({}, inline.normal, { + strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, + em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/, + link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(), + reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex() + }); + /** + * GFM Inline Grammar + */ + + inline.gfm = merge$1({}, inline.normal, { + escape: edit$1(inline.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]*?(?:(?=[\\`]+)?/; + var defaults$1 = defaults_1.defaults; + var block$1 = regexp.block; + var rtrim$1 = helpers.rtrim, + splitCells$1 = helpers.splitCells, + escape$1 = helpers.escape; + /** + * Block Lexer + */ + + var Lexer_1 = + /*#__PURE__*/ + function () { + function Lexer(options) { + _classCallCheck(this, Lexer); + + this.tokens = []; + this.tokens.links = Object.create(null); + this.options = options || defaults$1; + this.rules = block$1.normal; -inline.tag = edit(inline.tag) - .replace('comment', block._comment) - .replace('attribute', inline._attribute) - .getRegex(); + if (this.options.pedantic) { + this.rules = block$1.pedantic; + } else if (this.options.gfm) { + this.rules = block$1.gfm; + } + } + /** + * Expose Block Rules + */ -inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/; -inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/; -inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/; -inline.link = edit(inline.link) - .replace('label', inline._label) - .replace('href', inline._href) - .replace('title', inline._title) - .getRegex(); + _createClass(Lexer, [{ + key: "lex", -inline.reflink = edit(inline.reflink) - .replace('label', inline._label) - .getRegex(); + /** + * Preprocessing + */ + value: function lex(src) { + src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' '); + return this.token(src, true); + } + }, { + key: "token", + + /** + * Lexing + */ + value: function token(src, top) { + src = src.replace(/^ +$/gm, ''); + var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } // 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 (lastToken && lastToken.type === 'paragraph') { + lastToken.text += '\n' + cap[0].trimRight(); + } else { + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + codeBlockStyle: 'indented', + text: !this.options.pedantic ? rtrim$1(cap, '\n') : cap + }); + } + + continue; + } // fences + + + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2] ? cap[2].trim() : cap[2], + text: cap[3] || '' + }); + continue; + } // heading -/** - * Normal Inline Grammar - */ -inline.normal = merge({}, inline); + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } // table no leading pipe (gfm) + + + if (cap = this.rules.nptable.exec(src)) { + item = { + type: 'table', + header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [] + }; + + 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] = splitCells$1(item.cells[i], item.header.length); + } + + this.tokens.push(item); + continue; + } + } // hr + + + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } // blockquote -/** - * Pedantic Inline Grammar - */ -inline.pedantic = merge({}, inline.normal, { - strong: /^__(?=\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() -}); + if (cap = this.rules.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. -/** - * GFM Inline Grammar - */ + this.token(cap, top); + this.tokens.push({ + type: 'blockquote_end' + }); + continue; + } // list + + + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + isordered = bull.length > 1; + listStart = { + type: 'list_start', + ordered: isordered, + start: isordered ? +bull : '', + loose: false + }; + this.tokens.push(listStart); // Get each top-level item. + + cap = cap[0].match(this.rules.item); + listItems = []; + next = false; + l = cap.length; + i = 0; + + for (; i < l; i++) { + item = cap[i]; // Remove the list item's bullet + // so it is seen as the next token. + + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the + // list item contains. Hacky. + + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, ''); + } // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + + + if (i !== l - 1) { + 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; + i = l - 1; + } + } // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + + + loose = next || /\n\n(?!\s*$)/.test(item); + + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) loose = next; + } + + if (loose) { + listStart.loose = true; + } // Check for task list items + + + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); + } + + t = { + type: 'list_item_start', + 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' + }); + } + + if (listStart.loose) { + l = listItems.length; + i = 0; + + for (; i < l; i++) { + listItems[i].loose = true; + } + } -inline.gfm = merge({}, inline.normal, { - escape: edit(inline.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]*?(?:(?=[\\/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.options.sanitize - ? this.options.sanitizer - ? this.options.sanitizer(cap[0]) - : escape(cap[0]) - : cap[0]; - continue; + this.options = options || defaults$2; } - // link - if (cap = this.rules.link.exec(src)) { - var lastParenIndex = findClosingBracket(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); + _createClass(Renderer, [{ + key: "code", + value: function code(_code, infostring, escaped) { + var lang = (infostring || '').match(/\S*/)[0]; - 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; - } + if (this.options.highlight) { + var out = this.options.highlight(_code, lang); - // 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; - } + if (out != null && out !== _code) { + escaped = true; + _code = out; + } + } - // 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; - } + if (!lang) { + return '
    ' + (escaped ? _code : escape$2(_code, true)) + '
    '; + } - // 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; - } + return '
    ' + (escaped ? _code : escape$2(_code, true)) + '
    \n'; + } + }, { + key: "blockquote", + value: function blockquote(quote) { + return '
    \n' + quote + '
    \n'; + } + }, { + key: "html", + value: function html(_html) { + return _html; + } + }, { + key: "heading", + value: function heading(text, level, raw, slugger) { + if (this.options.headerIds) { + return '' + text + '\n'; + } // ignore IDs - // code - if (cap = this.rules.code.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.codespan(escape(cap[2].trim(), true)); - continue; - } - // br - if (cap = this.rules.br.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.br(); - continue; - } + return '' + text + '\n'; + } + }, { + key: "hr", + value: function hr() { + return this.options.xhtml ? '
    \n' : '
    \n'; + } + }, { + key: "list", + value: function list(body, ordered, start) { + var type = ordered ? 'ol' : 'ul', + startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; + return '<' + type + startatt + '>\n' + body + '\n'; + } + }, { + key: "listitem", + value: function listitem(text) { + return '
  • ' + text + '
  • \n'; + } + }, { + key: "checkbox", + value: function checkbox(checked) { + return ' '; + } + }, { + key: "paragraph", + value: function paragraph(text) { + return '

    ' + text + '

    \n'; + } + }, { + key: "table", + value: function table(header, body) { + if (body) body = '' + body + ''; + return '\n' + '\n' + header + '\n' + body + '
    \n'; + } + }, { + key: "tablerow", + value: function tablerow(content) { + return '\n' + content + '\n'; + } + }, { + key: "tablecell", + value: function tablecell(content, flags) { + var type = flags.header ? 'th' : 'td'; + var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; + return tag + content + '\n'; + } + }, { + key: "strong", + // span level renderer + value: function strong(text) { + return '' + text + ''; + } + }, { + key: "em", + value: function em(text) { + return '' + text + ''; + } + }, { + key: "codespan", + value: function codespan(text) { + return '' + text + ''; + } + }, { + key: "br", + value: function br() { + return this.options.xhtml ? '
    ' : '
    '; + } + }, { + key: "del", + value: function del(text) { + return '' + text + ''; + } + }, { + key: "link", + value: function link(href, title, text) { + href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); - // del (gfm) - if (cap = this.rules.del.exec(src)) { - src = src.substring(cap[0].length); - out += this.renderer.del(this.output(cap[1])); - continue; - } + if (href === null) { + return text; + } - // autolink - if (cap = this.rules.autolink.exec(src)) { - src = src.substring(cap[0].length); - if (cap[2] === '@') { - text = escape(this.mangle(cap[1])); - href = 'mailto:' + text; - } else { - text = escape(cap[1]); - href = text; - } - out += this.renderer.link(href, null, text); - continue; - } + var out = '
    '; + return out; } - continue; - } + }, { + key: "image", + value: function image(href, title, text) { + href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href); - if (src) { - throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); - } - } + if (href === null) { + return text; + } - return out; -}; + var out = '' + text + '' : '>'; + return out; + } + }, { + key: "text", + value: function text(_text) { + return _text; + } + }]); -InlineLexer.prototype.outputLink = function(cap, link) { - var href = link.href, - title = link.title ? escape(link.title) : null; + return Renderer; + }(); - return cap[0].charAt(0) !== '!' - ? this.renderer.link(href, title, this.output(cap[1])) - : this.renderer.image(href, title, escape(cap[1])); -}; + /** + * Slugger generates header id + */ + var Slugger_1 = + /*#__PURE__*/ + function () { + function Slugger() { + _classCallCheck(this, Slugger); -/** - * Smartypants Transformations - */ + this.seen = {}; + } + /** + * Convert string to unique id + */ -InlineLexer.prototype.smartypants = function(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 - */ + _createClass(Slugger, [{ + key: "slug", + value: function slug(value) { + var slug = value.toLowerCase().trim().replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-'); -InlineLexer.prototype.mangle = function(text) { - if (!this.options.mangle) return text; - var out = '', - l = text.length, - i = 0, - ch; - - for (; i < l; i++) { - ch = text.charCodeAt(i); - if (Math.random() > 0.5) { - ch = 'x' + ch.toString(16); - } - out += '&#' + ch + ';'; - } + if (this.seen.hasOwnProperty(slug)) { + var originalSlug = slug; - return out; -}; + do { + this.seen[originalSlug]++; + slug = originalSlug + '-' + this.seen[originalSlug]; + } while (this.seen.hasOwnProperty(slug)); + } -/** - * Renderer - */ + this.seen[slug] = 0; + return slug; + } + }]); + + return Slugger; + }(); + + var defaults$3 = defaults_1.defaults; + var inline$1 = regexp.inline; + var findClosingBracket$1 = helpers.findClosingBracket, + escape$3 = helpers.escape; + /** + * Inline Lexer & Compiler + */ + + var InlineLexer_1 = + /*#__PURE__*/ + function () { + function InlineLexer(links, options) { + _classCallCheck(this, InlineLexer); + + 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.'); + } -function Renderer(options) { - this.options = options || marked.defaults; -} - -Renderer.prototype.code = function(code, infostring, escaped) { - var lang = (infostring || '').match(/\S*/)[0]; - if (this.options.highlight) { - var out = this.options.highlight(code, lang); - if (out != null && out !== code) { - escaped = true; - code = out; + 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 + */ + + + _createClass(InlineLexer, [{ + key: "output", + + /** + * Lexing/Compiling + */ + value: 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.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 (!lang) { - return '
    '
    -      + (escaped ? code : escape(code, true))
    -      + '
    '; - } - return '
    '
    -    + (escaped ? code : escape(code, true))
    -    + '
    \n'; -}; - -Renderer.prototype.blockquote = function(quote) { - return '
    \n' + quote + '
    \n'; -}; - -Renderer.prototype.html = function(html) { - return html; -}; - -Renderer.prototype.heading = function(text, level, raw, slugger) { - if (this.options.headerIds) { - return '' - + text - + '\n'; - } - // ignore IDs - return '' + text + '\n'; -}; - -Renderer.prototype.hr = function() { - return this.options.xhtml ? '
    \n' : '
    \n'; -}; - -Renderer.prototype.list = function(body, ordered, start) { - var type = ordered ? 'ol' : 'ul', - startatt = (ordered && start !== 1) ? (' start="' + start + '"') : ''; - return '<' + type + startatt + '>\n' + body + '\n'; -}; - -Renderer.prototype.listitem = function(text) { - return '
  • ' + text + '
  • \n'; -}; - -Renderer.prototype.checkbox = function(checked) { - return ' '; -}; - -Renderer.prototype.paragraph = function(text) { - return '

    ' + text + '

    \n'; -}; - -Renderer.prototype.table = function(header, body) { - if (body) body = '' + body + ''; - - return '\n' - + '\n' - + header - + '\n' - + body - + '
    \n'; -}; - -Renderer.prototype.tablerow = function(content) { - return '\n' + content + '\n'; -}; - -Renderer.prototype.tablecell = function(content, flags) { - var type = flags.header ? 'th' : 'td'; - var tag = flags.align - ? '<' + type + ' align="' + flags.align + '">' - : '<' + type + '>'; - return tag + content + '\n'; -}; - -// span level renderer -Renderer.prototype.strong = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.em = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.codespan = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.br = function() { - return this.options.xhtml ? '
    ' : '
    '; -}; - -Renderer.prototype.del = function(text) { - return '' + text + ''; -}; - -Renderer.prototype.link = function(href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { - return text; - } - var out = '
    '; - return out; -}; - -Renderer.prototype.image = function(href, title, text) { - href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); - if (href === null) { - return text; - } + 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()]; - var out = '' + text + '' : '>'; - return out; -}; + if (!link || !link.href) { + out += cap[0].charAt(0); + src = cap[0].substring(1) + src; + continue; + } -Renderer.prototype.text = function(text) { - return text; -}; + this.inLink = true; + out += this.outputLink(cap, link); + this.inLink = false; + continue; + } // strong -/** - * TextRenderer - * returns only the textual part of the token - */ -function TextRenderer() {} + 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 -// no need for block level renderers -TextRenderer.prototype.strong = -TextRenderer.prototype.em = -TextRenderer.prototype.codespan = -TextRenderer.prototype.del = -TextRenderer.prototype.text = function(text) { - return text; -}; + 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 -TextRenderer.prototype.link = -TextRenderer.prototype.image = function(href, title, text) { - return '' + text; -}; -TextRenderer.prototype.br = function() { - return ''; -}; + 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 -/** - * Parsing & Compiling - */ -function Parser(options) { - this.tokens = []; - this.token = null; - this.options = options || marked.defaults; - this.options.renderer = this.options.renderer || new Renderer(); - this.renderer = this.options.renderer; - this.renderer.options = this.options; - this.slugger = new Slugger(); -} + if (cap = this.rules.br.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.br(); + continue; + } // del (gfm) -/** - * Static Parse Method - */ -Parser.parse = function(src, options) { - var parser = new Parser(options); - return parser.parse(src); -}; + if (cap = this.rules.del.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.del(this.output(cap[1])); + continue; + } // autolink -/** - * Parse Loop - */ -Parser.prototype.parse = function(src) { - this.inline = new InlineLexer(src.links, this.options); - // use an InlineLexer with a TextRenderer to extract pure text - this.inlineText = new InlineLexer( - src.links, - merge({}, this.options, { renderer: new TextRenderer() }) - ); - this.tokens = src.reverse(); - - var out = ''; - while (this.next()) { - out += this.tok(); - } + if (cap = this.rules.autolink.exec(src)) { + src = src.substring(cap[0].length); - return out; -}; + if (cap[2] === '@') { + text = escape$3(this.mangle(cap[1])); + href = 'mailto:' + text; + } else { + text = escape$3(cap[1]); + href = text; + } -/** - * Next Token - */ + out += this.renderer.link(href, null, text); + continue; + } // url (gfm) -Parser.prototype.next = function() { - this.token = this.tokens.pop(); - return this.token; -}; -/** - * Preview Next Token - */ + 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]); -Parser.prototype.peek = function() { - return this.tokens[this.tokens.length - 1] || 0; -}; + text = escape$3(cap[0]); -/** - * Parse Text Tokens - */ + if (cap[1] === 'www.') { + href = 'http://' + text; + } else { + href = text; + } + } -Parser.prototype.parseText = function() { - var body = this.token.text; + src = src.substring(cap[0].length); + out += this.renderer.link(href, null, text); + continue; + } // text - while (this.peek().type === 'text') { - body += '\n' + this.next().text; - } - return this.inline.output(body); -}; + if (cap = this.rules.text.exec(src)) { + src = src.substring(cap[0].length); -/** - * Parse Current Token - */ + 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]))); + } -Parser.prototype.tok = function() { - 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(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 = '', - body = '', - 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] } - ); + continue; + } + + if (src) { + throw new Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } } - body += this.renderer.tablerow(cell); + return out; } - return this.renderer.table(header, body); - } - case 'blockquote_start': { - body = ''; - - while (this.next().type !== 'blockquote_end') { - body += this.tok(); + }, { + key: "outputLink", + + /** + * Compile Link + */ + value: 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])); } - - 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(); + /** + * Smartypants Transformations + */ + + }, { + key: "smartypants", + value: 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 + */ + + }, { + key: "mangle", + value: function mangle(text) { + if (!this.options.mangle) return text; + var l = text.length; + var out = '', + i = 0, + ch; - 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) - }); + for (; i < l; i++) { + ch = text.charCodeAt(i); + + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); } - } else { - body += this.renderer.checkbox(checked); + + out += '&#' + ch + ';'; } - } - while (this.next().type !== 'list_item_end') { - body += !loose && this.token.type === 'text' - ? this.parseText() - : this.tok(); + return out; } - 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()); + }], [{ + key: "output", + + /** + * Static Lexing/Compiling Method + */ + value: function output(src, links, options) { + var inline = new InlineLexer(links, options); + return inline.output(src); + } + }, { + key: "escapes", + value: function escapes(text) { + return text ? text.replace(InlineLexer.rules._escapes, '$1') : text; + } + }, { + key: "rules", + get: function get() { + return inline$1; + } + }]); + + return InlineLexer; + }(); + + /** + * TextRenderer + * returns only the textual part of the token + */ + var TextRenderer_1 = + /*#__PURE__*/ + function () { + function TextRenderer() { + _classCallCheck(this, TextRenderer); } - default: { - var errMsg = 'Token with "' + this.token.type + '" type was not found.'; - if (this.options.silent) { - console.log(errMsg); - } else { - throw new Error(errMsg); + + _createClass(TextRenderer, [{ + key: "strong", + // no need for block level renderers + value: function strong(text) { + return text; } + }, { + key: "em", + value: function em(text) { + return text; + } + }, { + key: "codespan", + value: function codespan(text) { + return text; + } + }, { + key: "del", + value: function del(text) { + return text; + } + }, { + key: "text", + value: function text(_text) { + return _text; + } + }, { + key: "link", + value: function link(href, title, text) { + return '' + text; + } + }, { + key: "image", + value: function image(href, title, text) { + return '' + text; + } + }, { + key: "br", + value: function br() { + return ''; + } + }]); + + return TextRenderer; + }(); + + var defaults$4 = defaults_1.defaults; + var merge$2 = helpers.merge, + unescape$1 = helpers.unescape; + /** + * Parsing & Compiling + */ + + var Parser_1 = + /*#__PURE__*/ + function () { + function Parser(options) { + _classCallCheck(this, Parser); + + this.tokens = []; + this.token = null; + this.options = options || defaults$4; + this.options.renderer = this.options.renderer || new Renderer_1(); + this.renderer = this.options.renderer; + this.renderer.options = this.options; + this.slugger = new Slugger_1(); } - } -}; + /** + * Static Parse Method + */ -/** - * Slugger generates header id - */ -function Slugger() { - this.seen = {}; -} + _createClass(Parser, [{ + key: "parse", -/** - * Convert string to unique id - */ + /** + * Parse Loop + */ + value: function parse(src) { + this.inline = new InlineLexer_1(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text -Slugger.prototype.slug = function(value) { - var slug = value - .toLowerCase() - .trim() - .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; + this.inlineText = new InlineLexer_1(src.links, merge$2({}, this.options, { + renderer: new TextRenderer_1() + })); + this.tokens = src.reverse(); + var out = ''; - return slug; -}; + while (this.next()) { + out += this.tok(); + } -/** - * Helpers - */ + return out; + } + }, { + key: "next", + + /** + * Next Token + */ + value: function next() { + this.token = this.tokens.pop(); + return this.token; + } + }, { + key: "peek", + + /** + * Preview Next Token + */ + value: function peek() { + return this.tokens[this.tokens.length - 1] || 0; + } + }, { + key: "parseText", -function escape(html, encode) { - if (encode) { - if (escape.escapeTest.test(html)) { - return html.replace(escape.escapeReplace, function(ch) { return escape.replacements[ch]; }); - } - } else { - if (escape.escapeTestNoEncode.test(html)) { - return html.replace(escape.escapeReplaceNoEncode, function(ch) { return escape.replacements[ch]; }); - } - } + /** + * Parse Text Tokens + */ + value: function parseText() { + var body = this.token.text; - return html; -} - -escape.escapeTest = /[&<>"']/; -escape.escapeReplace = /[&<>"']/g; -escape.replacements = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' -}; - -escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; -escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; - -function unescape(html) { - // explicitly match decimal, hex, and named HTML entities - return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, function(_, n) { - n = n.toLowerCase(); - if (n === 'colon') return ':'; - if (n.charAt(0) === '#') { - return n.charAt(1) === 'x' - ? String.fromCharCode(parseInt(n.substring(2), 16)) - : String.fromCharCode(+n.substring(1)); - } - return ''; - }); -} - -function edit(regex, opt) { - regex = regex.source || regex; - opt = opt || ''; - return { - replace: function(name, val) { - val = val.source || val; - val = val.replace(/(^|[^\[])\^/g, '$1'); - regex = regex.replace(name, val); - return this; - }, - getRegex: function() { - return new RegExp(regex, opt); - } - }; -} + while (this.peek().type === 'text') { + body += '\n' + this.next().text; + } -function cleanUrl(sanitize, base, href) { - if (sanitize) { - try { - var prot = decodeURIComponent(unescape(href)) - .replace(/[^\w:]/g, '') - .toLowerCase(); - } catch (e) { - return null; - } - if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { - return null; - } - } - if (base && !originIndependentUrl.test(href)) { - href = resolveUrl(base, href); - } - try { - href = encodeURI(href).replace(/%25/g, '%'); - } catch (e) { - return null; - } - return href; -} - -function resolveUrl(base, href) { - if (!baseUrls[' ' + base]) { - // we can ignore everything in base after the last slash of its path component, - // but we might need to add _that_ - // https://tools.ietf.org/html/rfc3986#section-3 - if (/^[^:]+:\/*[^/]*$/.test(base)) { - baseUrls[' ' + base] = base + '/'; - } else { - baseUrls[' ' + base] = rtrim(base, '/', true); + return this.inline.output(body); + } + }, { + key: "tok", + + /** + * Parse Current Token + */ + value: 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); + } + } + } + } + }], [{ + key: "parse", + value: function parse(src, options) { + var parser = new Parser(options); + return parser.parse(src); + } + }]); + + return Parser; + }(); + + var merge$3 = helpers.merge, + checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation, + escape$4 = helpers.escape; + var getDefaults$1 = defaults_1.getDefaults, + changeDefaults$1 = defaults_1.changeDefaults, + defaults$5 = defaults_1.defaults; + /** + * Marked + */ + + function marked(src, opt, callback) { + // throw error in case of non string input + if (typeof src === 'undefined' || src === null) { + throw new Error('marked(): input parameter is undefined or null'); } - } - base = baseUrls[' ' + base]; - var relativeBase = base.indexOf(':') === -1; - if (href.slice(0, 2) === '//') { - if (relativeBase) { - return href; + if (typeof src !== 'string') { + throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected'); } - return base.replace(/^([^:]+:)[\s\S]*$/, '$1') + href; - } else if (href.charAt(0) === '/') { - if (relativeBase) { - return href; - } - return base.replace(/^([^:]+:\/*[^/]*)[\s\S]*$/, '$1') + href; - } else { - return base + href; - } -} -var baseUrls = {}; -var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; -function noop() {} -noop.exec = noop; + if (callback || typeof opt === 'function') { + var _ret = function () { + if (!callback) { + callback = opt; + opt = null; + } -function merge(obj) { - var i = 1, - target, - key; + opt = merge$3({}, marked.defaults, opt || {}); + checkSanitizeDeprecation$1(opt); + var highlight = opt.highlight; + var tokens, + pending, + i = 0; + + try { + tokens = Lexer_1.lex(src, opt); + } catch (e) { + return { + v: callback(e) + }; + } - for (; i < arguments.length; i++) { - target = arguments[i]; - for (key in target) { - if (Object.prototype.hasOwnProperty.call(target, key)) { - obj[key] = target[key]; - } - } - } + pending = tokens.length; - return obj; -} - -function splitCells(tableRow, count) { - // ensure that every cell-delimiting pipe has a space - // before it to distinguish it from an escaped pipe - var row = tableRow.replace(/\|/g, function(match, offset, str) { - var escaped = false, - curr = offset; - while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; - if (escaped) { - // odd number of slashes means | is escaped - // so we leave it alone - return '|'; - } else { - // add space before unescaped | - return ' |'; - } - }), - cells = row.split(/ \|/), - i = 0; - - if (cells.length > count) { - cells.splice(count); - } else { - while (cells.length < count) cells.push(''); - } + var done = function done(err) { + if (err) { + opt.highlight = highlight; + return callback(err); + } - for (; i < cells.length; i++) { - // leading or trailing whitespace is ignored per the gfm spec - cells[i] = cells[i].trim().replace(/\\\|/g, '|'); - } - return cells; -} - -// Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). -// /c*$/ is vulnerable to REDOS. -// invert: Remove suffix of non-c chars instead. Default falsey. -function rtrim(str, c, invert) { - if (str.length === 0) { - return ''; - } + var out; - // Length of suffix matching the invert condition. - var suffLen = 0; + try { + out = Parser_1.parse(tokens, opt); + } catch (e) { + err = e; + } - // Step left until we fail to match the invert condition. - while (suffLen < str.length) { - var currChar = str.charAt(str.length - suffLen - 1); - if (currChar === c && !invert) { - suffLen++; - } else if (currChar !== c && invert) { - suffLen++; - } else { - break; - } - } + opt.highlight = highlight; + return err ? callback(err) : callback(null, out); + }; - return str.substr(0, str.length - suffLen); -} + if (!highlight || highlight.length < 3) { + return { + v: done() + }; + } -function findClosingBracket(str, b) { - if (str.indexOf(b[1]) === -1) { - return -1; - } - var level = 0; - for (var i = 0; i < str.length; i++) { - if (str[i] === '\\') { - i++; - } else if (str[i] === b[0]) { - level++; - } else if (str[i] === b[1]) { - level--; - if (level < 0) { - return i; - } - } - } - return -1; -} + delete opt.highlight; + if (!pending) return { + v: done() + }; -function checkSanitizeDeprecation(opt) { - if (opt && opt.sanitize && !opt.silent) { - console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options'); - } -} + for (; i < tokens.length; i++) { + (function (token) { + if (token.type !== 'code') { + return --pending || done(); + } -/** - * Marked - */ + return highlight(token.text, token.lang, function (err, code) { + if (err) return done(err); -function marked(src, opt, callback) { - // throw error in case of non string input - if (typeof src === 'undefined' || src === null) { - throw new Error('marked(): input parameter is undefined or null'); - } - if (typeof src !== 'string') { - throw new Error('marked(): input parameter is of type ' - + Object.prototype.toString.call(src) + ', string expected'); - } + if (code == null || code === token.text) { + return --pending || done(); + } - if (callback || typeof opt === 'function') { - if (!callback) { - callback = opt; - opt = null; - } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } - opt = merge({}, marked.defaults, opt || {}); - checkSanitizeDeprecation(opt); + return { + v: void 0 + }; + }(); - var highlight = opt.highlight, - tokens, - pending, - i = 0; + if (_typeof(_ret) === "object") return _ret.v; + } try { - tokens = Lexer.lex(src, opt); + opt = merge$3({}, marked.defaults, opt || {}); + checkSanitizeDeprecation$1(opt); + return Parser_1.parse(Lexer_1.lex(src, opt), opt); } catch (e) { - return callback(e); - } - - pending = tokens.length; - - var done = function(err) { - if (err) { - opt.highlight = highlight; - return callback(err); - } + e.message += '\nPlease report this to https://github.com/markedjs/marked.'; - var out; - - try { - out = Parser.parse(tokens, opt); - } catch (e) { - err = e; + if ((opt || marked.defaults).silent) { + return '

    An error occurred:

    ' + escape$4(e.message + '', true) + '
    '; } - opt.highlight = highlight; - - return err - ? callback(err) - : callback(null, out); - }; - - if (!highlight || highlight.length < 3) { - return done(); - } - - delete opt.highlight; - - if (!pending) return done(); - - for (; i < tokens.length; i++) { - (function(token) { - if (token.type !== 'code') { - return --pending || done(); - } - return highlight(token.text, token.lang, function(err, code) { - if (err) return done(err); - if (code == null || code === token.text) { - return --pending || done(); - } - token.text = code; - token.escaped = true; - --pending || done(); - }); - })(tokens[i]); + throw e; } - - return; } - try { - if (opt) opt = merge({}, marked.defaults, opt); - checkSanitizeDeprecation(opt); - return Parser.parse(Lexer.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(e.message + '', true)
    -        + '
    '; - } - throw e; - } -} + /** + * Options + */ -/** - * Options - */ -marked.options = -marked.setOptions = function(opt) { - merge(marked.defaults, opt); - return marked; -}; - -marked.getDefaults = function() { - return { - baseUrl: null, - breaks: false, - gfm: true, - headerIds: true, - headerPrefix: '', - highlight: null, - langPrefix: 'language-', - mangle: true, - pedantic: false, - renderer: new Renderer(), - sanitize: false, - sanitizer: null, - silent: false, - smartLists: false, - smartypants: false, - xhtml: false + marked.options = marked.setOptions = function (opt) { + merge$3(marked.defaults, opt); + changeDefaults$1(marked.defaults); + return marked; }; -}; - -marked.defaults = marked.getDefaults(); - -/** - * Expose - */ - -marked.Parser = Parser; -marked.parser = Parser.parse; - -marked.Renderer = Renderer; -marked.TextRenderer = TextRenderer; - -marked.Lexer = Lexer; -marked.lexer = Lexer.lex; - -marked.InlineLexer = InlineLexer; -marked.inlineLexer = InlineLexer.output; - -marked.Slugger = Slugger; - -marked.parse = marked; -if (typeof module !== 'undefined' && typeof exports === 'object') { - module.exports = marked; -} else if (typeof define === 'function' && define.amd) { - define(function() { return marked; }); -} else { - root.marked = marked; -} -})(this || (typeof window !== 'undefined' ? window : global)); + marked.getDefaults = getDefaults$1; + marked.defaults = defaults$5; + /** + * Expose + */ + + marked.Parser = Parser_1; + marked.parser = Parser_1.parse; + marked.Renderer = Renderer_1; + 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; + + return marked_1; + +}))); From 9d098d563dc96cb30d99af2360b15d7b9764b129 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 8 Nov 2019 09:21:29 -0600 Subject: [PATCH 26/33] rename regex.js to rules.js --- src/InlineLexer.js | 2 +- src/Lexer.js | 2 +- src/{regexp.js => rules.js} | 0 test/vuln-regex.js | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/{regexp.js => rules.js} (100%) diff --git a/src/InlineLexer.js b/src/InlineLexer.js index a25bfea129..d0c9d4129b 100644 --- a/src/InlineLexer.js +++ b/src/InlineLexer.js @@ -1,6 +1,6 @@ const Renderer = require('./Renderer.js'); const { defaults } = require('./defaults.js'); -const { inline } = require('./regexp.js'); +const { inline } = require('./rules.js'); const { findClosingBracket, escape diff --git a/src/Lexer.js b/src/Lexer.js index 7c2789b25d..d4ab566294 100644 --- a/src/Lexer.js +++ b/src/Lexer.js @@ -1,5 +1,5 @@ const { defaults } = require('./defaults.js'); -const { block } = require('./regexp.js'); +const { block } = require('./rules.js'); const { rtrim, splitCells, diff --git a/src/regexp.js b/src/rules.js similarity index 100% rename from src/regexp.js rename to src/rules.js diff --git a/test/vuln-regex.js b/test/vuln-regex.js index e548c8038f..e5645f7046 100644 --- a/test/vuln-regex.js +++ b/test/vuln-regex.js @@ -1,4 +1,4 @@ -const regexp = require('../src/regexp.js'); +const regexp = require('../src/rules.js'); const vulnRegexDetector = require('vuln-regex-detector'); const promises = []; From d4fe8374fd2dae8789337bc001a99a9934c1c7c2 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 8 Nov 2019 10:06:25 -0600 Subject: [PATCH 27/33] rename parse argument to tokens --- src/Parser.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Parser.js b/src/Parser.js index ce7a95a654..30011dfe4b 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -25,22 +25,22 @@ module.exports = class Parser { /** * Static Parse Method */ - static parse(src, options) { + static parse(tokens, options) { const parser = new Parser(options); - return parser.parse(src); + return parser.parse(tokens); }; /** * Parse Loop */ - parse(src) { - this.inline = new InlineLexer(src.links, this.options); + parse(tokens) { + this.inline = new InlineLexer(tokens.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text this.inlineText = new InlineLexer( - src.links, + tokens.links, merge({}, this.options, { renderer: new TextRenderer() }) ); - this.tokens = src.reverse(); + this.tokens = tokens.reverse(); let out = ''; while (this.next()) { From 6e4880e7ffa2a0da66b318e576d8ee6248252a5a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 8 Nov 2019 12:06:47 -0600 Subject: [PATCH 28/33] change minify stage to build --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c17ffab2b..8dc423f499 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ jobs: script: npm run test:lint node_js: lts/* - - stage: minify 🗜️ + - stage: build 🗜️ script: | npm run build if ! git diff --quiet; then @@ -27,7 +27,7 @@ jobs: git config --global user.name "Travis-CI" git config credential.helper "store --file=.git/credentials" echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials - git commit -am '🗜️ minify [skip ci]' + git commit -am '🗜️ build [skip ci]' git push origin HEAD:${TRAVIS_BRANCH} fi node_js: lts/* From ebf983b1295994b6ad9ba84d0c23df7dcd0c3ad4 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 8 Nov 2019 13:07:23 -0600 Subject: [PATCH 29/33] update engines --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0fb720a586..9601209342 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,6 @@ "preversion": "npm run build && (git diff --quiet || git commit -am 'build')" }, "engines": { - "node": ">=0.10.0" + "node": ">= 8.16.2" } } From a8c3efb702558f7cd7beebbaa36e3601ab23b438 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 11 Nov 2019 11:24:05 -0600 Subject: [PATCH 30/33] Update copyright year Co-Authored-By: Steven --- rollup.config.esm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.esm.js b/rollup.config.esm.js index 0c9b5ef75b..47590d59ea 100644 --- a/rollup.config.esm.js +++ b/rollup.config.esm.js @@ -17,7 +17,7 @@ The code in this file is generated from files in ./src/ license({ banner: ` marked - a markdown parser -Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) +Copyright (c) 2011-${new Date().getFullYear()}, Christopher Jeffrey. (MIT Licensed) https://github.com/markedjs/marked ` }), From 0088d3f16200c5bd22cbdfc77d053f086a8fc10a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 11 Nov 2019 11:38:04 -0600 Subject: [PATCH 31/33] update copyright year --- rollup.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 7e42e11792..8a685e2c57 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -19,7 +19,7 @@ The code in this file is generated from files in ./src/ license({ banner: ` marked - a markdown parser -Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) +Copyright (c) 2011-${new Date().getFullYear()}, Christopher Jeffrey. (MIT Licensed) https://github.com/markedjs/marked ` }), From 1a157c391a3898fc09069bfa04e472884e69541a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 27 Nov 2019 00:34:23 -0600 Subject: [PATCH 32/33] remove security scan --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8dc423f499..b041475fca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,9 +33,9 @@ jobs: node_js: lts/* if: branch = master AND type = push - - stage: security scan 🔐 - script: npm run test:redos - node_js: lts/* + # - stage: security scan 🔐 + # script: npm run test:redos + # node_js: lts/* cache: directories: From 961883a57060508063a3e9bd6b5f11ed4227f940 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 27 Nov 2019 00:36:10 -0600 Subject: [PATCH 33/33] build marked.js --- lib/marked.esm.js | 20 ++++++++++---------- lib/marked.js | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/marked.esm.js b/lib/marked.esm.js index 0c5213057d..9d9d14b9c8 100644 --- a/lib/marked.esm.js +++ b/lib/marked.esm.js @@ -1,6 +1,6 @@ /** * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * Copyright (c) 2011-2019, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ @@ -521,13 +521,13 @@ inline.breaks = merge$1({}, inline.gfm, { .getRegex() }); -var regexp = { +var rules = { block, inline }; const { defaults: defaults$1 } = defaults_1; -const { block: block$1 } = regexp; +const { block: block$1 } = rules; const { rtrim: rtrim$1, splitCells: splitCells$1, @@ -1126,7 +1126,7 @@ var Slugger_1 = class Slugger { }; const { defaults: defaults$3 } = defaults_1; -const { inline: inline$1 } = regexp; +const { inline: inline$1 } = rules; const { findClosingBracket: findClosingBracket$1, escape: escape$3 @@ -1480,22 +1480,22 @@ var Parser_1 = class Parser { /** * Static Parse Method */ - static parse(src, options) { + static parse(tokens, options) { const parser = new Parser(options); - return parser.parse(src); + return parser.parse(tokens); }; /** * Parse Loop */ - parse(src) { - this.inline = new InlineLexer_1(src.links, this.options); + 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( - src.links, + tokens.links, merge$2({}, this.options, { renderer: new TextRenderer_1() }) ); - this.tokens = src.reverse(); + this.tokens = tokens.reverse(); let out = ''; while (this.next()) { diff --git a/lib/marked.js b/lib/marked.js index 8ccb660932..2181f3c9e2 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1,6 +1,6 @@ /** * marked - a markdown parser - * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * Copyright (c) 2011-2019, Christopher Jeffrey. (MIT Licensed) * https://github.com/markedjs/marked */ @@ -505,13 +505,13 @@ br: edit$1(inline.br).replace('{2,}', '*').getRegex(), text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex() }); - var regexp = { + var rules = { block: block, inline: inline }; var defaults$1 = defaults_1.defaults; - var block$1 = regexp.block; + var block$1 = rules.block; var rtrim$1 = helpers.rtrim, splitCells$1 = helpers.splitCells, escape$1 = helpers.escape; @@ -1100,7 +1100,7 @@ }(); var defaults$3 = defaults_1.defaults; - var inline$1 = regexp.inline; + var inline$1 = rules.inline; var findClosingBracket$1 = helpers.findClosingBracket, escape$3 = helpers.escape; /** @@ -1501,13 +1501,13 @@ /** * Parse Loop */ - value: function parse(src) { - this.inline = new InlineLexer_1(src.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text + value: 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(src.links, merge$2({}, this.options, { + this.inlineText = new InlineLexer_1(tokens.links, merge$2({}, this.options, { renderer: new TextRenderer_1() })); - this.tokens = src.reverse(); + this.tokens = tokens.reverse(); var out = ''; while (this.next()) { @@ -1700,9 +1700,9 @@ } }], [{ key: "parse", - value: function parse(src, options) { + value: function parse(tokens, options) { var parser = new Parser(options); - return parser.parse(src); + return parser.parse(tokens); } }]);