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/lib/marked.umd.js
CHANGED
|
@@ -133,6 +133,10 @@
|
|
|
133
133
|
return html;
|
|
134
134
|
}
|
|
135
135
|
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
136
|
+
/**
|
|
137
|
+
* @param {string} html
|
|
138
|
+
*/
|
|
139
|
+
|
|
136
140
|
function unescape(html) {
|
|
137
141
|
// explicitly match decimal, hex, and named HTML entities
|
|
138
142
|
return html.replace(unescapeTest, function (_, n) {
|
|
@@ -147,8 +151,13 @@
|
|
|
147
151
|
});
|
|
148
152
|
}
|
|
149
153
|
var caret = /(^|[^\[])\^/g;
|
|
154
|
+
/**
|
|
155
|
+
* @param {string | RegExp} regex
|
|
156
|
+
* @param {string} opt
|
|
157
|
+
*/
|
|
158
|
+
|
|
150
159
|
function edit(regex, opt) {
|
|
151
|
-
regex = regex
|
|
160
|
+
regex = typeof regex === 'string' ? regex : regex.source;
|
|
152
161
|
opt = opt || '';
|
|
153
162
|
var obj = {
|
|
154
163
|
replace: function replace(name, val) {
|
|
@@ -165,6 +174,12 @@
|
|
|
165
174
|
}
|
|
166
175
|
var nonWordAndColonTest = /[^\w:]/g;
|
|
167
176
|
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
177
|
+
/**
|
|
178
|
+
* @param {boolean} sanitize
|
|
179
|
+
* @param {string} base
|
|
180
|
+
* @param {string} href
|
|
181
|
+
*/
|
|
182
|
+
|
|
168
183
|
function cleanUrl(sanitize, base, href) {
|
|
169
184
|
if (sanitize) {
|
|
170
185
|
var prot;
|
|
@@ -196,6 +211,11 @@
|
|
|
196
211
|
var justDomain = /^[^:]+:\/*[^/]*$/;
|
|
197
212
|
var protocol = /^([^:]+:)[\s\S]*$/;
|
|
198
213
|
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
|
214
|
+
/**
|
|
215
|
+
* @param {string} base
|
|
216
|
+
* @param {string} href
|
|
217
|
+
*/
|
|
218
|
+
|
|
199
219
|
function resolveUrl(base, href) {
|
|
200
220
|
if (!baseUrls[' ' + base]) {
|
|
201
221
|
// we can ignore everything in base after the last slash of its path component,
|
|
@@ -274,7 +294,7 @@
|
|
|
274
294
|
cells.shift();
|
|
275
295
|
}
|
|
276
296
|
|
|
277
|
-
if (!cells[cells.length - 1].trim()) {
|
|
297
|
+
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
|
|
278
298
|
cells.pop();
|
|
279
299
|
}
|
|
280
300
|
|
|
@@ -292,9 +312,15 @@
|
|
|
292
312
|
}
|
|
293
313
|
|
|
294
314
|
return cells;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
|
318
|
+
* /c*$/ is vulnerable to REDOS.
|
|
319
|
+
*
|
|
320
|
+
* @param {string} str
|
|
321
|
+
* @param {string} c
|
|
322
|
+
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
|
|
323
|
+
*/
|
|
298
324
|
|
|
299
325
|
function rtrim(str, c, invert) {
|
|
300
326
|
var l = str.length;
|
|
@@ -318,7 +344,7 @@
|
|
|
318
344
|
}
|
|
319
345
|
}
|
|
320
346
|
|
|
321
|
-
return str.
|
|
347
|
+
return str.slice(0, l - suffLen);
|
|
322
348
|
}
|
|
323
349
|
function findClosingBracket(str, b) {
|
|
324
350
|
if (str.indexOf(b[1]) === -1) {
|
|
@@ -351,6 +377,11 @@
|
|
|
351
377
|
}
|
|
352
378
|
} // copied from https://stackoverflow.com/a/5450113/806777
|
|
353
379
|
|
|
380
|
+
/**
|
|
381
|
+
* @param {string} pattern
|
|
382
|
+
* @param {number} count
|
|
383
|
+
*/
|
|
384
|
+
|
|
354
385
|
function repeatString(pattern, count) {
|
|
355
386
|
if (count < 1) {
|
|
356
387
|
return '';
|
|
@@ -518,7 +549,7 @@
|
|
|
518
549
|
var cap = this.rules.block.blockquote.exec(src);
|
|
519
550
|
|
|
520
551
|
if (cap) {
|
|
521
|
-
var text = cap[0].replace(/^ *> ?/gm, '');
|
|
552
|
+
var text = cap[0].replace(/^ *>[ \t]?/gm, '');
|
|
522
553
|
return {
|
|
523
554
|
type: 'blockquote',
|
|
524
555
|
raw: cap[0],
|
|
@@ -550,7 +581,7 @@
|
|
|
550
581
|
} // Get next list item
|
|
551
582
|
|
|
552
583
|
|
|
553
|
-
var itemRegex = new RegExp("^( {0,3}" + bull + ")((?: [^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
|
|
584
|
+
var itemRegex = new RegExp("^( {0,3}" + bull + ")((?:[\t ][^\\n]*)?(?:\\n|$))"); // Check if current bullet point can start a new List Item
|
|
554
585
|
|
|
555
586
|
while (src) {
|
|
556
587
|
endEarly = false;
|
|
@@ -1187,10 +1218,10 @@
|
|
|
1187
1218
|
newline: /^(?: *(?:\n|$))+/,
|
|
1188
1219
|
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
1189
1220
|
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
|
|
1190
|
-
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
|
1221
|
+
hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
|
|
1191
1222
|
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
|
|
1192
1223
|
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
|
1193
|
-
list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
|
|
1224
|
+
list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
|
|
1194
1225
|
html: '^ {0,3}(?:' // optional indentation
|
|
1195
1226
|
+ '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
|
|
1196
1227
|
+ '|comment[^\\n]*(\\n+|$)' // (2)
|
|
@@ -1280,9 +1311,9 @@
|
|
|
1280
1311
|
emStrong: {
|
|
1281
1312
|
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
|
|
1282
1313
|
// (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.
|
|
1283
|
-
//
|
|
1284
|
-
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
|
|
1285
|
-
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
1314
|
+
// () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
|
|
1315
|
+
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
|
|
1316
|
+
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
1286
1317
|
|
|
1287
1318
|
},
|
|
1288
1319
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
@@ -1364,6 +1395,7 @@
|
|
|
1364
1395
|
|
|
1365
1396
|
/**
|
|
1366
1397
|
* smartypants text replacement
|
|
1398
|
+
* @param {string} text
|
|
1367
1399
|
*/
|
|
1368
1400
|
|
|
1369
1401
|
function smartypants(text) {
|
|
@@ -1378,6 +1410,7 @@
|
|
|
1378
1410
|
}
|
|
1379
1411
|
/**
|
|
1380
1412
|
* mangle email addresses
|
|
1413
|
+
* @param {string} text
|
|
1381
1414
|
*/
|
|
1382
1415
|
|
|
1383
1416
|
|
|
@@ -1468,7 +1501,7 @@
|
|
|
1468
1501
|
var _proto = Lexer.prototype;
|
|
1469
1502
|
|
|
1470
1503
|
_proto.lex = function lex(src) {
|
|
1471
|
-
src = src.replace(/\r\n|\r/g, '\n')
|
|
1504
|
+
src = src.replace(/\r\n|\r/g, '\n');
|
|
1472
1505
|
this.blockTokens(src, this.tokens);
|
|
1473
1506
|
var next;
|
|
1474
1507
|
|
|
@@ -1491,7 +1524,11 @@
|
|
|
1491
1524
|
}
|
|
1492
1525
|
|
|
1493
1526
|
if (this.options.pedantic) {
|
|
1494
|
-
src = src.replace(/^ +$/gm, '');
|
|
1527
|
+
src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
|
|
1528
|
+
} else {
|
|
1529
|
+
src = src.replace(/^( *)(\t+)/gm, function (_, leading, tabs) {
|
|
1530
|
+
return leading + ' '.repeat(tabs.length);
|
|
1531
|
+
});
|
|
1495
1532
|
}
|
|
1496
1533
|
|
|
1497
1534
|
var token, lastToken, cutSrc, lastParagraphClipped;
|
|
@@ -1951,23 +1988,35 @@
|
|
|
1951
1988
|
}
|
|
1952
1989
|
|
|
1953
1990
|
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
|
|
1954
|
-
}
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* @param {string} quote
|
|
1994
|
+
*/
|
|
1995
|
+
;
|
|
1955
1996
|
|
|
1956
1997
|
_proto.blockquote = function blockquote(quote) {
|
|
1957
|
-
return
|
|
1998
|
+
return "<blockquote>\n" + quote + "</blockquote>\n";
|
|
1958
1999
|
};
|
|
1959
2000
|
|
|
1960
2001
|
_proto.html = function html(_html) {
|
|
1961
2002
|
return _html;
|
|
1962
|
-
}
|
|
2003
|
+
}
|
|
2004
|
+
/**
|
|
2005
|
+
* @param {string} text
|
|
2006
|
+
* @param {string} level
|
|
2007
|
+
* @param {string} raw
|
|
2008
|
+
* @param {any} slugger
|
|
2009
|
+
*/
|
|
2010
|
+
;
|
|
1963
2011
|
|
|
1964
2012
|
_proto.heading = function heading(text, level, raw, slugger) {
|
|
1965
2013
|
if (this.options.headerIds) {
|
|
1966
|
-
|
|
2014
|
+
var id = this.options.headerPrefix + slugger.slug(raw);
|
|
2015
|
+
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
|
|
1967
2016
|
} // ignore IDs
|
|
1968
2017
|
|
|
1969
2018
|
|
|
1970
|
-
return
|
|
2019
|
+
return "<h" + level + ">" + text + "</h" + level + ">\n";
|
|
1971
2020
|
};
|
|
1972
2021
|
|
|
1973
2022
|
_proto.hr = function hr() {
|
|
@@ -1978,55 +2027,94 @@
|
|
|
1978
2027
|
var type = ordered ? 'ol' : 'ul',
|
|
1979
2028
|
startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
|
|
1980
2029
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
1981
|
-
}
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* @param {string} text
|
|
2033
|
+
*/
|
|
2034
|
+
;
|
|
1982
2035
|
|
|
1983
2036
|
_proto.listitem = function listitem(text) {
|
|
1984
|
-
return
|
|
2037
|
+
return "<li>" + text + "</li>\n";
|
|
1985
2038
|
};
|
|
1986
2039
|
|
|
1987
2040
|
_proto.checkbox = function checkbox(checked) {
|
|
1988
2041
|
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
|
|
1989
|
-
}
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* @param {string} text
|
|
2045
|
+
*/
|
|
2046
|
+
;
|
|
1990
2047
|
|
|
1991
2048
|
_proto.paragraph = function paragraph(text) {
|
|
1992
|
-
return
|
|
1993
|
-
}
|
|
2049
|
+
return "<p>" + text + "</p>\n";
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* @param {string} header
|
|
2053
|
+
* @param {string} body
|
|
2054
|
+
*/
|
|
2055
|
+
;
|
|
1994
2056
|
|
|
1995
2057
|
_proto.table = function table(header, body) {
|
|
1996
|
-
if (body) body =
|
|
2058
|
+
if (body) body = "<tbody>" + body + "</tbody>";
|
|
1997
2059
|
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
|
|
1998
|
-
}
|
|
2060
|
+
}
|
|
2061
|
+
/**
|
|
2062
|
+
* @param {string} content
|
|
2063
|
+
*/
|
|
2064
|
+
;
|
|
1999
2065
|
|
|
2000
2066
|
_proto.tablerow = function tablerow(content) {
|
|
2001
|
-
return
|
|
2067
|
+
return "<tr>\n" + content + "</tr>\n";
|
|
2002
2068
|
};
|
|
2003
2069
|
|
|
2004
2070
|
_proto.tablecell = function tablecell(content, flags) {
|
|
2005
2071
|
var type = flags.header ? 'th' : 'td';
|
|
2006
|
-
var tag = flags.align ?
|
|
2007
|
-
return tag + content +
|
|
2008
|
-
}
|
|
2072
|
+
var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
|
|
2073
|
+
return tag + content + ("</" + type + ">\n");
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* span level renderer
|
|
2077
|
+
* @param {string} text
|
|
2078
|
+
*/
|
|
2009
2079
|
;
|
|
2010
2080
|
|
|
2011
2081
|
_proto.strong = function strong(text) {
|
|
2012
|
-
return
|
|
2013
|
-
}
|
|
2082
|
+
return "<strong>" + text + "</strong>";
|
|
2083
|
+
}
|
|
2084
|
+
/**
|
|
2085
|
+
* @param {string} text
|
|
2086
|
+
*/
|
|
2087
|
+
;
|
|
2014
2088
|
|
|
2015
2089
|
_proto.em = function em(text) {
|
|
2016
|
-
return
|
|
2017
|
-
}
|
|
2090
|
+
return "<em>" + text + "</em>";
|
|
2091
|
+
}
|
|
2092
|
+
/**
|
|
2093
|
+
* @param {string} text
|
|
2094
|
+
*/
|
|
2095
|
+
;
|
|
2018
2096
|
|
|
2019
2097
|
_proto.codespan = function codespan(text) {
|
|
2020
|
-
return
|
|
2098
|
+
return "<code>" + text + "</code>";
|
|
2021
2099
|
};
|
|
2022
2100
|
|
|
2023
2101
|
_proto.br = function br() {
|
|
2024
2102
|
return this.options.xhtml ? '<br/>' : '<br>';
|
|
2025
|
-
}
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* @param {string} text
|
|
2106
|
+
*/
|
|
2107
|
+
;
|
|
2026
2108
|
|
|
2027
2109
|
_proto.del = function del(text) {
|
|
2028
|
-
return
|
|
2029
|
-
}
|
|
2110
|
+
return "<del>" + text + "</del>";
|
|
2111
|
+
}
|
|
2112
|
+
/**
|
|
2113
|
+
* @param {string} href
|
|
2114
|
+
* @param {string} title
|
|
2115
|
+
* @param {string} text
|
|
2116
|
+
*/
|
|
2117
|
+
;
|
|
2030
2118
|
|
|
2031
2119
|
_proto.link = function link(href, title, text) {
|
|
2032
2120
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
@@ -2043,7 +2131,13 @@
|
|
|
2043
2131
|
|
|
2044
2132
|
out += '>' + text + '</a>';
|
|
2045
2133
|
return out;
|
|
2046
|
-
}
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* @param {string} href
|
|
2137
|
+
* @param {string} title
|
|
2138
|
+
* @param {string} text
|
|
2139
|
+
*/
|
|
2140
|
+
;
|
|
2047
2141
|
|
|
2048
2142
|
_proto.image = function image(href, title, text) {
|
|
2049
2143
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
@@ -2052,10 +2146,10 @@
|
|
|
2052
2146
|
return text;
|
|
2053
2147
|
}
|
|
2054
2148
|
|
|
2055
|
-
var out =
|
|
2149
|
+
var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
|
|
2056
2150
|
|
|
2057
2151
|
if (title) {
|
|
2058
|
-
out +=
|
|
2152
|
+
out += " title=\"" + title + "\"";
|
|
2059
2153
|
}
|
|
2060
2154
|
|
|
2061
2155
|
out += this.options.xhtml ? '/>' : '>';
|
|
@@ -2125,6 +2219,10 @@
|
|
|
2125
2219
|
function Slugger() {
|
|
2126
2220
|
this.seen = {};
|
|
2127
2221
|
}
|
|
2222
|
+
/**
|
|
2223
|
+
* @param {string} value
|
|
2224
|
+
*/
|
|
2225
|
+
|
|
2128
2226
|
|
|
2129
2227
|
var _proto = Slugger.prototype;
|
|
2130
2228
|
|
|
@@ -2135,6 +2233,8 @@
|
|
|
2135
2233
|
}
|
|
2136
2234
|
/**
|
|
2137
2235
|
* Finds the next safe (unique) slug to use
|
|
2236
|
+
* @param {string} originalSlug
|
|
2237
|
+
* @param {boolean} isDryRun
|
|
2138
2238
|
*/
|
|
2139
2239
|
;
|
|
2140
2240
|
|
|
@@ -2160,8 +2260,9 @@
|
|
|
2160
2260
|
}
|
|
2161
2261
|
/**
|
|
2162
2262
|
* Convert string to unique id
|
|
2163
|
-
* @param {object} options
|
|
2164
|
-
* @param {boolean} options.dryrun Generates the next unique slug without
|
|
2263
|
+
* @param {object} [options]
|
|
2264
|
+
* @param {boolean} [options.dryrun] Generates the next unique slug without
|
|
2265
|
+
* updating the internal accumulator.
|
|
2165
2266
|
*/
|
|
2166
2267
|
;
|
|
2167
2268
|
|
|
@@ -2858,6 +2959,7 @@
|
|
|
2858
2959
|
};
|
|
2859
2960
|
/**
|
|
2860
2961
|
* Parse Inline
|
|
2962
|
+
* @param {string} src
|
|
2861
2963
|
*/
|
|
2862
2964
|
|
|
2863
2965
|
|