marked 4.0.12 → 4.0.13
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 +135 -37
- package/lib/marked.esm.js +109 -36
- package/lib/marked.umd.js +135 -37
- package/marked.min.js +1 -1
- package/package.json +12 -12
- package/src/Lexer.js +2 -0
- package/src/Renderer.js +63 -26
- package/src/Slugger.js +8 -2
- package/src/helpers.js +32 -5
- package/src/marked.js +1 -0
- package/src/rules.js +3 -3
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "marked",
|
|
3
3
|
"description": "A markdown parser built for speed",
|
|
4
4
|
"author": "Christopher Jeffrey",
|
|
5
|
-
"version": "4.0.
|
|
5
|
+
"version": "4.0.13",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./lib/marked.cjs",
|
|
8
8
|
"module": "./lib/marked.esm.js",
|
|
@@ -42,33 +42,33 @@
|
|
|
42
42
|
"html"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/core": "^7.
|
|
45
|
+
"@babel/core": "^7.17.8",
|
|
46
46
|
"@babel/preset-env": "^7.16.11",
|
|
47
|
-
"@markedjs/html-differ": "^4.0.
|
|
48
|
-
"@rollup/plugin-babel": "^5.3.
|
|
49
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
47
|
+
"@markedjs/html-differ": "^4.0.1",
|
|
48
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
49
|
+
"@rollup/plugin-commonjs": "^21.0.3",
|
|
50
50
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
51
51
|
"@semantic-release/git": "^10.0.1",
|
|
52
|
-
"@semantic-release/github": "^8.0.
|
|
53
|
-
"@semantic-release/npm": "^
|
|
52
|
+
"@semantic-release/github": "^8.0.4",
|
|
53
|
+
"@semantic-release/npm": "^9.0.1",
|
|
54
54
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
55
55
|
"cheerio": "^1.0.0-rc.10",
|
|
56
56
|
"commonmark": "0.30.0",
|
|
57
|
-
"eslint": "^8.
|
|
57
|
+
"eslint": "^8.12.0",
|
|
58
58
|
"eslint-config-standard": "^16.0.3",
|
|
59
59
|
"eslint-plugin-import": "^2.25.4",
|
|
60
60
|
"eslint-plugin-node": "^11.1.0",
|
|
61
61
|
"eslint-plugin-promise": "^6.0.0",
|
|
62
62
|
"front-matter": "^4.0.2",
|
|
63
|
-
"highlight.js": "^11.
|
|
63
|
+
"highlight.js": "^11.5.0",
|
|
64
64
|
"jasmine": "^4.0.2",
|
|
65
65
|
"markdown-it": "12.3.2",
|
|
66
|
-
"node-fetch": "^3.2.
|
|
67
|
-
"rollup": "^2.
|
|
66
|
+
"node-fetch": "^3.2.3",
|
|
67
|
+
"rollup": "^2.70.1",
|
|
68
68
|
"rollup-plugin-license": "^2.6.1",
|
|
69
69
|
"semantic-release": "^19.0.2",
|
|
70
70
|
"titleize": "^3.0.0",
|
|
71
|
-
"uglify-js": "^3.
|
|
71
|
+
"uglify-js": "^3.15.3",
|
|
72
72
|
"vuln-regex-detector": "^1.3.0"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
package/src/Lexer.js
CHANGED
|
@@ -5,6 +5,7 @@ import { repeatString } from './helpers.js';
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* smartypants text replacement
|
|
8
|
+
* @param {string} text
|
|
8
9
|
*/
|
|
9
10
|
function smartypants(text) {
|
|
10
11
|
return text
|
|
@@ -26,6 +27,7 @@ function smartypants(text) {
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* mangle email addresses
|
|
30
|
+
* @param {string} text
|
|
29
31
|
*/
|
|
30
32
|
function mangle(text) {
|
|
31
33
|
let out = '',
|
package/src/Renderer.js
CHANGED
|
@@ -38,29 +38,31 @@ export class Renderer {
|
|
|
38
38
|
+ '</code></pre>\n';
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} quote
|
|
43
|
+
*/
|
|
41
44
|
blockquote(quote) {
|
|
42
|
-
return
|
|
45
|
+
return `<blockquote>\n${quote}</blockquote>\n`;
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
html(html) {
|
|
46
49
|
return html;
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @param {string} text
|
|
54
|
+
* @param {string} level
|
|
55
|
+
* @param {string} raw
|
|
56
|
+
* @param {any} slugger
|
|
57
|
+
*/
|
|
49
58
|
heading(text, level, raw, slugger) {
|
|
50
59
|
if (this.options.headerIds) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
+ ' id="'
|
|
54
|
-
+ this.options.headerPrefix
|
|
55
|
-
+ slugger.slug(raw)
|
|
56
|
-
+ '">'
|
|
57
|
-
+ text
|
|
58
|
-
+ '</h'
|
|
59
|
-
+ level
|
|
60
|
-
+ '>\n';
|
|
60
|
+
const id = this.options.headerPrefix + slugger.slug(raw);
|
|
61
|
+
return `<h${level} id="${id}">${text}</h${level}>\n`;
|
|
61
62
|
}
|
|
63
|
+
|
|
62
64
|
// ignore IDs
|
|
63
|
-
return
|
|
65
|
+
return `<h${level}>${text}</h${level}>\n`;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
hr() {
|
|
@@ -73,8 +75,11 @@ export class Renderer {
|
|
|
73
75
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} text
|
|
80
|
+
*/
|
|
76
81
|
listitem(text) {
|
|
77
|
-
return
|
|
82
|
+
return `<li>${text}</li>\n`;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
checkbox(checked) {
|
|
@@ -85,12 +90,19 @@ export class Renderer {
|
|
|
85
90
|
+ '> ';
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} text
|
|
95
|
+
*/
|
|
88
96
|
paragraph(text) {
|
|
89
|
-
return
|
|
97
|
+
return `<p>${text}</p>\n`;
|
|
90
98
|
}
|
|
91
99
|
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} header
|
|
102
|
+
* @param {string} body
|
|
103
|
+
*/
|
|
92
104
|
table(header, body) {
|
|
93
|
-
if (body) body =
|
|
105
|
+
if (body) body = `<tbody>${body}</tbody>`;
|
|
94
106
|
|
|
95
107
|
return '<table>\n'
|
|
96
108
|
+ '<thead>\n'
|
|
@@ -100,39 +112,59 @@ export class Renderer {
|
|
|
100
112
|
+ '</table>\n';
|
|
101
113
|
}
|
|
102
114
|
|
|
115
|
+
/**
|
|
116
|
+
* @param {string} content
|
|
117
|
+
*/
|
|
103
118
|
tablerow(content) {
|
|
104
|
-
return
|
|
119
|
+
return `<tr>\n${content}</tr>\n`;
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
tablecell(content, flags) {
|
|
108
123
|
const type = flags.header ? 'th' : 'td';
|
|
109
124
|
const tag = flags.align
|
|
110
|
-
?
|
|
111
|
-
:
|
|
112
|
-
return tag + content +
|
|
125
|
+
? `<${type} align="${flags.align}">`
|
|
126
|
+
: `<${type}>`;
|
|
127
|
+
return tag + content + `</${type}>\n`;
|
|
113
128
|
}
|
|
114
129
|
|
|
115
|
-
|
|
130
|
+
/**
|
|
131
|
+
* span level renderer
|
|
132
|
+
* @param {string} text
|
|
133
|
+
*/
|
|
116
134
|
strong(text) {
|
|
117
|
-
return
|
|
135
|
+
return `<strong>${text}</strong>`;
|
|
118
136
|
}
|
|
119
137
|
|
|
138
|
+
/**
|
|
139
|
+
* @param {string} text
|
|
140
|
+
*/
|
|
120
141
|
em(text) {
|
|
121
|
-
return
|
|
142
|
+
return `<em>${text}</em>`;
|
|
122
143
|
}
|
|
123
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @param {string} text
|
|
147
|
+
*/
|
|
124
148
|
codespan(text) {
|
|
125
|
-
return
|
|
149
|
+
return `<code>${text}</code>`;
|
|
126
150
|
}
|
|
127
151
|
|
|
128
152
|
br() {
|
|
129
153
|
return this.options.xhtml ? '<br/>' : '<br>';
|
|
130
154
|
}
|
|
131
155
|
|
|
156
|
+
/**
|
|
157
|
+
* @param {string} text
|
|
158
|
+
*/
|
|
132
159
|
del(text) {
|
|
133
|
-
return
|
|
160
|
+
return `<del>${text}</del>`;
|
|
134
161
|
}
|
|
135
162
|
|
|
163
|
+
/**
|
|
164
|
+
* @param {string} href
|
|
165
|
+
* @param {string} title
|
|
166
|
+
* @param {string} text
|
|
167
|
+
*/
|
|
136
168
|
link(href, title, text) {
|
|
137
169
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
138
170
|
if (href === null) {
|
|
@@ -146,15 +178,20 @@ export class Renderer {
|
|
|
146
178
|
return out;
|
|
147
179
|
}
|
|
148
180
|
|
|
181
|
+
/**
|
|
182
|
+
* @param {string} href
|
|
183
|
+
* @param {string} title
|
|
184
|
+
* @param {string} text
|
|
185
|
+
*/
|
|
149
186
|
image(href, title, text) {
|
|
150
187
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
151
188
|
if (href === null) {
|
|
152
189
|
return text;
|
|
153
190
|
}
|
|
154
191
|
|
|
155
|
-
let out =
|
|
192
|
+
let out = `<img src="${href}" alt="${text}"`;
|
|
156
193
|
if (title) {
|
|
157
|
-
out +=
|
|
194
|
+
out += ` title="${title}"`;
|
|
158
195
|
}
|
|
159
196
|
out += this.options.xhtml ? '/>' : '>';
|
|
160
197
|
return out;
|
package/src/Slugger.js
CHANGED
|
@@ -6,6 +6,9 @@ export class Slugger {
|
|
|
6
6
|
this.seen = {};
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} value
|
|
11
|
+
*/
|
|
9
12
|
serialize(value) {
|
|
10
13
|
return value
|
|
11
14
|
.toLowerCase()
|
|
@@ -19,6 +22,8 @@ export class Slugger {
|
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* Finds the next safe (unique) slug to use
|
|
25
|
+
* @param {string} originalSlug
|
|
26
|
+
* @param {boolean} isDryRun
|
|
22
27
|
*/
|
|
23
28
|
getNextSafeSlug(originalSlug, isDryRun) {
|
|
24
29
|
let slug = originalSlug;
|
|
@@ -39,8 +44,9 @@ export class Slugger {
|
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
46
|
* Convert string to unique id
|
|
42
|
-
* @param {object} options
|
|
43
|
-
* @param {boolean} options.dryrun Generates the next unique slug without
|
|
47
|
+
* @param {object} [options]
|
|
48
|
+
* @param {boolean} [options.dryrun] Generates the next unique slug without
|
|
49
|
+
* updating the internal accumulator.
|
|
44
50
|
*/
|
|
45
51
|
slug(value, options = {}) {
|
|
46
52
|
const slug = this.serialize(value);
|
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,
|
|
@@ -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
|
@@ -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*$)/,
|