Skip to content

Commit d62ccbb

Browse files
author
MarkedJS bot
committed
🗜️ build [skip ci]
1 parent 35583c3 commit d62ccbb

File tree

4 files changed

+380
-111
lines changed

4 files changed

+380
-111
lines changed

lib/marked.cjs

+135-37
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ function escape(html, encode) {
131131
return html;
132132
}
133133
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
134+
/**
135+
* @param {string} html
136+
*/
137+
134138
function unescape(html) {
135139
// explicitly match decimal, hex, and named HTML entities
136140
return html.replace(unescapeTest, function (_, n) {
@@ -145,8 +149,13 @@ function unescape(html) {
145149
});
146150
}
147151
var caret = /(^|[^\[])\^/g;
152+
/**
153+
* @param {string | RegExp} regex
154+
* @param {string} opt
155+
*/
156+
148157
function edit(regex, opt) {
149-
regex = regex.source || regex;
158+
regex = typeof regex === 'string' ? regex : regex.source;
150159
opt = opt || '';
151160
var obj = {
152161
replace: function replace(name, val) {
@@ -163,6 +172,12 @@ function edit(regex, opt) {
163172
}
164173
var nonWordAndColonTest = /[^\w:]/g;
165174
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
175+
/**
176+
* @param {boolean} sanitize
177+
* @param {string} base
178+
* @param {string} href
179+
*/
180+
166181
function cleanUrl(sanitize, base, href) {
167182
if (sanitize) {
168183
var prot;
@@ -194,6 +209,11 @@ var baseUrls = {};
194209
var justDomain = /^[^:]+:\/*[^/]*$/;
195210
var protocol = /^([^:]+:)[\s\S]*$/;
196211
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
212+
/**
213+
* @param {string} base
214+
* @param {string} href
215+
*/
216+
197217
function resolveUrl(base, href) {
198218
if (!baseUrls[' ' + base]) {
199219
// we can ignore everything in base after the last slash of its path component,
@@ -290,9 +310,15 @@ function splitCells(tableRow, count) {
290310
}
291311

292312
return cells;
293-
} // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
294-
// /c*$/ is vulnerable to REDOS.
295-
// invert: Remove suffix of non-c chars instead. Default falsey.
313+
}
314+
/**
315+
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
316+
* /c*$/ is vulnerable to REDOS.
317+
*
318+
* @param {string} str
319+
* @param {string} c
320+
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
321+
*/
296322

297323
function rtrim(str, c, invert) {
298324
var l = str.length;
@@ -316,7 +342,7 @@ function rtrim(str, c, invert) {
316342
}
317343
}
318344

319-
return str.substr(0, l - suffLen);
345+
return str.slice(0, l - suffLen);
320346
}
321347
function findClosingBracket(str, b) {
322348
if (str.indexOf(b[1]) === -1) {
@@ -349,6 +375,11 @@ function checkSanitizeDeprecation(opt) {
349375
}
350376
} // copied from https://stackoverflow.com/a/5450113/806777
351377

378+
/**
379+
* @param {string} pattern
380+
* @param {number} count
381+
*/
382+
352383
function repeatString(pattern, count) {
353384
if (count < 1) {
354385
return '';
@@ -1278,9 +1309,9 @@ var inline = {
12781309
emStrong: {
12791310
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
12801311
// (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.
1281-
// () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1282-
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1283-
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1312+
// () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1313+
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1314+
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
12841315

12851316
},
12861317
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
@@ -1362,6 +1393,7 @@ inline.breaks = merge({}, inline.gfm, {
13621393

13631394
/**
13641395
* smartypants text replacement
1396+
* @param {string} text
13651397
*/
13661398

13671399
function smartypants(text) {
@@ -1376,6 +1408,7 @@ function smartypants(text) {
13761408
}
13771409
/**
13781410
* mangle email addresses
1411+
* @param {string} text
13791412
*/
13801413

13811414

@@ -1949,23 +1982,35 @@ var Renderer = /*#__PURE__*/function () {
19491982
}
19501983

19511984
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
1952-
};
1985+
}
1986+
/**
1987+
* @param {string} quote
1988+
*/
1989+
;
19531990

19541991
_proto.blockquote = function blockquote(quote) {
1955-
return '<blockquote>\n' + quote + '</blockquote>\n';
1992+
return "<blockquote>\n" + quote + "</blockquote>\n";
19561993
};
19571994

19581995
_proto.html = function html(_html) {
19591996
return _html;
1960-
};
1997+
}
1998+
/**
1999+
* @param {string} text
2000+
* @param {string} level
2001+
* @param {string} raw
2002+
* @param {any} slugger
2003+
*/
2004+
;
19612005

19622006
_proto.heading = function heading(text, level, raw, slugger) {
19632007
if (this.options.headerIds) {
1964-
return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
2008+
var id = this.options.headerPrefix + slugger.slug(raw);
2009+
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
19652010
} // ignore IDs
19662011

19672012

1968-
return '<h' + level + '>' + text + '</h' + level + '>\n';
2013+
return "<h" + level + ">" + text + "</h" + level + ">\n";
19692014
};
19702015

19712016
_proto.hr = function hr() {
@@ -1976,55 +2021,94 @@ var Renderer = /*#__PURE__*/function () {
19762021
var type = ordered ? 'ol' : 'ul',
19772022
startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
19782023
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1979-
};
2024+
}
2025+
/**
2026+
* @param {string} text
2027+
*/
2028+
;
19802029

19812030
_proto.listitem = function listitem(text) {
1982-
return '<li>' + text + '</li>\n';
2031+
return "<li>" + text + "</li>\n";
19832032
};
19842033

19852034
_proto.checkbox = function checkbox(checked) {
19862035
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
1987-
};
2036+
}
2037+
/**
2038+
* @param {string} text
2039+
*/
2040+
;
19882041

19892042
_proto.paragraph = function paragraph(text) {
1990-
return '<p>' + text + '</p>\n';
1991-
};
2043+
return "<p>" + text + "</p>\n";
2044+
}
2045+
/**
2046+
* @param {string} header
2047+
* @param {string} body
2048+
*/
2049+
;
19922050

19932051
_proto.table = function table(header, body) {
1994-
if (body) body = '<tbody>' + body + '</tbody>';
2052+
if (body) body = "<tbody>" + body + "</tbody>";
19952053
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
1996-
};
2054+
}
2055+
/**
2056+
* @param {string} content
2057+
*/
2058+
;
19972059

19982060
_proto.tablerow = function tablerow(content) {
1999-
return '<tr>\n' + content + '</tr>\n';
2061+
return "<tr>\n" + content + "</tr>\n";
20002062
};
20012063

20022064
_proto.tablecell = function tablecell(content, flags) {
20032065
var type = flags.header ? 'th' : 'td';
2004-
var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
2005-
return tag + content + '</' + type + '>\n';
2006-
} // span level renderer
2066+
var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
2067+
return tag + content + ("</" + type + ">\n");
2068+
}
2069+
/**
2070+
* span level renderer
2071+
* @param {string} text
2072+
*/
20072073
;
20082074

20092075
_proto.strong = function strong(text) {
2010-
return '<strong>' + text + '</strong>';
2011-
};
2076+
return "<strong>" + text + "</strong>";
2077+
}
2078+
/**
2079+
* @param {string} text
2080+
*/
2081+
;
20122082

20132083
_proto.em = function em(text) {
2014-
return '<em>' + text + '</em>';
2015-
};
2084+
return "<em>" + text + "</em>";
2085+
}
2086+
/**
2087+
* @param {string} text
2088+
*/
2089+
;
20162090

20172091
_proto.codespan = function codespan(text) {
2018-
return '<code>' + text + '</code>';
2092+
return "<code>" + text + "</code>";
20192093
};
20202094

20212095
_proto.br = function br() {
20222096
return this.options.xhtml ? '<br/>' : '<br>';
2023-
};
2097+
}
2098+
/**
2099+
* @param {string} text
2100+
*/
2101+
;
20242102

20252103
_proto.del = function del(text) {
2026-
return '<del>' + text + '</del>';
2027-
};
2104+
return "<del>" + text + "</del>";
2105+
}
2106+
/**
2107+
* @param {string} href
2108+
* @param {string} title
2109+
* @param {string} text
2110+
*/
2111+
;
20282112

20292113
_proto.link = function link(href, title, text) {
20302114
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@@ -2041,7 +2125,13 @@ var Renderer = /*#__PURE__*/function () {
20412125

20422126
out += '>' + text + '</a>';
20432127
return out;
2044-
};
2128+
}
2129+
/**
2130+
* @param {string} href
2131+
* @param {string} title
2132+
* @param {string} text
2133+
*/
2134+
;
20452135

20462136
_proto.image = function image(href, title, text) {
20472137
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
@@ -2050,10 +2140,10 @@ var Renderer = /*#__PURE__*/function () {
20502140
return text;
20512141
}
20522142

2053-
var out = '<img src="' + href + '" alt="' + text + '"';
2143+
var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
20542144

20552145
if (title) {
2056-
out += ' title="' + title + '"';
2146+
out += " title=\"" + title + "\"";
20572147
}
20582148

20592149
out += this.options.xhtml ? '/>' : '>';
@@ -2123,6 +2213,10 @@ var Slugger = /*#__PURE__*/function () {
21232213
function Slugger() {
21242214
this.seen = {};
21252215
}
2216+
/**
2217+
* @param {string} value
2218+
*/
2219+
21262220

21272221
var _proto = Slugger.prototype;
21282222

@@ -2133,6 +2227,8 @@ var Slugger = /*#__PURE__*/function () {
21332227
}
21342228
/**
21352229
* Finds the next safe (unique) slug to use
2230+
* @param {string} originalSlug
2231+
* @param {boolean} isDryRun
21362232
*/
21372233
;
21382234

@@ -2158,8 +2254,9 @@ var Slugger = /*#__PURE__*/function () {
21582254
}
21592255
/**
21602256
* Convert string to unique id
2161-
* @param {object} options
2162-
* @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
2257+
* @param {object} [options]
2258+
* @param {boolean} [options.dryrun] Generates the next unique slug without
2259+
* updating the internal accumulator.
21632260
*/
21642261
;
21652262

@@ -2856,6 +2953,7 @@ marked.walkTokens = function (tokens, callback) {
28562953
};
28572954
/**
28582955
* Parse Inline
2956+
* @param {string} src
28592957
*/
28602958

28612959

0 commit comments

Comments
 (0)