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/src/helpers.js
CHANGED
|
@@ -29,6 +29,9 @@ export function escape(html, encode) {
|
|
|
29
29
|
|
|
30
30
|
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} html
|
|
34
|
+
*/
|
|
32
35
|
export function unescape(html) {
|
|
33
36
|
// explicitly match decimal, hex, and named HTML entities
|
|
34
37
|
return html.replace(unescapeTest, (_, n) => {
|
|
@@ -44,8 +47,13 @@ export function unescape(html) {
|
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
const caret = /(^|[^\[])\^/g;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {string | RegExp} regex
|
|
53
|
+
* @param {string} opt
|
|
54
|
+
*/
|
|
47
55
|
export function edit(regex, opt) {
|
|
48
|
-
regex = regex
|
|
56
|
+
regex = typeof regex === 'string' ? regex : regex.source;
|
|
49
57
|
opt = opt || '';
|
|
50
58
|
const obj = {
|
|
51
59
|
replace: (name, val) => {
|
|
@@ -63,6 +71,12 @@ export function edit(regex, opt) {
|
|
|
63
71
|
|
|
64
72
|
const nonWordAndColonTest = /[^\w:]/g;
|
|
65
73
|
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {boolean} sanitize
|
|
77
|
+
* @param {string} base
|
|
78
|
+
* @param {string} href
|
|
79
|
+
*/
|
|
66
80
|
export function cleanUrl(sanitize, base, href) {
|
|
67
81
|
if (sanitize) {
|
|
68
82
|
let prot;
|
|
@@ -93,6 +107,10 @@ const justDomain = /^[^:]+:\/*[^/]*$/;
|
|
|
93
107
|
const protocol = /^([^:]+:)[\s\S]*$/;
|
|
94
108
|
const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
|
95
109
|
|
|
110
|
+
/**
|
|
111
|
+
* @param {string} base
|
|
112
|
+
* @param {string} href
|
|
113
|
+
*/
|
|
96
114
|
export function resolveUrl(base, href) {
|
|
97
115
|
if (!baseUrls[' ' + base]) {
|
|
98
116
|
// we can ignore everything in base after the last slash of its path component,
|
|
@@ -162,7 +180,7 @@ export function splitCells(tableRow, count) {
|
|
|
162
180
|
|
|
163
181
|
// First/last cell in a row cannot be empty if it has no leading/trailing pipe
|
|
164
182
|
if (!cells[0].trim()) { cells.shift(); }
|
|
165
|
-
if (!cells[cells.length - 1].trim()) { cells.pop(); }
|
|
183
|
+
if (cells.length > 0 && !cells[cells.length - 1].trim()) { cells.pop(); }
|
|
166
184
|
|
|
167
185
|
if (cells.length > count) {
|
|
168
186
|
cells.splice(count);
|
|
@@ -177,9 +195,14 @@ export function splitCells(tableRow, count) {
|
|
|
177
195
|
return cells;
|
|
178
196
|
}
|
|
179
197
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
|
200
|
+
* /c*$/ is vulnerable to REDOS.
|
|
201
|
+
*
|
|
202
|
+
* @param {string} str
|
|
203
|
+
* @param {string} c
|
|
204
|
+
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
|
|
205
|
+
*/
|
|
183
206
|
export function rtrim(str, c, invert) {
|
|
184
207
|
const l = str.length;
|
|
185
208
|
if (l === 0) {
|
|
@@ -201,7 +224,7 @@ export function rtrim(str, c, invert) {
|
|
|
201
224
|
}
|
|
202
225
|
}
|
|
203
226
|
|
|
204
|
-
return str.
|
|
227
|
+
return str.slice(0, l - suffLen);
|
|
205
228
|
}
|
|
206
229
|
|
|
207
230
|
export function findClosingBracket(str, b) {
|
|
@@ -233,6 +256,10 @@ export function checkSanitizeDeprecation(opt) {
|
|
|
233
256
|
}
|
|
234
257
|
|
|
235
258
|
// copied from https://stackoverflow.com/a/5450113/806777
|
|
259
|
+
/**
|
|
260
|
+
* @param {string} pattern
|
|
261
|
+
* @param {number} count
|
|
262
|
+
*/
|
|
236
263
|
export function repeatString(pattern, count) {
|
|
237
264
|
if (count < 1) {
|
|
238
265
|
return '';
|
package/src/marked.js
CHANGED
package/src/rules.js
CHANGED
|
@@ -11,10 +11,10 @@ export const block = {
|
|
|
11
11
|
newline: /^(?: *(?:\n|$))+/,
|
|
12
12
|
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
13
13
|
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
|
|
14
|
-
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
|
14
|
+
hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
|
|
15
15
|
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
|
|
16
16
|
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
|
17
|
-
list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
|
|
17
|
+
list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
|
|
18
18
|
html: '^ {0,3}(?:' // optional indentation
|
|
19
19
|
+ '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
|
|
20
20
|
+ '|comment[^\\n]*(\\n+|$)' // (2)
|
|
@@ -168,9 +168,9 @@ export const inline = {
|
|
|
168
168
|
emStrong: {
|
|
169
169
|
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
|
|
170
170
|
// (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.
|
|
171
|
-
//
|
|
172
|
-
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
|
|
173
|
-
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
171
|
+
// () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
|
|
172
|
+
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
|
|
173
|
+
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
174
174
|
},
|
|
175
175
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
176
176
|
br: /^( {2,}|\\)\n(?!\s*$)/,
|