marked 5.1.2 → 7.0.0
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/README.md +0 -1
- package/bin/marked.js +0 -0
- package/lib/marked.cjs +1117 -1699
- package/lib/marked.cjs.map +1 -0
- package/lib/marked.d.cts +624 -0
- package/lib/marked.d.ts +624 -0
- package/lib/marked.esm.js +695 -1400
- package/lib/marked.esm.js.map +1 -0
- package/lib/marked.umd.js +1099 -1707
- package/lib/marked.umd.js.map +1 -0
- package/marked.min.js +11 -2
- package/package.json +17 -11
- package/src/Hooks.ts +29 -0
- package/src/{Instance.js → Instance.ts} +74 -67
- package/src/{Lexer.js → Lexer.ts} +39 -23
- package/src/MarkedOptions.ts +212 -0
- package/src/{Parser.js → Parser.ts} +40 -34
- package/src/{Renderer.js → Renderer.ts} +34 -70
- package/src/{Slugger.js → Slugger.ts} +8 -12
- package/src/{TextRenderer.js → TextRenderer.ts} +9 -9
- package/src/{Tokenizer.js → Tokenizer.ts} +63 -49
- package/src/Tokens.ts +199 -0
- package/src/{defaults.js → defaults.ts} +11 -6
- package/src/{helpers.js → helpers.ts} +29 -36
- package/src/marked.ts +144 -0
- package/src/{rules.js → rules.ts} +76 -13
- package/src/Hooks.js +0 -26
- package/src/marked.js +0 -91
package/lib/marked.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* marked
|
|
2
|
+
* marked v7.0.0 - a markdown parser
|
|
3
3
|
* Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
|
|
4
4
|
* https://github.com/markedjs/marked
|
|
5
5
|
*/
|
|
@@ -9,19 +9,34 @@
|
|
|
9
9
|
* The code in this file is generated from files in ./src/
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
var __accessCheck = (obj, member, msg) => {
|
|
13
|
+
if (!member.has(obj))
|
|
14
|
+
throw TypeError("Cannot " + msg);
|
|
15
|
+
};
|
|
16
|
+
var __privateAdd = (obj, member, value) => {
|
|
17
|
+
if (member.has(obj))
|
|
18
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
19
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
20
|
+
};
|
|
21
|
+
var __privateMethod = (obj, member, method) => {
|
|
22
|
+
__accessCheck(obj, member, "access private method");
|
|
23
|
+
return method;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/defaults.ts
|
|
27
|
+
function _getDefaults() {
|
|
13
28
|
return {
|
|
14
29
|
async: false,
|
|
15
30
|
baseUrl: null,
|
|
16
31
|
breaks: false,
|
|
17
32
|
extensions: null,
|
|
18
33
|
gfm: true,
|
|
19
|
-
headerIds:
|
|
20
|
-
headerPrefix:
|
|
34
|
+
headerIds: false,
|
|
35
|
+
headerPrefix: "",
|
|
21
36
|
highlight: null,
|
|
22
37
|
hooks: null,
|
|
23
|
-
langPrefix:
|
|
24
|
-
mangle:
|
|
38
|
+
langPrefix: "language-",
|
|
39
|
+
mangle: false,
|
|
25
40
|
pedantic: false,
|
|
26
41
|
renderer: null,
|
|
27
42
|
sanitize: false,
|
|
@@ -33,28 +48,24 @@ function getDefaults() {
|
|
|
33
48
|
xhtml: false
|
|
34
49
|
};
|
|
35
50
|
}
|
|
36
|
-
|
|
37
|
-
let defaults = getDefaults();
|
|
38
|
-
|
|
51
|
+
var _defaults = _getDefaults();
|
|
39
52
|
function changeDefaults(newDefaults) {
|
|
40
|
-
|
|
53
|
+
_defaults = newDefaults;
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'"': '"',
|
|
55
|
-
"'": '''
|
|
56
|
+
// src/helpers.ts
|
|
57
|
+
var escapeTest = /[&<>"']/;
|
|
58
|
+
var escapeReplace = new RegExp(escapeTest.source, "g");
|
|
59
|
+
var escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
|
|
60
|
+
var escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, "g");
|
|
61
|
+
var escapeReplacements = {
|
|
62
|
+
"&": "&",
|
|
63
|
+
"<": "<",
|
|
64
|
+
">": ">",
|
|
65
|
+
'"': """,
|
|
66
|
+
"'": "'"
|
|
56
67
|
};
|
|
57
|
-
|
|
68
|
+
var getEscapeReplacement = (ch) => escapeReplacements[ch];
|
|
58
69
|
function escape(html, encode) {
|
|
59
70
|
if (encode) {
|
|
60
71
|
if (escapeTest.test(html)) {
|
|
@@ -65,42 +76,28 @@ function escape(html, encode) {
|
|
|
65
76
|
return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
|
|
66
77
|
}
|
|
67
78
|
}
|
|
68
|
-
|
|
69
79
|
return html;
|
|
70
80
|
}
|
|
71
|
-
|
|
72
|
-
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @param {string} html
|
|
76
|
-
*/
|
|
81
|
+
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
77
82
|
function unescape(html) {
|
|
78
|
-
// explicitly match decimal, hex, and named HTML entities
|
|
79
83
|
return html.replace(unescapeTest, (_, n) => {
|
|
80
84
|
n = n.toLowerCase();
|
|
81
|
-
if (n ===
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
: String.fromCharCode(+n.substring(1));
|
|
85
|
+
if (n === "colon")
|
|
86
|
+
return ":";
|
|
87
|
+
if (n.charAt(0) === "#") {
|
|
88
|
+
return n.charAt(1) === "x" ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
|
|
86
89
|
}
|
|
87
|
-
return
|
|
90
|
+
return "";
|
|
88
91
|
});
|
|
89
92
|
}
|
|
90
|
-
|
|
91
|
-
const caret = /(^|[^\[])\^/g;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @param {string | RegExp} regex
|
|
95
|
-
* @param {string} opt
|
|
96
|
-
*/
|
|
93
|
+
var caret = /(^|[^\[])\^/g;
|
|
97
94
|
function edit(regex, opt) {
|
|
98
|
-
regex = typeof regex ===
|
|
99
|
-
opt = opt ||
|
|
95
|
+
regex = typeof regex === "string" ? regex : regex.source;
|
|
96
|
+
opt = opt || "";
|
|
100
97
|
const obj = {
|
|
101
98
|
replace: (name, val) => {
|
|
102
|
-
val = val.source
|
|
103
|
-
val = val.replace(caret,
|
|
99
|
+
val = typeof val === "object" && "source" in val ? val.source : val;
|
|
100
|
+
val = val.replace(caret, "$1");
|
|
104
101
|
regex = regex.replace(name, val);
|
|
105
102
|
return obj;
|
|
106
103
|
},
|
|
@@ -110,26 +107,17 @@ function edit(regex, opt) {
|
|
|
110
107
|
};
|
|
111
108
|
return obj;
|
|
112
109
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @param {boolean} sanitize
|
|
119
|
-
* @param {string} base
|
|
120
|
-
* @param {string} href
|
|
121
|
-
*/
|
|
110
|
+
var nonWordAndColonTest = /[^\w:]/g;
|
|
111
|
+
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
122
112
|
function cleanUrl(sanitize, base, href) {
|
|
123
113
|
if (sanitize) {
|
|
124
114
|
let prot;
|
|
125
115
|
try {
|
|
126
|
-
prot = decodeURIComponent(unescape(href))
|
|
127
|
-
.replace(nonWordAndColonTest, '')
|
|
128
|
-
.toLowerCase();
|
|
116
|
+
prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, "").toLowerCase();
|
|
129
117
|
} catch (e) {
|
|
130
118
|
return null;
|
|
131
119
|
}
|
|
132
|
-
if (prot.indexOf(
|
|
120
|
+
if (prot.indexOf("javascript:") === 0 || prot.indexOf("vbscript:") === 0 || prot.indexOf("data:") === 0) {
|
|
133
121
|
return null;
|
|
134
122
|
}
|
|
135
123
|
}
|
|
@@ -137,107 +125,76 @@ function cleanUrl(sanitize, base, href) {
|
|
|
137
125
|
href = resolveUrl(base, href);
|
|
138
126
|
}
|
|
139
127
|
try {
|
|
140
|
-
href = encodeURI(href).replace(/%25/g,
|
|
128
|
+
href = encodeURI(href).replace(/%25/g, "%");
|
|
141
129
|
} catch (e) {
|
|
142
130
|
return null;
|
|
143
131
|
}
|
|
144
132
|
return href;
|
|
145
133
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @param {string} base
|
|
154
|
-
* @param {string} href
|
|
155
|
-
*/
|
|
134
|
+
var baseUrls = {};
|
|
135
|
+
var justDomain = /^[^:]+:\/*[^/]*$/;
|
|
136
|
+
var protocol = /^([^:]+:)[\s\S]*$/;
|
|
137
|
+
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
|
156
138
|
function resolveUrl(base, href) {
|
|
157
|
-
if (!baseUrls[
|
|
158
|
-
// we can ignore everything in base after the last slash of its path component,
|
|
159
|
-
// but we might need to add _that_
|
|
160
|
-
// https://tools.ietf.org/html/rfc3986#section-3
|
|
139
|
+
if (!baseUrls[" " + base]) {
|
|
161
140
|
if (justDomain.test(base)) {
|
|
162
|
-
baseUrls[
|
|
141
|
+
baseUrls[" " + base] = base + "/";
|
|
163
142
|
} else {
|
|
164
|
-
baseUrls[
|
|
143
|
+
baseUrls[" " + base] = rtrim(base, "/", true);
|
|
165
144
|
}
|
|
166
145
|
}
|
|
167
|
-
base = baseUrls[
|
|
168
|
-
const relativeBase = base.indexOf(
|
|
169
|
-
|
|
170
|
-
if (href.substring(0, 2) === '//') {
|
|
146
|
+
base = baseUrls[" " + base];
|
|
147
|
+
const relativeBase = base.indexOf(":") === -1;
|
|
148
|
+
if (href.substring(0, 2) === "//") {
|
|
171
149
|
if (relativeBase) {
|
|
172
150
|
return href;
|
|
173
151
|
}
|
|
174
|
-
return base.replace(protocol,
|
|
175
|
-
} else if (href.charAt(0) ===
|
|
152
|
+
return base.replace(protocol, "$1") + href;
|
|
153
|
+
} else if (href.charAt(0) === "/") {
|
|
176
154
|
if (relativeBase) {
|
|
177
155
|
return href;
|
|
178
156
|
}
|
|
179
|
-
return base.replace(domain,
|
|
157
|
+
return base.replace(domain, "$1") + href;
|
|
180
158
|
} else {
|
|
181
159
|
return base + href;
|
|
182
160
|
}
|
|
183
161
|
}
|
|
184
|
-
|
|
185
|
-
const noopTest = { exec: function noopTest() {} };
|
|
186
|
-
|
|
162
|
+
var noopTest = { exec: () => null };
|
|
187
163
|
function splitCells(tableRow, count) {
|
|
188
|
-
// ensure that every cell-delimiting pipe has a space
|
|
189
|
-
// before it to distinguish it from an escaped pipe
|
|
190
164
|
const row = tableRow.replace(/\|/g, (match, offset, str) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return ' |';
|
|
201
|
-
}
|
|
202
|
-
}),
|
|
203
|
-
cells = row.split(/ \|/);
|
|
165
|
+
let escaped = false, curr = offset;
|
|
166
|
+
while (--curr >= 0 && str[curr] === "\\")
|
|
167
|
+
escaped = !escaped;
|
|
168
|
+
if (escaped) {
|
|
169
|
+
return "|";
|
|
170
|
+
} else {
|
|
171
|
+
return " |";
|
|
172
|
+
}
|
|
173
|
+
}), cells = row.split(/ \|/);
|
|
204
174
|
let i = 0;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
|
|
209
|
-
|
|
175
|
+
if (!cells[0].trim()) {
|
|
176
|
+
cells.shift();
|
|
177
|
+
}
|
|
178
|
+
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
|
|
179
|
+
cells.pop();
|
|
180
|
+
}
|
|
210
181
|
if (cells.length > count) {
|
|
211
182
|
cells.splice(count);
|
|
212
183
|
} else {
|
|
213
|
-
while (cells.length < count)
|
|
184
|
+
while (cells.length < count)
|
|
185
|
+
cells.push("");
|
|
214
186
|
}
|
|
215
|
-
|
|
216
187
|
for (; i < cells.length; i++) {
|
|
217
|
-
|
|
218
|
-
cells[i] = cells[i].trim().replace(/\\\|/g, '|');
|
|
188
|
+
cells[i] = cells[i].trim().replace(/\\\|/g, "|");
|
|
219
189
|
}
|
|
220
190
|
return cells;
|
|
221
191
|
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
|
225
|
-
* /c*$/ is vulnerable to REDOS.
|
|
226
|
-
*
|
|
227
|
-
* @param {string} str
|
|
228
|
-
* @param {string} c
|
|
229
|
-
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
|
|
230
|
-
*/
|
|
231
192
|
function rtrim(str, c, invert) {
|
|
232
193
|
const l = str.length;
|
|
233
194
|
if (l === 0) {
|
|
234
|
-
return
|
|
195
|
+
return "";
|
|
235
196
|
}
|
|
236
|
-
|
|
237
|
-
// Length of suffix matching the invert condition.
|
|
238
197
|
let suffLen = 0;
|
|
239
|
-
|
|
240
|
-
// Step left until we fail to match the invert condition.
|
|
241
198
|
while (suffLen < l) {
|
|
242
199
|
const currChar = str.charAt(l - suffLen - 1);
|
|
243
200
|
if (currChar === c && !invert) {
|
|
@@ -248,19 +205,16 @@ function rtrim(str, c, invert) {
|
|
|
248
205
|
break;
|
|
249
206
|
}
|
|
250
207
|
}
|
|
251
|
-
|
|
252
208
|
return str.slice(0, l - suffLen);
|
|
253
209
|
}
|
|
254
|
-
|
|
255
210
|
function findClosingBracket(str, b) {
|
|
256
211
|
if (str.indexOf(b[1]) === -1) {
|
|
257
212
|
return -1;
|
|
258
213
|
}
|
|
259
214
|
const l = str.length;
|
|
260
|
-
let level = 0,
|
|
261
|
-
i = 0;
|
|
215
|
+
let level = 0, i = 0;
|
|
262
216
|
for (; i < l; i++) {
|
|
263
|
-
if (str[i] ===
|
|
217
|
+
if (str[i] === "\\") {
|
|
264
218
|
i++;
|
|
265
219
|
} else if (str[i] === b[0]) {
|
|
266
220
|
level++;
|
|
@@ -273,166 +227,132 @@ function findClosingBracket(str, b) {
|
|
|
273
227
|
}
|
|
274
228
|
return -1;
|
|
275
229
|
}
|
|
276
|
-
|
|
277
230
|
function checkDeprecations(opt, callback) {
|
|
278
231
|
if (!opt || opt.silent) {
|
|
279
232
|
return;
|
|
280
233
|
}
|
|
281
|
-
|
|
282
234
|
if (callback) {
|
|
283
|
-
console.warn(
|
|
235
|
+
console.warn("marked(): callback is deprecated since version 5.0.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/using_pro#async");
|
|
284
236
|
}
|
|
285
|
-
|
|
286
237
|
if (opt.sanitize || opt.sanitizer) {
|
|
287
|
-
console.warn(
|
|
238
|
+
console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options");
|
|
288
239
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
console.warn('marked(): highlight and langPrefix parameters are deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-highlight.');
|
|
240
|
+
if (opt.highlight || opt.langPrefix !== "language-") {
|
|
241
|
+
console.warn("marked(): highlight and langPrefix parameters are deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-highlight.");
|
|
292
242
|
}
|
|
293
|
-
|
|
294
243
|
if (opt.mangle) {
|
|
295
|
-
console.warn(
|
|
244
|
+
console.warn("marked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.");
|
|
296
245
|
}
|
|
297
|
-
|
|
298
246
|
if (opt.baseUrl) {
|
|
299
|
-
console.warn(
|
|
247
|
+
console.warn("marked(): baseUrl parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-base-url.");
|
|
300
248
|
}
|
|
301
|
-
|
|
302
249
|
if (opt.smartypants) {
|
|
303
|
-
console.warn(
|
|
250
|
+
console.warn("marked(): smartypants parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-smartypants.");
|
|
304
251
|
}
|
|
305
|
-
|
|
306
252
|
if (opt.xhtml) {
|
|
307
|
-
console.warn(
|
|
253
|
+
console.warn("marked(): xhtml parameter is deprecated since version 5.0.0, should not be used and will be removed in the future. Instead use https://www.npmjs.com/package/marked-xhtml.");
|
|
308
254
|
}
|
|
309
|
-
|
|
310
255
|
if (opt.headerIds || opt.headerPrefix) {
|
|
311
|
-
console.warn(
|
|
256
|
+
console.warn("marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.");
|
|
312
257
|
}
|
|
313
258
|
}
|
|
314
259
|
|
|
315
|
-
|
|
260
|
+
// src/Tokenizer.ts
|
|
261
|
+
function outputLink(cap, link, raw, lexer2) {
|
|
316
262
|
const href = link.href;
|
|
317
263
|
const title = link.title ? escape(link.title) : null;
|
|
318
|
-
const text = cap[1].replace(/\\([\[\]])/g,
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
lexer.state.inLink = true;
|
|
264
|
+
const text = cap[1].replace(/\\([\[\]])/g, "$1");
|
|
265
|
+
if (cap[0].charAt(0) !== "!") {
|
|
266
|
+
lexer2.state.inLink = true;
|
|
322
267
|
const token = {
|
|
323
|
-
type:
|
|
268
|
+
type: "link",
|
|
324
269
|
raw,
|
|
325
270
|
href,
|
|
326
271
|
title,
|
|
327
272
|
text,
|
|
328
|
-
tokens:
|
|
273
|
+
tokens: lexer2.inlineTokens(text)
|
|
329
274
|
};
|
|
330
|
-
|
|
275
|
+
lexer2.state.inLink = false;
|
|
331
276
|
return token;
|
|
332
277
|
}
|
|
333
278
|
return {
|
|
334
|
-
type:
|
|
279
|
+
type: "image",
|
|
335
280
|
raw,
|
|
336
281
|
href,
|
|
337
282
|
title,
|
|
338
283
|
text: escape(text)
|
|
339
284
|
};
|
|
340
285
|
}
|
|
341
|
-
|
|
342
286
|
function indentCodeCompensation(raw, text) {
|
|
343
287
|
const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
|
|
344
|
-
|
|
345
288
|
if (matchIndentToCode === null) {
|
|
346
289
|
return text;
|
|
347
290
|
}
|
|
348
|
-
|
|
349
291
|
const indentToCode = matchIndentToCode[1];
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
.map(node => {
|
|
354
|
-
const matchIndentInNode = node.match(/^\s+/);
|
|
355
|
-
if (matchIndentInNode === null) {
|
|
356
|
-
return node;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const [indentInNode] = matchIndentInNode;
|
|
360
|
-
|
|
361
|
-
if (indentInNode.length >= indentToCode.length) {
|
|
362
|
-
return node.slice(indentToCode.length);
|
|
363
|
-
}
|
|
364
|
-
|
|
292
|
+
return text.split("\n").map((node) => {
|
|
293
|
+
const matchIndentInNode = node.match(/^\s+/);
|
|
294
|
+
if (matchIndentInNode === null) {
|
|
365
295
|
return node;
|
|
366
|
-
}
|
|
367
|
-
|
|
296
|
+
}
|
|
297
|
+
const [indentInNode] = matchIndentInNode;
|
|
298
|
+
if (indentInNode.length >= indentToCode.length) {
|
|
299
|
+
return node.slice(indentToCode.length);
|
|
300
|
+
}
|
|
301
|
+
return node;
|
|
302
|
+
}).join("\n");
|
|
368
303
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
*/
|
|
373
|
-
class Tokenizer {
|
|
374
|
-
constructor(options) {
|
|
375
|
-
this.options = options || defaults;
|
|
304
|
+
var _Tokenizer = class {
|
|
305
|
+
constructor(options2) {
|
|
306
|
+
this.options = options2 || _defaults;
|
|
376
307
|
}
|
|
377
|
-
|
|
378
308
|
space(src) {
|
|
379
309
|
const cap = this.rules.block.newline.exec(src);
|
|
380
310
|
if (cap && cap[0].length > 0) {
|
|
381
311
|
return {
|
|
382
|
-
type:
|
|
312
|
+
type: "space",
|
|
383
313
|
raw: cap[0]
|
|
384
314
|
};
|
|
385
315
|
}
|
|
386
316
|
}
|
|
387
|
-
|
|
388
317
|
code(src) {
|
|
389
318
|
const cap = this.rules.block.code.exec(src);
|
|
390
319
|
if (cap) {
|
|
391
|
-
const text = cap[0].replace(/^ {1,4}/gm,
|
|
320
|
+
const text = cap[0].replace(/^ {1,4}/gm, "");
|
|
392
321
|
return {
|
|
393
|
-
type:
|
|
322
|
+
type: "code",
|
|
394
323
|
raw: cap[0],
|
|
395
|
-
codeBlockStyle:
|
|
396
|
-
text: !this.options.pedantic
|
|
397
|
-
? rtrim(text, '\n')
|
|
398
|
-
: text
|
|
324
|
+
codeBlockStyle: "indented",
|
|
325
|
+
text: !this.options.pedantic ? rtrim(text, "\n") : text
|
|
399
326
|
};
|
|
400
327
|
}
|
|
401
328
|
}
|
|
402
|
-
|
|
403
329
|
fences(src) {
|
|
404
330
|
const cap = this.rules.block.fences.exec(src);
|
|
405
331
|
if (cap) {
|
|
406
332
|
const raw = cap[0];
|
|
407
|
-
const text = indentCodeCompensation(raw, cap[3] ||
|
|
408
|
-
|
|
333
|
+
const text = indentCodeCompensation(raw, cap[3] || "");
|
|
409
334
|
return {
|
|
410
|
-
type:
|
|
335
|
+
type: "code",
|
|
411
336
|
raw,
|
|
412
|
-
lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes,
|
|
337
|
+
lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes, "$1") : cap[2],
|
|
413
338
|
text
|
|
414
339
|
};
|
|
415
340
|
}
|
|
416
341
|
}
|
|
417
|
-
|
|
418
342
|
heading(src) {
|
|
419
343
|
const cap = this.rules.block.heading.exec(src);
|
|
420
344
|
if (cap) {
|
|
421
345
|
let text = cap[2].trim();
|
|
422
|
-
|
|
423
|
-
// remove trailing #s
|
|
424
346
|
if (/#$/.test(text)) {
|
|
425
|
-
const trimmed = rtrim(text,
|
|
347
|
+
const trimmed = rtrim(text, "#");
|
|
426
348
|
if (this.options.pedantic) {
|
|
427
349
|
text = trimmed.trim();
|
|
428
350
|
} else if (!trimmed || / $/.test(trimmed)) {
|
|
429
|
-
// CommonMark requires space before trailing #s
|
|
430
351
|
text = trimmed.trim();
|
|
431
352
|
}
|
|
432
353
|
}
|
|
433
|
-
|
|
434
354
|
return {
|
|
435
|
-
type:
|
|
355
|
+
type: "heading",
|
|
436
356
|
raw: cap[0],
|
|
437
357
|
depth: cap[1].length,
|
|
438
358
|
text,
|
|
@@ -440,142 +360,107 @@ class Tokenizer {
|
|
|
440
360
|
};
|
|
441
361
|
}
|
|
442
362
|
}
|
|
443
|
-
|
|
444
363
|
hr(src) {
|
|
445
364
|
const cap = this.rules.block.hr.exec(src);
|
|
446
365
|
if (cap) {
|
|
447
366
|
return {
|
|
448
|
-
type:
|
|
367
|
+
type: "hr",
|
|
449
368
|
raw: cap[0]
|
|
450
369
|
};
|
|
451
370
|
}
|
|
452
371
|
}
|
|
453
|
-
|
|
454
372
|
blockquote(src) {
|
|
455
373
|
const cap = this.rules.block.blockquote.exec(src);
|
|
456
374
|
if (cap) {
|
|
457
|
-
const text = cap[0].replace(/^ *>[ \t]?/gm,
|
|
375
|
+
const text = cap[0].replace(/^ *>[ \t]?/gm, "");
|
|
458
376
|
const top = this.lexer.state.top;
|
|
459
377
|
this.lexer.state.top = true;
|
|
460
378
|
const tokens = this.lexer.blockTokens(text);
|
|
461
379
|
this.lexer.state.top = top;
|
|
462
380
|
return {
|
|
463
|
-
type:
|
|
381
|
+
type: "blockquote",
|
|
464
382
|
raw: cap[0],
|
|
465
383
|
tokens,
|
|
466
384
|
text
|
|
467
385
|
};
|
|
468
386
|
}
|
|
469
387
|
}
|
|
470
|
-
|
|
471
388
|
list(src) {
|
|
472
389
|
let cap = this.rules.block.list.exec(src);
|
|
473
390
|
if (cap) {
|
|
474
|
-
let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine,
|
|
475
|
-
line, nextLine, rawLine, itemContents, endEarly;
|
|
476
|
-
|
|
391
|
+
let raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
|
|
477
392
|
let bull = cap[1].trim();
|
|
478
393
|
const isordered = bull.length > 1;
|
|
479
|
-
|
|
480
394
|
const list = {
|
|
481
|
-
type:
|
|
482
|
-
raw:
|
|
395
|
+
type: "list",
|
|
396
|
+
raw: "",
|
|
483
397
|
ordered: isordered,
|
|
484
|
-
start: isordered ? +bull.slice(0, -1) :
|
|
398
|
+
start: isordered ? +bull.slice(0, -1) : "",
|
|
485
399
|
loose: false,
|
|
486
400
|
items: []
|
|
487
401
|
};
|
|
488
|
-
|
|
489
402
|
bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
|
|
490
|
-
|
|
491
403
|
if (this.options.pedantic) {
|
|
492
|
-
bull = isordered ? bull :
|
|
404
|
+
bull = isordered ? bull : "[*+-]";
|
|
493
405
|
}
|
|
494
|
-
|
|
495
|
-
// Get next list item
|
|
496
|
-
const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
|
|
497
|
-
|
|
498
|
-
// Check if current bullet point can start a new List Item
|
|
406
|
+
const itemRegex = new RegExp(`^( {0,3}${bull})((?:[ ][^\\n]*)?(?:\\n|$))`);
|
|
499
407
|
while (src) {
|
|
500
408
|
endEarly = false;
|
|
501
409
|
if (!(cap = itemRegex.exec(src))) {
|
|
502
410
|
break;
|
|
503
411
|
}
|
|
504
|
-
|
|
505
|
-
if (this.rules.block.hr.test(src)) { // End list if bullet was actually HR (possibly move into itemRegex?)
|
|
412
|
+
if (this.rules.block.hr.test(src)) {
|
|
506
413
|
break;
|
|
507
414
|
}
|
|
508
|
-
|
|
509
415
|
raw = cap[0];
|
|
510
416
|
src = src.substring(raw.length);
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
nextLine = src.split('\n', 1)[0];
|
|
514
|
-
|
|
417
|
+
line = cap[2].split("\n", 1)[0].replace(/^\t+/, (t) => " ".repeat(3 * t.length));
|
|
418
|
+
nextLine = src.split("\n", 1)[0];
|
|
515
419
|
if (this.options.pedantic) {
|
|
516
420
|
indent = 2;
|
|
517
421
|
itemContents = line.trimLeft();
|
|
518
422
|
} else {
|
|
519
|
-
indent = cap[2].search(/[^ ]/);
|
|
520
|
-
indent = indent > 4 ? 1 : indent;
|
|
423
|
+
indent = cap[2].search(/[^ ]/);
|
|
424
|
+
indent = indent > 4 ? 1 : indent;
|
|
521
425
|
itemContents = line.slice(indent);
|
|
522
426
|
indent += cap[1].length;
|
|
523
427
|
}
|
|
524
|
-
|
|
525
428
|
blankLine = false;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
raw += nextLine + '\n';
|
|
429
|
+
if (!line && /^ *$/.test(nextLine)) {
|
|
430
|
+
raw += nextLine + "\n";
|
|
529
431
|
src = src.substring(nextLine.length + 1);
|
|
530
432
|
endEarly = true;
|
|
531
433
|
}
|
|
532
|
-
|
|
533
434
|
if (!endEarly) {
|
|
534
|
-
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[
|
|
435
|
+
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`);
|
|
535
436
|
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
|
|
536
437
|
const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
|
|
537
438
|
const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
|
|
538
|
-
|
|
539
|
-
// Check if following lines should be included in List Item
|
|
540
439
|
while (src) {
|
|
541
|
-
rawLine = src.split(
|
|
440
|
+
rawLine = src.split("\n", 1)[0];
|
|
542
441
|
nextLine = rawLine;
|
|
543
|
-
|
|
544
|
-
// Re-align to follow commonmark nesting rules
|
|
545
442
|
if (this.options.pedantic) {
|
|
546
|
-
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g,
|
|
443
|
+
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, " ");
|
|
547
444
|
}
|
|
548
|
-
|
|
549
|
-
// End list item if found code fences
|
|
550
445
|
if (fencesBeginRegex.test(nextLine)) {
|
|
551
446
|
break;
|
|
552
447
|
}
|
|
553
|
-
|
|
554
|
-
// End list item if found start of new heading
|
|
555
448
|
if (headingBeginRegex.test(nextLine)) {
|
|
556
449
|
break;
|
|
557
450
|
}
|
|
558
|
-
|
|
559
|
-
// End list item if found start of new bullet
|
|
560
451
|
if (nextBulletRegex.test(nextLine)) {
|
|
561
452
|
break;
|
|
562
453
|
}
|
|
563
|
-
|
|
564
|
-
// Horizontal rule found
|
|
565
454
|
if (hrRegex.test(src)) {
|
|
566
455
|
break;
|
|
567
456
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
itemContents += '\n' + nextLine.slice(indent);
|
|
457
|
+
if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) {
|
|
458
|
+
itemContents += "\n" + nextLine.slice(indent);
|
|
571
459
|
} else {
|
|
572
|
-
// not enough indentation
|
|
573
460
|
if (blankLine) {
|
|
574
461
|
break;
|
|
575
462
|
}
|
|
576
|
-
|
|
577
|
-
// paragraph continuation unless last line was a different block level element
|
|
578
|
-
if (line.search(/[^ ]/) >= 4) { // indented code block
|
|
463
|
+
if (line.search(/[^ ]/) >= 4) {
|
|
579
464
|
break;
|
|
580
465
|
}
|
|
581
466
|
if (fencesBeginRegex.test(line)) {
|
|
@@ -587,111 +472,89 @@ class Tokenizer {
|
|
|
587
472
|
if (hrRegex.test(line)) {
|
|
588
473
|
break;
|
|
589
474
|
}
|
|
590
|
-
|
|
591
|
-
itemContents += '\n' + nextLine;
|
|
475
|
+
itemContents += "\n" + nextLine;
|
|
592
476
|
}
|
|
593
|
-
|
|
594
|
-
if (!blankLine && !nextLine.trim()) { // Check if current line is blank
|
|
477
|
+
if (!blankLine && !nextLine.trim()) {
|
|
595
478
|
blankLine = true;
|
|
596
479
|
}
|
|
597
|
-
|
|
598
|
-
raw += rawLine + '\n';
|
|
480
|
+
raw += rawLine + "\n";
|
|
599
481
|
src = src.substring(rawLine.length + 1);
|
|
600
482
|
line = nextLine.slice(indent);
|
|
601
483
|
}
|
|
602
484
|
}
|
|
603
|
-
|
|
604
485
|
if (!list.loose) {
|
|
605
|
-
// If the previous item ended with a blank line, the list is loose
|
|
606
486
|
if (endsWithBlankLine) {
|
|
607
487
|
list.loose = true;
|
|
608
488
|
} else if (/\n *\n *$/.test(raw)) {
|
|
609
489
|
endsWithBlankLine = true;
|
|
610
490
|
}
|
|
611
491
|
}
|
|
612
|
-
|
|
613
|
-
// Check for task list items
|
|
614
492
|
if (this.options.gfm) {
|
|
615
493
|
istask = /^\[[ xX]\] /.exec(itemContents);
|
|
616
494
|
if (istask) {
|
|
617
|
-
ischecked = istask[0] !==
|
|
618
|
-
itemContents = itemContents.replace(/^\[[ xX]\] +/,
|
|
495
|
+
ischecked = istask[0] !== "[ ] ";
|
|
496
|
+
itemContents = itemContents.replace(/^\[[ xX]\] +/, "");
|
|
619
497
|
}
|
|
620
498
|
}
|
|
621
|
-
|
|
622
499
|
list.items.push({
|
|
623
|
-
type:
|
|
500
|
+
type: "list_item",
|
|
624
501
|
raw,
|
|
625
502
|
task: !!istask,
|
|
626
503
|
checked: ischecked,
|
|
627
504
|
loose: false,
|
|
628
505
|
text: itemContents
|
|
629
506
|
});
|
|
630
|
-
|
|
631
507
|
list.raw += raw;
|
|
632
508
|
}
|
|
633
|
-
|
|
634
|
-
// Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
|
|
635
509
|
list.items[list.items.length - 1].raw = raw.trimRight();
|
|
636
510
|
list.items[list.items.length - 1].text = itemContents.trimRight();
|
|
637
511
|
list.raw = list.raw.trimRight();
|
|
638
|
-
|
|
639
512
|
const l = list.items.length;
|
|
640
|
-
|
|
641
|
-
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
|
642
513
|
for (i = 0; i < l; i++) {
|
|
643
514
|
this.lexer.state.top = false;
|
|
644
515
|
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
|
|
645
|
-
|
|
646
516
|
if (!list.loose) {
|
|
647
|
-
|
|
648
|
-
const
|
|
649
|
-
const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
|
|
650
|
-
|
|
517
|
+
const spacers = list.items[i].tokens.filter((t) => t.type === "space");
|
|
518
|
+
const hasMultipleLineBreaks = spacers.length > 0 && spacers.some((t) => /\n.*\n/.test(t.raw));
|
|
651
519
|
list.loose = hasMultipleLineBreaks;
|
|
652
520
|
}
|
|
653
521
|
}
|
|
654
|
-
|
|
655
|
-
// Set all items to loose if list is loose
|
|
656
522
|
if (list.loose) {
|
|
657
523
|
for (i = 0; i < l; i++) {
|
|
658
524
|
list.items[i].loose = true;
|
|
659
525
|
}
|
|
660
526
|
}
|
|
661
|
-
|
|
662
527
|
return list;
|
|
663
528
|
}
|
|
664
529
|
}
|
|
665
|
-
|
|
666
530
|
html(src) {
|
|
667
531
|
const cap = this.rules.block.html.exec(src);
|
|
668
532
|
if (cap) {
|
|
669
533
|
const token = {
|
|
670
|
-
type:
|
|
534
|
+
type: "html",
|
|
671
535
|
block: true,
|
|
672
536
|
raw: cap[0],
|
|
673
|
-
pre: !this.options.sanitizer
|
|
674
|
-
&& (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
|
537
|
+
pre: !this.options.sanitizer && (cap[1] === "pre" || cap[1] === "script" || cap[1] === "style"),
|
|
675
538
|
text: cap[0]
|
|
676
539
|
};
|
|
677
540
|
if (this.options.sanitize) {
|
|
678
541
|
const text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
542
|
+
const paragraph = token;
|
|
543
|
+
paragraph.type = "paragraph";
|
|
544
|
+
paragraph.text = text;
|
|
545
|
+
paragraph.tokens = this.lexer.inline(text);
|
|
682
546
|
}
|
|
683
547
|
return token;
|
|
684
548
|
}
|
|
685
549
|
}
|
|
686
|
-
|
|
687
550
|
def(src) {
|
|
688
551
|
const cap = this.rules.block.def.exec(src);
|
|
689
552
|
if (cap) {
|
|
690
|
-
const tag = cap[1].toLowerCase().replace(/\s+/g,
|
|
691
|
-
const href = cap[2] ? cap[2].replace(/^<(.*)>$/,
|
|
692
|
-
const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes,
|
|
553
|
+
const tag = cap[1].toLowerCase().replace(/\s+/g, " ");
|
|
554
|
+
const href = cap[2] ? cap[2].replace(/^<(.*)>$/, "$1").replace(this.rules.inline._escapes, "$1") : "";
|
|
555
|
+
const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes, "$1") : cap[3];
|
|
693
556
|
return {
|
|
694
|
-
type:
|
|
557
|
+
type: "def",
|
|
695
558
|
tag,
|
|
696
559
|
raw: cap[0],
|
|
697
560
|
href,
|
|
@@ -699,48 +562,44 @@ class Tokenizer {
|
|
|
699
562
|
};
|
|
700
563
|
}
|
|
701
564
|
}
|
|
702
|
-
|
|
703
565
|
table(src) {
|
|
704
566
|
const cap = this.rules.block.table.exec(src);
|
|
705
567
|
if (cap) {
|
|
706
568
|
const item = {
|
|
707
|
-
type:
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
569
|
+
type: "table",
|
|
570
|
+
// splitCells expects a number as second argument
|
|
571
|
+
// @ts-expect-error
|
|
572
|
+
header: splitCells(cap[1]).map((c) => {
|
|
573
|
+
return { text: c };
|
|
574
|
+
}),
|
|
575
|
+
align: cap[2].replace(/^ *|\| *$/g, "").split(/ *\| */),
|
|
576
|
+
rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, "").split("\n") : []
|
|
711
577
|
};
|
|
712
|
-
|
|
713
578
|
if (item.header.length === item.align.length) {
|
|
714
579
|
item.raw = cap[0];
|
|
715
|
-
|
|
716
580
|
let l = item.align.length;
|
|
717
581
|
let i, j, k, row;
|
|
718
582
|
for (i = 0; i < l; i++) {
|
|
719
583
|
if (/^ *-+: *$/.test(item.align[i])) {
|
|
720
|
-
item.align[i] =
|
|
584
|
+
item.align[i] = "right";
|
|
721
585
|
} else if (/^ *:-+: *$/.test(item.align[i])) {
|
|
722
|
-
item.align[i] =
|
|
586
|
+
item.align[i] = "center";
|
|
723
587
|
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
|
724
|
-
item.align[i] =
|
|
588
|
+
item.align[i] = "left";
|
|
725
589
|
} else {
|
|
726
590
|
item.align[i] = null;
|
|
727
591
|
}
|
|
728
592
|
}
|
|
729
|
-
|
|
730
593
|
l = item.rows.length;
|
|
731
594
|
for (i = 0; i < l; i++) {
|
|
732
|
-
item.rows[i] = splitCells(item.rows[i], item.header.length).map(c => {
|
|
595
|
+
item.rows[i] = splitCells(item.rows[i], item.header.length).map((c) => {
|
|
596
|
+
return { text: c };
|
|
597
|
+
});
|
|
733
598
|
}
|
|
734
|
-
|
|
735
|
-
// parse child tokens inside headers and cells
|
|
736
|
-
|
|
737
|
-
// header child tokens
|
|
738
599
|
l = item.header.length;
|
|
739
600
|
for (j = 0; j < l; j++) {
|
|
740
601
|
item.header[j].tokens = this.lexer.inline(item.header[j].text);
|
|
741
602
|
}
|
|
742
|
-
|
|
743
|
-
// cell child tokens
|
|
744
603
|
l = item.rows.length;
|
|
745
604
|
for (j = 0; j < l; j++) {
|
|
746
605
|
row = item.rows[j];
|
|
@@ -748,63 +607,55 @@ class Tokenizer {
|
|
|
748
607
|
row[k].tokens = this.lexer.inline(row[k].text);
|
|
749
608
|
}
|
|
750
609
|
}
|
|
751
|
-
|
|
752
610
|
return item;
|
|
753
611
|
}
|
|
754
612
|
}
|
|
755
613
|
}
|
|
756
|
-
|
|
757
614
|
lheading(src) {
|
|
758
615
|
const cap = this.rules.block.lheading.exec(src);
|
|
759
616
|
if (cap) {
|
|
760
617
|
return {
|
|
761
|
-
type:
|
|
618
|
+
type: "heading",
|
|
762
619
|
raw: cap[0],
|
|
763
|
-
depth: cap[2].charAt(0) ===
|
|
620
|
+
depth: cap[2].charAt(0) === "=" ? 1 : 2,
|
|
764
621
|
text: cap[1],
|
|
765
622
|
tokens: this.lexer.inline(cap[1])
|
|
766
623
|
};
|
|
767
624
|
}
|
|
768
625
|
}
|
|
769
|
-
|
|
770
626
|
paragraph(src) {
|
|
771
627
|
const cap = this.rules.block.paragraph.exec(src);
|
|
772
628
|
if (cap) {
|
|
773
|
-
const text = cap[1].charAt(cap[1].length - 1) ===
|
|
774
|
-
? cap[1].slice(0, -1)
|
|
775
|
-
: cap[1];
|
|
629
|
+
const text = cap[1].charAt(cap[1].length - 1) === "\n" ? cap[1].slice(0, -1) : cap[1];
|
|
776
630
|
return {
|
|
777
|
-
type:
|
|
631
|
+
type: "paragraph",
|
|
778
632
|
raw: cap[0],
|
|
779
633
|
text,
|
|
780
634
|
tokens: this.lexer.inline(text)
|
|
781
635
|
};
|
|
782
636
|
}
|
|
783
637
|
}
|
|
784
|
-
|
|
785
638
|
text(src) {
|
|
786
639
|
const cap = this.rules.block.text.exec(src);
|
|
787
640
|
if (cap) {
|
|
788
641
|
return {
|
|
789
|
-
type:
|
|
642
|
+
type: "text",
|
|
790
643
|
raw: cap[0],
|
|
791
644
|
text: cap[0],
|
|
792
645
|
tokens: this.lexer.inline(cap[0])
|
|
793
646
|
};
|
|
794
647
|
}
|
|
795
648
|
}
|
|
796
|
-
|
|
797
649
|
escape(src) {
|
|
798
650
|
const cap = this.rules.inline.escape.exec(src);
|
|
799
651
|
if (cap) {
|
|
800
652
|
return {
|
|
801
|
-
type:
|
|
653
|
+
type: "escape",
|
|
802
654
|
raw: cap[0],
|
|
803
655
|
text: escape(cap[1])
|
|
804
656
|
};
|
|
805
657
|
}
|
|
806
658
|
}
|
|
807
|
-
|
|
808
659
|
tag(src) {
|
|
809
660
|
const cap = this.rules.inline.tag.exec(src);
|
|
810
661
|
if (cap) {
|
|
@@ -818,90 +669,72 @@ class Tokenizer {
|
|
|
818
669
|
} else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
819
670
|
this.lexer.state.inRawBlock = false;
|
|
820
671
|
}
|
|
821
|
-
|
|
822
672
|
return {
|
|
823
|
-
type: this.options.sanitize
|
|
824
|
-
? 'text'
|
|
825
|
-
: 'html',
|
|
673
|
+
type: this.options.sanitize ? "text" : "html",
|
|
826
674
|
raw: cap[0],
|
|
827
675
|
inLink: this.lexer.state.inLink,
|
|
828
676
|
inRawBlock: this.lexer.state.inRawBlock,
|
|
829
677
|
block: false,
|
|
830
|
-
text: this.options.sanitize
|
|
831
|
-
? (this.options.sanitizer
|
|
832
|
-
? this.options.sanitizer(cap[0])
|
|
833
|
-
: escape(cap[0]))
|
|
834
|
-
: cap[0]
|
|
678
|
+
text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0]
|
|
835
679
|
};
|
|
836
680
|
}
|
|
837
681
|
}
|
|
838
|
-
|
|
839
682
|
link(src) {
|
|
840
683
|
const cap = this.rules.inline.link.exec(src);
|
|
841
684
|
if (cap) {
|
|
842
685
|
const trimmedUrl = cap[2].trim();
|
|
843
686
|
if (!this.options.pedantic && /^</.test(trimmedUrl)) {
|
|
844
|
-
|
|
845
|
-
if (!(/>$/.test(trimmedUrl))) {
|
|
687
|
+
if (!/>$/.test(trimmedUrl)) {
|
|
846
688
|
return;
|
|
847
689
|
}
|
|
848
|
-
|
|
849
|
-
// ending angle bracket cannot be escaped
|
|
850
|
-
const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
|
|
690
|
+
const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), "\\");
|
|
851
691
|
if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
|
|
852
692
|
return;
|
|
853
693
|
}
|
|
854
694
|
} else {
|
|
855
|
-
|
|
856
|
-
const lastParenIndex = findClosingBracket(cap[2], '()');
|
|
695
|
+
const lastParenIndex = findClosingBracket(cap[2], "()");
|
|
857
696
|
if (lastParenIndex > -1) {
|
|
858
|
-
const start = cap[0].indexOf(
|
|
697
|
+
const start = cap[0].indexOf("!") === 0 ? 5 : 4;
|
|
859
698
|
const linkLen = start + cap[1].length + lastParenIndex;
|
|
860
699
|
cap[2] = cap[2].substring(0, lastParenIndex);
|
|
861
700
|
cap[0] = cap[0].substring(0, linkLen).trim();
|
|
862
|
-
cap[3] =
|
|
701
|
+
cap[3] = "";
|
|
863
702
|
}
|
|
864
703
|
}
|
|
865
704
|
let href = cap[2];
|
|
866
|
-
let title =
|
|
705
|
+
let title = "";
|
|
867
706
|
if (this.options.pedantic) {
|
|
868
|
-
// split pedantic href and title
|
|
869
707
|
const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
|
|
870
|
-
|
|
871
708
|
if (link) {
|
|
872
709
|
href = link[1];
|
|
873
710
|
title = link[3];
|
|
874
711
|
}
|
|
875
712
|
} else {
|
|
876
|
-
title = cap[3] ? cap[3].slice(1, -1) :
|
|
713
|
+
title = cap[3] ? cap[3].slice(1, -1) : "";
|
|
877
714
|
}
|
|
878
|
-
|
|
879
715
|
href = href.trim();
|
|
880
716
|
if (/^</.test(href)) {
|
|
881
|
-
if (this.options.pedantic &&
|
|
882
|
-
// pedantic allows starting angle bracket without ending angle bracket
|
|
717
|
+
if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
|
|
883
718
|
href = href.slice(1);
|
|
884
719
|
} else {
|
|
885
720
|
href = href.slice(1, -1);
|
|
886
721
|
}
|
|
887
722
|
}
|
|
888
723
|
return outputLink(cap, {
|
|
889
|
-
href: href ? href.replace(this.rules.inline._escapes,
|
|
890
|
-
title: title ? title.replace(this.rules.inline._escapes,
|
|
724
|
+
href: href ? href.replace(this.rules.inline._escapes, "$1") : href,
|
|
725
|
+
title: title ? title.replace(this.rules.inline._escapes, "$1") : title
|
|
891
726
|
}, cap[0], this.lexer);
|
|
892
727
|
}
|
|
893
728
|
}
|
|
894
|
-
|
|
895
729
|
reflink(src, links) {
|
|
896
730
|
let cap;
|
|
897
|
-
if ((cap = this.rules.inline.reflink.exec(src))
|
|
898
|
-
|
|
899
|
-
let link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
|
731
|
+
if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
|
|
732
|
+
let link = (cap[2] || cap[1]).replace(/\s+/g, " ");
|
|
900
733
|
link = links[link.toLowerCase()];
|
|
901
734
|
if (!link) {
|
|
902
735
|
const text = cap[0].charAt(0);
|
|
903
736
|
return {
|
|
904
|
-
type:
|
|
737
|
+
type: "text",
|
|
905
738
|
raw: text,
|
|
906
739
|
text
|
|
907
740
|
};
|
|
@@ -909,67 +742,50 @@ class Tokenizer {
|
|
|
909
742
|
return outputLink(cap, link, cap[0], this.lexer);
|
|
910
743
|
}
|
|
911
744
|
}
|
|
912
|
-
|
|
913
|
-
emStrong(src, maskedSrc, prevChar = '') {
|
|
745
|
+
emStrong(src, maskedSrc, prevChar = "") {
|
|
914
746
|
let match = this.rules.inline.emStrong.lDelim.exec(src);
|
|
915
|
-
if (!match)
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
const nextChar = match[1] || match[2] || '';
|
|
921
|
-
|
|
747
|
+
if (!match)
|
|
748
|
+
return;
|
|
749
|
+
if (match[3] && prevChar.match(/[\p{L}\p{N}]/u))
|
|
750
|
+
return;
|
|
751
|
+
const nextChar = match[1] || match[2] || "";
|
|
922
752
|
if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
|
|
923
753
|
const lLength = match[0].length - 1;
|
|
924
754
|
let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
|
|
925
|
-
|
|
926
|
-
const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
|
|
755
|
+
const endReg = match[0][0] === "*" ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
|
|
927
756
|
endReg.lastIndex = 0;
|
|
928
|
-
|
|
929
|
-
// Clip maskedSrc to same section of string as src (move to lexer?)
|
|
930
757
|
maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
|
|
931
|
-
|
|
932
758
|
while ((match = endReg.exec(maskedSrc)) != null) {
|
|
933
759
|
rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
760
|
+
if (!rDelim)
|
|
761
|
+
continue;
|
|
937
762
|
rLength = rDelim.length;
|
|
938
|
-
|
|
939
|
-
if (match[3] || match[4]) { // found another Left Delim
|
|
763
|
+
if (match[3] || match[4]) {
|
|
940
764
|
delimTotal += rLength;
|
|
941
765
|
continue;
|
|
942
|
-
} else if (match[5] || match[6]) {
|
|
766
|
+
} else if (match[5] || match[6]) {
|
|
943
767
|
if (lLength % 3 && !((lLength + rLength) % 3)) {
|
|
944
768
|
midDelimTotal += rLength;
|
|
945
|
-
continue;
|
|
769
|
+
continue;
|
|
946
770
|
}
|
|
947
771
|
}
|
|
948
|
-
|
|
949
772
|
delimTotal -= rLength;
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
// Remove extra characters. *a*** -> *a*
|
|
773
|
+
if (delimTotal > 0)
|
|
774
|
+
continue;
|
|
954
775
|
rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
|
|
955
|
-
|
|
956
776
|
const raw = src.slice(0, lLength + match.index + rLength + 1);
|
|
957
|
-
|
|
958
|
-
// Create `em` if smallest delimiter has odd char count. *a***
|
|
959
777
|
if (Math.min(lLength, rLength) % 2) {
|
|
960
|
-
const
|
|
778
|
+
const text2 = raw.slice(1, -1);
|
|
961
779
|
return {
|
|
962
|
-
type:
|
|
780
|
+
type: "em",
|
|
963
781
|
raw,
|
|
964
|
-
text,
|
|
965
|
-
tokens: this.lexer.inlineTokens(
|
|
782
|
+
text: text2,
|
|
783
|
+
tokens: this.lexer.inlineTokens(text2)
|
|
966
784
|
};
|
|
967
785
|
}
|
|
968
|
-
|
|
969
|
-
// Create 'strong' if smallest delimiter has even char count. **a***
|
|
970
786
|
const text = raw.slice(2, -2);
|
|
971
787
|
return {
|
|
972
|
-
type:
|
|
788
|
+
type: "strong",
|
|
973
789
|
raw,
|
|
974
790
|
text,
|
|
975
791
|
tokens: this.lexer.inlineTokens(text)
|
|
@@ -977,11 +793,10 @@ class Tokenizer {
|
|
|
977
793
|
}
|
|
978
794
|
}
|
|
979
795
|
}
|
|
980
|
-
|
|
981
796
|
codespan(src) {
|
|
982
797
|
const cap = this.rules.inline.code.exec(src);
|
|
983
798
|
if (cap) {
|
|
984
|
-
let text = cap[2].replace(/\n/g,
|
|
799
|
+
let text = cap[2].replace(/\n/g, " ");
|
|
985
800
|
const hasNonSpaceChars = /[^ ]/.test(text);
|
|
986
801
|
const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
|
|
987
802
|
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
|
|
@@ -989,55 +804,51 @@ class Tokenizer {
|
|
|
989
804
|
}
|
|
990
805
|
text = escape(text, true);
|
|
991
806
|
return {
|
|
992
|
-
type:
|
|
807
|
+
type: "codespan",
|
|
993
808
|
raw: cap[0],
|
|
994
809
|
text
|
|
995
810
|
};
|
|
996
811
|
}
|
|
997
812
|
}
|
|
998
|
-
|
|
999
813
|
br(src) {
|
|
1000
814
|
const cap = this.rules.inline.br.exec(src);
|
|
1001
815
|
if (cap) {
|
|
1002
816
|
return {
|
|
1003
|
-
type:
|
|
817
|
+
type: "br",
|
|
1004
818
|
raw: cap[0]
|
|
1005
819
|
};
|
|
1006
820
|
}
|
|
1007
821
|
}
|
|
1008
|
-
|
|
1009
822
|
del(src) {
|
|
1010
823
|
const cap = this.rules.inline.del.exec(src);
|
|
1011
824
|
if (cap) {
|
|
1012
825
|
return {
|
|
1013
|
-
type:
|
|
826
|
+
type: "del",
|
|
1014
827
|
raw: cap[0],
|
|
1015
828
|
text: cap[2],
|
|
1016
829
|
tokens: this.lexer.inlineTokens(cap[2])
|
|
1017
830
|
};
|
|
1018
831
|
}
|
|
1019
832
|
}
|
|
1020
|
-
|
|
1021
|
-
autolink(src, mangle) {
|
|
833
|
+
autolink(src, mangle2) {
|
|
1022
834
|
const cap = this.rules.inline.autolink.exec(src);
|
|
1023
835
|
if (cap) {
|
|
1024
836
|
let text, href;
|
|
1025
|
-
if (cap[2] ===
|
|
1026
|
-
text = escape(this.options.mangle ?
|
|
1027
|
-
href =
|
|
837
|
+
if (cap[2] === "@") {
|
|
838
|
+
text = escape(this.options.mangle ? mangle2(cap[1]) : cap[1]);
|
|
839
|
+
href = "mailto:" + text;
|
|
1028
840
|
} else {
|
|
1029
841
|
text = escape(cap[1]);
|
|
1030
842
|
href = text;
|
|
1031
843
|
}
|
|
1032
|
-
|
|
1033
844
|
return {
|
|
1034
|
-
type:
|
|
845
|
+
type: "link",
|
|
1035
846
|
raw: cap[0],
|
|
1036
847
|
text,
|
|
1037
848
|
href,
|
|
1038
849
|
tokens: [
|
|
1039
850
|
{
|
|
1040
|
-
type:
|
|
851
|
+
type: "text",
|
|
1041
852
|
raw: text,
|
|
1042
853
|
text
|
|
1043
854
|
}
|
|
@@ -1045,36 +856,34 @@ class Tokenizer {
|
|
|
1045
856
|
};
|
|
1046
857
|
}
|
|
1047
858
|
}
|
|
1048
|
-
|
|
1049
|
-
url(src, mangle) {
|
|
859
|
+
url(src, mangle2) {
|
|
1050
860
|
let cap;
|
|
1051
861
|
if (cap = this.rules.inline.url.exec(src)) {
|
|
1052
862
|
let text, href;
|
|
1053
|
-
if (cap[2] ===
|
|
1054
|
-
text = escape(this.options.mangle ?
|
|
1055
|
-
href =
|
|
863
|
+
if (cap[2] === "@") {
|
|
864
|
+
text = escape(this.options.mangle ? mangle2(cap[0]) : cap[0]);
|
|
865
|
+
href = "mailto:" + text;
|
|
1056
866
|
} else {
|
|
1057
|
-
// do extended autolink path validation
|
|
1058
867
|
let prevCapZero;
|
|
1059
868
|
do {
|
|
1060
869
|
prevCapZero = cap[0];
|
|
1061
870
|
cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
|
|
1062
871
|
} while (prevCapZero !== cap[0]);
|
|
1063
872
|
text = escape(cap[0]);
|
|
1064
|
-
if (cap[1] ===
|
|
1065
|
-
href =
|
|
873
|
+
if (cap[1] === "www.") {
|
|
874
|
+
href = "http://" + cap[0];
|
|
1066
875
|
} else {
|
|
1067
876
|
href = cap[0];
|
|
1068
877
|
}
|
|
1069
878
|
}
|
|
1070
879
|
return {
|
|
1071
|
-
type:
|
|
880
|
+
type: "link",
|
|
1072
881
|
raw: cap[0],
|
|
1073
882
|
text,
|
|
1074
883
|
href,
|
|
1075
884
|
tokens: [
|
|
1076
885
|
{
|
|
1077
|
-
type:
|
|
886
|
+
type: "text",
|
|
1078
887
|
raw: text,
|
|
1079
888
|
text
|
|
1080
889
|
}
|
|
@@ -1082,29 +891,26 @@ class Tokenizer {
|
|
|
1082
891
|
};
|
|
1083
892
|
}
|
|
1084
893
|
}
|
|
1085
|
-
|
|
1086
|
-
inlineText(src, smartypants) {
|
|
894
|
+
inlineText(src, smartypants2) {
|
|
1087
895
|
const cap = this.rules.inline.text.exec(src);
|
|
1088
896
|
if (cap) {
|
|
1089
897
|
let text;
|
|
1090
898
|
if (this.lexer.state.inRawBlock) {
|
|
1091
|
-
text = this.options.sanitize ?
|
|
899
|
+
text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0];
|
|
1092
900
|
} else {
|
|
1093
|
-
text = escape(this.options.smartypants ?
|
|
901
|
+
text = escape(this.options.smartypants ? smartypants2(cap[0]) : cap[0]);
|
|
1094
902
|
}
|
|
1095
903
|
return {
|
|
1096
|
-
type:
|
|
904
|
+
type: "text",
|
|
1097
905
|
raw: cap[0],
|
|
1098
906
|
text
|
|
1099
907
|
};
|
|
1100
908
|
}
|
|
1101
909
|
}
|
|
1102
|
-
}
|
|
910
|
+
};
|
|
1103
911
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
*/
|
|
1107
|
-
const block = {
|
|
912
|
+
// src/rules.ts
|
|
913
|
+
var block = {
|
|
1108
914
|
newline: /^(?: *(?:\n|$))+/,
|
|
1109
915
|
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
1110
916
|
fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
|
|
@@ -1112,16 +918,7 @@ const block = {
|
|
|
1112
918
|
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
|
|
1113
919
|
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
|
1114
920
|
list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
|
|
1115
|
-
html:
|
|
1116
|
-
+ '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
|
|
1117
|
-
+ '|comment[^\\n]*(\\n+|$)' // (2)
|
|
1118
|
-
+ '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
|
|
1119
|
-
+ '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
|
|
1120
|
-
+ '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
|
|
1121
|
-
+ '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
|
|
1122
|
-
+ '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
|
|
1123
|
-
+ '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
|
|
1124
|
-
+ ')',
|
|
921
|
+
html: "^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",
|
|
1125
922
|
def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
|
|
1126
923
|
table: noopTest,
|
|
1127
924
|
lheading: /^((?:(?!^bull ).|\n(?!\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
@@ -1130,151 +927,55 @@ const block = {
|
|
|
1130
927
|
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
|
|
1131
928
|
text: /^[^\n]+/
|
|
1132
929
|
};
|
|
1133
|
-
|
|
1134
930
|
block._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
|
|
1135
931
|
block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
|
|
1136
|
-
block.def = edit(block.def)
|
|
1137
|
-
.replace('label', block._label)
|
|
1138
|
-
.replace('title', block._title)
|
|
1139
|
-
.getRegex();
|
|
1140
|
-
|
|
932
|
+
block.def = edit(block.def).replace("label", block._label).replace("title", block._title).getRegex();
|
|
1141
933
|
block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
|
1142
|
-
block.listItemStart = edit(/^( *)(bull) */)
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
block.list = edit(block.list)
|
|
1147
|
-
.replace(/bull/g, block.bullet)
|
|
1148
|
-
.replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
|
|
1149
|
-
.replace('def', '\\n+(?=' + block.def.source + ')')
|
|
1150
|
-
.getRegex();
|
|
1151
|
-
|
|
1152
|
-
block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
|
|
1153
|
-
+ '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
|
|
1154
|
-
+ '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
|
|
1155
|
-
+ '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
|
|
1156
|
-
+ '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
|
|
1157
|
-
+ '|track|ul';
|
|
934
|
+
block.listItemStart = edit(/^( *)(bull) */).replace("bull", block.bullet).getRegex();
|
|
935
|
+
block.list = edit(block.list).replace(/bull/g, block.bullet).replace("hr", "\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def", "\\n+(?=" + block.def.source + ")").getRegex();
|
|
936
|
+
block._tag = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
|
|
1158
937
|
block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
|
|
1159
|
-
block.html = edit(block.html,
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
.getRegex();
|
|
1164
|
-
|
|
1165
|
-
block.lheading = edit(block.lheading)
|
|
1166
|
-
.replace(/bull/g, block.bullet) // lists can interrupt
|
|
1167
|
-
.getRegex();
|
|
1168
|
-
|
|
1169
|
-
block.paragraph = edit(block._paragraph)
|
|
1170
|
-
.replace('hr', block.hr)
|
|
1171
|
-
.replace('heading', ' {0,3}#{1,6} ')
|
|
1172
|
-
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
|
|
1173
|
-
.replace('|table', '')
|
|
1174
|
-
.replace('blockquote', ' {0,3}>')
|
|
1175
|
-
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
|
|
1176
|
-
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
1177
|
-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
|
|
1178
|
-
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
|
|
1179
|
-
.getRegex();
|
|
1180
|
-
|
|
1181
|
-
block.blockquote = edit(block.blockquote)
|
|
1182
|
-
.replace('paragraph', block.paragraph)
|
|
1183
|
-
.getRegex();
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
* Normal Block Grammar
|
|
1187
|
-
*/
|
|
1188
|
-
|
|
938
|
+
block.html = edit(block.html, "i").replace("comment", block._comment).replace("tag", block._tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
939
|
+
block.lheading = edit(block.lheading).replace(/bull/g, block.bullet).getRegex();
|
|
940
|
+
block.paragraph = edit(block._paragraph).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
|
|
941
|
+
block.blockquote = edit(block.blockquote).replace("paragraph", block.paragraph).getRegex();
|
|
1189
942
|
block.normal = { ...block };
|
|
1190
|
-
|
|
1191
|
-
/**
|
|
1192
|
-
* GFM Block Grammar
|
|
1193
|
-
*/
|
|
1194
|
-
|
|
1195
943
|
block.gfm = {
|
|
1196
944
|
...block.normal,
|
|
1197
|
-
table:
|
|
1198
|
-
|
|
1199
|
-
+ '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
|
945
|
+
table: "^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
|
|
946
|
+
// Cells
|
|
1200
947
|
};
|
|
1201
|
-
|
|
1202
|
-
block.gfm.
|
|
1203
|
-
.replace('hr', block.hr)
|
|
1204
|
-
.replace('heading', ' {0,3}#{1,6} ')
|
|
1205
|
-
.replace('blockquote', ' {0,3}>')
|
|
1206
|
-
.replace('code', ' {4}[^\\n]')
|
|
1207
|
-
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
|
|
1208
|
-
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
1209
|
-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
|
|
1210
|
-
.replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
1211
|
-
.getRegex();
|
|
1212
|
-
|
|
1213
|
-
block.gfm.paragraph = edit(block._paragraph)
|
|
1214
|
-
.replace('hr', block.hr)
|
|
1215
|
-
.replace('heading', ' {0,3}#{1,6} ')
|
|
1216
|
-
.replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
|
|
1217
|
-
.replace('table', block.gfm.table) // interrupt paragraphs with table
|
|
1218
|
-
.replace('blockquote', ' {0,3}>')
|
|
1219
|
-
.replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
|
|
1220
|
-
.replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
1221
|
-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
|
|
1222
|
-
.replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
|
|
1223
|
-
.getRegex();
|
|
1224
|
-
/**
|
|
1225
|
-
* Pedantic grammar (original John Gruber's loose markdown specification)
|
|
1226
|
-
*/
|
|
1227
|
-
|
|
948
|
+
block.gfm.table = edit(block.gfm.table).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("blockquote", " {0,3}>").replace("code", " {4}[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
|
|
949
|
+
block.gfm.paragraph = edit(block._paragraph).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("table", block.gfm.table).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
|
|
1228
950
|
block.pedantic = {
|
|
1229
951
|
...block.normal,
|
|
1230
952
|
html: edit(
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
+ '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
|
|
1234
|
-
.replace('comment', block._comment)
|
|
1235
|
-
.replace(/tag/g, '(?!(?:'
|
|
1236
|
-
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
|
|
1237
|
-
+ '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
|
|
1238
|
-
+ '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
|
|
1239
|
-
.getRegex(),
|
|
953
|
+
`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
|
|
954
|
+
).replace("comment", block._comment).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
|
|
1240
955
|
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
1241
956
|
heading: /^(#{1,6})(.*)(?:\n+|$)/,
|
|
1242
|
-
fences: noopTest,
|
|
957
|
+
fences: noopTest,
|
|
958
|
+
// fences not supported
|
|
1243
959
|
lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
1244
|
-
paragraph: edit(block.normal._paragraph)
|
|
1245
|
-
.replace('hr', block.hr)
|
|
1246
|
-
.replace('heading', ' *#{1,6} *[^\n]')
|
|
1247
|
-
.replace('lheading', block.lheading)
|
|
1248
|
-
.replace('blockquote', ' {0,3}>')
|
|
1249
|
-
.replace('|fences', '')
|
|
1250
|
-
.replace('|list', '')
|
|
1251
|
-
.replace('|html', '')
|
|
1252
|
-
.getRegex()
|
|
960
|
+
paragraph: edit(block.normal._paragraph).replace("hr", block.hr).replace("heading", " *#{1,6} *[^\n]").replace("lheading", block.lheading).replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").getRegex()
|
|
1253
961
|
};
|
|
1254
|
-
|
|
1255
|
-
/**
|
|
1256
|
-
* Inline-Level Grammar
|
|
1257
|
-
*/
|
|
1258
|
-
const inline = {
|
|
962
|
+
var inline = {
|
|
1259
963
|
escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
|
|
1260
964
|
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
|
1261
965
|
url: noopTest,
|
|
1262
|
-
tag:
|
|
1263
|
-
|
|
1264
|
-
+ '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
|
|
1265
|
-
+ '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
|
|
1266
|
-
+ '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
|
|
1267
|
-
+ '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
|
|
966
|
+
tag: "^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",
|
|
967
|
+
// CDATA section
|
|
1268
968
|
link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
|
|
1269
969
|
reflink: /^!?\[(label)\]\[(ref)\]/,
|
|
1270
970
|
nolink: /^!?\[(ref)\](?:\[\])?/,
|
|
1271
|
-
reflinkSearch:
|
|
971
|
+
reflinkSearch: "reflink|nolink(?!\\()",
|
|
1272
972
|
emStrong: {
|
|
1273
973
|
lDelim: /^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,
|
|
1274
974
|
// (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.
|
|
1275
975
|
// | Skip orphan inside strong | Consume to delim | (1) #*** | (2) a***#, a*** | (3) #***a, ***a | (4) ***# | (5) #***# | (6) a***a
|
|
1276
976
|
rDelimAst: /^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[punct](\*+)(?=[\s]|$)|[^punct\s](\*+)(?!\*)(?=[punct\s]|$)|(?!\*)[punct\s](\*+)(?=[^punct\s])|[\s](\*+)(?!\*)(?=[punct])|(?!\*)[punct](\*+)(?!\*)(?=[punct])|[^punct\s](\*+)(?=[^punct\s])/,
|
|
1277
|
-
rDelimUnd: /^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/
|
|
977
|
+
rDelimUnd: /^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/
|
|
978
|
+
// ^- Not allowed for _
|
|
1278
979
|
},
|
|
1279
980
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
1280
981
|
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
@@ -1282,86 +983,30 @@ const inline = {
|
|
|
1282
983
|
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
|
|
1283
984
|
punctuation: /^((?![*_])[\spunctuation])/
|
|
1284
985
|
};
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
inline._punctuation = '\\p{P}$+<=>`^|~';
|
|
1288
|
-
inline.punctuation = edit(inline.punctuation, 'u').replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1289
|
-
|
|
1290
|
-
// sequences em should skip over [title](link), `code`, <html>
|
|
986
|
+
inline._punctuation = "\\p{P}$+<=>`^|~";
|
|
987
|
+
inline.punctuation = edit(inline.punctuation, "u").replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1291
988
|
inline.blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
|
|
1292
989
|
inline.anyPunctuation = /\\[punct]/g;
|
|
1293
990
|
inline._escapes = /\\([punct])/g;
|
|
1294
|
-
|
|
1295
|
-
inline.
|
|
1296
|
-
|
|
1297
|
-
inline.emStrong.
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'gu')
|
|
1302
|
-
.replace(/punct/g, inline._punctuation)
|
|
1303
|
-
.getRegex();
|
|
1304
|
-
|
|
1305
|
-
inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, 'gu')
|
|
1306
|
-
.replace(/punct/g, inline._punctuation)
|
|
1307
|
-
.getRegex();
|
|
1308
|
-
|
|
1309
|
-
inline.anyPunctuation = edit(inline.anyPunctuation, 'gu')
|
|
1310
|
-
.replace(/punct/g, inline._punctuation)
|
|
1311
|
-
.getRegex();
|
|
1312
|
-
|
|
1313
|
-
inline._escapes = edit(inline._escapes, 'gu')
|
|
1314
|
-
.replace(/punct/g, inline._punctuation)
|
|
1315
|
-
.getRegex();
|
|
1316
|
-
|
|
991
|
+
inline._comment = edit(block._comment).replace("(?:-->|$)", "-->").getRegex();
|
|
992
|
+
inline.emStrong.lDelim = edit(inline.emStrong.lDelim, "u").replace(/punct/g, inline._punctuation).getRegex();
|
|
993
|
+
inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, "gu").replace(/punct/g, inline._punctuation).getRegex();
|
|
994
|
+
inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, "gu").replace(/punct/g, inline._punctuation).getRegex();
|
|
995
|
+
inline.anyPunctuation = edit(inline.anyPunctuation, "gu").replace(/punct/g, inline._punctuation).getRegex();
|
|
996
|
+
inline._escapes = edit(inline._escapes, "gu").replace(/punct/g, inline._punctuation).getRegex();
|
|
1317
997
|
inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
|
|
1318
998
|
inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
|
|
1319
|
-
inline.autolink = edit(inline.autolink)
|
|
1320
|
-
.replace('scheme', inline._scheme)
|
|
1321
|
-
.replace('email', inline._email)
|
|
1322
|
-
.getRegex();
|
|
1323
|
-
|
|
999
|
+
inline.autolink = edit(inline.autolink).replace("scheme", inline._scheme).replace("email", inline._email).getRegex();
|
|
1324
1000
|
inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
|
|
1325
|
-
|
|
1326
|
-
inline.tag = edit(inline.tag)
|
|
1327
|
-
.replace('comment', inline._comment)
|
|
1328
|
-
.replace('attribute', inline._attribute)
|
|
1329
|
-
.getRegex();
|
|
1330
|
-
|
|
1001
|
+
inline.tag = edit(inline.tag).replace("comment", inline._comment).replace("attribute", inline._attribute).getRegex();
|
|
1331
1002
|
inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
|
|
1332
1003
|
inline._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
|
|
1333
1004
|
inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
|
|
1334
|
-
|
|
1335
|
-
inline.
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
.replace('title', inline._title)
|
|
1339
|
-
.getRegex();
|
|
1340
|
-
|
|
1341
|
-
inline.reflink = edit(inline.reflink)
|
|
1342
|
-
.replace('label', inline._label)
|
|
1343
|
-
.replace('ref', block._label)
|
|
1344
|
-
.getRegex();
|
|
1345
|
-
|
|
1346
|
-
inline.nolink = edit(inline.nolink)
|
|
1347
|
-
.replace('ref', block._label)
|
|
1348
|
-
.getRegex();
|
|
1349
|
-
|
|
1350
|
-
inline.reflinkSearch = edit(inline.reflinkSearch, 'g')
|
|
1351
|
-
.replace('reflink', inline.reflink)
|
|
1352
|
-
.replace('nolink', inline.nolink)
|
|
1353
|
-
.getRegex();
|
|
1354
|
-
|
|
1355
|
-
/**
|
|
1356
|
-
* Normal Inline Grammar
|
|
1357
|
-
*/
|
|
1358
|
-
|
|
1005
|
+
inline.link = edit(inline.link).replace("label", inline._label).replace("href", inline._href).replace("title", inline._title).getRegex();
|
|
1006
|
+
inline.reflink = edit(inline.reflink).replace("label", inline._label).replace("ref", block._label).getRegex();
|
|
1007
|
+
inline.nolink = edit(inline.nolink).replace("ref", block._label).getRegex();
|
|
1008
|
+
inline.reflinkSearch = edit(inline.reflinkSearch, "g").replace("reflink", inline.reflink).replace("nolink", inline.nolink).getRegex();
|
|
1359
1009
|
inline.normal = { ...inline };
|
|
1360
|
-
|
|
1361
|
-
/**
|
|
1362
|
-
* Pedantic Inline Grammar
|
|
1363
|
-
*/
|
|
1364
|
-
|
|
1365
1010
|
inline.pedantic = {
|
|
1366
1011
|
...inline.normal,
|
|
1367
1012
|
strong: {
|
|
@@ -1376,96 +1021,47 @@ inline.pedantic = {
|
|
|
1376
1021
|
endAst: /\*(?!\*)/g,
|
|
1377
1022
|
endUnd: /_(?!_)/g
|
|
1378
1023
|
},
|
|
1379
|
-
link: edit(/^!?\[(label)\]\((.*?)\)/)
|
|
1380
|
-
|
|
1381
|
-
.getRegex(),
|
|
1382
|
-
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
|
|
1383
|
-
.replace('label', inline._label)
|
|
1384
|
-
.getRegex()
|
|
1024
|
+
link: edit(/^!?\[(label)\]\((.*?)\)/).replace("label", inline._label).getRegex(),
|
|
1025
|
+
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", inline._label).getRegex()
|
|
1385
1026
|
};
|
|
1386
|
-
|
|
1387
|
-
/**
|
|
1388
|
-
* GFM Inline Grammar
|
|
1389
|
-
*/
|
|
1390
|
-
|
|
1391
1027
|
inline.gfm = {
|
|
1392
1028
|
...inline.normal,
|
|
1393
|
-
escape: edit(inline.escape).replace(
|
|
1029
|
+
escape: edit(inline.escape).replace("])", "~|])").getRegex(),
|
|
1394
1030
|
_extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
|
|
1395
1031
|
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
|
|
1396
1032
|
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
1397
1033
|
del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
|
|
1398
1034
|
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
|
|
1399
1035
|
};
|
|
1400
|
-
|
|
1401
|
-
inline.gfm.url = edit(inline.gfm.url, 'i')
|
|
1402
|
-
.replace('email', inline.gfm._extended_email)
|
|
1403
|
-
.getRegex();
|
|
1404
|
-
/**
|
|
1405
|
-
* GFM + Line Breaks Inline Grammar
|
|
1406
|
-
*/
|
|
1407
|
-
|
|
1036
|
+
inline.gfm.url = edit(inline.gfm.url, "i").replace("email", inline.gfm._extended_email).getRegex();
|
|
1408
1037
|
inline.breaks = {
|
|
1409
1038
|
...inline.gfm,
|
|
1410
|
-
br: edit(inline.br).replace(
|
|
1411
|
-
text: edit(inline.gfm.text)
|
|
1412
|
-
.replace('\\b_', '\\b_| {2,}\\n')
|
|
1413
|
-
.replace(/\{2,\}/g, '*')
|
|
1414
|
-
.getRegex()
|
|
1039
|
+
br: edit(inline.br).replace("{2,}", "*").getRegex(),
|
|
1040
|
+
text: edit(inline.gfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
|
|
1415
1041
|
};
|
|
1416
1042
|
|
|
1417
|
-
|
|
1418
|
-
* smartypants text replacement
|
|
1419
|
-
* @param {string} text
|
|
1420
|
-
*/
|
|
1043
|
+
// src/Lexer.ts
|
|
1421
1044
|
function smartypants(text) {
|
|
1422
|
-
return text
|
|
1423
|
-
// em-dashes
|
|
1424
|
-
.replace(/---/g, '\u2014')
|
|
1425
|
-
// en-dashes
|
|
1426
|
-
.replace(/--/g, '\u2013')
|
|
1427
|
-
// opening singles
|
|
1428
|
-
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
|
|
1429
|
-
// closing singles & apostrophes
|
|
1430
|
-
.replace(/'/g, '\u2019')
|
|
1431
|
-
// opening doubles
|
|
1432
|
-
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
|
|
1433
|
-
// closing doubles
|
|
1434
|
-
.replace(/"/g, '\u201d')
|
|
1435
|
-
// ellipses
|
|
1436
|
-
.replace(/\.{3}/g, '\u2026');
|
|
1045
|
+
return text.replace(/---/g, "\u2014").replace(/--/g, "\u2013").replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018").replace(/'/g, "\u2019").replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C").replace(/"/g, "\u201D").replace(/\.{3}/g, "\u2026");
|
|
1437
1046
|
}
|
|
1438
|
-
|
|
1439
|
-
/**
|
|
1440
|
-
* mangle email addresses
|
|
1441
|
-
* @param {string} text
|
|
1442
|
-
*/
|
|
1443
1047
|
function mangle(text) {
|
|
1444
|
-
let out =
|
|
1445
|
-
i,
|
|
1446
|
-
ch;
|
|
1447
|
-
|
|
1048
|
+
let out = "", i, ch;
|
|
1448
1049
|
const l = text.length;
|
|
1449
1050
|
for (i = 0; i < l; i++) {
|
|
1450
1051
|
ch = text.charCodeAt(i);
|
|
1451
1052
|
if (Math.random() > 0.5) {
|
|
1452
|
-
ch =
|
|
1053
|
+
ch = "x" + ch.toString(16);
|
|
1453
1054
|
}
|
|
1454
|
-
out +=
|
|
1055
|
+
out += "&#" + ch + ";";
|
|
1455
1056
|
}
|
|
1456
|
-
|
|
1457
1057
|
return out;
|
|
1458
1058
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
* Block Lexer
|
|
1462
|
-
*/
|
|
1463
|
-
class Lexer {
|
|
1464
|
-
constructor(options) {
|
|
1059
|
+
var _Lexer2 = class __Lexer {
|
|
1060
|
+
constructor(options2) {
|
|
1465
1061
|
this.tokens = [];
|
|
1466
|
-
this.tokens.links = Object.create(null);
|
|
1467
|
-
this.options =
|
|
1468
|
-
this.options.tokenizer = this.options.tokenizer || new
|
|
1062
|
+
this.tokens.links = /* @__PURE__ */ Object.create(null);
|
|
1063
|
+
this.options = options2 || _defaults;
|
|
1064
|
+
this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
|
|
1469
1065
|
this.tokenizer = this.options.tokenizer;
|
|
1470
1066
|
this.tokenizer.options = this.options;
|
|
1471
1067
|
this.tokenizer.lexer = this;
|
|
@@ -1475,12 +1071,10 @@ class Lexer {
|
|
|
1475
1071
|
inRawBlock: false,
|
|
1476
1072
|
top: true
|
|
1477
1073
|
};
|
|
1478
|
-
|
|
1479
1074
|
const rules = {
|
|
1480
1075
|
block: block.normal,
|
|
1481
1076
|
inline: inline.normal
|
|
1482
1077
|
};
|
|
1483
|
-
|
|
1484
1078
|
if (this.options.pedantic) {
|
|
1485
1079
|
rules.block = block.pedantic;
|
|
1486
1080
|
rules.inline = inline.pedantic;
|
|
@@ -1494,7 +1088,6 @@ class Lexer {
|
|
|
1494
1088
|
}
|
|
1495
1089
|
this.tokenizer.rules = rules;
|
|
1496
1090
|
}
|
|
1497
|
-
|
|
1498
1091
|
/**
|
|
1499
1092
|
* Expose Rules
|
|
1500
1093
|
*/
|
|
@@ -1504,145 +1097,109 @@ class Lexer {
|
|
|
1504
1097
|
inline
|
|
1505
1098
|
};
|
|
1506
1099
|
}
|
|
1507
|
-
|
|
1508
1100
|
/**
|
|
1509
1101
|
* Static Lex Method
|
|
1510
1102
|
*/
|
|
1511
|
-
static lex(src,
|
|
1512
|
-
const
|
|
1513
|
-
return
|
|
1103
|
+
static lex(src, options2) {
|
|
1104
|
+
const lexer2 = new __Lexer(options2);
|
|
1105
|
+
return lexer2.lex(src);
|
|
1514
1106
|
}
|
|
1515
|
-
|
|
1516
1107
|
/**
|
|
1517
1108
|
* Static Lex Inline Method
|
|
1518
1109
|
*/
|
|
1519
|
-
static lexInline(src,
|
|
1520
|
-
const
|
|
1521
|
-
return
|
|
1110
|
+
static lexInline(src, options2) {
|
|
1111
|
+
const lexer2 = new __Lexer(options2);
|
|
1112
|
+
return lexer2.inlineTokens(src);
|
|
1522
1113
|
}
|
|
1523
|
-
|
|
1524
1114
|
/**
|
|
1525
1115
|
* Preprocessing
|
|
1526
1116
|
*/
|
|
1527
1117
|
lex(src) {
|
|
1528
|
-
src = src
|
|
1529
|
-
.replace(/\r\n|\r/g, '\n');
|
|
1530
|
-
|
|
1118
|
+
src = src.replace(/\r\n|\r/g, "\n");
|
|
1531
1119
|
this.blockTokens(src, this.tokens);
|
|
1532
|
-
|
|
1533
1120
|
let next;
|
|
1534
1121
|
while (next = this.inlineQueue.shift()) {
|
|
1535
1122
|
this.inlineTokens(next.src, next.tokens);
|
|
1536
1123
|
}
|
|
1537
|
-
|
|
1538
1124
|
return this.tokens;
|
|
1539
1125
|
}
|
|
1540
|
-
|
|
1541
|
-
/**
|
|
1542
|
-
* Lexing
|
|
1543
|
-
*/
|
|
1544
1126
|
blockTokens(src, tokens = []) {
|
|
1545
1127
|
if (this.options.pedantic) {
|
|
1546
|
-
src = src.replace(/\t/g,
|
|
1128
|
+
src = src.replace(/\t/g, " ").replace(/^ +$/gm, "");
|
|
1547
1129
|
} else {
|
|
1548
1130
|
src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
|
|
1549
|
-
return leading +
|
|
1131
|
+
return leading + " ".repeat(tabs.length);
|
|
1550
1132
|
});
|
|
1551
1133
|
}
|
|
1552
|
-
|
|
1553
1134
|
let token, lastToken, cutSrc, lastParagraphClipped;
|
|
1554
|
-
|
|
1555
1135
|
while (src) {
|
|
1556
|
-
if (this.options.extensions
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
return false;
|
|
1565
|
-
})) {
|
|
1136
|
+
if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some((extTokenizer) => {
|
|
1137
|
+
if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
|
|
1138
|
+
src = src.substring(token.raw.length);
|
|
1139
|
+
tokens.push(token);
|
|
1140
|
+
return true;
|
|
1141
|
+
}
|
|
1142
|
+
return false;
|
|
1143
|
+
})) {
|
|
1566
1144
|
continue;
|
|
1567
1145
|
}
|
|
1568
|
-
|
|
1569
|
-
// newline
|
|
1570
1146
|
if (token = this.tokenizer.space(src)) {
|
|
1571
1147
|
src = src.substring(token.raw.length);
|
|
1572
1148
|
if (token.raw.length === 1 && tokens.length > 0) {
|
|
1573
|
-
|
|
1574
|
-
// so move it there so that we don't get unecessary paragraph tags
|
|
1575
|
-
tokens[tokens.length - 1].raw += '\n';
|
|
1149
|
+
tokens[tokens.length - 1].raw += "\n";
|
|
1576
1150
|
} else {
|
|
1577
1151
|
tokens.push(token);
|
|
1578
1152
|
}
|
|
1579
1153
|
continue;
|
|
1580
1154
|
}
|
|
1581
|
-
|
|
1582
|
-
// code
|
|
1583
1155
|
if (token = this.tokenizer.code(src)) {
|
|
1584
1156
|
src = src.substring(token.raw.length);
|
|
1585
1157
|
lastToken = tokens[tokens.length - 1];
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
lastToken.
|
|
1589
|
-
lastToken.text += '\n' + token.text;
|
|
1158
|
+
if (lastToken && (lastToken.type === "paragraph" || lastToken.type === "text")) {
|
|
1159
|
+
lastToken.raw += "\n" + token.raw;
|
|
1160
|
+
lastToken.text += "\n" + token.text;
|
|
1590
1161
|
this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
|
|
1591
1162
|
} else {
|
|
1592
1163
|
tokens.push(token);
|
|
1593
1164
|
}
|
|
1594
1165
|
continue;
|
|
1595
1166
|
}
|
|
1596
|
-
|
|
1597
|
-
// fences
|
|
1598
1167
|
if (token = this.tokenizer.fences(src)) {
|
|
1599
1168
|
src = src.substring(token.raw.length);
|
|
1600
1169
|
tokens.push(token);
|
|
1601
1170
|
continue;
|
|
1602
1171
|
}
|
|
1603
|
-
|
|
1604
|
-
// heading
|
|
1605
1172
|
if (token = this.tokenizer.heading(src)) {
|
|
1606
1173
|
src = src.substring(token.raw.length);
|
|
1607
1174
|
tokens.push(token);
|
|
1608
1175
|
continue;
|
|
1609
1176
|
}
|
|
1610
|
-
|
|
1611
|
-
// hr
|
|
1612
1177
|
if (token = this.tokenizer.hr(src)) {
|
|
1613
1178
|
src = src.substring(token.raw.length);
|
|
1614
1179
|
tokens.push(token);
|
|
1615
1180
|
continue;
|
|
1616
1181
|
}
|
|
1617
|
-
|
|
1618
|
-
// blockquote
|
|
1619
1182
|
if (token = this.tokenizer.blockquote(src)) {
|
|
1620
1183
|
src = src.substring(token.raw.length);
|
|
1621
1184
|
tokens.push(token);
|
|
1622
1185
|
continue;
|
|
1623
1186
|
}
|
|
1624
|
-
|
|
1625
|
-
// list
|
|
1626
1187
|
if (token = this.tokenizer.list(src)) {
|
|
1627
1188
|
src = src.substring(token.raw.length);
|
|
1628
1189
|
tokens.push(token);
|
|
1629
1190
|
continue;
|
|
1630
1191
|
}
|
|
1631
|
-
|
|
1632
|
-
// html
|
|
1633
1192
|
if (token = this.tokenizer.html(src)) {
|
|
1634
1193
|
src = src.substring(token.raw.length);
|
|
1635
1194
|
tokens.push(token);
|
|
1636
1195
|
continue;
|
|
1637
1196
|
}
|
|
1638
|
-
|
|
1639
|
-
// def
|
|
1640
1197
|
if (token = this.tokenizer.def(src)) {
|
|
1641
1198
|
src = src.substring(token.raw.length);
|
|
1642
1199
|
lastToken = tokens[tokens.length - 1];
|
|
1643
|
-
if (lastToken && (lastToken.type ===
|
|
1644
|
-
lastToken.raw +=
|
|
1645
|
-
lastToken.text +=
|
|
1200
|
+
if (lastToken && (lastToken.type === "paragraph" || lastToken.type === "text")) {
|
|
1201
|
+
lastToken.raw += "\n" + token.raw;
|
|
1202
|
+
lastToken.text += "\n" + token.raw;
|
|
1646
1203
|
this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
|
|
1647
1204
|
} else if (!this.tokens.links[token.tag]) {
|
|
1648
1205
|
this.tokens.links[token.tag] = {
|
|
@@ -1652,31 +1209,26 @@ class Lexer {
|
|
|
1652
1209
|
}
|
|
1653
1210
|
continue;
|
|
1654
1211
|
}
|
|
1655
|
-
|
|
1656
|
-
// table (gfm)
|
|
1657
1212
|
if (token = this.tokenizer.table(src)) {
|
|
1658
1213
|
src = src.substring(token.raw.length);
|
|
1659
1214
|
tokens.push(token);
|
|
1660
1215
|
continue;
|
|
1661
1216
|
}
|
|
1662
|
-
|
|
1663
|
-
// lheading
|
|
1664
1217
|
if (token = this.tokenizer.lheading(src)) {
|
|
1665
1218
|
src = src.substring(token.raw.length);
|
|
1666
1219
|
tokens.push(token);
|
|
1667
1220
|
continue;
|
|
1668
1221
|
}
|
|
1669
|
-
|
|
1670
|
-
// top-level paragraph
|
|
1671
|
-
// prevent paragraph consuming extensions by clipping 'src' to extension start
|
|
1672
1222
|
cutSrc = src;
|
|
1673
1223
|
if (this.options.extensions && this.options.extensions.startBlock) {
|
|
1674
1224
|
let startIndex = Infinity;
|
|
1675
1225
|
const tempSrc = src.slice(1);
|
|
1676
1226
|
let tempStart;
|
|
1677
|
-
this.options.extensions.startBlock.forEach(
|
|
1227
|
+
this.options.extensions.startBlock.forEach((getStartIndex) => {
|
|
1678
1228
|
tempStart = getStartIndex.call({ lexer: this }, tempSrc);
|
|
1679
|
-
if (typeof tempStart ===
|
|
1229
|
+
if (typeof tempStart === "number" && tempStart >= 0) {
|
|
1230
|
+
startIndex = Math.min(startIndex, tempStart);
|
|
1231
|
+
}
|
|
1680
1232
|
});
|
|
1681
1233
|
if (startIndex < Infinity && startIndex >= 0) {
|
|
1682
1234
|
cutSrc = src.substring(0, startIndex + 1);
|
|
@@ -1684,26 +1236,24 @@ class Lexer {
|
|
|
1684
1236
|
}
|
|
1685
1237
|
if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
|
|
1686
1238
|
lastToken = tokens[tokens.length - 1];
|
|
1687
|
-
if (lastParagraphClipped && lastToken.type ===
|
|
1688
|
-
lastToken.raw +=
|
|
1689
|
-
lastToken.text +=
|
|
1239
|
+
if (lastParagraphClipped && lastToken.type === "paragraph") {
|
|
1240
|
+
lastToken.raw += "\n" + token.raw;
|
|
1241
|
+
lastToken.text += "\n" + token.text;
|
|
1690
1242
|
this.inlineQueue.pop();
|
|
1691
1243
|
this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
|
|
1692
1244
|
} else {
|
|
1693
1245
|
tokens.push(token);
|
|
1694
1246
|
}
|
|
1695
|
-
lastParagraphClipped =
|
|
1247
|
+
lastParagraphClipped = cutSrc.length !== src.length;
|
|
1696
1248
|
src = src.substring(token.raw.length);
|
|
1697
1249
|
continue;
|
|
1698
1250
|
}
|
|
1699
|
-
|
|
1700
|
-
// text
|
|
1701
1251
|
if (token = this.tokenizer.text(src)) {
|
|
1702
1252
|
src = src.substring(token.raw.length);
|
|
1703
1253
|
lastToken = tokens[tokens.length - 1];
|
|
1704
|
-
if (lastToken && lastToken.type ===
|
|
1705
|
-
lastToken.raw +=
|
|
1706
|
-
lastToken.text +=
|
|
1254
|
+
if (lastToken && lastToken.type === "text") {
|
|
1255
|
+
lastToken.raw += "\n" + token.raw;
|
|
1256
|
+
lastToken.text += "\n" + token.text;
|
|
1707
1257
|
this.inlineQueue.pop();
|
|
1708
1258
|
this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
|
|
1709
1259
|
} else {
|
|
@@ -1711,9 +1261,8 @@ class Lexer {
|
|
|
1711
1261
|
}
|
|
1712
1262
|
continue;
|
|
1713
1263
|
}
|
|
1714
|
-
|
|
1715
1264
|
if (src) {
|
|
1716
|
-
const errMsg =
|
|
1265
|
+
const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
|
|
1717
1266
|
if (this.options.silent) {
|
|
1718
1267
|
console.error(errMsg);
|
|
1719
1268
|
break;
|
|
@@ -1722,80 +1271,61 @@ class Lexer {
|
|
|
1722
1271
|
}
|
|
1723
1272
|
}
|
|
1724
1273
|
}
|
|
1725
|
-
|
|
1726
1274
|
this.state.top = true;
|
|
1727
1275
|
return tokens;
|
|
1728
1276
|
}
|
|
1729
|
-
|
|
1730
1277
|
inline(src, tokens = []) {
|
|
1731
1278
|
this.inlineQueue.push({ src, tokens });
|
|
1732
1279
|
return tokens;
|
|
1733
1280
|
}
|
|
1734
|
-
|
|
1735
1281
|
/**
|
|
1736
1282
|
* Lexing/Compiling
|
|
1737
1283
|
*/
|
|
1738
1284
|
inlineTokens(src, tokens = []) {
|
|
1739
1285
|
let token, lastToken, cutSrc;
|
|
1740
|
-
|
|
1741
|
-
// String with links masked to avoid interference with em and strong
|
|
1742
1286
|
let maskedSrc = src;
|
|
1743
1287
|
let match;
|
|
1744
1288
|
let keepPrevChar, prevChar;
|
|
1745
|
-
|
|
1746
|
-
// Mask out reflinks
|
|
1747
1289
|
if (this.tokens.links) {
|
|
1748
1290
|
const links = Object.keys(this.tokens.links);
|
|
1749
1291
|
if (links.length > 0) {
|
|
1750
1292
|
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
|
1751
|
-
if (links.includes(match[0].slice(match[0].lastIndexOf(
|
|
1752
|
-
maskedSrc = maskedSrc.slice(0, match.index) +
|
|
1293
|
+
if (links.includes(match[0].slice(match[0].lastIndexOf("[") + 1, -1))) {
|
|
1294
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
|
1753
1295
|
}
|
|
1754
1296
|
}
|
|
1755
1297
|
}
|
|
1756
1298
|
}
|
|
1757
|
-
// Mask out other blocks
|
|
1758
1299
|
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
|
1759
|
-
maskedSrc = maskedSrc.slice(0, match.index) +
|
|
1300
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "[" + "a".repeat(match[0].length - 2) + "]" + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
1760
1301
|
}
|
|
1761
|
-
|
|
1762
|
-
// Mask out escaped characters
|
|
1763
1302
|
while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
|
|
1764
|
-
maskedSrc = maskedSrc.slice(0, match.index) +
|
|
1303
|
+
maskedSrc = maskedSrc.slice(0, match.index) + "++" + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
1765
1304
|
}
|
|
1766
|
-
|
|
1767
1305
|
while (src) {
|
|
1768
1306
|
if (!keepPrevChar) {
|
|
1769
|
-
prevChar =
|
|
1307
|
+
prevChar = "";
|
|
1770
1308
|
}
|
|
1771
1309
|
keepPrevChar = false;
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
return true;
|
|
1781
|
-
}
|
|
1782
|
-
return false;
|
|
1783
|
-
})) {
|
|
1310
|
+
if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some((extTokenizer) => {
|
|
1311
|
+
if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
|
|
1312
|
+
src = src.substring(token.raw.length);
|
|
1313
|
+
tokens.push(token);
|
|
1314
|
+
return true;
|
|
1315
|
+
}
|
|
1316
|
+
return false;
|
|
1317
|
+
})) {
|
|
1784
1318
|
continue;
|
|
1785
1319
|
}
|
|
1786
|
-
|
|
1787
|
-
// escape
|
|
1788
1320
|
if (token = this.tokenizer.escape(src)) {
|
|
1789
1321
|
src = src.substring(token.raw.length);
|
|
1790
1322
|
tokens.push(token);
|
|
1791
1323
|
continue;
|
|
1792
1324
|
}
|
|
1793
|
-
|
|
1794
|
-
// tag
|
|
1795
1325
|
if (token = this.tokenizer.tag(src)) {
|
|
1796
1326
|
src = src.substring(token.raw.length);
|
|
1797
1327
|
lastToken = tokens[tokens.length - 1];
|
|
1798
|
-
if (lastToken && token.type ===
|
|
1328
|
+
if (lastToken && token.type === "text" && lastToken.type === "text") {
|
|
1799
1329
|
lastToken.raw += token.raw;
|
|
1800
1330
|
lastToken.text += token.text;
|
|
1801
1331
|
} else {
|
|
@@ -1803,19 +1333,15 @@ class Lexer {
|
|
|
1803
1333
|
}
|
|
1804
1334
|
continue;
|
|
1805
1335
|
}
|
|
1806
|
-
|
|
1807
|
-
// link
|
|
1808
1336
|
if (token = this.tokenizer.link(src)) {
|
|
1809
1337
|
src = src.substring(token.raw.length);
|
|
1810
1338
|
tokens.push(token);
|
|
1811
1339
|
continue;
|
|
1812
1340
|
}
|
|
1813
|
-
|
|
1814
|
-
// reflink, nolink
|
|
1815
1341
|
if (token = this.tokenizer.reflink(src, this.tokens.links)) {
|
|
1816
1342
|
src = src.substring(token.raw.length);
|
|
1817
1343
|
lastToken = tokens[tokens.length - 1];
|
|
1818
|
-
if (lastToken && token.type ===
|
|
1344
|
+
if (lastToken && token.type === "text" && lastToken.type === "text") {
|
|
1819
1345
|
lastToken.raw += token.raw;
|
|
1820
1346
|
lastToken.text += token.text;
|
|
1821
1347
|
} else {
|
|
@@ -1823,59 +1349,46 @@ class Lexer {
|
|
|
1823
1349
|
}
|
|
1824
1350
|
continue;
|
|
1825
1351
|
}
|
|
1826
|
-
|
|
1827
|
-
// em & strong
|
|
1828
1352
|
if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
|
|
1829
1353
|
src = src.substring(token.raw.length);
|
|
1830
1354
|
tokens.push(token);
|
|
1831
1355
|
continue;
|
|
1832
1356
|
}
|
|
1833
|
-
|
|
1834
|
-
// code
|
|
1835
1357
|
if (token = this.tokenizer.codespan(src)) {
|
|
1836
1358
|
src = src.substring(token.raw.length);
|
|
1837
1359
|
tokens.push(token);
|
|
1838
1360
|
continue;
|
|
1839
1361
|
}
|
|
1840
|
-
|
|
1841
|
-
// br
|
|
1842
1362
|
if (token = this.tokenizer.br(src)) {
|
|
1843
1363
|
src = src.substring(token.raw.length);
|
|
1844
1364
|
tokens.push(token);
|
|
1845
1365
|
continue;
|
|
1846
1366
|
}
|
|
1847
|
-
|
|
1848
|
-
// del (gfm)
|
|
1849
1367
|
if (token = this.tokenizer.del(src)) {
|
|
1850
1368
|
src = src.substring(token.raw.length);
|
|
1851
1369
|
tokens.push(token);
|
|
1852
1370
|
continue;
|
|
1853
1371
|
}
|
|
1854
|
-
|
|
1855
|
-
// autolink
|
|
1856
1372
|
if (token = this.tokenizer.autolink(src, mangle)) {
|
|
1857
1373
|
src = src.substring(token.raw.length);
|
|
1858
1374
|
tokens.push(token);
|
|
1859
1375
|
continue;
|
|
1860
1376
|
}
|
|
1861
|
-
|
|
1862
|
-
// url (gfm)
|
|
1863
1377
|
if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
|
|
1864
1378
|
src = src.substring(token.raw.length);
|
|
1865
1379
|
tokens.push(token);
|
|
1866
1380
|
continue;
|
|
1867
1381
|
}
|
|
1868
|
-
|
|
1869
|
-
// text
|
|
1870
|
-
// prevent inlineText consuming extensions by clipping 'src' to extension start
|
|
1871
1382
|
cutSrc = src;
|
|
1872
1383
|
if (this.options.extensions && this.options.extensions.startInline) {
|
|
1873
1384
|
let startIndex = Infinity;
|
|
1874
1385
|
const tempSrc = src.slice(1);
|
|
1875
1386
|
let tempStart;
|
|
1876
|
-
this.options.extensions.startInline.forEach(
|
|
1387
|
+
this.options.extensions.startInline.forEach((getStartIndex) => {
|
|
1877
1388
|
tempStart = getStartIndex.call({ lexer: this }, tempSrc);
|
|
1878
|
-
if (typeof tempStart ===
|
|
1389
|
+
if (typeof tempStart === "number" && tempStart >= 0) {
|
|
1390
|
+
startIndex = Math.min(startIndex, tempStart);
|
|
1391
|
+
}
|
|
1879
1392
|
});
|
|
1880
1393
|
if (startIndex < Infinity && startIndex >= 0) {
|
|
1881
1394
|
cutSrc = src.substring(0, startIndex + 1);
|
|
@@ -1883,12 +1396,12 @@ class Lexer {
|
|
|
1883
1396
|
}
|
|
1884
1397
|
if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
|
|
1885
1398
|
src = src.substring(token.raw.length);
|
|
1886
|
-
if (token.raw.slice(-1) !==
|
|
1399
|
+
if (token.raw.slice(-1) !== "_") {
|
|
1887
1400
|
prevChar = token.raw.slice(-1);
|
|
1888
1401
|
}
|
|
1889
1402
|
keepPrevChar = true;
|
|
1890
1403
|
lastToken = tokens[tokens.length - 1];
|
|
1891
|
-
if (lastToken && lastToken.type ===
|
|
1404
|
+
if (lastToken && lastToken.type === "text") {
|
|
1892
1405
|
lastToken.raw += token.raw;
|
|
1893
1406
|
lastToken.text += token.text;
|
|
1894
1407
|
} else {
|
|
@@ -1896,9 +1409,8 @@ class Lexer {
|
|
|
1896
1409
|
}
|
|
1897
1410
|
continue;
|
|
1898
1411
|
}
|
|
1899
|
-
|
|
1900
1412
|
if (src) {
|
|
1901
|
-
const errMsg =
|
|
1413
|
+
const errMsg = "Infinite loop on byte: " + src.charCodeAt(0);
|
|
1902
1414
|
if (this.options.silent) {
|
|
1903
1415
|
console.error(errMsg);
|
|
1904
1416
|
break;
|
|
@@ -1907,21 +1419,17 @@ class Lexer {
|
|
|
1907
1419
|
}
|
|
1908
1420
|
}
|
|
1909
1421
|
}
|
|
1910
|
-
|
|
1911
1422
|
return tokens;
|
|
1912
1423
|
}
|
|
1913
|
-
}
|
|
1424
|
+
};
|
|
1914
1425
|
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
constructor(options) {
|
|
1920
|
-
this.options = options || defaults;
|
|
1426
|
+
// src/Renderer.ts
|
|
1427
|
+
var _Renderer = class {
|
|
1428
|
+
constructor(options2) {
|
|
1429
|
+
this.options = options2 || _defaults;
|
|
1921
1430
|
}
|
|
1922
|
-
|
|
1923
1431
|
code(code, infostring, escaped) {
|
|
1924
|
-
const lang = (infostring ||
|
|
1432
|
+
const lang = (infostring || "").match(/\S*/)[0];
|
|
1925
1433
|
if (this.options.highlight) {
|
|
1926
1434
|
const out = this.options.highlight(code, lang);
|
|
1927
1435
|
if (out != null && out !== code) {
|
|
@@ -1929,150 +1437,81 @@ class Renderer {
|
|
|
1929
1437
|
code = out;
|
|
1930
1438
|
}
|
|
1931
1439
|
}
|
|
1932
|
-
|
|
1933
|
-
code = code.replace(/\n$/, '') + '\n';
|
|
1934
|
-
|
|
1440
|
+
code = code.replace(/\n$/, "") + "\n";
|
|
1935
1441
|
if (!lang) {
|
|
1936
|
-
return
|
|
1937
|
-
+ (escaped ? code : escape(code, true))
|
|
1938
|
-
+ '</code></pre>\n';
|
|
1442
|
+
return "<pre><code>" + (escaped ? code : escape(code, true)) + "</code></pre>\n";
|
|
1939
1443
|
}
|
|
1940
|
-
|
|
1941
|
-
return '<pre><code class="'
|
|
1942
|
-
+ this.options.langPrefix
|
|
1943
|
-
+ escape(lang)
|
|
1944
|
-
+ '">'
|
|
1945
|
-
+ (escaped ? code : escape(code, true))
|
|
1946
|
-
+ '</code></pre>\n';
|
|
1444
|
+
return '<pre><code class="' + this.options.langPrefix + escape(lang) + '">' + (escaped ? code : escape(code, true)) + "</code></pre>\n";
|
|
1947
1445
|
}
|
|
1948
|
-
|
|
1949
|
-
/**
|
|
1950
|
-
* @param {string} quote
|
|
1951
|
-
*/
|
|
1952
1446
|
blockquote(quote) {
|
|
1953
|
-
return `<blockquote
|
|
1447
|
+
return `<blockquote>
|
|
1448
|
+
${quote}</blockquote>
|
|
1449
|
+
`;
|
|
1954
1450
|
}
|
|
1955
|
-
|
|
1956
|
-
html(html, block) {
|
|
1451
|
+
html(html, block2) {
|
|
1957
1452
|
return html;
|
|
1958
1453
|
}
|
|
1959
|
-
|
|
1960
|
-
/**
|
|
1961
|
-
* @param {string} text
|
|
1962
|
-
* @param {string} level
|
|
1963
|
-
* @param {string} raw
|
|
1964
|
-
* @param {any} slugger
|
|
1965
|
-
*/
|
|
1966
1454
|
heading(text, level, raw, slugger) {
|
|
1967
1455
|
if (this.options.headerIds) {
|
|
1968
1456
|
const id = this.options.headerPrefix + slugger.slug(raw);
|
|
1969
|
-
return `<h${level} id="${id}">${text}</h${level}
|
|
1457
|
+
return `<h${level} id="${id}">${text}</h${level}>
|
|
1458
|
+
`;
|
|
1970
1459
|
}
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
return `<h${level}>${text}</h${level}>\n`;
|
|
1460
|
+
return `<h${level}>${text}</h${level}>
|
|
1461
|
+
`;
|
|
1974
1462
|
}
|
|
1975
|
-
|
|
1976
1463
|
hr() {
|
|
1977
|
-
return this.options.xhtml ?
|
|
1464
|
+
return this.options.xhtml ? "<hr/>\n" : "<hr>\n";
|
|
1978
1465
|
}
|
|
1979
|
-
|
|
1980
1466
|
list(body, ordered, start) {
|
|
1981
|
-
const type = ordered ?
|
|
1982
|
-
|
|
1983
|
-
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
1467
|
+
const type = ordered ? "ol" : "ul", startatt = ordered && start !== 1 ? ' start="' + start + '"' : "";
|
|
1468
|
+
return "<" + type + startatt + ">\n" + body + "</" + type + ">\n";
|
|
1984
1469
|
}
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
*/
|
|
1989
|
-
listitem(text) {
|
|
1990
|
-
return `<li>${text}</li>\n`;
|
|
1470
|
+
listitem(text, task, checked) {
|
|
1471
|
+
return `<li>${text}</li>
|
|
1472
|
+
`;
|
|
1991
1473
|
}
|
|
1992
|
-
|
|
1993
1474
|
checkbox(checked) {
|
|
1994
|
-
return
|
|
1995
|
-
+ (checked ? 'checked="" ' : '')
|
|
1996
|
-
+ 'disabled="" type="checkbox"'
|
|
1997
|
-
+ (this.options.xhtml ? ' /' : '')
|
|
1998
|
-
+ '> ';
|
|
1475
|
+
return "<input " + (checked ? 'checked="" ' : "") + 'disabled="" type="checkbox"' + (this.options.xhtml ? " /" : "") + "> ";
|
|
1999
1476
|
}
|
|
2000
|
-
|
|
2001
|
-
/**
|
|
2002
|
-
* @param {string} text
|
|
2003
|
-
*/
|
|
2004
1477
|
paragraph(text) {
|
|
2005
|
-
return `<p>${text}</p
|
|
1478
|
+
return `<p>${text}</p>
|
|
1479
|
+
`;
|
|
2006
1480
|
}
|
|
2007
|
-
|
|
2008
|
-
/**
|
|
2009
|
-
* @param {string} header
|
|
2010
|
-
* @param {string} body
|
|
2011
|
-
*/
|
|
2012
1481
|
table(header, body) {
|
|
2013
|
-
if (body)
|
|
2014
|
-
|
|
2015
|
-
return
|
|
2016
|
-
+ '<thead>\n'
|
|
2017
|
-
+ header
|
|
2018
|
-
+ '</thead>\n'
|
|
2019
|
-
+ body
|
|
2020
|
-
+ '</table>\n';
|
|
1482
|
+
if (body)
|
|
1483
|
+
body = `<tbody>${body}</tbody>`;
|
|
1484
|
+
return "<table>\n<thead>\n" + header + "</thead>\n" + body + "</table>\n";
|
|
2021
1485
|
}
|
|
2022
|
-
|
|
2023
|
-
/**
|
|
2024
|
-
* @param {string} content
|
|
2025
|
-
*/
|
|
2026
1486
|
tablerow(content) {
|
|
2027
|
-
return `<tr
|
|
1487
|
+
return `<tr>
|
|
1488
|
+
${content}</tr>
|
|
1489
|
+
`;
|
|
2028
1490
|
}
|
|
2029
|
-
|
|
2030
1491
|
tablecell(content, flags) {
|
|
2031
|
-
const type = flags.header ?
|
|
2032
|
-
const tag = flags.align
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
return tag + content + `</${type}>\n`;
|
|
1492
|
+
const type = flags.header ? "th" : "td";
|
|
1493
|
+
const tag = flags.align ? `<${type} align="${flags.align}">` : `<${type}>`;
|
|
1494
|
+
return tag + content + `</${type}>
|
|
1495
|
+
`;
|
|
2036
1496
|
}
|
|
2037
|
-
|
|
2038
1497
|
/**
|
|
2039
1498
|
* span level renderer
|
|
2040
|
-
* @param {string} text
|
|
2041
1499
|
*/
|
|
2042
1500
|
strong(text) {
|
|
2043
1501
|
return `<strong>${text}</strong>`;
|
|
2044
1502
|
}
|
|
2045
|
-
|
|
2046
|
-
/**
|
|
2047
|
-
* @param {string} text
|
|
2048
|
-
*/
|
|
2049
1503
|
em(text) {
|
|
2050
1504
|
return `<em>${text}</em>`;
|
|
2051
1505
|
}
|
|
2052
|
-
|
|
2053
|
-
/**
|
|
2054
|
-
* @param {string} text
|
|
2055
|
-
*/
|
|
2056
1506
|
codespan(text) {
|
|
2057
1507
|
return `<code>${text}</code>`;
|
|
2058
1508
|
}
|
|
2059
|
-
|
|
2060
1509
|
br() {
|
|
2061
|
-
return this.options.xhtml ?
|
|
1510
|
+
return this.options.xhtml ? "<br/>" : "<br>";
|
|
2062
1511
|
}
|
|
2063
|
-
|
|
2064
|
-
/**
|
|
2065
|
-
* @param {string} text
|
|
2066
|
-
*/
|
|
2067
1512
|
del(text) {
|
|
2068
1513
|
return `<del>${text}</del>`;
|
|
2069
1514
|
}
|
|
2070
|
-
|
|
2071
|
-
/**
|
|
2072
|
-
* @param {string} href
|
|
2073
|
-
* @param {string} title
|
|
2074
|
-
* @param {string} text
|
|
2075
|
-
*/
|
|
2076
1515
|
link(href, title, text) {
|
|
2077
1516
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
2078
1517
|
if (href === null) {
|
|
@@ -2082,103 +1521,68 @@ class Renderer {
|
|
|
2082
1521
|
if (title) {
|
|
2083
1522
|
out += ' title="' + title + '"';
|
|
2084
1523
|
}
|
|
2085
|
-
out +=
|
|
1524
|
+
out += ">" + text + "</a>";
|
|
2086
1525
|
return out;
|
|
2087
1526
|
}
|
|
2088
|
-
|
|
2089
|
-
/**
|
|
2090
|
-
* @param {string} href
|
|
2091
|
-
* @param {string} title
|
|
2092
|
-
* @param {string} text
|
|
2093
|
-
*/
|
|
2094
1527
|
image(href, title, text) {
|
|
2095
1528
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
2096
1529
|
if (href === null) {
|
|
2097
1530
|
return text;
|
|
2098
1531
|
}
|
|
2099
|
-
|
|
2100
1532
|
let out = `<img src="${href}" alt="${text}"`;
|
|
2101
1533
|
if (title) {
|
|
2102
1534
|
out += ` title="${title}"`;
|
|
2103
1535
|
}
|
|
2104
|
-
out += this.options.xhtml ?
|
|
1536
|
+
out += this.options.xhtml ? "/>" : ">";
|
|
2105
1537
|
return out;
|
|
2106
1538
|
}
|
|
2107
|
-
|
|
2108
1539
|
text(text) {
|
|
2109
1540
|
return text;
|
|
2110
1541
|
}
|
|
2111
|
-
}
|
|
1542
|
+
};
|
|
2112
1543
|
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
* returns only the textual part of the token
|
|
2116
|
-
*/
|
|
2117
|
-
class TextRenderer {
|
|
1544
|
+
// src/TextRenderer.ts
|
|
1545
|
+
var _TextRenderer = class {
|
|
2118
1546
|
// no need for block level renderers
|
|
2119
1547
|
strong(text) {
|
|
2120
1548
|
return text;
|
|
2121
1549
|
}
|
|
2122
|
-
|
|
2123
1550
|
em(text) {
|
|
2124
1551
|
return text;
|
|
2125
1552
|
}
|
|
2126
|
-
|
|
2127
1553
|
codespan(text) {
|
|
2128
1554
|
return text;
|
|
2129
1555
|
}
|
|
2130
|
-
|
|
2131
1556
|
del(text) {
|
|
2132
1557
|
return text;
|
|
2133
1558
|
}
|
|
2134
|
-
|
|
2135
1559
|
html(text) {
|
|
2136
1560
|
return text;
|
|
2137
1561
|
}
|
|
2138
|
-
|
|
2139
1562
|
text(text) {
|
|
2140
1563
|
return text;
|
|
2141
1564
|
}
|
|
2142
|
-
|
|
2143
1565
|
link(href, title, text) {
|
|
2144
|
-
return
|
|
1566
|
+
return "" + text;
|
|
2145
1567
|
}
|
|
2146
|
-
|
|
2147
1568
|
image(href, title, text) {
|
|
2148
|
-
return
|
|
1569
|
+
return "" + text;
|
|
2149
1570
|
}
|
|
2150
|
-
|
|
2151
1571
|
br() {
|
|
2152
|
-
return
|
|
1572
|
+
return "";
|
|
2153
1573
|
}
|
|
2154
|
-
}
|
|
1574
|
+
};
|
|
2155
1575
|
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
*/
|
|
2159
|
-
class Slugger {
|
|
1576
|
+
// src/Slugger.ts
|
|
1577
|
+
var _Slugger = class {
|
|
2160
1578
|
constructor() {
|
|
2161
1579
|
this.seen = {};
|
|
2162
1580
|
}
|
|
2163
|
-
|
|
2164
|
-
/**
|
|
2165
|
-
* @param {string} value
|
|
2166
|
-
*/
|
|
2167
1581
|
serialize(value) {
|
|
2168
|
-
return value
|
|
2169
|
-
.toLowerCase()
|
|
2170
|
-
.trim()
|
|
2171
|
-
// remove html tags
|
|
2172
|
-
.replace(/<[!\/a-z].*?>/ig, '')
|
|
2173
|
-
// remove unwanted chars
|
|
2174
|
-
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '')
|
|
2175
|
-
.replace(/\s/g, '-');
|
|
1582
|
+
return value.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig, "").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, "").replace(/\s/g, "-");
|
|
2176
1583
|
}
|
|
2177
|
-
|
|
2178
1584
|
/**
|
|
2179
1585
|
* Finds the next safe (unique) slug to use
|
|
2180
|
-
* @param {string} originalSlug
|
|
2181
|
-
* @param {boolean} isDryRun
|
|
2182
1586
|
*/
|
|
2183
1587
|
getNextSafeSlug(originalSlug, isDryRun) {
|
|
2184
1588
|
let slug = originalSlug;
|
|
@@ -2187,7 +1591,7 @@ class Slugger {
|
|
|
2187
1591
|
occurenceAccumulator = this.seen[originalSlug];
|
|
2188
1592
|
do {
|
|
2189
1593
|
occurenceAccumulator++;
|
|
2190
|
-
slug = originalSlug +
|
|
1594
|
+
slug = originalSlug + "-" + occurenceAccumulator;
|
|
2191
1595
|
} while (this.seen.hasOwnProperty(slug));
|
|
2192
1596
|
}
|
|
2193
1597
|
if (!isDryRun) {
|
|
@@ -2196,113 +1600,82 @@ class Slugger {
|
|
|
2196
1600
|
}
|
|
2197
1601
|
return slug;
|
|
2198
1602
|
}
|
|
2199
|
-
|
|
2200
1603
|
/**
|
|
2201
1604
|
* Convert string to unique id
|
|
2202
|
-
* @param {object} [options]
|
|
2203
|
-
* @param {boolean} [options.dryrun] Generates the next unique slug without
|
|
2204
|
-
* updating the internal accumulator.
|
|
2205
1605
|
*/
|
|
2206
|
-
slug(value,
|
|
1606
|
+
slug(value, options2 = {}) {
|
|
2207
1607
|
const slug = this.serialize(value);
|
|
2208
|
-
return this.getNextSafeSlug(slug,
|
|
1608
|
+
return this.getNextSafeSlug(slug, options2.dryrun);
|
|
2209
1609
|
}
|
|
2210
|
-
}
|
|
1610
|
+
};
|
|
2211
1611
|
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
this.options = options || defaults;
|
|
2218
|
-
this.options.renderer = this.options.renderer || new Renderer();
|
|
1612
|
+
// src/Parser.ts
|
|
1613
|
+
var _Parser = class __Parser {
|
|
1614
|
+
constructor(options2) {
|
|
1615
|
+
this.options = options2 || _defaults;
|
|
1616
|
+
this.options.renderer = this.options.renderer || new _Renderer();
|
|
2219
1617
|
this.renderer = this.options.renderer;
|
|
2220
1618
|
this.renderer.options = this.options;
|
|
2221
|
-
this.textRenderer = new
|
|
2222
|
-
this.slugger = new
|
|
1619
|
+
this.textRenderer = new _TextRenderer();
|
|
1620
|
+
this.slugger = new _Slugger();
|
|
2223
1621
|
}
|
|
2224
|
-
|
|
2225
1622
|
/**
|
|
2226
1623
|
* Static Parse Method
|
|
2227
1624
|
*/
|
|
2228
|
-
static parse(tokens,
|
|
2229
|
-
const
|
|
2230
|
-
return
|
|
1625
|
+
static parse(tokens, options2) {
|
|
1626
|
+
const parser2 = new __Parser(options2);
|
|
1627
|
+
return parser2.parse(tokens);
|
|
2231
1628
|
}
|
|
2232
|
-
|
|
2233
1629
|
/**
|
|
2234
1630
|
* Static Parse Inline Method
|
|
2235
1631
|
*/
|
|
2236
|
-
static parseInline(tokens,
|
|
2237
|
-
const
|
|
2238
|
-
return
|
|
1632
|
+
static parseInline(tokens, options2) {
|
|
1633
|
+
const parser2 = new __Parser(options2);
|
|
1634
|
+
return parser2.parseInline(tokens);
|
|
2239
1635
|
}
|
|
2240
|
-
|
|
2241
1636
|
/**
|
|
2242
1637
|
* Parse Loop
|
|
2243
1638
|
*/
|
|
2244
1639
|
parse(tokens, top = true) {
|
|
2245
|
-
let out =
|
|
2246
|
-
i,
|
|
2247
|
-
j,
|
|
2248
|
-
k,
|
|
2249
|
-
l2,
|
|
2250
|
-
l3,
|
|
2251
|
-
row,
|
|
2252
|
-
cell,
|
|
2253
|
-
header,
|
|
2254
|
-
body,
|
|
2255
|
-
token,
|
|
2256
|
-
ordered,
|
|
2257
|
-
start,
|
|
2258
|
-
loose,
|
|
2259
|
-
itemBody,
|
|
2260
|
-
item,
|
|
2261
|
-
checked,
|
|
2262
|
-
task,
|
|
2263
|
-
checkbox,
|
|
2264
|
-
ret;
|
|
2265
|
-
|
|
1640
|
+
let out = "", i, j, k, l2, l3, row, cell, header, body, token, ordered, start, loose, itemBody, item, checked, task, checkbox, ret;
|
|
2266
1641
|
const l = tokens.length;
|
|
2267
1642
|
for (i = 0; i < l; i++) {
|
|
2268
1643
|
token = tokens[i];
|
|
2269
|
-
|
|
2270
|
-
// Run any renderer extensions
|
|
2271
1644
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2272
1645
|
ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
|
|
2273
|
-
if (ret !== false || ![
|
|
2274
|
-
out += ret ||
|
|
1646
|
+
if (ret !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(token.type)) {
|
|
1647
|
+
out += ret || "";
|
|
2275
1648
|
continue;
|
|
2276
1649
|
}
|
|
2277
1650
|
}
|
|
2278
|
-
|
|
2279
1651
|
switch (token.type) {
|
|
2280
|
-
case
|
|
1652
|
+
case "space": {
|
|
2281
1653
|
continue;
|
|
2282
1654
|
}
|
|
2283
|
-
case
|
|
1655
|
+
case "hr": {
|
|
2284
1656
|
out += this.renderer.hr();
|
|
2285
1657
|
continue;
|
|
2286
1658
|
}
|
|
2287
|
-
case
|
|
1659
|
+
case "heading": {
|
|
2288
1660
|
out += this.renderer.heading(
|
|
2289
1661
|
this.parseInline(token.tokens),
|
|
2290
1662
|
token.depth,
|
|
2291
1663
|
unescape(this.parseInline(token.tokens, this.textRenderer)),
|
|
2292
|
-
this.slugger
|
|
1664
|
+
this.slugger
|
|
1665
|
+
);
|
|
2293
1666
|
continue;
|
|
2294
1667
|
}
|
|
2295
|
-
case
|
|
2296
|
-
out += this.renderer.code(
|
|
1668
|
+
case "code": {
|
|
1669
|
+
out += this.renderer.code(
|
|
1670
|
+
token.text,
|
|
2297
1671
|
token.lang,
|
|
2298
|
-
token.escaped
|
|
1672
|
+
!!token.escaped
|
|
1673
|
+
);
|
|
2299
1674
|
continue;
|
|
2300
1675
|
}
|
|
2301
|
-
case
|
|
2302
|
-
header =
|
|
2303
|
-
|
|
2304
|
-
// header
|
|
2305
|
-
cell = '';
|
|
1676
|
+
case "table": {
|
|
1677
|
+
header = "";
|
|
1678
|
+
cell = "";
|
|
2306
1679
|
l2 = token.header.length;
|
|
2307
1680
|
for (j = 0; j < l2; j++) {
|
|
2308
1681
|
cell += this.renderer.tablecell(
|
|
@@ -2311,13 +1684,11 @@ class Parser {
|
|
|
2311
1684
|
);
|
|
2312
1685
|
}
|
|
2313
1686
|
header += this.renderer.tablerow(cell);
|
|
2314
|
-
|
|
2315
|
-
body = '';
|
|
1687
|
+
body = "";
|
|
2316
1688
|
l2 = token.rows.length;
|
|
2317
1689
|
for (j = 0; j < l2; j++) {
|
|
2318
1690
|
row = token.rows[j];
|
|
2319
|
-
|
|
2320
|
-
cell = '';
|
|
1691
|
+
cell = "";
|
|
2321
1692
|
l3 = row.length;
|
|
2322
1693
|
for (k = 0; k < l3; k++) {
|
|
2323
1694
|
cell += this.renderer.tablecell(
|
|
@@ -2325,41 +1696,38 @@ class Parser {
|
|
|
2325
1696
|
{ header: false, align: token.align[k] }
|
|
2326
1697
|
);
|
|
2327
1698
|
}
|
|
2328
|
-
|
|
2329
1699
|
body += this.renderer.tablerow(cell);
|
|
2330
1700
|
}
|
|
2331
1701
|
out += this.renderer.table(header, body);
|
|
2332
1702
|
continue;
|
|
2333
1703
|
}
|
|
2334
|
-
case
|
|
1704
|
+
case "blockquote": {
|
|
2335
1705
|
body = this.parse(token.tokens);
|
|
2336
1706
|
out += this.renderer.blockquote(body);
|
|
2337
1707
|
continue;
|
|
2338
1708
|
}
|
|
2339
|
-
case
|
|
1709
|
+
case "list": {
|
|
2340
1710
|
ordered = token.ordered;
|
|
2341
1711
|
start = token.start;
|
|
2342
1712
|
loose = token.loose;
|
|
2343
1713
|
l2 = token.items.length;
|
|
2344
|
-
|
|
2345
|
-
body = '';
|
|
1714
|
+
body = "";
|
|
2346
1715
|
for (j = 0; j < l2; j++) {
|
|
2347
1716
|
item = token.items[j];
|
|
2348
1717
|
checked = item.checked;
|
|
2349
1718
|
task = item.task;
|
|
2350
|
-
|
|
2351
|
-
itemBody = '';
|
|
1719
|
+
itemBody = "";
|
|
2352
1720
|
if (item.task) {
|
|
2353
|
-
checkbox = this.renderer.checkbox(checked);
|
|
1721
|
+
checkbox = this.renderer.checkbox(!!checked);
|
|
2354
1722
|
if (loose) {
|
|
2355
|
-
if (item.tokens.length > 0 && item.tokens[0].type ===
|
|
2356
|
-
item.tokens[0].text = checkbox +
|
|
2357
|
-
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type ===
|
|
2358
|
-
item.tokens[0].tokens[0].text = checkbox +
|
|
1723
|
+
if (item.tokens.length > 0 && item.tokens[0].type === "paragraph") {
|
|
1724
|
+
item.tokens[0].text = checkbox + " " + item.tokens[0].text;
|
|
1725
|
+
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === "text") {
|
|
1726
|
+
item.tokens[0].tokens[0].text = checkbox + " " + item.tokens[0].tokens[0].text;
|
|
2359
1727
|
}
|
|
2360
1728
|
} else {
|
|
2361
1729
|
item.tokens.unshift({
|
|
2362
|
-
type:
|
|
1730
|
+
type: "text",
|
|
2363
1731
|
text: checkbox
|
|
2364
1732
|
});
|
|
2365
1733
|
}
|
|
@@ -2367,108 +1735,96 @@ class Parser {
|
|
|
2367
1735
|
itemBody += checkbox;
|
|
2368
1736
|
}
|
|
2369
1737
|
}
|
|
2370
|
-
|
|
2371
1738
|
itemBody += this.parse(item.tokens, loose);
|
|
2372
|
-
body += this.renderer.listitem(itemBody, task, checked);
|
|
1739
|
+
body += this.renderer.listitem(itemBody, task, !!checked);
|
|
2373
1740
|
}
|
|
2374
|
-
|
|
2375
1741
|
out += this.renderer.list(body, ordered, start);
|
|
2376
1742
|
continue;
|
|
2377
1743
|
}
|
|
2378
|
-
case
|
|
1744
|
+
case "html": {
|
|
2379
1745
|
out += this.renderer.html(token.text, token.block);
|
|
2380
1746
|
continue;
|
|
2381
1747
|
}
|
|
2382
|
-
case
|
|
1748
|
+
case "paragraph": {
|
|
2383
1749
|
out += this.renderer.paragraph(this.parseInline(token.tokens));
|
|
2384
1750
|
continue;
|
|
2385
1751
|
}
|
|
2386
|
-
case
|
|
1752
|
+
case "text": {
|
|
2387
1753
|
body = token.tokens ? this.parseInline(token.tokens) : token.text;
|
|
2388
|
-
while (i + 1 < l && tokens[i + 1].type ===
|
|
1754
|
+
while (i + 1 < l && tokens[i + 1].type === "text") {
|
|
2389
1755
|
token = tokens[++i];
|
|
2390
|
-
body +=
|
|
1756
|
+
body += "\n" + (token.tokens ? this.parseInline(token.tokens) : token.text);
|
|
2391
1757
|
}
|
|
2392
1758
|
out += top ? this.renderer.paragraph(body) : body;
|
|
2393
1759
|
continue;
|
|
2394
1760
|
}
|
|
2395
|
-
|
|
2396
1761
|
default: {
|
|
2397
1762
|
const errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2398
1763
|
if (this.options.silent) {
|
|
2399
1764
|
console.error(errMsg);
|
|
2400
|
-
return;
|
|
1765
|
+
return "";
|
|
2401
1766
|
} else {
|
|
2402
1767
|
throw new Error(errMsg);
|
|
2403
1768
|
}
|
|
2404
1769
|
}
|
|
2405
1770
|
}
|
|
2406
1771
|
}
|
|
2407
|
-
|
|
2408
1772
|
return out;
|
|
2409
1773
|
}
|
|
2410
|
-
|
|
2411
1774
|
/**
|
|
2412
1775
|
* Parse Inline Tokens
|
|
2413
1776
|
*/
|
|
2414
1777
|
parseInline(tokens, renderer) {
|
|
2415
1778
|
renderer = renderer || this.renderer;
|
|
2416
|
-
let out =
|
|
2417
|
-
i,
|
|
2418
|
-
token,
|
|
2419
|
-
ret;
|
|
2420
|
-
|
|
1779
|
+
let out = "", i, token, ret;
|
|
2421
1780
|
const l = tokens.length;
|
|
2422
1781
|
for (i = 0; i < l; i++) {
|
|
2423
1782
|
token = tokens[i];
|
|
2424
|
-
|
|
2425
|
-
// Run any renderer extensions
|
|
2426
1783
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2427
1784
|
ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
|
|
2428
|
-
if (ret !== false || ![
|
|
2429
|
-
out += ret ||
|
|
1785
|
+
if (ret !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(token.type)) {
|
|
1786
|
+
out += ret || "";
|
|
2430
1787
|
continue;
|
|
2431
1788
|
}
|
|
2432
1789
|
}
|
|
2433
|
-
|
|
2434
1790
|
switch (token.type) {
|
|
2435
|
-
case
|
|
1791
|
+
case "escape": {
|
|
2436
1792
|
out += renderer.text(token.text);
|
|
2437
1793
|
break;
|
|
2438
1794
|
}
|
|
2439
|
-
case
|
|
1795
|
+
case "html": {
|
|
2440
1796
|
out += renderer.html(token.text);
|
|
2441
1797
|
break;
|
|
2442
1798
|
}
|
|
2443
|
-
case
|
|
1799
|
+
case "link": {
|
|
2444
1800
|
out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
|
|
2445
1801
|
break;
|
|
2446
1802
|
}
|
|
2447
|
-
case
|
|
1803
|
+
case "image": {
|
|
2448
1804
|
out += renderer.image(token.href, token.title, token.text);
|
|
2449
1805
|
break;
|
|
2450
1806
|
}
|
|
2451
|
-
case
|
|
1807
|
+
case "strong": {
|
|
2452
1808
|
out += renderer.strong(this.parseInline(token.tokens, renderer));
|
|
2453
1809
|
break;
|
|
2454
1810
|
}
|
|
2455
|
-
case
|
|
1811
|
+
case "em": {
|
|
2456
1812
|
out += renderer.em(this.parseInline(token.tokens, renderer));
|
|
2457
1813
|
break;
|
|
2458
1814
|
}
|
|
2459
|
-
case
|
|
1815
|
+
case "codespan": {
|
|
2460
1816
|
out += renderer.codespan(token.text);
|
|
2461
1817
|
break;
|
|
2462
1818
|
}
|
|
2463
|
-
case
|
|
1819
|
+
case "br": {
|
|
2464
1820
|
out += renderer.br();
|
|
2465
1821
|
break;
|
|
2466
1822
|
}
|
|
2467
|
-
case
|
|
1823
|
+
case "del": {
|
|
2468
1824
|
out += renderer.del(this.parseInline(token.tokens, renderer));
|
|
2469
1825
|
break;
|
|
2470
1826
|
}
|
|
2471
|
-
case
|
|
1827
|
+
case "text": {
|
|
2472
1828
|
out += renderer.text(token.text);
|
|
2473
1829
|
break;
|
|
2474
1830
|
}
|
|
@@ -2476,7 +1832,7 @@ class Parser {
|
|
|
2476
1832
|
const errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2477
1833
|
if (this.options.silent) {
|
|
2478
1834
|
console.error(errMsg);
|
|
2479
|
-
return;
|
|
1835
|
+
return "";
|
|
2480
1836
|
} else {
|
|
2481
1837
|
throw new Error(errMsg);
|
|
2482
1838
|
}
|
|
@@ -2485,60 +1841,61 @@ class Parser {
|
|
|
2485
1841
|
}
|
|
2486
1842
|
return out;
|
|
2487
1843
|
}
|
|
2488
|
-
}
|
|
1844
|
+
};
|
|
2489
1845
|
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
1846
|
+
// src/Hooks.ts
|
|
1847
|
+
var _Hooks = class {
|
|
1848
|
+
constructor(options2) {
|
|
1849
|
+
this.options = options2 || _defaults;
|
|
2493
1850
|
}
|
|
2494
|
-
|
|
2495
|
-
static passThroughHooks = new Set([
|
|
2496
|
-
'preprocess',
|
|
2497
|
-
'postprocess'
|
|
2498
|
-
]);
|
|
2499
|
-
|
|
2500
1851
|
/**
|
|
2501
1852
|
* Process markdown before marked
|
|
2502
1853
|
*/
|
|
2503
1854
|
preprocess(markdown) {
|
|
2504
1855
|
return markdown;
|
|
2505
1856
|
}
|
|
2506
|
-
|
|
2507
1857
|
/**
|
|
2508
1858
|
* Process HTML after marked is finished
|
|
2509
1859
|
*/
|
|
2510
1860
|
postprocess(html) {
|
|
2511
1861
|
return html;
|
|
2512
1862
|
}
|
|
2513
|
-
}
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
Parser = Parser;
|
|
2523
|
-
parser = Parser.parse;
|
|
2524
|
-
Renderer = Renderer;
|
|
2525
|
-
TextRenderer = TextRenderer;
|
|
2526
|
-
Lexer = Lexer;
|
|
2527
|
-
lexer = Lexer.lex;
|
|
2528
|
-
Tokenizer = Tokenizer;
|
|
2529
|
-
Slugger = Slugger;
|
|
2530
|
-
Hooks = Hooks;
|
|
2531
|
-
|
|
1863
|
+
};
|
|
1864
|
+
_Hooks.passThroughHooks = /* @__PURE__ */ new Set([
|
|
1865
|
+
"preprocess",
|
|
1866
|
+
"postprocess"
|
|
1867
|
+
]);
|
|
1868
|
+
|
|
1869
|
+
// src/Instance.ts
|
|
1870
|
+
var _parseMarkdown, parseMarkdown_fn, _onError, onError_fn;
|
|
1871
|
+
var Marked = class {
|
|
2532
1872
|
constructor(...args) {
|
|
1873
|
+
__privateAdd(this, _parseMarkdown);
|
|
1874
|
+
__privateAdd(this, _onError);
|
|
1875
|
+
this.defaults = _getDefaults();
|
|
1876
|
+
this.options = this.setOptions;
|
|
1877
|
+
this.parse = __privateMethod(this, _parseMarkdown, parseMarkdown_fn).call(this, _Lexer2.lex, _Parser.parse);
|
|
1878
|
+
this.parseInline = __privateMethod(this, _parseMarkdown, parseMarkdown_fn).call(this, _Lexer2.lexInline, _Parser.parseInline);
|
|
1879
|
+
this.Parser = _Parser;
|
|
1880
|
+
this.parser = _Parser.parse;
|
|
1881
|
+
this.Renderer = _Renderer;
|
|
1882
|
+
this.TextRenderer = _TextRenderer;
|
|
1883
|
+
this.Lexer = _Lexer2;
|
|
1884
|
+
this.lexer = _Lexer2.lex;
|
|
1885
|
+
this.Tokenizer = _Tokenizer;
|
|
1886
|
+
this.Slugger = _Slugger;
|
|
1887
|
+
this.Hooks = _Hooks;
|
|
2533
1888
|
this.use(...args);
|
|
2534
1889
|
}
|
|
2535
|
-
|
|
1890
|
+
/**
|
|
1891
|
+
* Run callback for every token
|
|
1892
|
+
*/
|
|
2536
1893
|
walkTokens(tokens, callback) {
|
|
2537
1894
|
let values = [];
|
|
2538
1895
|
for (const token of tokens) {
|
|
2539
1896
|
values = values.concat(callback.call(this, token));
|
|
2540
1897
|
switch (token.type) {
|
|
2541
|
-
case
|
|
1898
|
+
case "table": {
|
|
2542
1899
|
for (const cell of token.header) {
|
|
2543
1900
|
values = values.concat(this.walkTokens(cell.tokens, callback));
|
|
2544
1901
|
}
|
|
@@ -2549,12 +1906,12 @@ class Marked {
|
|
|
2549
1906
|
}
|
|
2550
1907
|
break;
|
|
2551
1908
|
}
|
|
2552
|
-
case
|
|
1909
|
+
case "list": {
|
|
2553
1910
|
values = values.concat(this.walkTokens(token.items, callback));
|
|
2554
1911
|
break;
|
|
2555
1912
|
}
|
|
2556
1913
|
default: {
|
|
2557
|
-
if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) {
|
|
1914
|
+
if (this.defaults.extensions && this.defaults.extensions.childTokens && this.defaults.extensions.childTokens[token.type]) {
|
|
2558
1915
|
this.defaults.extensions.childTokens[token.type].forEach((childTokens) => {
|
|
2559
1916
|
values = values.concat(this.walkTokens(token[childTokens], callback));
|
|
2560
1917
|
});
|
|
@@ -2566,31 +1923,23 @@ class Marked {
|
|
|
2566
1923
|
}
|
|
2567
1924
|
return values;
|
|
2568
1925
|
}
|
|
2569
|
-
|
|
2570
1926
|
use(...args) {
|
|
2571
1927
|
const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
2572
|
-
|
|
2573
1928
|
args.forEach((pack) => {
|
|
2574
|
-
// copy options to new object
|
|
2575
1929
|
const opts = { ...pack };
|
|
2576
|
-
|
|
2577
|
-
// set async to true if it was set to true before
|
|
2578
1930
|
opts.async = this.defaults.async || opts.async || false;
|
|
2579
|
-
|
|
2580
|
-
// ==-- Parse "addon" extensions --== //
|
|
2581
1931
|
if (pack.extensions) {
|
|
2582
1932
|
pack.extensions.forEach((ext) => {
|
|
2583
1933
|
if (!ext.name) {
|
|
2584
|
-
throw new Error(
|
|
1934
|
+
throw new Error("extension name required");
|
|
2585
1935
|
}
|
|
2586
|
-
if (ext
|
|
1936
|
+
if ("renderer" in ext) {
|
|
2587
1937
|
const prevRenderer = extensions.renderers[ext.name];
|
|
2588
1938
|
if (prevRenderer) {
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
let ret = ext.renderer.apply(this, args);
|
|
1939
|
+
extensions.renderers[ext.name] = function(...args2) {
|
|
1940
|
+
let ret = ext.renderer.apply(this, args2);
|
|
2592
1941
|
if (ret === false) {
|
|
2593
|
-
ret = prevRenderer.apply(this,
|
|
1942
|
+
ret = prevRenderer.apply(this, args2);
|
|
2594
1943
|
}
|
|
2595
1944
|
return ret;
|
|
2596
1945
|
};
|
|
@@ -2598,8 +1947,8 @@ class Marked {
|
|
|
2598
1947
|
extensions.renderers[ext.name] = ext.renderer;
|
|
2599
1948
|
}
|
|
2600
1949
|
}
|
|
2601
|
-
if (ext
|
|
2602
|
-
if (!ext.level ||
|
|
1950
|
+
if ("tokenizer" in ext) {
|
|
1951
|
+
if (!ext.level || ext.level !== "block" && ext.level !== "inline") {
|
|
2603
1952
|
throw new Error("extension level must be 'block' or 'inline'");
|
|
2604
1953
|
}
|
|
2605
1954
|
if (extensions[ext.level]) {
|
|
@@ -2607,14 +1956,14 @@ class Marked {
|
|
|
2607
1956
|
} else {
|
|
2608
1957
|
extensions[ext.level] = [ext.tokenizer];
|
|
2609
1958
|
}
|
|
2610
|
-
if (ext.start) {
|
|
2611
|
-
if (ext.level ===
|
|
1959
|
+
if (ext.start) {
|
|
1960
|
+
if (ext.level === "block") {
|
|
2612
1961
|
if (extensions.startBlock) {
|
|
2613
1962
|
extensions.startBlock.push(ext.start);
|
|
2614
1963
|
} else {
|
|
2615
1964
|
extensions.startBlock = [ext.start];
|
|
2616
1965
|
}
|
|
2617
|
-
} else if (ext.level ===
|
|
1966
|
+
} else if (ext.level === "inline") {
|
|
2618
1967
|
if (extensions.startInline) {
|
|
2619
1968
|
extensions.startInline.push(ext.start);
|
|
2620
1969
|
} else {
|
|
@@ -2623,23 +1972,20 @@ class Marked {
|
|
|
2623
1972
|
}
|
|
2624
1973
|
}
|
|
2625
1974
|
}
|
|
2626
|
-
if (ext.childTokens) {
|
|
1975
|
+
if ("childTokens" in ext && ext.childTokens) {
|
|
2627
1976
|
extensions.childTokens[ext.name] = ext.childTokens;
|
|
2628
1977
|
}
|
|
2629
1978
|
});
|
|
2630
1979
|
opts.extensions = extensions;
|
|
2631
1980
|
}
|
|
2632
|
-
|
|
2633
|
-
// ==-- Parse "overwrite" extensions --== //
|
|
2634
1981
|
if (pack.renderer) {
|
|
2635
|
-
const renderer = this.defaults.renderer || new
|
|
1982
|
+
const renderer = this.defaults.renderer || new _Renderer(this.defaults);
|
|
2636
1983
|
for (const prop in pack.renderer) {
|
|
2637
1984
|
const prevRenderer = renderer[prop];
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
let ret = pack.renderer[prop].apply(renderer, args);
|
|
1985
|
+
renderer[prop] = (...args2) => {
|
|
1986
|
+
let ret = pack.renderer[prop].apply(renderer, args2);
|
|
2641
1987
|
if (ret === false) {
|
|
2642
|
-
ret = prevRenderer.apply(renderer,
|
|
1988
|
+
ret = prevRenderer.apply(renderer, args2);
|
|
2643
1989
|
}
|
|
2644
1990
|
return ret;
|
|
2645
1991
|
};
|
|
@@ -2647,42 +1993,38 @@ class Marked {
|
|
|
2647
1993
|
opts.renderer = renderer;
|
|
2648
1994
|
}
|
|
2649
1995
|
if (pack.tokenizer) {
|
|
2650
|
-
const tokenizer = this.defaults.tokenizer || new
|
|
1996
|
+
const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
|
|
2651
1997
|
for (const prop in pack.tokenizer) {
|
|
2652
1998
|
const prevTokenizer = tokenizer[prop];
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
let ret = pack.tokenizer[prop].apply(tokenizer, args);
|
|
1999
|
+
tokenizer[prop] = (...args2) => {
|
|
2000
|
+
let ret = pack.tokenizer[prop].apply(tokenizer, args2);
|
|
2656
2001
|
if (ret === false) {
|
|
2657
|
-
ret = prevTokenizer.apply(tokenizer,
|
|
2002
|
+
ret = prevTokenizer.apply(tokenizer, args2);
|
|
2658
2003
|
}
|
|
2659
2004
|
return ret;
|
|
2660
2005
|
};
|
|
2661
2006
|
}
|
|
2662
2007
|
opts.tokenizer = tokenizer;
|
|
2663
2008
|
}
|
|
2664
|
-
|
|
2665
|
-
// ==-- Parse Hooks extensions --== //
|
|
2666
2009
|
if (pack.hooks) {
|
|
2667
|
-
const hooks = this.defaults.hooks || new
|
|
2010
|
+
const hooks = this.defaults.hooks || new _Hooks();
|
|
2668
2011
|
for (const prop in pack.hooks) {
|
|
2669
2012
|
const prevHook = hooks[prop];
|
|
2670
|
-
if (
|
|
2013
|
+
if (_Hooks.passThroughHooks.has(prop)) {
|
|
2671
2014
|
hooks[prop] = (arg) => {
|
|
2672
2015
|
if (this.defaults.async) {
|
|
2673
|
-
return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then(
|
|
2674
|
-
return prevHook.call(hooks,
|
|
2016
|
+
return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then((ret2) => {
|
|
2017
|
+
return prevHook.call(hooks, ret2);
|
|
2675
2018
|
});
|
|
2676
2019
|
}
|
|
2677
|
-
|
|
2678
2020
|
const ret = pack.hooks[prop].call(hooks, arg);
|
|
2679
2021
|
return prevHook.call(hooks, ret);
|
|
2680
2022
|
};
|
|
2681
2023
|
} else {
|
|
2682
|
-
hooks[prop] = (...
|
|
2683
|
-
let ret = pack.hooks[prop].apply(hooks,
|
|
2024
|
+
hooks[prop] = (...args2) => {
|
|
2025
|
+
let ret = pack.hooks[prop].apply(hooks, args2);
|
|
2684
2026
|
if (ret === false) {
|
|
2685
|
-
ret = prevHook.apply(hooks,
|
|
2027
|
+
ret = prevHook.apply(hooks, args2);
|
|
2686
2028
|
}
|
|
2687
2029
|
return ret;
|
|
2688
2030
|
};
|
|
@@ -2690,261 +2032,214 @@ class Marked {
|
|
|
2690
2032
|
}
|
|
2691
2033
|
opts.hooks = hooks;
|
|
2692
2034
|
}
|
|
2693
|
-
|
|
2694
|
-
// ==-- Parse WalkTokens extensions --== //
|
|
2695
2035
|
if (pack.walkTokens) {
|
|
2696
|
-
const
|
|
2036
|
+
const walkTokens2 = this.defaults.walkTokens;
|
|
2697
2037
|
opts.walkTokens = function(token) {
|
|
2698
2038
|
let values = [];
|
|
2699
2039
|
values.push(pack.walkTokens.call(this, token));
|
|
2700
|
-
if (
|
|
2701
|
-
values = values.concat(
|
|
2040
|
+
if (walkTokens2) {
|
|
2041
|
+
values = values.concat(walkTokens2.call(this, token));
|
|
2702
2042
|
}
|
|
2703
2043
|
return values;
|
|
2704
2044
|
};
|
|
2705
2045
|
}
|
|
2706
|
-
|
|
2707
2046
|
this.defaults = { ...this.defaults, ...opts };
|
|
2708
2047
|
});
|
|
2709
|
-
|
|
2710
2048
|
return this;
|
|
2711
2049
|
}
|
|
2712
|
-
|
|
2713
2050
|
setOptions(opt) {
|
|
2714
2051
|
this.defaults = { ...this.defaults, ...opt };
|
|
2715
2052
|
return this;
|
|
2716
2053
|
}
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2054
|
+
};
|
|
2055
|
+
_parseMarkdown = new WeakSet();
|
|
2056
|
+
parseMarkdown_fn = function(lexer2, parser2) {
|
|
2057
|
+
return (src, optOrCallback, callback) => {
|
|
2058
|
+
if (typeof optOrCallback === "function") {
|
|
2059
|
+
callback = optOrCallback;
|
|
2060
|
+
optOrCallback = null;
|
|
2061
|
+
}
|
|
2062
|
+
const origOpt = { ...optOrCallback };
|
|
2063
|
+
const opt = { ...this.defaults, ...origOpt };
|
|
2064
|
+
const throwError = __privateMethod(this, _onError, onError_fn).call(this, !!opt.silent, !!opt.async, callback);
|
|
2065
|
+
if (typeof src === "undefined" || src === null) {
|
|
2066
|
+
return throwError(new Error("marked(): input parameter is undefined or null"));
|
|
2067
|
+
}
|
|
2068
|
+
if (typeof src !== "string") {
|
|
2069
|
+
return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
|
|
2070
|
+
}
|
|
2071
|
+
checkDeprecations(opt, callback);
|
|
2072
|
+
if (opt.hooks) {
|
|
2073
|
+
opt.hooks.options = opt;
|
|
2074
|
+
}
|
|
2075
|
+
if (callback) {
|
|
2076
|
+
const highlight = opt.highlight;
|
|
2077
|
+
let tokens;
|
|
2078
|
+
try {
|
|
2079
|
+
if (opt.hooks) {
|
|
2080
|
+
src = opt.hooks.preprocess(src);
|
|
2081
|
+
}
|
|
2082
|
+
tokens = lexer2(src, opt);
|
|
2083
|
+
} catch (e) {
|
|
2084
|
+
return throwError(e);
|
|
2742
2085
|
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2086
|
+
const done = (err) => {
|
|
2087
|
+
let out;
|
|
2088
|
+
if (!err) {
|
|
2089
|
+
try {
|
|
2090
|
+
if (opt.walkTokens) {
|
|
2091
|
+
this.walkTokens(tokens, opt.walkTokens);
|
|
2092
|
+
}
|
|
2093
|
+
out = parser2(tokens, opt);
|
|
2094
|
+
if (opt.hooks) {
|
|
2095
|
+
out = opt.hooks.postprocess(out);
|
|
2096
|
+
}
|
|
2097
|
+
} catch (e) {
|
|
2098
|
+
err = e;
|
|
2751
2099
|
}
|
|
2752
|
-
tokens = lexer(src, opt);
|
|
2753
|
-
} catch (e) {
|
|
2754
|
-
return throwError(e);
|
|
2755
2100
|
}
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2101
|
+
opt.highlight = highlight;
|
|
2102
|
+
return err ? throwError(err) : callback(null, out);
|
|
2103
|
+
};
|
|
2104
|
+
if (!highlight || highlight.length < 3) {
|
|
2105
|
+
return done();
|
|
2106
|
+
}
|
|
2107
|
+
delete opt.highlight;
|
|
2108
|
+
if (!tokens.length)
|
|
2109
|
+
return done();
|
|
2110
|
+
let pending = 0;
|
|
2111
|
+
this.walkTokens(tokens, (token) => {
|
|
2112
|
+
if (token.type === "code") {
|
|
2113
|
+
pending++;
|
|
2114
|
+
setTimeout(() => {
|
|
2115
|
+
highlight(token.text, token.lang, (err, code) => {
|
|
2116
|
+
if (err) {
|
|
2117
|
+
return done(err);
|
|
2764
2118
|
}
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2119
|
+
if (code != null && code !== token.text) {
|
|
2120
|
+
token.text = code;
|
|
2121
|
+
token.escaped = true;
|
|
2768
2122
|
}
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
return err
|
|
2777
|
-
? throwError(err)
|
|
2778
|
-
: callback(null, out);
|
|
2779
|
-
};
|
|
2780
|
-
|
|
2781
|
-
if (!highlight || highlight.length < 3) {
|
|
2782
|
-
return done();
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
delete opt.highlight;
|
|
2786
|
-
|
|
2787
|
-
if (!tokens.length) return done();
|
|
2788
|
-
|
|
2789
|
-
let pending = 0;
|
|
2790
|
-
this.walkTokens(tokens, (token) => {
|
|
2791
|
-
if (token.type === 'code') {
|
|
2792
|
-
pending++;
|
|
2793
|
-
setTimeout(() => {
|
|
2794
|
-
highlight(token.text, token.lang, (err, code) => {
|
|
2795
|
-
if (err) {
|
|
2796
|
-
return done(err);
|
|
2797
|
-
}
|
|
2798
|
-
if (code != null && code !== token.text) {
|
|
2799
|
-
token.text = code;
|
|
2800
|
-
token.escaped = true;
|
|
2801
|
-
}
|
|
2802
|
-
|
|
2803
|
-
pending--;
|
|
2804
|
-
if (pending === 0) {
|
|
2805
|
-
done();
|
|
2806
|
-
}
|
|
2807
|
-
});
|
|
2808
|
-
}, 0);
|
|
2809
|
-
}
|
|
2810
|
-
});
|
|
2811
|
-
|
|
2812
|
-
if (pending === 0) {
|
|
2813
|
-
done();
|
|
2123
|
+
pending--;
|
|
2124
|
+
if (pending === 0) {
|
|
2125
|
+
done();
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
}, 0);
|
|
2814
2129
|
}
|
|
2815
|
-
|
|
2816
|
-
|
|
2130
|
+
});
|
|
2131
|
+
if (pending === 0) {
|
|
2132
|
+
done();
|
|
2817
2133
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2134
|
+
return;
|
|
2135
|
+
}
|
|
2136
|
+
if (opt.async) {
|
|
2137
|
+
return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then((src2) => lexer2(src2, opt)).then((tokens) => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then((tokens) => parser2(tokens, opt)).then((html) => opt.hooks ? opt.hooks.postprocess(html) : html).catch(throwError);
|
|
2138
|
+
}
|
|
2139
|
+
try {
|
|
2140
|
+
if (opt.hooks) {
|
|
2141
|
+
src = opt.hooks.preprocess(src);
|
|
2826
2142
|
}
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
src = opt.hooks.preprocess(src);
|
|
2831
|
-
}
|
|
2832
|
-
const tokens = lexer(src, opt);
|
|
2833
|
-
if (opt.walkTokens) {
|
|
2834
|
-
this.walkTokens(tokens, opt.walkTokens);
|
|
2835
|
-
}
|
|
2836
|
-
let html = parser(tokens, opt);
|
|
2837
|
-
if (opt.hooks) {
|
|
2838
|
-
html = opt.hooks.postprocess(html);
|
|
2839
|
-
}
|
|
2840
|
-
return html;
|
|
2841
|
-
} catch (e) {
|
|
2842
|
-
return throwError(e);
|
|
2143
|
+
const tokens = lexer2(src, opt);
|
|
2144
|
+
if (opt.walkTokens) {
|
|
2145
|
+
this.walkTokens(tokens, opt.walkTokens);
|
|
2843
2146
|
}
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
#onError(silent, async, callback) {
|
|
2848
|
-
return (e) => {
|
|
2849
|
-
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2850
|
-
|
|
2851
|
-
if (silent) {
|
|
2852
|
-
const msg = '<p>An error occurred:</p><pre>'
|
|
2853
|
-
+ escape(e.message + '', true)
|
|
2854
|
-
+ '</pre>';
|
|
2855
|
-
if (async) {
|
|
2856
|
-
return Promise.resolve(msg);
|
|
2857
|
-
}
|
|
2858
|
-
if (callback) {
|
|
2859
|
-
callback(null, msg);
|
|
2860
|
-
return;
|
|
2861
|
-
}
|
|
2862
|
-
return msg;
|
|
2147
|
+
let html = parser2(tokens, opt);
|
|
2148
|
+
if (opt.hooks) {
|
|
2149
|
+
html = opt.hooks.postprocess(html);
|
|
2863
2150
|
}
|
|
2864
|
-
|
|
2151
|
+
return html;
|
|
2152
|
+
} catch (e) {
|
|
2153
|
+
return throwError(e);
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
};
|
|
2157
|
+
_onError = new WeakSet();
|
|
2158
|
+
onError_fn = function(silent, async, callback) {
|
|
2159
|
+
return (e) => {
|
|
2160
|
+
e.message += "\nPlease report this to https://github.com/markedjs/marked.";
|
|
2161
|
+
if (silent) {
|
|
2162
|
+
const msg = "<p>An error occurred:</p><pre>" + escape(e.message + "", true) + "</pre>";
|
|
2865
2163
|
if (async) {
|
|
2866
|
-
return Promise.
|
|
2164
|
+
return Promise.resolve(msg);
|
|
2867
2165
|
}
|
|
2868
2166
|
if (callback) {
|
|
2869
|
-
callback(
|
|
2167
|
+
callback(null, msg);
|
|
2870
2168
|
return;
|
|
2871
2169
|
}
|
|
2872
|
-
|
|
2873
|
-
}
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2170
|
+
return msg;
|
|
2171
|
+
}
|
|
2172
|
+
if (async) {
|
|
2173
|
+
return Promise.reject(e);
|
|
2174
|
+
}
|
|
2175
|
+
if (callback) {
|
|
2176
|
+
callback(e);
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
throw e;
|
|
2180
|
+
};
|
|
2181
|
+
};
|
|
2878
2182
|
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
*/
|
|
2183
|
+
// src/marked.ts
|
|
2184
|
+
var markedInstance = new Marked();
|
|
2882
2185
|
function marked(src, opt, callback) {
|
|
2883
2186
|
return markedInstance.parse(src, opt, callback);
|
|
2884
2187
|
}
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
* Options
|
|
2888
|
-
*/
|
|
2889
|
-
|
|
2890
|
-
marked.options =
|
|
2891
|
-
marked.setOptions = function(opt) {
|
|
2892
|
-
markedInstance.setOptions(opt);
|
|
2188
|
+
marked.options = marked.setOptions = function(options2) {
|
|
2189
|
+
markedInstance.setOptions(options2);
|
|
2893
2190
|
marked.defaults = markedInstance.defaults;
|
|
2894
2191
|
changeDefaults(marked.defaults);
|
|
2895
2192
|
return marked;
|
|
2896
2193
|
};
|
|
2897
|
-
|
|
2898
|
-
marked.
|
|
2899
|
-
|
|
2900
|
-
marked.defaults = defaults;
|
|
2901
|
-
|
|
2902
|
-
/**
|
|
2903
|
-
* Use Extension
|
|
2904
|
-
*/
|
|
2905
|
-
|
|
2194
|
+
marked.getDefaults = _getDefaults;
|
|
2195
|
+
marked.defaults = _defaults;
|
|
2906
2196
|
marked.use = function(...args) {
|
|
2907
2197
|
markedInstance.use(...args);
|
|
2908
2198
|
marked.defaults = markedInstance.defaults;
|
|
2909
2199
|
changeDefaults(marked.defaults);
|
|
2910
2200
|
return marked;
|
|
2911
2201
|
};
|
|
2912
|
-
|
|
2913
|
-
/**
|
|
2914
|
-
* Run callback for every token
|
|
2915
|
-
*/
|
|
2916
|
-
|
|
2917
2202
|
marked.walkTokens = function(tokens, callback) {
|
|
2918
2203
|
return markedInstance.walkTokens(tokens, callback);
|
|
2919
2204
|
};
|
|
2920
|
-
|
|
2921
|
-
/**
|
|
2922
|
-
* Parse Inline
|
|
2923
|
-
* @param {string} src
|
|
2924
|
-
*/
|
|
2925
2205
|
marked.parseInline = markedInstance.parseInline;
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
marked.
|
|
2931
|
-
marked.
|
|
2932
|
-
marked.
|
|
2933
|
-
marked.
|
|
2934
|
-
marked.
|
|
2935
|
-
marked.lexer = Lexer.lex;
|
|
2936
|
-
marked.Tokenizer = Tokenizer;
|
|
2937
|
-
marked.Slugger = Slugger;
|
|
2938
|
-
marked.Hooks = Hooks;
|
|
2206
|
+
marked.Parser = _Parser;
|
|
2207
|
+
marked.parser = _Parser.parse;
|
|
2208
|
+
marked.Renderer = _Renderer;
|
|
2209
|
+
marked.TextRenderer = _TextRenderer;
|
|
2210
|
+
marked.Lexer = _Lexer2;
|
|
2211
|
+
marked.lexer = _Lexer2.lex;
|
|
2212
|
+
marked.Tokenizer = _Tokenizer;
|
|
2213
|
+
marked.Slugger = _Slugger;
|
|
2214
|
+
marked.Hooks = _Hooks;
|
|
2939
2215
|
marked.parse = marked;
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2216
|
+
var options = marked.options;
|
|
2217
|
+
var setOptions = marked.setOptions;
|
|
2218
|
+
var use = marked.use;
|
|
2219
|
+
var walkTokens = marked.walkTokens;
|
|
2220
|
+
var parseInline = marked.parseInline;
|
|
2221
|
+
var parse = marked;
|
|
2222
|
+
var parser = _Parser.parse;
|
|
2223
|
+
var lexer = _Lexer2.lex;
|
|
2224
|
+
export {
|
|
2225
|
+
_Hooks as Hooks,
|
|
2226
|
+
_Lexer2 as Lexer,
|
|
2227
|
+
Marked,
|
|
2228
|
+
_Parser as Parser,
|
|
2229
|
+
_Renderer as Renderer,
|
|
2230
|
+
_Slugger as Slugger,
|
|
2231
|
+
_TextRenderer as TextRenderer,
|
|
2232
|
+
_Tokenizer as Tokenizer,
|
|
2233
|
+
_defaults as defaults,
|
|
2234
|
+
_getDefaults as getDefaults,
|
|
2235
|
+
lexer,
|
|
2236
|
+
marked,
|
|
2237
|
+
options,
|
|
2238
|
+
parse,
|
|
2239
|
+
parseInline,
|
|
2240
|
+
parser,
|
|
2241
|
+
setOptions,
|
|
2242
|
+
use,
|
|
2243
|
+
walkTokens
|
|
2244
|
+
};
|
|
2245
|
+
//# sourceMappingURL=marked.esm.js.map
|