🗜️ build [skip ci]

This commit is contained in:
MarkedJS bot 2022-04-08 01:54:20 +00:00
parent 35583c3dec
commit d62ccbbd67
4 changed files with 380 additions and 111 deletions

View File

@ -131,6 +131,10 @@ function escape(html, encode) {
return html; return html;
} }
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig; var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
/**
* @param {string} html
*/
function unescape(html) { function unescape(html) {
// explicitly match decimal, hex, and named HTML entities // explicitly match decimal, hex, and named HTML entities
return html.replace(unescapeTest, function (_, n) { return html.replace(unescapeTest, function (_, n) {
@ -145,8 +149,13 @@ function unescape(html) {
}); });
} }
var caret = /(^|[^\[])\^/g; var caret = /(^|[^\[])\^/g;
/**
* @param {string | RegExp} regex
* @param {string} opt
*/
function edit(regex, opt) { function edit(regex, opt) {
regex = regex.source || regex; regex = typeof regex === 'string' ? regex : regex.source;
opt = opt || ''; opt = opt || '';
var obj = { var obj = {
replace: function replace(name, val) { replace: function replace(name, val) {
@ -163,6 +172,12 @@ function edit(regex, opt) {
} }
var nonWordAndColonTest = /[^\w:]/g; var nonWordAndColonTest = /[^\w:]/g;
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
/**
* @param {boolean} sanitize
* @param {string} base
* @param {string} href
*/
function cleanUrl(sanitize, base, href) { function cleanUrl(sanitize, base, href) {
if (sanitize) { if (sanitize) {
var prot; var prot;
@ -194,6 +209,11 @@ var baseUrls = {};
var justDomain = /^[^:]+:\/*[^/]*$/; var justDomain = /^[^:]+:\/*[^/]*$/;
var protocol = /^([^:]+:)[\s\S]*$/; var protocol = /^([^:]+:)[\s\S]*$/;
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
/**
* @param {string} base
* @param {string} href
*/
function resolveUrl(base, href) { function resolveUrl(base, href) {
if (!baseUrls[' ' + base]) { if (!baseUrls[' ' + base]) {
// we can ignore everything in base after the last slash of its path component, // we can ignore everything in base after the last slash of its path component,
@ -290,9 +310,15 @@ function splitCells(tableRow, count) {
} }
return cells; 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. * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
* /c*$/ is vulnerable to REDOS.
*
* @param {string} str
* @param {string} c
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
*/
function rtrim(str, c, invert) { function rtrim(str, c, invert) {
var l = str.length; var l = str.length;
@ -316,7 +342,7 @@ function rtrim(str, c, invert) {
} }
} }
return str.substr(0, l - suffLen); return str.slice(0, l - suffLen);
} }
function findClosingBracket(str, b) { function findClosingBracket(str, b) {
if (str.indexOf(b[1]) === -1) { if (str.indexOf(b[1]) === -1) {
@ -349,6 +375,11 @@ function checkSanitizeDeprecation(opt) {
} }
} // copied from https://stackoverflow.com/a/5450113/806777 } // copied from https://stackoverflow.com/a/5450113/806777
/**
* @param {string} pattern
* @param {number} count
*/
function repeatString(pattern, count) { function repeatString(pattern, count) {
if (count < 1) { if (count < 1) {
return ''; return '';
@ -1278,9 +1309,9 @@ var inline = {
emStrong: { emStrong: {
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/, lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right. // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
// () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/, rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _ rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
}, },
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
@ -1362,6 +1393,7 @@ inline.breaks = merge({}, inline.gfm, {
/** /**
* smartypants text replacement * smartypants text replacement
* @param {string} text
*/ */
function smartypants(text) { function smartypants(text) {
@ -1376,6 +1408,7 @@ function smartypants(text) {
} }
/** /**
* mangle email addresses * mangle email addresses
* @param {string} text
*/ */
@ -1949,23 +1982,35 @@ var Renderer = /*#__PURE__*/function () {
} }
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n'; return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
}; }
/**
* @param {string} quote
*/
;
_proto.blockquote = function blockquote(quote) { _proto.blockquote = function blockquote(quote) {
return '<blockquote>\n' + quote + '</blockquote>\n'; return "<blockquote>\n" + quote + "</blockquote>\n";
}; };
_proto.html = function html(_html) { _proto.html = function html(_html) {
return _html; return _html;
}; }
/**
* @param {string} text
* @param {string} level
* @param {string} raw
* @param {any} slugger
*/
;
_proto.heading = function heading(text, level, raw, slugger) { _proto.heading = function heading(text, level, raw, slugger) {
if (this.options.headerIds) { if (this.options.headerIds) {
return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n'; var id = this.options.headerPrefix + slugger.slug(raw);
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
} // ignore IDs } // ignore IDs
return '<h' + level + '>' + text + '</h' + level + '>\n'; return "<h" + level + ">" + text + "</h" + level + ">\n";
}; };
_proto.hr = function hr() { _proto.hr = function hr() {
@ -1976,55 +2021,94 @@ var Renderer = /*#__PURE__*/function () {
var type = ordered ? 'ol' : 'ul', var type = ordered ? 'ol' : 'ul',
startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n'; return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
}; }
/**
* @param {string} text
*/
;
_proto.listitem = function listitem(text) { _proto.listitem = function listitem(text) {
return '<li>' + text + '</li>\n'; return "<li>" + text + "</li>\n";
}; };
_proto.checkbox = function checkbox(checked) { _proto.checkbox = function checkbox(checked) {
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> '; return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
}; }
/**
* @param {string} text
*/
;
_proto.paragraph = function paragraph(text) { _proto.paragraph = function paragraph(text) {
return '<p>' + text + '</p>\n'; return "<p>" + text + "</p>\n";
}; }
/**
* @param {string} header
* @param {string} body
*/
;
_proto.table = function table(header, body) { _proto.table = function table(header, body) {
if (body) body = '<tbody>' + body + '</tbody>'; if (body) body = "<tbody>" + body + "</tbody>";
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n'; return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
}; }
/**
* @param {string} content
*/
;
_proto.tablerow = function tablerow(content) { _proto.tablerow = function tablerow(content) {
return '<tr>\n' + content + '</tr>\n'; return "<tr>\n" + content + "</tr>\n";
}; };
_proto.tablecell = function tablecell(content, flags) { _proto.tablecell = function tablecell(content, flags) {
var type = flags.header ? 'th' : 'td'; var type = flags.header ? 'th' : 'td';
var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
return tag + content + '</' + type + '>\n'; return tag + content + ("</" + type + ">\n");
} // span level renderer }
/**
* span level renderer
* @param {string} text
*/
; ;
_proto.strong = function strong(text) { _proto.strong = function strong(text) {
return '<strong>' + text + '</strong>'; return "<strong>" + text + "</strong>";
}; }
/**
* @param {string} text
*/
;
_proto.em = function em(text) { _proto.em = function em(text) {
return '<em>' + text + '</em>'; return "<em>" + text + "</em>";
}; }
/**
* @param {string} text
*/
;
_proto.codespan = function codespan(text) { _proto.codespan = function codespan(text) {
return '<code>' + text + '</code>'; return "<code>" + text + "</code>";
}; };
_proto.br = function br() { _proto.br = function br() {
return this.options.xhtml ? '<br/>' : '<br>'; return this.options.xhtml ? '<br/>' : '<br>';
}; }
/**
* @param {string} text
*/
;
_proto.del = function del(text) { _proto.del = function del(text) {
return '<del>' + text + '</del>'; return "<del>" + text + "</del>";
}; }
/**
* @param {string} href
* @param {string} title
* @param {string} text
*/
;
_proto.link = function link(href, title, text) { _proto.link = function link(href, title, text) {
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@ -2041,7 +2125,13 @@ var Renderer = /*#__PURE__*/function () {
out += '>' + text + '</a>'; out += '>' + text + '</a>';
return out; return out;
}; }
/**
* @param {string} href
* @param {string} title
* @param {string} text
*/
;
_proto.image = function image(href, title, text) { _proto.image = function image(href, title, text) {
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@ -2050,10 +2140,10 @@ var Renderer = /*#__PURE__*/function () {
return text; return text;
} }
var out = '<img src="' + href + '" alt="' + text + '"'; var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
if (title) { if (title) {
out += ' title="' + title + '"'; out += " title=\"" + title + "\"";
} }
out += this.options.xhtml ? '/>' : '>'; out += this.options.xhtml ? '/>' : '>';
@ -2123,6 +2213,10 @@ var Slugger = /*#__PURE__*/function () {
function Slugger() { function Slugger() {
this.seen = {}; this.seen = {};
} }
/**
* @param {string} value
*/
var _proto = Slugger.prototype; var _proto = Slugger.prototype;
@ -2133,6 +2227,8 @@ var Slugger = /*#__PURE__*/function () {
} }
/** /**
* Finds the next safe (unique) slug to use * Finds the next safe (unique) slug to use
* @param {string} originalSlug
* @param {boolean} isDryRun
*/ */
; ;
@ -2158,8 +2254,9 @@ var Slugger = /*#__PURE__*/function () {
} }
/** /**
* Convert string to unique id * Convert string to unique id
* @param {object} options * @param {object} [options]
* @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator. * @param {boolean} [options.dryrun] Generates the next unique slug without
* updating the internal accumulator.
*/ */
; ;
@ -2856,6 +2953,7 @@ marked.walkTokens = function (tokens, callback) {
}; };
/** /**
* Parse Inline * Parse Inline
* @param {string} src
*/ */

View File

@ -70,6 +70,9 @@ function escape(html, encode) {
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig; const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
/**
* @param {string} html
*/
function unescape(html) { function unescape(html) {
// explicitly match decimal, hex, and named HTML entities // explicitly match decimal, hex, and named HTML entities
return html.replace(unescapeTest, (_, n) => { return html.replace(unescapeTest, (_, n) => {
@ -85,8 +88,13 @@ function unescape(html) {
} }
const caret = /(^|[^\[])\^/g; const caret = /(^|[^\[])\^/g;
/**
* @param {string | RegExp} regex
* @param {string} opt
*/
function edit(regex, opt) { function edit(regex, opt) {
regex = regex.source || regex; regex = typeof regex === 'string' ? regex : regex.source;
opt = opt || ''; opt = opt || '';
const obj = { const obj = {
replace: (name, val) => { replace: (name, val) => {
@ -104,6 +112,12 @@ function edit(regex, opt) {
const nonWordAndColonTest = /[^\w:]/g; const nonWordAndColonTest = /[^\w:]/g;
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
/**
* @param {boolean} sanitize
* @param {string} base
* @param {string} href
*/
function cleanUrl(sanitize, base, href) { function cleanUrl(sanitize, base, href) {
if (sanitize) { if (sanitize) {
let prot; let prot;
@ -134,6 +148,10 @@ const justDomain = /^[^:]+:\/*[^/]*$/;
const protocol = /^([^:]+:)[\s\S]*$/; const protocol = /^([^:]+:)[\s\S]*$/;
const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
/**
* @param {string} base
* @param {string} href
*/
function resolveUrl(base, href) { function resolveUrl(base, href) {
if (!baseUrls[' ' + base]) { if (!baseUrls[' ' + base]) {
// we can ignore everything in base after the last slash of its path component, // we can ignore everything in base after the last slash of its path component,
@ -218,9 +236,14 @@ function splitCells(tableRow, count) {
return cells; return cells;
} }
// Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /**
// /c*$/ is vulnerable to REDOS. * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
// invert: Remove suffix of non-c chars instead. Default falsey. * /c*$/ is vulnerable to REDOS.
*
* @param {string} str
* @param {string} c
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
*/
function rtrim(str, c, invert) { function rtrim(str, c, invert) {
const l = str.length; const l = str.length;
if (l === 0) { if (l === 0) {
@ -242,7 +265,7 @@ function rtrim(str, c, invert) {
} }
} }
return str.substr(0, l - suffLen); return str.slice(0, l - suffLen);
} }
function findClosingBracket(str, b) { function findClosingBracket(str, b) {
@ -274,6 +297,10 @@ function checkSanitizeDeprecation(opt) {
} }
// copied from https://stackoverflow.com/a/5450113/806777 // copied from https://stackoverflow.com/a/5450113/806777
/**
* @param {string} pattern
* @param {number} count
*/
function repeatString(pattern, count) { function repeatString(pattern, count) {
if (count < 1) { if (count < 1) {
return ''; return '';
@ -1214,9 +1241,9 @@ const inline = {
emStrong: { emStrong: {
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/, lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right. // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
// () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/, rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _ rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
}, },
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
br: /^( {2,}|\\)\n(?!\s*$)/, br: /^( {2,}|\\)\n(?!\s*$)/,
@ -1349,6 +1376,7 @@ inline.breaks = merge({}, inline.gfm, {
/** /**
* smartypants text replacement * smartypants text replacement
* @param {string} text
*/ */
function smartypants(text) { function smartypants(text) {
return text return text
@ -1370,6 +1398,7 @@ function smartypants(text) {
/** /**
* mangle email addresses * mangle email addresses
* @param {string} text
*/ */
function mangle(text) { function mangle(text) {
let out = '', let out = '',
@ -1872,29 +1901,31 @@ class Renderer {
+ '</code></pre>\n'; + '</code></pre>\n';
} }
/**
* @param {string} quote
*/
blockquote(quote) { blockquote(quote) {
return '<blockquote>\n' + quote + '</blockquote>\n'; return `<blockquote>\n${quote}</blockquote>\n`;
} }
html(html) { html(html) {
return html; return html;
} }
/**
* @param {string} text
* @param {string} level
* @param {string} raw
* @param {any} slugger
*/
heading(text, level, raw, slugger) { heading(text, level, raw, slugger) {
if (this.options.headerIds) { if (this.options.headerIds) {
return '<h' const id = this.options.headerPrefix + slugger.slug(raw);
+ level return `<h${level} id="${id}">${text}</h${level}>\n`;
+ ' id="'
+ this.options.headerPrefix
+ slugger.slug(raw)
+ '">'
+ text
+ '</h'
+ level
+ '>\n';
} }
// ignore IDs // ignore IDs
return '<h' + level + '>' + text + '</h' + level + '>\n'; return `<h${level}>${text}</h${level}>\n`;
} }
hr() { hr() {
@ -1907,8 +1938,11 @@ class Renderer {
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n'; return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
} }
/**
* @param {string} text
*/
listitem(text) { listitem(text) {
return '<li>' + text + '</li>\n'; return `<li>${text}</li>\n`;
} }
checkbox(checked) { checkbox(checked) {
@ -1919,12 +1953,19 @@ class Renderer {
+ '> '; + '> ';
} }
/**
* @param {string} text
*/
paragraph(text) { paragraph(text) {
return '<p>' + text + '</p>\n'; return `<p>${text}</p>\n`;
} }
/**
* @param {string} header
* @param {string} body
*/
table(header, body) { table(header, body) {
if (body) body = '<tbody>' + body + '</tbody>'; if (body) body = `<tbody>${body}</tbody>`;
return '<table>\n' return '<table>\n'
+ '<thead>\n' + '<thead>\n'
@ -1934,39 +1975,59 @@ class Renderer {
+ '</table>\n'; + '</table>\n';
} }
/**
* @param {string} content
*/
tablerow(content) { tablerow(content) {
return '<tr>\n' + content + '</tr>\n'; return `<tr>\n${content}</tr>\n`;
} }
tablecell(content, flags) { tablecell(content, flags) {
const type = flags.header ? 'th' : 'td'; const type = flags.header ? 'th' : 'td';
const tag = flags.align const tag = flags.align
? '<' + type + ' align="' + flags.align + '">' ? `<${type} align="${flags.align}">`
: '<' + type + '>'; : `<${type}>`;
return tag + content + '</' + type + '>\n'; return tag + content + `</${type}>\n`;
} }
// span level renderer /**
* span level renderer
* @param {string} text
*/
strong(text) { strong(text) {
return '<strong>' + text + '</strong>'; return `<strong>${text}</strong>`;
} }
/**
* @param {string} text
*/
em(text) { em(text) {
return '<em>' + text + '</em>'; return `<em>${text}</em>`;
} }
/**
* @param {string} text
*/
codespan(text) { codespan(text) {
return '<code>' + text + '</code>'; return `<code>${text}</code>`;
} }
br() { br() {
return this.options.xhtml ? '<br/>' : '<br>'; return this.options.xhtml ? '<br/>' : '<br>';
} }
/**
* @param {string} text
*/
del(text) { del(text) {
return '<del>' + text + '</del>'; return `<del>${text}</del>`;
} }
/**
* @param {string} href
* @param {string} title
* @param {string} text
*/
link(href, title, text) { link(href, title, text) {
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
if (href === null) { if (href === null) {
@ -1980,15 +2041,20 @@ class Renderer {
return out; return out;
} }
/**
* @param {string} href
* @param {string} title
* @param {string} text
*/
image(href, title, text) { image(href, title, text) {
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
if (href === null) { if (href === null) {
return text; return text;
} }
let out = '<img src="' + href + '" alt="' + text + '"'; let out = `<img src="${href}" alt="${text}"`;
if (title) { if (title) {
out += ' title="' + title + '"'; out += ` title="${title}"`;
} }
out += this.options.xhtml ? '/>' : '>'; out += this.options.xhtml ? '/>' : '>';
return out; return out;
@ -2050,6 +2116,9 @@ class Slugger {
this.seen = {}; this.seen = {};
} }
/**
* @param {string} value
*/
serialize(value) { serialize(value) {
return value return value
.toLowerCase() .toLowerCase()
@ -2063,6 +2132,8 @@ class Slugger {
/** /**
* Finds the next safe (unique) slug to use * Finds the next safe (unique) slug to use
* @param {string} originalSlug
* @param {boolean} isDryRun
*/ */
getNextSafeSlug(originalSlug, isDryRun) { getNextSafeSlug(originalSlug, isDryRun) {
let slug = originalSlug; let slug = originalSlug;
@ -2083,8 +2154,9 @@ class Slugger {
/** /**
* Convert string to unique id * Convert string to unique id
* @param {object} options * @param {object} [options]
* @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator. * @param {boolean} [options.dryrun] Generates the next unique slug without
* updating the internal accumulator.
*/ */
slug(value, options = {}) { slug(value, options = {}) {
const slug = this.serialize(value); const slug = this.serialize(value);
@ -2645,6 +2717,7 @@ marked.walkTokens = function(tokens, callback) {
/** /**
* Parse Inline * Parse Inline
* @param {string} src
*/ */
marked.parseInline = function(src, opt) { marked.parseInline = function(src, opt) {
// throw error in case of non string input // throw error in case of non string input

View File

@ -133,6 +133,10 @@
return html; return html;
} }
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig; var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
/**
* @param {string} html
*/
function unescape(html) { function unescape(html) {
// explicitly match decimal, hex, and named HTML entities // explicitly match decimal, hex, and named HTML entities
return html.replace(unescapeTest, function (_, n) { return html.replace(unescapeTest, function (_, n) {
@ -147,8 +151,13 @@
}); });
} }
var caret = /(^|[^\[])\^/g; var caret = /(^|[^\[])\^/g;
/**
* @param {string | RegExp} regex
* @param {string} opt
*/
function edit(regex, opt) { function edit(regex, opt) {
regex = regex.source || regex; regex = typeof regex === 'string' ? regex : regex.source;
opt = opt || ''; opt = opt || '';
var obj = { var obj = {
replace: function replace(name, val) { replace: function replace(name, val) {
@ -165,6 +174,12 @@
} }
var nonWordAndColonTest = /[^\w:]/g; var nonWordAndColonTest = /[^\w:]/g;
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i; var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
/**
* @param {boolean} sanitize
* @param {string} base
* @param {string} href
*/
function cleanUrl(sanitize, base, href) { function cleanUrl(sanitize, base, href) {
if (sanitize) { if (sanitize) {
var prot; var prot;
@ -196,6 +211,11 @@
var justDomain = /^[^:]+:\/*[^/]*$/; var justDomain = /^[^:]+:\/*[^/]*$/;
var protocol = /^([^:]+:)[\s\S]*$/; var protocol = /^([^:]+:)[\s\S]*$/;
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/; var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
/**
* @param {string} base
* @param {string} href
*/
function resolveUrl(base, href) { function resolveUrl(base, href) {
if (!baseUrls[' ' + base]) { if (!baseUrls[' ' + base]) {
// we can ignore everything in base after the last slash of its path component, // we can ignore everything in base after the last slash of its path component,
@ -292,9 +312,15 @@
} }
return cells; 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. * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
* /c*$/ is vulnerable to REDOS.
*
* @param {string} str
* @param {string} c
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
*/
function rtrim(str, c, invert) { function rtrim(str, c, invert) {
var l = str.length; var l = str.length;
@ -318,7 +344,7 @@
} }
} }
return str.substr(0, l - suffLen); return str.slice(0, l - suffLen);
} }
function findClosingBracket(str, b) { function findClosingBracket(str, b) {
if (str.indexOf(b[1]) === -1) { if (str.indexOf(b[1]) === -1) {
@ -351,6 +377,11 @@
} }
} // copied from https://stackoverflow.com/a/5450113/806777 } // copied from https://stackoverflow.com/a/5450113/806777
/**
* @param {string} pattern
* @param {number} count
*/
function repeatString(pattern, count) { function repeatString(pattern, count) {
if (count < 1) { if (count < 1) {
return ''; return '';
@ -1280,9 +1311,9 @@
emStrong: { emStrong: {
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/, lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right. // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
// () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/, rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _ rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
}, },
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/, code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
@ -1364,6 +1395,7 @@
/** /**
* smartypants text replacement * smartypants text replacement
* @param {string} text
*/ */
function smartypants(text) { function smartypants(text) {
@ -1378,6 +1410,7 @@
} }
/** /**
* mangle email addresses * mangle email addresses
* @param {string} text
*/ */
@ -1951,23 +1984,35 @@
} }
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n'; return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
}; }
/**
* @param {string} quote
*/
;
_proto.blockquote = function blockquote(quote) { _proto.blockquote = function blockquote(quote) {
return '<blockquote>\n' + quote + '</blockquote>\n'; return "<blockquote>\n" + quote + "</blockquote>\n";
}; };
_proto.html = function html(_html) { _proto.html = function html(_html) {
return _html; return _html;
}; }
/**
* @param {string} text
* @param {string} level
* @param {string} raw
* @param {any} slugger
*/
;
_proto.heading = function heading(text, level, raw, slugger) { _proto.heading = function heading(text, level, raw, slugger) {
if (this.options.headerIds) { if (this.options.headerIds) {
return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n'; var id = this.options.headerPrefix + slugger.slug(raw);
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
} // ignore IDs } // ignore IDs
return '<h' + level + '>' + text + '</h' + level + '>\n'; return "<h" + level + ">" + text + "</h" + level + ">\n";
}; };
_proto.hr = function hr() { _proto.hr = function hr() {
@ -1978,55 +2023,94 @@
var type = ordered ? 'ol' : 'ul', var type = ordered ? 'ol' : 'ul',
startatt = ordered && start !== 1 ? ' start="' + start + '"' : ''; startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n'; return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
}; }
/**
* @param {string} text
*/
;
_proto.listitem = function listitem(text) { _proto.listitem = function listitem(text) {
return '<li>' + text + '</li>\n'; return "<li>" + text + "</li>\n";
}; };
_proto.checkbox = function checkbox(checked) { _proto.checkbox = function checkbox(checked) {
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> '; return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
}; }
/**
* @param {string} text
*/
;
_proto.paragraph = function paragraph(text) { _proto.paragraph = function paragraph(text) {
return '<p>' + text + '</p>\n'; return "<p>" + text + "</p>\n";
}; }
/**
* @param {string} header
* @param {string} body
*/
;
_proto.table = function table(header, body) { _proto.table = function table(header, body) {
if (body) body = '<tbody>' + body + '</tbody>'; if (body) body = "<tbody>" + body + "</tbody>";
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n'; return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
}; }
/**
* @param {string} content
*/
;
_proto.tablerow = function tablerow(content) { _proto.tablerow = function tablerow(content) {
return '<tr>\n' + content + '</tr>\n'; return "<tr>\n" + content + "</tr>\n";
}; };
_proto.tablecell = function tablecell(content, flags) { _proto.tablecell = function tablecell(content, flags) {
var type = flags.header ? 'th' : 'td'; var type = flags.header ? 'th' : 'td';
var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>'; var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
return tag + content + '</' + type + '>\n'; return tag + content + ("</" + type + ">\n");
} // span level renderer }
/**
* span level renderer
* @param {string} text
*/
; ;
_proto.strong = function strong(text) { _proto.strong = function strong(text) {
return '<strong>' + text + '</strong>'; return "<strong>" + text + "</strong>";
}; }
/**
* @param {string} text
*/
;
_proto.em = function em(text) { _proto.em = function em(text) {
return '<em>' + text + '</em>'; return "<em>" + text + "</em>";
}; }
/**
* @param {string} text
*/
;
_proto.codespan = function codespan(text) { _proto.codespan = function codespan(text) {
return '<code>' + text + '</code>'; return "<code>" + text + "</code>";
}; };
_proto.br = function br() { _proto.br = function br() {
return this.options.xhtml ? '<br/>' : '<br>'; return this.options.xhtml ? '<br/>' : '<br>';
}; }
/**
* @param {string} text
*/
;
_proto.del = function del(text) { _proto.del = function del(text) {
return '<del>' + text + '</del>'; return "<del>" + text + "</del>";
}; }
/**
* @param {string} href
* @param {string} title
* @param {string} text
*/
;
_proto.link = function link(href, title, text) { _proto.link = function link(href, title, text) {
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@ -2043,7 +2127,13 @@
out += '>' + text + '</a>'; out += '>' + text + '</a>';
return out; return out;
}; }
/**
* @param {string} href
* @param {string} title
* @param {string} text
*/
;
_proto.image = function image(href, title, text) { _proto.image = function image(href, title, text) {
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@ -2052,10 +2142,10 @@
return text; return text;
} }
var out = '<img src="' + href + '" alt="' + text + '"'; var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
if (title) { if (title) {
out += ' title="' + title + '"'; out += " title=\"" + title + "\"";
} }
out += this.options.xhtml ? '/>' : '>'; out += this.options.xhtml ? '/>' : '>';
@ -2125,6 +2215,10 @@
function Slugger() { function Slugger() {
this.seen = {}; this.seen = {};
} }
/**
* @param {string} value
*/
var _proto = Slugger.prototype; var _proto = Slugger.prototype;
@ -2135,6 +2229,8 @@
} }
/** /**
* Finds the next safe (unique) slug to use * Finds the next safe (unique) slug to use
* @param {string} originalSlug
* @param {boolean} isDryRun
*/ */
; ;
@ -2160,8 +2256,9 @@
} }
/** /**
* Convert string to unique id * Convert string to unique id
* @param {object} options * @param {object} [options]
* @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator. * @param {boolean} [options.dryrun] Generates the next unique slug without
* updating the internal accumulator.
*/ */
; ;
@ -2858,6 +2955,7 @@
}; };
/** /**
* Parse Inline * Parse Inline
* @param {string} src
*/ */

2
marked.min.js vendored

File diff suppressed because one or more lines are too long