marked 4.0.11 → 4.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/marked.js +3 -0
- package/lib/marked.cjs +146 -44
- package/lib/marked.esm.js +121 -44
- package/lib/marked.umd.js +146 -44
- package/marked.min.js +1 -1
- package/package.json +12 -12
- package/src/Lexer.js +9 -3
- package/src/Renderer.js +63 -26
- package/src/Slugger.js +8 -2
- package/src/Tokenizer.js +2 -2
- package/src/helpers.js +33 -6
- package/src/marked.js +1 -0
- package/src/rules.js +5 -5
package/bin/marked.js
CHANGED
package/lib/marked.cjs
CHANGED
|
@@ -131,6 +131,10 @@ function escape(html, encode) {
|
|
|
131
131
|
return html;
|
|
132
132
|
}
|
|
133
133
|
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
134
|
+
/**
|
|
135
|
+
* @param {string} html
|
|
136
|
+
*/
|
|
137
|
+
|
|
134
138
|
function unescape(html) {
|
|
135
139
|
// explicitly match decimal, hex, and named HTML entities
|
|
136
140
|
return html.replace(unescapeTest, function (_, n) {
|
|
@@ -145,8 +149,13 @@ function unescape(html) {
|
|
|
145
149
|
});
|
|
146
150
|
}
|
|
147
151
|
var caret = /(^|[^\[])\^/g;
|
|
152
|
+
/**
|
|
153
|
+
* @param {string | RegExp} regex
|
|
154
|
+
* @param {string} opt
|
|
155
|
+
*/
|
|
156
|
+
|
|
148
157
|
function edit(regex, opt) {
|
|
149
|
-
regex = regex
|
|
158
|
+
regex = typeof regex === 'string' ? regex : regex.source;
|
|
150
159
|
opt = opt || '';
|
|
151
160
|
var obj = {
|
|
152
161
|
replace: function replace(name, val) {
|
|
@@ -163,6 +172,12 @@ function edit(regex, opt) {
|
|
|
163
172
|
}
|
|
164
173
|
var nonWordAndColonTest = /[^\w:]/g;
|
|
165
174
|
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
175
|
+
/**
|
|
176
|
+
* @param {boolean} sanitize
|
|
177
|
+
* @param {string} base
|
|
178
|
+
* @param {string} href
|
|
179
|
+
*/
|
|
180
|
+
|
|
166
181
|
function cleanUrl(sanitize, base, href) {
|
|
167
182
|
if (sanitize) {
|
|
168
183
|
var prot;
|
|
@@ -194,6 +209,11 @@ var baseUrls = {};
|
|
|
194
209
|
var justDomain = /^[^:]+:\/*[^/]*$/;
|
|
195
210
|
var protocol = /^([^:]+:)[\s\S]*$/;
|
|
196
211
|
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
|
212
|
+
/**
|
|
213
|
+
* @param {string} base
|
|
214
|
+
* @param {string} href
|
|
215
|
+
*/
|
|
216
|
+
|
|
197
217
|
function resolveUrl(base, href) {
|
|
198
218
|
if (!baseUrls[' ' + base]) {
|
|
199
219
|
// we can ignore everything in base after the last slash of its path component,
|
|
@@ -272,7 +292,7 @@ function splitCells(tableRow, count) {
|
|
|
272
292
|
cells.shift();
|
|
273
293
|
}
|
|
274
294
|
|
|
275
|
-
if (!cells[cells.length - 1].trim()) {
|
|
295
|
+
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
|
|
276
296
|
cells.pop();
|
|
277
297
|
}
|
|
278
298
|
|
|
@@ -290,9 +310,15 @@ function splitCells(tableRow, count) {
|
|
|
290
310
|
}
|
|
291
311
|
|
|
292
312
|
return cells;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
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
|
+
*/
|
|
296
322
|
|
|
297
323
|
function rtrim(str, c, invert) {
|
|
298
324
|
var l = str.length;
|
|
@@ -316,7 +342,7 @@ function rtrim(str, c, invert) {
|
|
|
316
342
|
}
|
|
317
343
|
}
|
|
318
344
|
|
|
319
|
-
return str.
|
|
345
|
+
return str.slice(0, l - suffLen);
|
|
320
346
|
}
|
|
321
347
|
function findClosingBracket(str, b) {
|
|
322
348
|
if (str.indexOf(b[1]) === -1) {
|
|
@@ -349,6 +375,11 @@ function checkSanitizeDeprecation(opt) {
|
|
|
349
375
|
}
|
|
350
376
|
} // copied from https://stackoverflow.com/a/5450113/806777
|
|
351
377
|
|
|
378
|
+
/**
|
|
379
|
+
* @param {string} pattern
|
|
380
|
+
* @param {number} count
|
|
381
|
+
*/
|
|
382
|
+
|
|
352
383
|
function repeatString(pattern, count) {
|
|
353
384
|
if (count < 1) {
|
|
354
385
|
return '';
|
|
@@ -516,7 +547,7 @@ var Tokenizer = /*#__PURE__*/function () {
|
|
|
516
547
|
var cap = this.rules.block.blockquote.exec(src);
|
|
517
548
|
|
|
518
549
|
if (cap) {
|
|
519
|
-
var text = cap[0].replace(/^ *> ?/gm, '');
|
|
550
|
+
var text = cap[0].replace(/^ *>[ \t]?/gm, '');
|
|
520
551
|
return {
|
|
521
552
|
type: 'blockquote',
|
|
522
553
|
raw: cap[0],
|
|
@@ -548,7 +579,7 @@ var Tokenizer = /*#__PURE__*/function () {
|
|
|
548
579
|
} // Get next list item
|
|
549
580
|
|
|
550
581
|
|
|
551
|
-
var itemRegex = new RegExp("^( {0,3}" + bull + ")((?: [^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
|
|
582
|
+
var itemRegex = new RegExp("^( {0,3}" + bull + ")((?:[\t ][^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
|
|
552
583
|
|
|
553
584
|
while (src) {
|
|
554
585
|
endEarly = false;
|
|
@@ -1185,10 +1216,10 @@ var block = {
|
|
|
1185
1216
|
newline: /^(?: *(?:\n|$))+/,
|
|
1186
1217
|
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
1187
1218
|
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
|
|
1188
|
-
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
|
1219
|
+
hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
|
|
1189
1220
|
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
|
|
1190
1221
|
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
|
1191
|
-
list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
|
|
1222
|
+
list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
|
|
1192
1223
|
html: '^ {0,3}(?:' // optional indentation
|
|
1193
1224
|
+ '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
|
|
1194
1225
|
+ '|comment[^\\n]*(\\n+|$)' // (2)
|
|
@@ -1278,9 +1309,9 @@ var inline = {
|
|
|
1278
1309
|
emStrong: {
|
|
1279
1310
|
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
|
|
1280
1311
|
// (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
|
-
//
|
|
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 _
|
|
1284
1315
|
|
|
1285
1316
|
},
|
|
1286
1317
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
@@ -1362,6 +1393,7 @@ inline.breaks = merge({}, inline.gfm, {
|
|
|
1362
1393
|
|
|
1363
1394
|
/**
|
|
1364
1395
|
* smartypants text replacement
|
|
1396
|
+
* @param {string} text
|
|
1365
1397
|
*/
|
|
1366
1398
|
|
|
1367
1399
|
function smartypants(text) {
|
|
@@ -1376,6 +1408,7 @@ function smartypants(text) {
|
|
|
1376
1408
|
}
|
|
1377
1409
|
/**
|
|
1378
1410
|
* mangle email addresses
|
|
1411
|
+
* @param {string} text
|
|
1379
1412
|
*/
|
|
1380
1413
|
|
|
1381
1414
|
|
|
@@ -1466,7 +1499,7 @@ var Lexer = /*#__PURE__*/function () {
|
|
|
1466
1499
|
var _proto = Lexer.prototype;
|
|
1467
1500
|
|
|
1468
1501
|
_proto.lex = function lex(src) {
|
|
1469
|
-
src = src.replace(/\r\n|\r/g, '\n')
|
|
1502
|
+
src = src.replace(/\r\n|\r/g, '\n');
|
|
1470
1503
|
this.blockTokens(src, this.tokens);
|
|
1471
1504
|
var next;
|
|
1472
1505
|
|
|
@@ -1489,7 +1522,11 @@ var Lexer = /*#__PURE__*/function () {
|
|
|
1489
1522
|
}
|
|
1490
1523
|
|
|
1491
1524
|
if (this.options.pedantic) {
|
|
1492
|
-
src = src.replace(/^ +$/gm, '');
|
|
1525
|
+
src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
|
|
1526
|
+
} else {
|
|
1527
|
+
src = src.replace(/^( *)(\t+)/gm, function (_, leading, tabs) {
|
|
1528
|
+
return leading + ' '.repeat(tabs.length);
|
|
1529
|
+
});
|
|
1493
1530
|
}
|
|
1494
1531
|
|
|
1495
1532
|
var token, lastToken, cutSrc, lastParagraphClipped;
|
|
@@ -1949,23 +1986,35 @@ var Renderer = /*#__PURE__*/function () {
|
|
|
1949
1986
|
}
|
|
1950
1987
|
|
|
1951
1988
|
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
|
|
1952
|
-
}
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* @param {string} quote
|
|
1992
|
+
*/
|
|
1993
|
+
;
|
|
1953
1994
|
|
|
1954
1995
|
_proto.blockquote = function blockquote(quote) {
|
|
1955
|
-
return
|
|
1996
|
+
return "<blockquote>\n" + quote + "</blockquote>\n";
|
|
1956
1997
|
};
|
|
1957
1998
|
|
|
1958
1999
|
_proto.html = function html(_html) {
|
|
1959
2000
|
return _html;
|
|
1960
|
-
}
|
|
2001
|
+
}
|
|
2002
|
+
/**
|
|
2003
|
+
* @param {string} text
|
|
2004
|
+
* @param {string} level
|
|
2005
|
+
* @param {string} raw
|
|
2006
|
+
* @param {any} slugger
|
|
2007
|
+
*/
|
|
2008
|
+
;
|
|
1961
2009
|
|
|
1962
2010
|
_proto.heading = function heading(text, level, raw, slugger) {
|
|
1963
2011
|
if (this.options.headerIds) {
|
|
1964
|
-
|
|
2012
|
+
var id = this.options.headerPrefix + slugger.slug(raw);
|
|
2013
|
+
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
|
|
1965
2014
|
} // ignore IDs
|
|
1966
2015
|
|
|
1967
2016
|
|
|
1968
|
-
return
|
|
2017
|
+
return "<h" + level + ">" + text + "</h" + level + ">\n";
|
|
1969
2018
|
};
|
|
1970
2019
|
|
|
1971
2020
|
_proto.hr = function hr() {
|
|
@@ -1976,55 +2025,94 @@ var Renderer = /*#__PURE__*/function () {
|
|
|
1976
2025
|
var type = ordered ? 'ol' : 'ul',
|
|
1977
2026
|
startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
|
|
1978
2027
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
1979
|
-
}
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* @param {string} text
|
|
2031
|
+
*/
|
|
2032
|
+
;
|
|
1980
2033
|
|
|
1981
2034
|
_proto.listitem = function listitem(text) {
|
|
1982
|
-
return
|
|
2035
|
+
return "<li>" + text + "</li>\n";
|
|
1983
2036
|
};
|
|
1984
2037
|
|
|
1985
2038
|
_proto.checkbox = function checkbox(checked) {
|
|
1986
2039
|
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
|
|
1987
|
-
}
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* @param {string} text
|
|
2043
|
+
*/
|
|
2044
|
+
;
|
|
1988
2045
|
|
|
1989
2046
|
_proto.paragraph = function paragraph(text) {
|
|
1990
|
-
return
|
|
1991
|
-
}
|
|
2047
|
+
return "<p>" + text + "</p>\n";
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* @param {string} header
|
|
2051
|
+
* @param {string} body
|
|
2052
|
+
*/
|
|
2053
|
+
;
|
|
1992
2054
|
|
|
1993
2055
|
_proto.table = function table(header, body) {
|
|
1994
|
-
if (body) body =
|
|
2056
|
+
if (body) body = "<tbody>" + body + "</tbody>";
|
|
1995
2057
|
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
|
|
1996
|
-
}
|
|
2058
|
+
}
|
|
2059
|
+
/**
|
|
2060
|
+
* @param {string} content
|
|
2061
|
+
*/
|
|
2062
|
+
;
|
|
1997
2063
|
|
|
1998
2064
|
_proto.tablerow = function tablerow(content) {
|
|
1999
|
-
return
|
|
2065
|
+
return "<tr>\n" + content + "</tr>\n";
|
|
2000
2066
|
};
|
|
2001
2067
|
|
|
2002
2068
|
_proto.tablecell = function tablecell(content, flags) {
|
|
2003
2069
|
var type = flags.header ? 'th' : 'td';
|
|
2004
|
-
var tag = flags.align ?
|
|
2005
|
-
return tag + content +
|
|
2006
|
-
}
|
|
2070
|
+
var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
|
|
2071
|
+
return tag + content + ("</" + type + ">\n");
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* span level renderer
|
|
2075
|
+
* @param {string} text
|
|
2076
|
+
*/
|
|
2007
2077
|
;
|
|
2008
2078
|
|
|
2009
2079
|
_proto.strong = function strong(text) {
|
|
2010
|
-
return
|
|
2011
|
-
}
|
|
2080
|
+
return "<strong>" + text + "</strong>";
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* @param {string} text
|
|
2084
|
+
*/
|
|
2085
|
+
;
|
|
2012
2086
|
|
|
2013
2087
|
_proto.em = function em(text) {
|
|
2014
|
-
return
|
|
2015
|
-
}
|
|
2088
|
+
return "<em>" + text + "</em>";
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* @param {string} text
|
|
2092
|
+
*/
|
|
2093
|
+
;
|
|
2016
2094
|
|
|
2017
2095
|
_proto.codespan = function codespan(text) {
|
|
2018
|
-
return
|
|
2096
|
+
return "<code>" + text + "</code>";
|
|
2019
2097
|
};
|
|
2020
2098
|
|
|
2021
2099
|
_proto.br = function br() {
|
|
2022
2100
|
return this.options.xhtml ? '<br/>' : '<br>';
|
|
2023
|
-
}
|
|
2101
|
+
}
|
|
2102
|
+
/**
|
|
2103
|
+
* @param {string} text
|
|
2104
|
+
*/
|
|
2105
|
+
;
|
|
2024
2106
|
|
|
2025
2107
|
_proto.del = function del(text) {
|
|
2026
|
-
return
|
|
2027
|
-
}
|
|
2108
|
+
return "<del>" + text + "</del>";
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* @param {string} href
|
|
2112
|
+
* @param {string} title
|
|
2113
|
+
* @param {string} text
|
|
2114
|
+
*/
|
|
2115
|
+
;
|
|
2028
2116
|
|
|
2029
2117
|
_proto.link = function link(href, title, text) {
|
|
2030
2118
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
@@ -2041,7 +2129,13 @@ var Renderer = /*#__PURE__*/function () {
|
|
|
2041
2129
|
|
|
2042
2130
|
out += '>' + text + '</a>';
|
|
2043
2131
|
return out;
|
|
2044
|
-
}
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* @param {string} href
|
|
2135
|
+
* @param {string} title
|
|
2136
|
+
* @param {string} text
|
|
2137
|
+
*/
|
|
2138
|
+
;
|
|
2045
2139
|
|
|
2046
2140
|
_proto.image = function image(href, title, text) {
|
|
2047
2141
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
@@ -2050,10 +2144,10 @@ var Renderer = /*#__PURE__*/function () {
|
|
|
2050
2144
|
return text;
|
|
2051
2145
|
}
|
|
2052
2146
|
|
|
2053
|
-
var out =
|
|
2147
|
+
var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
|
|
2054
2148
|
|
|
2055
2149
|
if (title) {
|
|
2056
|
-
out +=
|
|
2150
|
+
out += " title=\"" + title + "\"";
|
|
2057
2151
|
}
|
|
2058
2152
|
|
|
2059
2153
|
out += this.options.xhtml ? '/>' : '>';
|
|
@@ -2123,6 +2217,10 @@ var Slugger = /*#__PURE__*/function () {
|
|
|
2123
2217
|
function Slugger() {
|
|
2124
2218
|
this.seen = {};
|
|
2125
2219
|
}
|
|
2220
|
+
/**
|
|
2221
|
+
* @param {string} value
|
|
2222
|
+
*/
|
|
2223
|
+
|
|
2126
2224
|
|
|
2127
2225
|
var _proto = Slugger.prototype;
|
|
2128
2226
|
|
|
@@ -2133,6 +2231,8 @@ var Slugger = /*#__PURE__*/function () {
|
|
|
2133
2231
|
}
|
|
2134
2232
|
/**
|
|
2135
2233
|
* Finds the next safe (unique) slug to use
|
|
2234
|
+
* @param {string} originalSlug
|
|
2235
|
+
* @param {boolean} isDryRun
|
|
2136
2236
|
*/
|
|
2137
2237
|
;
|
|
2138
2238
|
|
|
@@ -2158,8 +2258,9 @@ var Slugger = /*#__PURE__*/function () {
|
|
|
2158
2258
|
}
|
|
2159
2259
|
/**
|
|
2160
2260
|
* Convert string to unique id
|
|
2161
|
-
* @param {object} options
|
|
2162
|
-
* @param {boolean} options.dryrun Generates the next unique slug without
|
|
2261
|
+
* @param {object} [options]
|
|
2262
|
+
* @param {boolean} [options.dryrun] Generates the next unique slug without
|
|
2263
|
+
* updating the internal accumulator.
|
|
2163
2264
|
*/
|
|
2164
2265
|
;
|
|
2165
2266
|
|
|
@@ -2856,6 +2957,7 @@ marked.walkTokens = function (tokens, callback) {
|
|
|
2856
2957
|
};
|
|
2857
2958
|
/**
|
|
2858
2959
|
* Parse Inline
|
|
2960
|
+
* @param {string} src
|
|
2859
2961
|
*/
|
|
2860
2962
|
|
|
2861
2963
|
|