From 099983ffcbbf7ac7f84f18bfba9ada5c3cfb8243 Mon Sep 17 00:00:00 2001
From: Tony Brix ' + text + ' An error occurred: ' + text + ' ' + text + ' An error occurred: An error occurred: "+e+"
';
+ }
+
+ return ''
+ + (escaped ? code : escape(code, true))
+ + '
\n';
+};
+
+Renderer.prototype.blockquote = function(quote) {
+ return ''
+ + (escaped ? code : escape(code, true))
+ + '
\n' + quote + '
\n';
+};
+
+Renderer.prototype.html = function(html) {
+ return html;
+};
+
+Renderer.prototype.heading = function(text, level, raw, slugger) {
+ if (this.options.headerIds) {
+ return '
\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 + '' + type + '>\n';
+};
+
+Renderer.prototype.listitem = function(text) {
+ 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 + '' + type + '>\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 = '' + text + '';
+ 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 = '' : '>';
+ 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 ''
+ + 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]*?(?:\\1>[^\\n]*\\n+|$)' // (1)
+ + '|comment[^\\n]*(\\n+|$)' // (2)
+ + '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
+ + '|\\n*' // (4)
+ + '|\\n*' // (5)
+ + '|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
+ + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
+ + '|(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
+ + ')',
+ def: /^ {0,3}\[(label)\]: *\n? *([^\s>]+)>?(?:(?: +\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', '?(?:tag)(?: +|\\n|/?>)|<(?: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]+?\\1> *(?:\\n{2,}|\\s*$)' // closed tag
+ + '|
';
+ }
+
+ return '' + (escaped ? code : escape(code, true)) + '
\n';
+ };
+
+ Renderer.prototype.blockquote = function (quote) {
+ return '' + (escaped ? code : escape(code, true)) + '
\n' + quote + '
\n';
+ };
+
+ Renderer.prototype.html = function (html) {
+ return html;
+ };
+
+ Renderer.prototype.heading = function (text, level, raw, slugger) {
+ if (this.options.headerIds) {
+ return '
\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 + '' + type + '>\n';
+ };
+
+ Renderer.prototype.listitem = function (text) {
+ 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 + '' + type + '>\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 = '' + text + '';
+ 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 = '' : '>';
+ 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'
- + '|^[a-zA-Z][\\w:-]*\\s*>' // 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 '
';
- }
+ return out;
+ };
- return ''
- + (escaped ? code : escape(code, true))
- + '
\n';
-};
-
-Renderer.prototype.blockquote = function(quote) {
- return ''
- + (escaped ? code : escape(code, true))
- + '
\n' + quote + '
\n';
-};
-
-Renderer.prototype.html = function(html) {
- return html;
-};
-
-Renderer.prototype.heading = function(text, level, raw, slugger) {
- if (this.options.headerIds) {
- return '
\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 + '' + type + '>\n';
-};
-
-Renderer.prototype.listitem = function(text) {
- 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 + '' + type + '>\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 = '' + text + '';
- 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 = '' : '>';
- 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 ''
- + 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 '' + 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]*?(?:\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *([^\s>]+)>?(?:(?: +\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","?(?:tag)(?: +|\\n|/?>)|<(?: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]+?\\1> *(?:\\n{2,}|\\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:_(e,!0))+"
\n":"
"},r.prototype.blockquote=function(e){return""+(n?e:_(e,!0))+"
\n"+e+"
\n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,n,r){return this.options.headerIds?"
\n":"
\n"},r.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+""+r+">\n"},r.prototype.listitem=function(e){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+">\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='"+n+""},r.prototype.image=function(e,t,n){if(null===(e=l(this.options.sanitize,this.options.baseUrl,e)))return n;var r='":">"},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
"+_(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;r
"+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"},u.prototype.table=function(e,t){return""+e+"
"},u.prototype.br=function(){return this.options.xhtml?"'
- + (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'; -}; - -Renderer.prototype.table = function(header, body) { - if (body) body = '' + body + ''; - - return '' + text + '
';
-};
-
-Renderer.prototype.br = function() {
- return this.options.xhtml ? '\n' + quote + '\n'; + }; + + html(html) { + return html; + }; + + heading(text, level, raw, slugger) { + if (this.options.headerIds) { + return '
' + text + '
\n'; + }; + + table(header, body) { + if (body) body = '' + body + ''; + + return '' + text + '
';
+ };
+
+ br() {
+ return this.options.xhtml ? '' + (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'; - }; - - Renderer.prototype.table = function (header, body) { - if (body) body = '' + body + ''; - return '' + text + '
';
- };
+ if (out != null && out !== _code) {
+ escaped = true;
+ _code = out;
+ }
+ }
- Renderer.prototype.br = function () {
- return this.options.xhtml ? '' + (escaped ? _code : escape$2(_code, true)) + '
';
+ }
- Renderer.prototype.del = function (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'; + } + }, { + key: "table", + value: function table(header, body) { + if (body) body = '' + body + ''; + return '' + text + '
';
+ }
+ }, {
+ key: "br",
+ value: function br() {
+ return this.options.xhtml ? '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;n
'+(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"}},{key:"table",value:function(e,t){return""+e+"
"}},{key:"br",value:function(){return this.options.xhtml?""+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"},u.prototype.table=function(e,t){return""+e+"
"},u.prototype.br=function(){return this.options.xhtml?""+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 a4652f1363f37ae630969c2af7caf57a8a3d5f42 Mon Sep 17 00:00:00 2001 From: Tony Brix
'+(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"}},{key:"table",value:function(e,t){return""+e+"
"}},{key:"br",value:function(){return this.options.xhtml?""+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
'+(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"}},{key:"table",value:function(e,t){return""+e+"
"}},{key:"br",value:function(){return this.options.xhtml?""+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 83fa29778530bbfe689d907665c8333d49a42b31 Mon Sep 17 00:00:00 2001 From: Tony Brix
' + (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'; - } - }, { - key: "table", - value: function table(header, body) { - if (body) body = '' + body + ''; - return '' + text + '
';
- }
- }, {
- key: "br",
- value: function br() {
- return this.options.xhtml ? ''
+ + (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'; +}; + +Renderer.prototype.table = function(header, body) { + if (body) body = '' + body + ''; + + return '' + text + '
';
+};
+
+Renderer.prototype.br = function() {
+ return this.options.xhtml ? '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
'+(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"}},{key:"table",value:function(e,t){return""+e+"
"}},{key:"br",value:function(){return this.options.xhtml?""+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]*?(?:\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *([^\s>]+)>?(?:(?: +\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","?(?:tag)(?: +|\\n|/?>)|<(?: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]+?\\1> *(?:\\n{2,}|\\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"},r.prototype.table=function(e,t){return""+e+"
"},r.prototype.br=function(){return this.options.xhtml?""+_(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 ba45b32dd75170fb151eb34c342ea9cc563fc6af Mon Sep 17 00:00:00 2001 From: Tony Brix
' + text + '
';
+ };
+
+ br() {
+ return this.options.xhtml ? '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]*?(?:\\1>[^\\n]*\\n+|$)' // (1) - + '|comment[^\\n]*(\\n+|$)' // (2) - + '|<\\?[\\s\\S]*?\\?>\\n*' // (3) - + '|\\n*' // (4) - + '|\\n*' // (5) - + '|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6) - + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag - + '|(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag - + ')', - def: /^ {0,3}\[(label)\]: *\n? *([^\s>]+)>?(?:(?: +\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', '?(?:tag)(?: +|\\n|/?>)|<(?: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]+?\\1> *(?:\\n{2,}|\\s*$)' // closed tag - + '|
' + (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'; + } + }, { + key: "table", + value: function table(header, body) { + if (body) body = '' + body + ''; + return '' + text + '
';
+ }
+ }, {
+ key: "br",
+ value: function br() {
+ return this.options.xhtml ? ''
- + (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'; -}; - -Renderer.prototype.table = function(header, body) { - if (body) body = '' + body + ''; - - return '' + text + '
';
-};
-
-Renderer.prototype.br = function() {
- return this.options.xhtml ? '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 fb80552c0110b7b988bbc722be4320daf24a3bbb Mon Sep 17 00:00:00 2001 From: Tony Brix