marked 4.1.0 → 4.2.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 +1 -0
- package/lib/marked.cjs +260 -638
- package/lib/marked.esm.js +0 -1
- package/lib/marked.umd.js +260 -638
- package/marked.min.js +1 -1
- package/package.json +13 -12
- package/src/defaults.js +0 -1
package/lib/marked.umd.js
CHANGED
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
Object.defineProperty(target, descriptor.key, descriptor);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
function _createClass(Constructor, protoProps, staticProps) {
|
|
29
28
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
30
29
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
@@ -33,7 +32,6 @@
|
|
|
33
32
|
});
|
|
34
33
|
return Constructor;
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
function _unsupportedIterableToArray(o, minLen) {
|
|
38
36
|
if (!o) return;
|
|
39
37
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -42,19 +40,14 @@
|
|
|
42
40
|
if (n === "Map" || n === "Set") return Array.from(o);
|
|
43
41
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
function _arrayLikeToArray(arr, len) {
|
|
47
44
|
if (len == null || len > arr.length) len = arr.length;
|
|
48
|
-
|
|
49
45
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
50
|
-
|
|
51
46
|
return arr2;
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
55
49
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
56
50
|
if (it) return (it = it.call(o)).next.bind(it);
|
|
57
|
-
|
|
58
51
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
59
52
|
if (it) o = it;
|
|
60
53
|
var i = 0;
|
|
@@ -68,7 +61,6 @@
|
|
|
68
61
|
};
|
|
69
62
|
};
|
|
70
63
|
}
|
|
71
|
-
|
|
72
64
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
73
65
|
}
|
|
74
66
|
|
|
@@ -89,7 +81,6 @@
|
|
|
89
81
|
sanitize: false,
|
|
90
82
|
sanitizer: null,
|
|
91
83
|
silent: false,
|
|
92
|
-
smartLists: false,
|
|
93
84
|
smartypants: false,
|
|
94
85
|
tokenizer: null,
|
|
95
86
|
walkTokens: null,
|
|
@@ -115,11 +106,9 @@
|
|
|
115
106
|
'"': '"',
|
|
116
107
|
"'": '''
|
|
117
108
|
};
|
|
118
|
-
|
|
119
109
|
var getEscapeReplacement = function getEscapeReplacement(ch) {
|
|
120
110
|
return escapeReplacements[ch];
|
|
121
111
|
};
|
|
122
|
-
|
|
123
112
|
function escape(html, encode) {
|
|
124
113
|
if (encode) {
|
|
125
114
|
if (escapeTest.test(html)) {
|
|
@@ -130,33 +119,30 @@
|
|
|
130
119
|
return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
|
|
131
120
|
}
|
|
132
121
|
}
|
|
133
|
-
|
|
134
122
|
return html;
|
|
135
123
|
}
|
|
136
124
|
var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
|
125
|
+
|
|
137
126
|
/**
|
|
138
127
|
* @param {string} html
|
|
139
128
|
*/
|
|
140
|
-
|
|
141
129
|
function unescape(html) {
|
|
142
130
|
// explicitly match decimal, hex, and named HTML entities
|
|
143
131
|
return html.replace(unescapeTest, function (_, n) {
|
|
144
132
|
n = n.toLowerCase();
|
|
145
133
|
if (n === 'colon') return ':';
|
|
146
|
-
|
|
147
134
|
if (n.charAt(0) === '#') {
|
|
148
135
|
return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
|
|
149
136
|
}
|
|
150
|
-
|
|
151
137
|
return '';
|
|
152
138
|
});
|
|
153
139
|
}
|
|
154
140
|
var caret = /(^|[^\[])\^/g;
|
|
141
|
+
|
|
155
142
|
/**
|
|
156
143
|
* @param {string | RegExp} regex
|
|
157
144
|
* @param {string} opt
|
|
158
145
|
*/
|
|
159
|
-
|
|
160
146
|
function edit(regex, opt) {
|
|
161
147
|
regex = typeof regex === 'string' ? regex : regex.source;
|
|
162
148
|
opt = opt || '';
|
|
@@ -175,48 +161,43 @@
|
|
|
175
161
|
}
|
|
176
162
|
var nonWordAndColonTest = /[^\w:]/g;
|
|
177
163
|
var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
|
164
|
+
|
|
178
165
|
/**
|
|
179
166
|
* @param {boolean} sanitize
|
|
180
167
|
* @param {string} base
|
|
181
168
|
* @param {string} href
|
|
182
169
|
*/
|
|
183
|
-
|
|
184
170
|
function cleanUrl(sanitize, base, href) {
|
|
185
171
|
if (sanitize) {
|
|
186
172
|
var prot;
|
|
187
|
-
|
|
188
173
|
try {
|
|
189
174
|
prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
|
|
190
175
|
} catch (e) {
|
|
191
176
|
return null;
|
|
192
177
|
}
|
|
193
|
-
|
|
194
178
|
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
|
195
179
|
return null;
|
|
196
180
|
}
|
|
197
181
|
}
|
|
198
|
-
|
|
199
182
|
if (base && !originIndependentUrl.test(href)) {
|
|
200
183
|
href = resolveUrl(base, href);
|
|
201
184
|
}
|
|
202
|
-
|
|
203
185
|
try {
|
|
204
186
|
href = encodeURI(href).replace(/%25/g, '%');
|
|
205
187
|
} catch (e) {
|
|
206
188
|
return null;
|
|
207
189
|
}
|
|
208
|
-
|
|
209
190
|
return href;
|
|
210
191
|
}
|
|
211
192
|
var baseUrls = {};
|
|
212
193
|
var justDomain = /^[^:]+:\/*[^/]*$/;
|
|
213
194
|
var protocol = /^([^:]+:)[\s\S]*$/;
|
|
214
195
|
var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
|
196
|
+
|
|
215
197
|
/**
|
|
216
198
|
* @param {string} base
|
|
217
199
|
* @param {string} href
|
|
218
200
|
*/
|
|
219
|
-
|
|
220
201
|
function resolveUrl(base, href) {
|
|
221
202
|
if (!baseUrls[' ' + base]) {
|
|
222
203
|
// we can ignore everything in base after the last slash of its path component,
|
|
@@ -228,21 +209,17 @@
|
|
|
228
209
|
baseUrls[' ' + base] = rtrim(base, '/', true);
|
|
229
210
|
}
|
|
230
211
|
}
|
|
231
|
-
|
|
232
212
|
base = baseUrls[' ' + base];
|
|
233
213
|
var relativeBase = base.indexOf(':') === -1;
|
|
234
|
-
|
|
235
214
|
if (href.substring(0, 2) === '//') {
|
|
236
215
|
if (relativeBase) {
|
|
237
216
|
return href;
|
|
238
217
|
}
|
|
239
|
-
|
|
240
218
|
return base.replace(protocol, '$1') + href;
|
|
241
219
|
} else if (href.charAt(0) === '/') {
|
|
242
220
|
if (relativeBase) {
|
|
243
221
|
return href;
|
|
244
222
|
}
|
|
245
|
-
|
|
246
223
|
return base.replace(domain, '$1') + href;
|
|
247
224
|
} else {
|
|
248
225
|
return base + href;
|
|
@@ -253,52 +230,46 @@
|
|
|
253
230
|
};
|
|
254
231
|
function merge(obj) {
|
|
255
232
|
var i = 1,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
233
|
+
target,
|
|
234
|
+
key;
|
|
259
235
|
for (; i < arguments.length; i++) {
|
|
260
236
|
target = arguments[i];
|
|
261
|
-
|
|
262
237
|
for (key in target) {
|
|
263
238
|
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
264
239
|
obj[key] = target[key];
|
|
265
240
|
}
|
|
266
241
|
}
|
|
267
242
|
}
|
|
268
|
-
|
|
269
243
|
return obj;
|
|
270
244
|
}
|
|
271
245
|
function splitCells(tableRow, count) {
|
|
272
246
|
// ensure that every cell-delimiting pipe has a space
|
|
273
247
|
// before it to distinguish it from an escaped pipe
|
|
274
248
|
var row = tableRow.replace(/\|/g, function (match, offset, str) {
|
|
275
|
-
|
|
249
|
+
var escaped = false,
|
|
276
250
|
curr = offset;
|
|
251
|
+
while (--curr >= 0 && str[curr] === '\\') {
|
|
252
|
+
escaped = !escaped;
|
|
253
|
+
}
|
|
254
|
+
if (escaped) {
|
|
255
|
+
// odd number of slashes means | is escaped
|
|
256
|
+
// so we leave it alone
|
|
257
|
+
return '|';
|
|
258
|
+
} else {
|
|
259
|
+
// add space before unescaped |
|
|
260
|
+
return ' |';
|
|
261
|
+
}
|
|
262
|
+
}),
|
|
263
|
+
cells = row.split(/ \|/);
|
|
264
|
+
var i = 0;
|
|
277
265
|
|
|
278
|
-
|
|
279
|
-
escaped = !escaped;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (escaped) {
|
|
283
|
-
// odd number of slashes means | is escaped
|
|
284
|
-
// so we leave it alone
|
|
285
|
-
return '|';
|
|
286
|
-
} else {
|
|
287
|
-
// add space before unescaped |
|
|
288
|
-
return ' |';
|
|
289
|
-
}
|
|
290
|
-
}),
|
|
291
|
-
cells = row.split(/ \|/);
|
|
292
|
-
var i = 0; // First/last cell in a row cannot be empty if it has no leading/trailing pipe
|
|
293
|
-
|
|
266
|
+
// First/last cell in a row cannot be empty if it has no leading/trailing pipe
|
|
294
267
|
if (!cells[0].trim()) {
|
|
295
268
|
cells.shift();
|
|
296
269
|
}
|
|
297
|
-
|
|
298
270
|
if (cells.length > 0 && !cells[cells.length - 1].trim()) {
|
|
299
271
|
cells.pop();
|
|
300
272
|
}
|
|
301
|
-
|
|
302
273
|
if (cells.length > count) {
|
|
303
274
|
cells.splice(count);
|
|
304
275
|
} else {
|
|
@@ -306,14 +277,13 @@
|
|
|
306
277
|
cells.push('');
|
|
307
278
|
}
|
|
308
279
|
}
|
|
309
|
-
|
|
310
280
|
for (; i < cells.length; i++) {
|
|
311
281
|
// leading or trailing whitespace is ignored per the gfm spec
|
|
312
282
|
cells[i] = cells[i].trim().replace(/\\\|/g, '|');
|
|
313
283
|
}
|
|
314
|
-
|
|
315
284
|
return cells;
|
|
316
285
|
}
|
|
286
|
+
|
|
317
287
|
/**
|
|
318
288
|
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
|
|
319
289
|
* /c*$/ is vulnerable to REDOS.
|
|
@@ -322,20 +292,18 @@
|
|
|
322
292
|
* @param {string} c
|
|
323
293
|
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
|
|
324
294
|
*/
|
|
325
|
-
|
|
326
295
|
function rtrim(str, c, invert) {
|
|
327
296
|
var l = str.length;
|
|
328
|
-
|
|
329
297
|
if (l === 0) {
|
|
330
298
|
return '';
|
|
331
|
-
}
|
|
332
|
-
|
|
299
|
+
}
|
|
333
300
|
|
|
334
|
-
|
|
301
|
+
// Length of suffix matching the invert condition.
|
|
302
|
+
var suffLen = 0;
|
|
335
303
|
|
|
304
|
+
// Step left until we fail to match the invert condition.
|
|
336
305
|
while (suffLen < l) {
|
|
337
306
|
var currChar = str.charAt(l - suffLen - 1);
|
|
338
|
-
|
|
339
307
|
if (currChar === c && !invert) {
|
|
340
308
|
suffLen++;
|
|
341
309
|
} else if (currChar !== c && invert) {
|
|
@@ -344,18 +312,15 @@
|
|
|
344
312
|
break;
|
|
345
313
|
}
|
|
346
314
|
}
|
|
347
|
-
|
|
348
315
|
return str.slice(0, l - suffLen);
|
|
349
316
|
}
|
|
350
317
|
function findClosingBracket(str, b) {
|
|
351
318
|
if (str.indexOf(b[1]) === -1) {
|
|
352
319
|
return -1;
|
|
353
320
|
}
|
|
354
|
-
|
|
355
321
|
var l = str.length;
|
|
356
322
|
var level = 0,
|
|
357
|
-
|
|
358
|
-
|
|
323
|
+
i = 0;
|
|
359
324
|
for (; i < l; i++) {
|
|
360
325
|
if (str[i] === '\\') {
|
|
361
326
|
i++;
|
|
@@ -363,42 +328,36 @@
|
|
|
363
328
|
level++;
|
|
364
329
|
} else if (str[i] === b[1]) {
|
|
365
330
|
level--;
|
|
366
|
-
|
|
367
331
|
if (level < 0) {
|
|
368
332
|
return i;
|
|
369
333
|
}
|
|
370
334
|
}
|
|
371
335
|
}
|
|
372
|
-
|
|
373
336
|
return -1;
|
|
374
337
|
}
|
|
375
338
|
function checkSanitizeDeprecation(opt) {
|
|
376
339
|
if (opt && opt.sanitize && !opt.silent) {
|
|
377
340
|
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');
|
|
378
341
|
}
|
|
379
|
-
}
|
|
342
|
+
}
|
|
380
343
|
|
|
344
|
+
// copied from https://stackoverflow.com/a/5450113/806777
|
|
381
345
|
/**
|
|
382
346
|
* @param {string} pattern
|
|
383
347
|
* @param {number} count
|
|
384
348
|
*/
|
|
385
|
-
|
|
386
349
|
function repeatString(pattern, count) {
|
|
387
350
|
if (count < 1) {
|
|
388
351
|
return '';
|
|
389
352
|
}
|
|
390
|
-
|
|
391
353
|
var result = '';
|
|
392
|
-
|
|
393
354
|
while (count > 1) {
|
|
394
355
|
if (count & 1) {
|
|
395
356
|
result += pattern;
|
|
396
357
|
}
|
|
397
|
-
|
|
398
358
|
count >>= 1;
|
|
399
359
|
pattern += pattern;
|
|
400
360
|
}
|
|
401
|
-
|
|
402
361
|
return result + pattern;
|
|
403
362
|
}
|
|
404
363
|
|
|
@@ -406,7 +365,6 @@
|
|
|
406
365
|
var href = link.href;
|
|
407
366
|
var title = link.title ? escape(link.title) : null;
|
|
408
367
|
var text = cap[1].replace(/\\([\[\]])/g, '$1');
|
|
409
|
-
|
|
410
368
|
if (cap[0].charAt(0) !== '!') {
|
|
411
369
|
lexer.state.inLink = true;
|
|
412
370
|
var token = {
|
|
@@ -420,7 +378,6 @@
|
|
|
420
378
|
lexer.state.inLink = false;
|
|
421
379
|
return token;
|
|
422
380
|
}
|
|
423
|
-
|
|
424
381
|
return {
|
|
425
382
|
type: 'image',
|
|
426
383
|
raw: raw,
|
|
@@ -429,46 +386,35 @@
|
|
|
429
386
|
text: escape(text)
|
|
430
387
|
};
|
|
431
388
|
}
|
|
432
|
-
|
|
433
389
|
function indentCodeCompensation(raw, text) {
|
|
434
390
|
var matchIndentToCode = raw.match(/^(\s+)(?:```)/);
|
|
435
|
-
|
|
436
391
|
if (matchIndentToCode === null) {
|
|
437
392
|
return text;
|
|
438
393
|
}
|
|
439
|
-
|
|
440
394
|
var indentToCode = matchIndentToCode[1];
|
|
441
395
|
return text.split('\n').map(function (node) {
|
|
442
396
|
var matchIndentInNode = node.match(/^\s+/);
|
|
443
|
-
|
|
444
397
|
if (matchIndentInNode === null) {
|
|
445
398
|
return node;
|
|
446
399
|
}
|
|
447
|
-
|
|
448
400
|
var indentInNode = matchIndentInNode[0];
|
|
449
|
-
|
|
450
401
|
if (indentInNode.length >= indentToCode.length) {
|
|
451
402
|
return node.slice(indentToCode.length);
|
|
452
403
|
}
|
|
453
|
-
|
|
454
404
|
return node;
|
|
455
405
|
}).join('\n');
|
|
456
406
|
}
|
|
407
|
+
|
|
457
408
|
/**
|
|
458
409
|
* Tokenizer
|
|
459
410
|
*/
|
|
460
|
-
|
|
461
|
-
|
|
462
411
|
var Tokenizer = /*#__PURE__*/function () {
|
|
463
412
|
function Tokenizer(options) {
|
|
464
413
|
this.options = options || exports.defaults;
|
|
465
414
|
}
|
|
466
|
-
|
|
467
415
|
var _proto = Tokenizer.prototype;
|
|
468
|
-
|
|
469
416
|
_proto.space = function space(src) {
|
|
470
417
|
var cap = this.rules.block.newline.exec(src);
|
|
471
|
-
|
|
472
418
|
if (cap && cap[0].length > 0) {
|
|
473
419
|
return {
|
|
474
420
|
type: 'space',
|
|
@@ -476,10 +422,8 @@
|
|
|
476
422
|
};
|
|
477
423
|
}
|
|
478
424
|
};
|
|
479
|
-
|
|
480
425
|
_proto.code = function code(src) {
|
|
481
426
|
var cap = this.rules.block.code.exec(src);
|
|
482
|
-
|
|
483
427
|
if (cap) {
|
|
484
428
|
var text = cap[0].replace(/^ {1,4}/gm, '');
|
|
485
429
|
return {
|
|
@@ -490,10 +434,8 @@
|
|
|
490
434
|
};
|
|
491
435
|
}
|
|
492
436
|
};
|
|
493
|
-
|
|
494
437
|
_proto.fences = function fences(src) {
|
|
495
438
|
var cap = this.rules.block.fences.exec(src);
|
|
496
|
-
|
|
497
439
|
if (cap) {
|
|
498
440
|
var raw = cap[0];
|
|
499
441
|
var text = indentCodeCompensation(raw, cap[3] || '');
|
|
@@ -505,16 +447,14 @@
|
|
|
505
447
|
};
|
|
506
448
|
}
|
|
507
449
|
};
|
|
508
|
-
|
|
509
450
|
_proto.heading = function heading(src) {
|
|
510
451
|
var cap = this.rules.block.heading.exec(src);
|
|
511
|
-
|
|
512
452
|
if (cap) {
|
|
513
|
-
var text = cap[2].trim();
|
|
453
|
+
var text = cap[2].trim();
|
|
514
454
|
|
|
455
|
+
// remove trailing #s
|
|
515
456
|
if (/#$/.test(text)) {
|
|
516
457
|
var trimmed = rtrim(text, '#');
|
|
517
|
-
|
|
518
458
|
if (this.options.pedantic) {
|
|
519
459
|
text = trimmed.trim();
|
|
520
460
|
} else if (!trimmed || / $/.test(trimmed)) {
|
|
@@ -522,7 +462,6 @@
|
|
|
522
462
|
text = trimmed.trim();
|
|
523
463
|
}
|
|
524
464
|
}
|
|
525
|
-
|
|
526
465
|
return {
|
|
527
466
|
type: 'heading',
|
|
528
467
|
raw: cap[0],
|
|
@@ -532,10 +471,8 @@
|
|
|
532
471
|
};
|
|
533
472
|
}
|
|
534
473
|
};
|
|
535
|
-
|
|
536
474
|
_proto.hr = function hr(src) {
|
|
537
475
|
var cap = this.rules.block.hr.exec(src);
|
|
538
|
-
|
|
539
476
|
if (cap) {
|
|
540
477
|
return {
|
|
541
478
|
type: 'hr',
|
|
@@ -543,10 +480,8 @@
|
|
|
543
480
|
};
|
|
544
481
|
}
|
|
545
482
|
};
|
|
546
|
-
|
|
547
483
|
_proto.blockquote = function blockquote(src) {
|
|
548
484
|
var cap = this.rules.block.blockquote.exec(src);
|
|
549
|
-
|
|
550
485
|
if (cap) {
|
|
551
486
|
var text = cap[0].replace(/^ *>[ \t]?/gm, '');
|
|
552
487
|
return {
|
|
@@ -557,10 +492,8 @@
|
|
|
557
492
|
};
|
|
558
493
|
}
|
|
559
494
|
};
|
|
560
|
-
|
|
561
495
|
_proto.list = function list(src) {
|
|
562
496
|
var cap = this.rules.block.list.exec(src);
|
|
563
|
-
|
|
564
497
|
if (cap) {
|
|
565
498
|
var raw, istask, ischecked, indent, i, blankLine, endsWithBlankLine, line, nextLine, rawLine, itemContents, endEarly;
|
|
566
499
|
var bull = cap[1].trim();
|
|
@@ -574,86 +507,78 @@
|
|
|
574
507
|
items: []
|
|
575
508
|
};
|
|
576
509
|
bull = isordered ? "\\d{1,9}\\" + bull.slice(-1) : "\\" + bull;
|
|
577
|
-
|
|
578
510
|
if (this.options.pedantic) {
|
|
579
511
|
bull = isordered ? bull : '[*+-]';
|
|
580
|
-
}
|
|
581
|
-
|
|
512
|
+
}
|
|
582
513
|
|
|
583
|
-
|
|
514
|
+
// Get next list item
|
|
515
|
+
var itemRegex = new RegExp("^( {0,3}" + bull + ")((?:[\t ][^\\n]*)?(?:\\n|$))");
|
|
584
516
|
|
|
517
|
+
// Check if current bullet point can start a new List Item
|
|
585
518
|
while (src) {
|
|
586
519
|
endEarly = false;
|
|
587
|
-
|
|
588
520
|
if (!(cap = itemRegex.exec(src))) {
|
|
589
521
|
break;
|
|
590
522
|
}
|
|
591
|
-
|
|
592
523
|
if (this.rules.block.hr.test(src)) {
|
|
593
524
|
// End list if bullet was actually HR (possibly move into itemRegex?)
|
|
594
525
|
break;
|
|
595
526
|
}
|
|
596
|
-
|
|
597
527
|
raw = cap[0];
|
|
598
528
|
src = src.substring(raw.length);
|
|
599
529
|
line = cap[2].split('\n', 1)[0];
|
|
600
530
|
nextLine = src.split('\n', 1)[0];
|
|
601
|
-
|
|
602
531
|
if (this.options.pedantic) {
|
|
603
532
|
indent = 2;
|
|
604
533
|
itemContents = line.trimLeft();
|
|
605
534
|
} else {
|
|
606
535
|
indent = cap[2].search(/[^ ]/); // Find first non-space char
|
|
607
|
-
|
|
608
536
|
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
|
609
|
-
|
|
610
537
|
itemContents = line.slice(indent);
|
|
611
538
|
indent += cap[1].length;
|
|
612
539
|
}
|
|
613
|
-
|
|
614
540
|
blankLine = false;
|
|
615
|
-
|
|
616
541
|
if (!line && /^ *$/.test(nextLine)) {
|
|
617
542
|
// Items begin with at most one blank line
|
|
618
543
|
raw += nextLine + '\n';
|
|
619
544
|
src = src.substring(nextLine.length + 1);
|
|
620
545
|
endEarly = true;
|
|
621
546
|
}
|
|
622
|
-
|
|
623
547
|
if (!endEarly) {
|
|
624
548
|
var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))");
|
|
625
549
|
var hrRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)");
|
|
626
550
|
var fencesBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:```|~~~)");
|
|
627
|
-
var headingBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}#");
|
|
551
|
+
var headingBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}#");
|
|
628
552
|
|
|
553
|
+
// Check if following lines should be included in List Item
|
|
629
554
|
while (src) {
|
|
630
555
|
rawLine = src.split('\n', 1)[0];
|
|
631
|
-
line = rawLine;
|
|
556
|
+
line = rawLine;
|
|
632
557
|
|
|
558
|
+
// Re-align to follow commonmark nesting rules
|
|
633
559
|
if (this.options.pedantic) {
|
|
634
560
|
line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
|
|
635
|
-
}
|
|
636
|
-
|
|
561
|
+
}
|
|
637
562
|
|
|
563
|
+
// End list item if found code fences
|
|
638
564
|
if (fencesBeginRegex.test(line)) {
|
|
639
565
|
break;
|
|
640
|
-
}
|
|
641
|
-
|
|
566
|
+
}
|
|
642
567
|
|
|
568
|
+
// End list item if found start of new heading
|
|
643
569
|
if (headingBeginRegex.test(line)) {
|
|
644
570
|
break;
|
|
645
|
-
}
|
|
646
|
-
|
|
571
|
+
}
|
|
647
572
|
|
|
573
|
+
// End list item if found start of new bullet
|
|
648
574
|
if (nextBulletRegex.test(line)) {
|
|
649
575
|
break;
|
|
650
|
-
}
|
|
651
|
-
|
|
576
|
+
}
|
|
652
577
|
|
|
578
|
+
// Horizontal rule found
|
|
653
579
|
if (hrRegex.test(src)) {
|
|
654
580
|
break;
|
|
655
581
|
}
|
|
656
|
-
|
|
657
582
|
if (line.search(/[^ ]/) >= indent || !line.trim()) {
|
|
658
583
|
// Dedent if possible
|
|
659
584
|
itemContents += '\n' + line.slice(indent);
|
|
@@ -664,17 +589,14 @@
|
|
|
664
589
|
// Otherwise, improper indentation ends this item
|
|
665
590
|
break;
|
|
666
591
|
}
|
|
667
|
-
|
|
668
592
|
if (!blankLine && !line.trim()) {
|
|
669
593
|
// Check if current line is blank
|
|
670
594
|
blankLine = true;
|
|
671
595
|
}
|
|
672
|
-
|
|
673
596
|
raw += rawLine + '\n';
|
|
674
597
|
src = src.substring(rawLine.length + 1);
|
|
675
598
|
}
|
|
676
599
|
}
|
|
677
|
-
|
|
678
600
|
if (!list.loose) {
|
|
679
601
|
// If the previous item ended with a blank line, the list is loose
|
|
680
602
|
if (endsWithBlankLine) {
|
|
@@ -682,18 +604,16 @@
|
|
|
682
604
|
} else if (/\n *\n *$/.test(raw)) {
|
|
683
605
|
endsWithBlankLine = true;
|
|
684
606
|
}
|
|
685
|
-
}
|
|
686
|
-
|
|
607
|
+
}
|
|
687
608
|
|
|
609
|
+
// Check for task list items
|
|
688
610
|
if (this.options.gfm) {
|
|
689
611
|
istask = /^\[[ xX]\] /.exec(itemContents);
|
|
690
|
-
|
|
691
612
|
if (istask) {
|
|
692
613
|
ischecked = istask[0] !== '[ ] ';
|
|
693
614
|
itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
|
|
694
615
|
}
|
|
695
616
|
}
|
|
696
|
-
|
|
697
617
|
list.items.push({
|
|
698
618
|
type: 'list_item',
|
|
699
619
|
raw: raw,
|
|
@@ -703,14 +623,15 @@
|
|
|
703
623
|
text: itemContents
|
|
704
624
|
});
|
|
705
625
|
list.raw += raw;
|
|
706
|
-
}
|
|
707
|
-
|
|
626
|
+
}
|
|
708
627
|
|
|
628
|
+
// Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
|
|
709
629
|
list.items[list.items.length - 1].raw = raw.trimRight();
|
|
710
630
|
list.items[list.items.length - 1].text = itemContents.trimRight();
|
|
711
631
|
list.raw = list.raw.trimRight();
|
|
712
|
-
var l = list.items.length;
|
|
632
|
+
var l = list.items.length;
|
|
713
633
|
|
|
634
|
+
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
|
714
635
|
for (i = 0; i < l; i++) {
|
|
715
636
|
this.lexer.state.top = false;
|
|
716
637
|
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
|
|
@@ -720,36 +641,28 @@
|
|
|
720
641
|
var hasMultipleLineBreaks = spacers.every(function (t) {
|
|
721
642
|
var chars = t.raw.split('');
|
|
722
643
|
var lineBreaks = 0;
|
|
723
|
-
|
|
724
644
|
for (var _iterator = _createForOfIteratorHelperLoose(chars), _step; !(_step = _iterator()).done;) {
|
|
725
645
|
var _char = _step.value;
|
|
726
|
-
|
|
727
646
|
if (_char === '\n') {
|
|
728
647
|
lineBreaks += 1;
|
|
729
648
|
}
|
|
730
|
-
|
|
731
649
|
if (lineBreaks > 1) {
|
|
732
650
|
return true;
|
|
733
651
|
}
|
|
734
652
|
}
|
|
735
|
-
|
|
736
653
|
return false;
|
|
737
654
|
});
|
|
738
|
-
|
|
739
655
|
if (!list.loose && spacers.length && hasMultipleLineBreaks) {
|
|
740
656
|
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
|
|
741
657
|
list.loose = true;
|
|
742
658
|
list.items[i].loose = true;
|
|
743
659
|
}
|
|
744
660
|
}
|
|
745
|
-
|
|
746
661
|
return list;
|
|
747
662
|
}
|
|
748
663
|
};
|
|
749
|
-
|
|
750
664
|
_proto.html = function html(src) {
|
|
751
665
|
var cap = this.rules.block.html.exec(src);
|
|
752
|
-
|
|
753
666
|
if (cap) {
|
|
754
667
|
var token = {
|
|
755
668
|
type: 'html',
|
|
@@ -757,21 +670,17 @@
|
|
|
757
670
|
pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
|
758
671
|
text: cap[0]
|
|
759
672
|
};
|
|
760
|
-
|
|
761
673
|
if (this.options.sanitize) {
|
|
762
674
|
var text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
|
|
763
675
|
token.type = 'paragraph';
|
|
764
676
|
token.text = text;
|
|
765
677
|
token.tokens = this.lexer.inline(text);
|
|
766
678
|
}
|
|
767
|
-
|
|
768
679
|
return token;
|
|
769
680
|
}
|
|
770
681
|
};
|
|
771
|
-
|
|
772
682
|
_proto.def = function def(src) {
|
|
773
683
|
var cap = this.rules.block.def.exec(src);
|
|
774
|
-
|
|
775
684
|
if (cap) {
|
|
776
685
|
if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
|
|
777
686
|
var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
|
|
@@ -784,10 +693,8 @@
|
|
|
784
693
|
};
|
|
785
694
|
}
|
|
786
695
|
};
|
|
787
|
-
|
|
788
696
|
_proto.table = function table(src) {
|
|
789
697
|
var cap = this.rules.block.table.exec(src);
|
|
790
|
-
|
|
791
698
|
if (cap) {
|
|
792
699
|
var item = {
|
|
793
700
|
type: 'table',
|
|
@@ -799,12 +706,10 @@
|
|
|
799
706
|
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
|
800
707
|
rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
|
|
801
708
|
};
|
|
802
|
-
|
|
803
709
|
if (item.header.length === item.align.length) {
|
|
804
710
|
item.raw = cap[0];
|
|
805
711
|
var l = item.align.length;
|
|
806
712
|
var i, j, k, row;
|
|
807
|
-
|
|
808
713
|
for (i = 0; i < l; i++) {
|
|
809
714
|
if (/^ *-+: *$/.test(item.align[i])) {
|
|
810
715
|
item.align[i] = 'right';
|
|
@@ -816,44 +721,37 @@
|
|
|
816
721
|
item.align[i] = null;
|
|
817
722
|
}
|
|
818
723
|
}
|
|
819
|
-
|
|
820
724
|
l = item.rows.length;
|
|
821
|
-
|
|
822
725
|
for (i = 0; i < l; i++) {
|
|
823
726
|
item.rows[i] = splitCells(item.rows[i], item.header.length).map(function (c) {
|
|
824
727
|
return {
|
|
825
728
|
text: c
|
|
826
729
|
};
|
|
827
730
|
});
|
|
828
|
-
}
|
|
829
|
-
// header child tokens
|
|
731
|
+
}
|
|
830
732
|
|
|
733
|
+
// parse child tokens inside headers and cells
|
|
831
734
|
|
|
735
|
+
// header child tokens
|
|
832
736
|
l = item.header.length;
|
|
833
|
-
|
|
834
737
|
for (j = 0; j < l; j++) {
|
|
835
738
|
item.header[j].tokens = this.lexer.inline(item.header[j].text);
|
|
836
|
-
}
|
|
837
|
-
|
|
739
|
+
}
|
|
838
740
|
|
|
741
|
+
// cell child tokens
|
|
839
742
|
l = item.rows.length;
|
|
840
|
-
|
|
841
743
|
for (j = 0; j < l; j++) {
|
|
842
744
|
row = item.rows[j];
|
|
843
|
-
|
|
844
745
|
for (k = 0; k < row.length; k++) {
|
|
845
746
|
row[k].tokens = this.lexer.inline(row[k].text);
|
|
846
747
|
}
|
|
847
748
|
}
|
|
848
|
-
|
|
849
749
|
return item;
|
|
850
750
|
}
|
|
851
751
|
}
|
|
852
752
|
};
|
|
853
|
-
|
|
854
753
|
_proto.lheading = function lheading(src) {
|
|
855
754
|
var cap = this.rules.block.lheading.exec(src);
|
|
856
|
-
|
|
857
755
|
if (cap) {
|
|
858
756
|
return {
|
|
859
757
|
type: 'heading',
|
|
@@ -864,10 +762,8 @@
|
|
|
864
762
|
};
|
|
865
763
|
}
|
|
866
764
|
};
|
|
867
|
-
|
|
868
765
|
_proto.paragraph = function paragraph(src) {
|
|
869
766
|
var cap = this.rules.block.paragraph.exec(src);
|
|
870
|
-
|
|
871
767
|
if (cap) {
|
|
872
768
|
var text = cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1];
|
|
873
769
|
return {
|
|
@@ -878,10 +774,8 @@
|
|
|
878
774
|
};
|
|
879
775
|
}
|
|
880
776
|
};
|
|
881
|
-
|
|
882
777
|
_proto.text = function text(src) {
|
|
883
778
|
var cap = this.rules.block.text.exec(src);
|
|
884
|
-
|
|
885
779
|
if (cap) {
|
|
886
780
|
return {
|
|
887
781
|
type: 'text',
|
|
@@ -891,10 +785,8 @@
|
|
|
891
785
|
};
|
|
892
786
|
}
|
|
893
787
|
};
|
|
894
|
-
|
|
895
788
|
_proto.escape = function escape$1(src) {
|
|
896
789
|
var cap = this.rules.inline.escape.exec(src);
|
|
897
|
-
|
|
898
790
|
if (cap) {
|
|
899
791
|
return {
|
|
900
792
|
type: 'escape',
|
|
@@ -903,23 +795,19 @@
|
|
|
903
795
|
};
|
|
904
796
|
}
|
|
905
797
|
};
|
|
906
|
-
|
|
907
798
|
_proto.tag = function tag(src) {
|
|
908
799
|
var cap = this.rules.inline.tag.exec(src);
|
|
909
|
-
|
|
910
800
|
if (cap) {
|
|
911
801
|
if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
|
|
912
802
|
this.lexer.state.inLink = true;
|
|
913
803
|
} else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
|
|
914
804
|
this.lexer.state.inLink = false;
|
|
915
805
|
}
|
|
916
|
-
|
|
917
806
|
if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
918
807
|
this.lexer.state.inRawBlock = true;
|
|
919
808
|
} else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
920
809
|
this.lexer.state.inRawBlock = false;
|
|
921
810
|
}
|
|
922
|
-
|
|
923
811
|
return {
|
|
924
812
|
type: this.options.sanitize ? 'text' : 'html',
|
|
925
813
|
raw: cap[0],
|
|
@@ -929,29 +817,24 @@
|
|
|
929
817
|
};
|
|
930
818
|
}
|
|
931
819
|
};
|
|
932
|
-
|
|
933
820
|
_proto.link = function link(src) {
|
|
934
821
|
var cap = this.rules.inline.link.exec(src);
|
|
935
|
-
|
|
936
822
|
if (cap) {
|
|
937
823
|
var trimmedUrl = cap[2].trim();
|
|
938
|
-
|
|
939
824
|
if (!this.options.pedantic && /^</.test(trimmedUrl)) {
|
|
940
825
|
// commonmark requires matching angle brackets
|
|
941
826
|
if (!/>$/.test(trimmedUrl)) {
|
|
942
827
|
return;
|
|
943
|
-
}
|
|
944
|
-
|
|
828
|
+
}
|
|
945
829
|
|
|
830
|
+
// ending angle bracket cannot be escaped
|
|
946
831
|
var rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
|
|
947
|
-
|
|
948
832
|
if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
|
|
949
833
|
return;
|
|
950
834
|
}
|
|
951
835
|
} else {
|
|
952
836
|
// find closing parenthesis
|
|
953
837
|
var lastParenIndex = findClosingBracket(cap[2], '()');
|
|
954
|
-
|
|
955
838
|
if (lastParenIndex > -1) {
|
|
956
839
|
var start = cap[0].indexOf('!') === 0 ? 5 : 4;
|
|
957
840
|
var linkLen = start + cap[1].length + lastParenIndex;
|
|
@@ -960,14 +843,11 @@
|
|
|
960
843
|
cap[3] = '';
|
|
961
844
|
}
|
|
962
845
|
}
|
|
963
|
-
|
|
964
846
|
var href = cap[2];
|
|
965
847
|
var title = '';
|
|
966
|
-
|
|
967
848
|
if (this.options.pedantic) {
|
|
968
849
|
// split pedantic href and title
|
|
969
850
|
var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
|
|
970
|
-
|
|
971
851
|
if (link) {
|
|
972
852
|
href = link[1];
|
|
973
853
|
title = link[3];
|
|
@@ -975,9 +855,7 @@
|
|
|
975
855
|
} else {
|
|
976
856
|
title = cap[3] ? cap[3].slice(1, -1) : '';
|
|
977
857
|
}
|
|
978
|
-
|
|
979
858
|
href = href.trim();
|
|
980
|
-
|
|
981
859
|
if (/^</.test(href)) {
|
|
982
860
|
if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
|
|
983
861
|
// pedantic allows starting angle bracket without ending angle bracket
|
|
@@ -986,21 +864,17 @@
|
|
|
986
864
|
href = href.slice(1, -1);
|
|
987
865
|
}
|
|
988
866
|
}
|
|
989
|
-
|
|
990
867
|
return outputLink(cap, {
|
|
991
868
|
href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
|
|
992
869
|
title: title ? title.replace(this.rules.inline._escapes, '$1') : title
|
|
993
870
|
}, cap[0], this.lexer);
|
|
994
871
|
}
|
|
995
872
|
};
|
|
996
|
-
|
|
997
873
|
_proto.reflink = function reflink(src, links) {
|
|
998
874
|
var cap;
|
|
999
|
-
|
|
1000
875
|
if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
|
|
1001
876
|
var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
|
1002
877
|
link = links[link.toLowerCase()];
|
|
1003
|
-
|
|
1004
878
|
if (!link || !link.href) {
|
|
1005
879
|
var text = cap[0].charAt(0);
|
|
1006
880
|
return {
|
|
@@ -1009,39 +883,35 @@
|
|
|
1009
883
|
text: text
|
|
1010
884
|
};
|
|
1011
885
|
}
|
|
1012
|
-
|
|
1013
886
|
return outputLink(cap, link, cap[0], this.lexer);
|
|
1014
887
|
}
|
|
1015
888
|
};
|
|
1016
|
-
|
|
1017
889
|
_proto.emStrong = function emStrong(src, maskedSrc, prevChar) {
|
|
1018
890
|
if (prevChar === void 0) {
|
|
1019
891
|
prevChar = '';
|
|
1020
892
|
}
|
|
1021
|
-
|
|
1022
893
|
var match = this.rules.inline.emStrong.lDelim.exec(src);
|
|
1023
|
-
if (!match) return;
|
|
894
|
+
if (!match) return;
|
|
1024
895
|
|
|
896
|
+
// _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
|
|
1025
897
|
if (match[3] && prevChar.match(/(?:[0-9A-Za-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u0660-\u0669\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0966-\u096F\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09F9\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AE6-\u0AEF\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F\u0B71-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0BE6-\u0BF2\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C66-\u0C6F\u0C78-\u0C7E\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D58-\u0D61\u0D66-\u0D78\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DE6-\u0DEF\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F20-\u0F33\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F-\u1049\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u1090-\u1099\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u17E0-\u17E9\u17F0-\u17F9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A20-\u1A54\u1A80-\u1A89\u1A90-\u1A99\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B50-\u1B59\u1B83-\u1BA0\u1BAE-\u1BE5\u1C00-\u1C23\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA830-\uA835\uA840-\uA873\uA882-\uA8B3\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA900-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF-\uA9D9\uA9E0-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDE80-\uDE9C\uDEA0-\uDED0\uDEE1-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE40-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE4\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD23\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF27\uDF30-\uDF45\uDF51-\uDF54\uDF70-\uDF81\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC52-\uDC6F\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD03-\uDD26\uDD36-\uDD3F\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDD0-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDEF0-\uDEF9\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC50-\uDC59\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE50-\uDE59\uDE80-\uDEAA\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF30-\uDF3B\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF2\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDE70-\uDEBE\uDEC0-\uDEC9\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD834[\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD837[\uDF00-\uDF1E]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD40-\uDD49\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB\uDEF0-\uDEF9]|\uD839[\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCCF\uDD00-\uDD43\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF38\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A])/)) return;
|
|
1026
898
|
var nextChar = match[1] || match[2] || '';
|
|
1027
|
-
|
|
1028
899
|
if (!nextChar || nextChar && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar))) {
|
|
1029
900
|
var lLength = match[0].length - 1;
|
|
1030
901
|
var rDelim,
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
902
|
+
rLength,
|
|
903
|
+
delimTotal = lLength,
|
|
904
|
+
midDelimTotal = 0;
|
|
1034
905
|
var endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
|
|
1035
|
-
endReg.lastIndex = 0;
|
|
906
|
+
endReg.lastIndex = 0;
|
|
1036
907
|
|
|
908
|
+
// Clip maskedSrc to same section of string as src (move to lexer?)
|
|
1037
909
|
maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
|
|
1038
|
-
|
|
1039
910
|
while ((match = endReg.exec(maskedSrc)) != null) {
|
|
1040
911
|
rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
|
|
1041
912
|
if (!rDelim) continue; // skip single * in __abc*abc__
|
|
1042
913
|
|
|
1043
914
|
rLength = rDelim.length;
|
|
1044
|
-
|
|
1045
915
|
if (match[3] || match[4]) {
|
|
1046
916
|
// found another Left Delim
|
|
1047
917
|
delimTotal += rLength;
|
|
@@ -1056,22 +926,22 @@
|
|
|
1056
926
|
|
|
1057
927
|
delimTotal -= rLength;
|
|
1058
928
|
if (delimTotal > 0) continue; // Haven't found enough closing delimiters
|
|
1059
|
-
// Remove extra characters. *a*** -> *a*
|
|
1060
929
|
|
|
1061
|
-
|
|
930
|
+
// Remove extra characters. *a*** -> *a*
|
|
931
|
+
rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
|
|
1062
932
|
|
|
933
|
+
// Create `em` if smallest delimiter has odd char count. *a***
|
|
1063
934
|
if (Math.min(lLength, rLength) % 2) {
|
|
1064
935
|
var _text = src.slice(1, lLength + match.index + rLength);
|
|
1065
|
-
|
|
1066
936
|
return {
|
|
1067
937
|
type: 'em',
|
|
1068
938
|
raw: src.slice(0, lLength + match.index + rLength + 1),
|
|
1069
939
|
text: _text,
|
|
1070
940
|
tokens: this.lexer.inlineTokens(_text)
|
|
1071
941
|
};
|
|
1072
|
-
}
|
|
1073
|
-
|
|
942
|
+
}
|
|
1074
943
|
|
|
944
|
+
// Create 'strong' if smallest delimiter has even char count. **a***
|
|
1075
945
|
var text = src.slice(2, lLength + match.index + rLength - 1);
|
|
1076
946
|
return {
|
|
1077
947
|
type: 'strong',
|
|
@@ -1082,19 +952,15 @@
|
|
|
1082
952
|
}
|
|
1083
953
|
}
|
|
1084
954
|
};
|
|
1085
|
-
|
|
1086
955
|
_proto.codespan = function codespan(src) {
|
|
1087
956
|
var cap = this.rules.inline.code.exec(src);
|
|
1088
|
-
|
|
1089
957
|
if (cap) {
|
|
1090
958
|
var text = cap[2].replace(/\n/g, ' ');
|
|
1091
959
|
var hasNonSpaceChars = /[^ ]/.test(text);
|
|
1092
960
|
var hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
|
|
1093
|
-
|
|
1094
961
|
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
|
|
1095
962
|
text = text.substring(1, text.length - 1);
|
|
1096
963
|
}
|
|
1097
|
-
|
|
1098
964
|
text = escape(text, true);
|
|
1099
965
|
return {
|
|
1100
966
|
type: 'codespan',
|
|
@@ -1103,10 +969,8 @@
|
|
|
1103
969
|
};
|
|
1104
970
|
}
|
|
1105
971
|
};
|
|
1106
|
-
|
|
1107
972
|
_proto.br = function br(src) {
|
|
1108
973
|
var cap = this.rules.inline.br.exec(src);
|
|
1109
|
-
|
|
1110
974
|
if (cap) {
|
|
1111
975
|
return {
|
|
1112
976
|
type: 'br',
|
|
@@ -1114,10 +978,8 @@
|
|
|
1114
978
|
};
|
|
1115
979
|
}
|
|
1116
980
|
};
|
|
1117
|
-
|
|
1118
981
|
_proto.del = function del(src) {
|
|
1119
982
|
var cap = this.rules.inline.del.exec(src);
|
|
1120
|
-
|
|
1121
983
|
if (cap) {
|
|
1122
984
|
return {
|
|
1123
985
|
type: 'del',
|
|
@@ -1127,13 +989,10 @@
|
|
|
1127
989
|
};
|
|
1128
990
|
}
|
|
1129
991
|
};
|
|
1130
|
-
|
|
1131
992
|
_proto.autolink = function autolink(src, mangle) {
|
|
1132
993
|
var cap = this.rules.inline.autolink.exec(src);
|
|
1133
|
-
|
|
1134
994
|
if (cap) {
|
|
1135
995
|
var text, href;
|
|
1136
|
-
|
|
1137
996
|
if (cap[2] === '@') {
|
|
1138
997
|
text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
|
|
1139
998
|
href = 'mailto:' + text;
|
|
@@ -1141,7 +1000,6 @@
|
|
|
1141
1000
|
text = escape(cap[1]);
|
|
1142
1001
|
href = text;
|
|
1143
1002
|
}
|
|
1144
|
-
|
|
1145
1003
|
return {
|
|
1146
1004
|
type: 'link',
|
|
1147
1005
|
raw: cap[0],
|
|
@@ -1155,34 +1013,27 @@
|
|
|
1155
1013
|
};
|
|
1156
1014
|
}
|
|
1157
1015
|
};
|
|
1158
|
-
|
|
1159
1016
|
_proto.url = function url(src, mangle) {
|
|
1160
1017
|
var cap;
|
|
1161
|
-
|
|
1162
1018
|
if (cap = this.rules.inline.url.exec(src)) {
|
|
1163
1019
|
var text, href;
|
|
1164
|
-
|
|
1165
1020
|
if (cap[2] === '@') {
|
|
1166
1021
|
text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
|
|
1167
1022
|
href = 'mailto:' + text;
|
|
1168
1023
|
} else {
|
|
1169
1024
|
// do extended autolink path validation
|
|
1170
1025
|
var prevCapZero;
|
|
1171
|
-
|
|
1172
1026
|
do {
|
|
1173
1027
|
prevCapZero = cap[0];
|
|
1174
1028
|
cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
|
|
1175
1029
|
} while (prevCapZero !== cap[0]);
|
|
1176
|
-
|
|
1177
1030
|
text = escape(cap[0]);
|
|
1178
|
-
|
|
1179
1031
|
if (cap[1] === 'www.') {
|
|
1180
1032
|
href = 'http://' + text;
|
|
1181
1033
|
} else {
|
|
1182
1034
|
href = text;
|
|
1183
1035
|
}
|
|
1184
1036
|
}
|
|
1185
|
-
|
|
1186
1037
|
return {
|
|
1187
1038
|
type: 'link',
|
|
1188
1039
|
raw: cap[0],
|
|
@@ -1196,19 +1047,15 @@
|
|
|
1196
1047
|
};
|
|
1197
1048
|
}
|
|
1198
1049
|
};
|
|
1199
|
-
|
|
1200
1050
|
_proto.inlineText = function inlineText(src, smartypants) {
|
|
1201
1051
|
var cap = this.rules.inline.text.exec(src);
|
|
1202
|
-
|
|
1203
1052
|
if (cap) {
|
|
1204
1053
|
var text;
|
|
1205
|
-
|
|
1206
1054
|
if (this.lexer.state.inRawBlock) {
|
|
1207
1055
|
text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0];
|
|
1208
1056
|
} else {
|
|
1209
1057
|
text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
|
|
1210
1058
|
}
|
|
1211
|
-
|
|
1212
1059
|
return {
|
|
1213
1060
|
type: 'text',
|
|
1214
1061
|
raw: cap[0],
|
|
@@ -1216,14 +1063,12 @@
|
|
|
1216
1063
|
};
|
|
1217
1064
|
}
|
|
1218
1065
|
};
|
|
1219
|
-
|
|
1220
1066
|
return Tokenizer;
|
|
1221
1067
|
}();
|
|
1222
1068
|
|
|
1223
1069
|
/**
|
|
1224
1070
|
* Block-Level Grammar
|
|
1225
1071
|
*/
|
|
1226
|
-
|
|
1227
1072
|
var block = {
|
|
1228
1073
|
newline: /^(?: *(?:\n|$))+/,
|
|
1229
1074
|
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
@@ -1264,11 +1109,13 @@
|
|
|
1264
1109
|
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
|
|
1265
1110
|
.getRegex();
|
|
1266
1111
|
block.blockquote = edit(block.blockquote).replace('paragraph', block.paragraph).getRegex();
|
|
1112
|
+
|
|
1267
1113
|
/**
|
|
1268
1114
|
* Normal Block Grammar
|
|
1269
1115
|
*/
|
|
1270
1116
|
|
|
1271
1117
|
block.normal = merge({}, block);
|
|
1118
|
+
|
|
1272
1119
|
/**
|
|
1273
1120
|
* GFM Block Grammar
|
|
1274
1121
|
*/
|
|
@@ -1277,8 +1124,8 @@
|
|
|
1277
1124
|
table: '^ *([^\\n ].*\\|.*)\\n' // Header
|
|
1278
1125
|
+ ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' // Align
|
|
1279
1126
|
+ '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
|
1280
|
-
|
|
1281
1127
|
});
|
|
1128
|
+
|
|
1282
1129
|
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[.)]) ') // only lists starting from 1 can interrupt
|
|
1283
1130
|
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
1284
1131
|
.getRegex();
|
|
@@ -1300,10 +1147,10 @@
|
|
|
1300
1147
|
// fences not supported
|
|
1301
1148
|
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()
|
|
1302
1149
|
});
|
|
1150
|
+
|
|
1303
1151
|
/**
|
|
1304
1152
|
* Inline-Level Grammar
|
|
1305
1153
|
*/
|
|
1306
|
-
|
|
1307
1154
|
var inline = {
|
|
1308
1155
|
escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
|
|
1309
1156
|
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
|
@@ -1324,19 +1171,21 @@
|
|
|
1324
1171
|
// () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
|
|
1325
1172
|
rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
|
|
1326
1173
|
rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
1327
|
-
|
|
1328
1174
|
},
|
|
1175
|
+
|
|
1329
1176
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
1330
1177
|
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
1331
1178
|
del: noopTest,
|
|
1332
1179
|
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
|
|
1333
1180
|
punctuation: /^([\spunctuation])/
|
|
1334
|
-
};
|
|
1335
|
-
// without * and _ to handle the different emphasis markers * and _
|
|
1181
|
+
};
|
|
1336
1182
|
|
|
1183
|
+
// list of punctuation marks from CommonMark spec
|
|
1184
|
+
// without * and _ to handle the different emphasis markers * and _
|
|
1337
1185
|
inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
|
|
1338
|
-
inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1186
|
+
inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1339
1187
|
|
|
1188
|
+
// sequences em should skip over [title](link), `code`, <html>
|
|
1340
1189
|
inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
|
|
1341
1190
|
inline.escapedEmSt = /\\\*|\\_/g;
|
|
1342
1191
|
inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
|
|
@@ -1356,11 +1205,13 @@
|
|
|
1356
1205
|
inline.reflink = edit(inline.reflink).replace('label', inline._label).replace('ref', block._label).getRegex();
|
|
1357
1206
|
inline.nolink = edit(inline.nolink).replace('ref', block._label).getRegex();
|
|
1358
1207
|
inline.reflinkSearch = edit(inline.reflinkSearch, 'g').replace('reflink', inline.reflink).replace('nolink', inline.nolink).getRegex();
|
|
1208
|
+
|
|
1359
1209
|
/**
|
|
1360
1210
|
* Normal Inline Grammar
|
|
1361
1211
|
*/
|
|
1362
1212
|
|
|
1363
1213
|
inline.normal = merge({}, inline);
|
|
1214
|
+
|
|
1364
1215
|
/**
|
|
1365
1216
|
* Pedantic Inline Grammar
|
|
1366
1217
|
*/
|
|
@@ -1381,6 +1232,7 @@
|
|
|
1381
1232
|
link: edit(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
|
|
1382
1233
|
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
|
|
1383
1234
|
});
|
|
1235
|
+
|
|
1384
1236
|
/**
|
|
1385
1237
|
* GFM Inline Grammar
|
|
1386
1238
|
*/
|
|
@@ -1407,46 +1259,46 @@
|
|
|
1407
1259
|
* smartypants text replacement
|
|
1408
1260
|
* @param {string} text
|
|
1409
1261
|
*/
|
|
1410
|
-
|
|
1411
1262
|
function smartypants(text) {
|
|
1412
|
-
return text
|
|
1413
|
-
|
|
1414
|
-
.replace(
|
|
1415
|
-
|
|
1416
|
-
.replace(
|
|
1417
|
-
|
|
1418
|
-
.replace(/"/g, "\
|
|
1263
|
+
return text
|
|
1264
|
+
// em-dashes
|
|
1265
|
+
.replace(/---/g, "\u2014")
|
|
1266
|
+
// en-dashes
|
|
1267
|
+
.replace(/--/g, "\u2013")
|
|
1268
|
+
// opening singles
|
|
1269
|
+
.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018")
|
|
1270
|
+
// closing singles & apostrophes
|
|
1271
|
+
.replace(/'/g, "\u2019")
|
|
1272
|
+
// opening doubles
|
|
1273
|
+
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C")
|
|
1274
|
+
// closing doubles
|
|
1275
|
+
.replace(/"/g, "\u201D")
|
|
1276
|
+
// ellipses
|
|
1419
1277
|
.replace(/\.{3}/g, "\u2026");
|
|
1420
1278
|
}
|
|
1279
|
+
|
|
1421
1280
|
/**
|
|
1422
1281
|
* mangle email addresses
|
|
1423
1282
|
* @param {string} text
|
|
1424
1283
|
*/
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
1284
|
function mangle(text) {
|
|
1428
1285
|
var out = '',
|
|
1429
|
-
|
|
1430
|
-
|
|
1286
|
+
i,
|
|
1287
|
+
ch;
|
|
1431
1288
|
var l = text.length;
|
|
1432
|
-
|
|
1433
1289
|
for (i = 0; i < l; i++) {
|
|
1434
1290
|
ch = text.charCodeAt(i);
|
|
1435
|
-
|
|
1436
1291
|
if (Math.random() > 0.5) {
|
|
1437
1292
|
ch = 'x' + ch.toString(16);
|
|
1438
1293
|
}
|
|
1439
|
-
|
|
1440
1294
|
out += '&#' + ch + ';';
|
|
1441
1295
|
}
|
|
1442
|
-
|
|
1443
1296
|
return out;
|
|
1444
1297
|
}
|
|
1298
|
+
|
|
1445
1299
|
/**
|
|
1446
1300
|
* Block Lexer
|
|
1447
1301
|
*/
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
1302
|
var Lexer = /*#__PURE__*/function () {
|
|
1451
1303
|
function Lexer(options) {
|
|
1452
1304
|
this.tokens = [];
|
|
@@ -1466,27 +1318,23 @@
|
|
|
1466
1318
|
block: block.normal,
|
|
1467
1319
|
inline: inline.normal
|
|
1468
1320
|
};
|
|
1469
|
-
|
|
1470
1321
|
if (this.options.pedantic) {
|
|
1471
1322
|
rules.block = block.pedantic;
|
|
1472
1323
|
rules.inline = inline.pedantic;
|
|
1473
1324
|
} else if (this.options.gfm) {
|
|
1474
1325
|
rules.block = block.gfm;
|
|
1475
|
-
|
|
1476
1326
|
if (this.options.breaks) {
|
|
1477
1327
|
rules.inline = inline.breaks;
|
|
1478
1328
|
} else {
|
|
1479
1329
|
rules.inline = inline.gfm;
|
|
1480
1330
|
}
|
|
1481
1331
|
}
|
|
1482
|
-
|
|
1483
1332
|
this.tokenizer.rules = rules;
|
|
1484
1333
|
}
|
|
1334
|
+
|
|
1485
1335
|
/**
|
|
1486
1336
|
* Expose Rules
|
|
1487
1337
|
*/
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
1338
|
/**
|
|
1491
1339
|
* Static Lex Method
|
|
1492
1340
|
*/
|
|
@@ -1494,45 +1342,37 @@
|
|
|
1494
1342
|
var lexer = new Lexer(options);
|
|
1495
1343
|
return lexer.lex(src);
|
|
1496
1344
|
}
|
|
1345
|
+
|
|
1497
1346
|
/**
|
|
1498
1347
|
* Static Lex Inline Method
|
|
1499
|
-
|
|
1500
|
-
;
|
|
1501
|
-
|
|
1348
|
+
*/;
|
|
1502
1349
|
Lexer.lexInline = function lexInline(src, options) {
|
|
1503
1350
|
var lexer = new Lexer(options);
|
|
1504
1351
|
return lexer.inlineTokens(src);
|
|
1505
1352
|
}
|
|
1353
|
+
|
|
1506
1354
|
/**
|
|
1507
1355
|
* Preprocessing
|
|
1508
|
-
|
|
1509
|
-
;
|
|
1510
|
-
|
|
1356
|
+
*/;
|
|
1511
1357
|
var _proto = Lexer.prototype;
|
|
1512
|
-
|
|
1513
1358
|
_proto.lex = function lex(src) {
|
|
1514
1359
|
src = src.replace(/\r\n|\r/g, '\n');
|
|
1515
1360
|
this.blockTokens(src, this.tokens);
|
|
1516
1361
|
var next;
|
|
1517
|
-
|
|
1518
1362
|
while (next = this.inlineQueue.shift()) {
|
|
1519
1363
|
this.inlineTokens(next.src, next.tokens);
|
|
1520
1364
|
}
|
|
1521
|
-
|
|
1522
1365
|
return this.tokens;
|
|
1523
1366
|
}
|
|
1367
|
+
|
|
1524
1368
|
/**
|
|
1525
1369
|
* Lexing
|
|
1526
|
-
|
|
1527
|
-
;
|
|
1528
|
-
|
|
1370
|
+
*/;
|
|
1529
1371
|
_proto.blockTokens = function blockTokens(src, tokens) {
|
|
1530
1372
|
var _this = this;
|
|
1531
|
-
|
|
1532
1373
|
if (tokens === void 0) {
|
|
1533
1374
|
tokens = [];
|
|
1534
1375
|
}
|
|
1535
|
-
|
|
1536
1376
|
if (this.options.pedantic) {
|
|
1537
1377
|
src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
|
|
1538
1378
|
} else {
|
|
@@ -1540,9 +1380,7 @@
|
|
|
1540
1380
|
return leading + ' '.repeat(tabs.length);
|
|
1541
1381
|
});
|
|
1542
1382
|
}
|
|
1543
|
-
|
|
1544
1383
|
var token, lastToken, cutSrc, lastParagraphClipped;
|
|
1545
|
-
|
|
1546
1384
|
while (src) {
|
|
1547
1385
|
if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some(function (extTokenizer) {
|
|
1548
1386
|
if (token = extTokenizer.call({
|
|
@@ -1552,16 +1390,14 @@
|
|
|
1552
1390
|
tokens.push(token);
|
|
1553
1391
|
return true;
|
|
1554
1392
|
}
|
|
1555
|
-
|
|
1556
1393
|
return false;
|
|
1557
1394
|
})) {
|
|
1558
1395
|
continue;
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1396
|
+
}
|
|
1561
1397
|
|
|
1398
|
+
// newline
|
|
1562
1399
|
if (token = this.tokenizer.space(src)) {
|
|
1563
1400
|
src = src.substring(token.raw.length);
|
|
1564
|
-
|
|
1565
1401
|
if (token.raw.length === 1 && tokens.length > 0) {
|
|
1566
1402
|
// if there's a single \n as a spacer, it's terminating the last line,
|
|
1567
1403
|
// so move it there so that we don't get unecessary paragraph tags
|
|
@@ -1569,15 +1405,14 @@
|
|
|
1569
1405
|
} else {
|
|
1570
1406
|
tokens.push(token);
|
|
1571
1407
|
}
|
|
1572
|
-
|
|
1573
1408
|
continue;
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1409
|
+
}
|
|
1576
1410
|
|
|
1411
|
+
// code
|
|
1577
1412
|
if (token = this.tokenizer.code(src)) {
|
|
1578
1413
|
src = src.substring(token.raw.length);
|
|
1579
|
-
lastToken = tokens[tokens.length - 1];
|
|
1580
|
-
|
|
1414
|
+
lastToken = tokens[tokens.length - 1];
|
|
1415
|
+
// An indented code block cannot interrupt a paragraph.
|
|
1581
1416
|
if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
|
|
1582
1417
|
lastToken.raw += '\n' + token.raw;
|
|
1583
1418
|
lastToken.text += '\n' + token.text;
|
|
@@ -1585,57 +1420,55 @@
|
|
|
1585
1420
|
} else {
|
|
1586
1421
|
tokens.push(token);
|
|
1587
1422
|
}
|
|
1588
|
-
|
|
1589
1423
|
continue;
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1424
|
+
}
|
|
1592
1425
|
|
|
1426
|
+
// fences
|
|
1593
1427
|
if (token = this.tokenizer.fences(src)) {
|
|
1594
1428
|
src = src.substring(token.raw.length);
|
|
1595
1429
|
tokens.push(token);
|
|
1596
1430
|
continue;
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1431
|
+
}
|
|
1599
1432
|
|
|
1433
|
+
// heading
|
|
1600
1434
|
if (token = this.tokenizer.heading(src)) {
|
|
1601
1435
|
src = src.substring(token.raw.length);
|
|
1602
1436
|
tokens.push(token);
|
|
1603
1437
|
continue;
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1438
|
+
}
|
|
1606
1439
|
|
|
1440
|
+
// hr
|
|
1607
1441
|
if (token = this.tokenizer.hr(src)) {
|
|
1608
1442
|
src = src.substring(token.raw.length);
|
|
1609
1443
|
tokens.push(token);
|
|
1610
1444
|
continue;
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1445
|
+
}
|
|
1613
1446
|
|
|
1447
|
+
// blockquote
|
|
1614
1448
|
if (token = this.tokenizer.blockquote(src)) {
|
|
1615
1449
|
src = src.substring(token.raw.length);
|
|
1616
1450
|
tokens.push(token);
|
|
1617
1451
|
continue;
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1452
|
+
}
|
|
1620
1453
|
|
|
1454
|
+
// list
|
|
1621
1455
|
if (token = this.tokenizer.list(src)) {
|
|
1622
1456
|
src = src.substring(token.raw.length);
|
|
1623
1457
|
tokens.push(token);
|
|
1624
1458
|
continue;
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1459
|
+
}
|
|
1627
1460
|
|
|
1461
|
+
// html
|
|
1628
1462
|
if (token = this.tokenizer.html(src)) {
|
|
1629
1463
|
src = src.substring(token.raw.length);
|
|
1630
1464
|
tokens.push(token);
|
|
1631
1465
|
continue;
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1466
|
+
}
|
|
1634
1467
|
|
|
1468
|
+
// def
|
|
1635
1469
|
if (token = this.tokenizer.def(src)) {
|
|
1636
1470
|
src = src.substring(token.raw.length);
|
|
1637
1471
|
lastToken = tokens[tokens.length - 1];
|
|
1638
|
-
|
|
1639
1472
|
if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
|
|
1640
1473
|
lastToken.raw += '\n' + token.raw;
|
|
1641
1474
|
lastToken.text += '\n' + token.raw;
|
|
@@ -1646,53 +1479,46 @@
|
|
|
1646
1479
|
title: token.title
|
|
1647
1480
|
};
|
|
1648
1481
|
}
|
|
1649
|
-
|
|
1650
1482
|
continue;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1483
|
+
}
|
|
1653
1484
|
|
|
1485
|
+
// table (gfm)
|
|
1654
1486
|
if (token = this.tokenizer.table(src)) {
|
|
1655
1487
|
src = src.substring(token.raw.length);
|
|
1656
1488
|
tokens.push(token);
|
|
1657
1489
|
continue;
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1490
|
+
}
|
|
1660
1491
|
|
|
1492
|
+
// lheading
|
|
1661
1493
|
if (token = this.tokenizer.lheading(src)) {
|
|
1662
1494
|
src = src.substring(token.raw.length);
|
|
1663
1495
|
tokens.push(token);
|
|
1664
1496
|
continue;
|
|
1665
|
-
}
|
|
1666
|
-
// prevent paragraph consuming extensions by clipping 'src' to extension start
|
|
1667
|
-
|
|
1497
|
+
}
|
|
1668
1498
|
|
|
1499
|
+
// top-level paragraph
|
|
1500
|
+
// prevent paragraph consuming extensions by clipping 'src' to extension start
|
|
1669
1501
|
cutSrc = src;
|
|
1670
|
-
|
|
1671
1502
|
if (this.options.extensions && this.options.extensions.startBlock) {
|
|
1672
1503
|
(function () {
|
|
1673
1504
|
var startIndex = Infinity;
|
|
1674
1505
|
var tempSrc = src.slice(1);
|
|
1675
1506
|
var tempStart = void 0;
|
|
1676
|
-
|
|
1677
1507
|
_this.options.extensions.startBlock.forEach(function (getStartIndex) {
|
|
1678
1508
|
tempStart = getStartIndex.call({
|
|
1679
1509
|
lexer: this
|
|
1680
1510
|
}, tempSrc);
|
|
1681
|
-
|
|
1682
1511
|
if (typeof tempStart === 'number' && tempStart >= 0) {
|
|
1683
1512
|
startIndex = Math.min(startIndex, tempStart);
|
|
1684
1513
|
}
|
|
1685
1514
|
});
|
|
1686
|
-
|
|
1687
1515
|
if (startIndex < Infinity && startIndex >= 0) {
|
|
1688
1516
|
cutSrc = src.substring(0, startIndex + 1);
|
|
1689
1517
|
}
|
|
1690
1518
|
})();
|
|
1691
1519
|
}
|
|
1692
|
-
|
|
1693
1520
|
if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
|
|
1694
1521
|
lastToken = tokens[tokens.length - 1];
|
|
1695
|
-
|
|
1696
1522
|
if (lastParagraphClipped && lastToken.type === 'paragraph') {
|
|
1697
1523
|
lastToken.raw += '\n' + token.raw;
|
|
1698
1524
|
lastToken.text += '\n' + token.text;
|
|
@@ -1701,17 +1527,15 @@
|
|
|
1701
1527
|
} else {
|
|
1702
1528
|
tokens.push(token);
|
|
1703
1529
|
}
|
|
1704
|
-
|
|
1705
1530
|
lastParagraphClipped = cutSrc.length !== src.length;
|
|
1706
1531
|
src = src.substring(token.raw.length);
|
|
1707
1532
|
continue;
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1533
|
+
}
|
|
1710
1534
|
|
|
1535
|
+
// text
|
|
1711
1536
|
if (token = this.tokenizer.text(src)) {
|
|
1712
1537
|
src = src.substring(token.raw.length);
|
|
1713
1538
|
lastToken = tokens[tokens.length - 1];
|
|
1714
|
-
|
|
1715
1539
|
if (lastToken && lastToken.type === 'text') {
|
|
1716
1540
|
lastToken.raw += '\n' + token.raw;
|
|
1717
1541
|
lastToken.text += '\n' + token.text;
|
|
@@ -1720,13 +1544,10 @@
|
|
|
1720
1544
|
} else {
|
|
1721
1545
|
tokens.push(token);
|
|
1722
1546
|
}
|
|
1723
|
-
|
|
1724
1547
|
continue;
|
|
1725
1548
|
}
|
|
1726
|
-
|
|
1727
1549
|
if (src) {
|
|
1728
1550
|
var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
|
1729
|
-
|
|
1730
1551
|
if (this.options.silent) {
|
|
1731
1552
|
console.error(errMsg);
|
|
1732
1553
|
break;
|
|
@@ -1735,43 +1556,38 @@
|
|
|
1735
1556
|
}
|
|
1736
1557
|
}
|
|
1737
1558
|
}
|
|
1738
|
-
|
|
1739
1559
|
this.state.top = true;
|
|
1740
1560
|
return tokens;
|
|
1741
1561
|
};
|
|
1742
|
-
|
|
1743
1562
|
_proto.inline = function inline(src, tokens) {
|
|
1744
1563
|
if (tokens === void 0) {
|
|
1745
1564
|
tokens = [];
|
|
1746
1565
|
}
|
|
1747
|
-
|
|
1748
1566
|
this.inlineQueue.push({
|
|
1749
1567
|
src: src,
|
|
1750
1568
|
tokens: tokens
|
|
1751
1569
|
});
|
|
1752
1570
|
return tokens;
|
|
1753
1571
|
}
|
|
1572
|
+
|
|
1754
1573
|
/**
|
|
1755
1574
|
* Lexing/Compiling
|
|
1756
|
-
|
|
1757
|
-
;
|
|
1758
|
-
|
|
1575
|
+
*/;
|
|
1759
1576
|
_proto.inlineTokens = function inlineTokens(src, tokens) {
|
|
1760
1577
|
var _this2 = this;
|
|
1761
|
-
|
|
1762
1578
|
if (tokens === void 0) {
|
|
1763
1579
|
tokens = [];
|
|
1764
1580
|
}
|
|
1581
|
+
var token, lastToken, cutSrc;
|
|
1765
1582
|
|
|
1766
|
-
|
|
1767
|
-
|
|
1583
|
+
// String with links masked to avoid interference with em and strong
|
|
1768
1584
|
var maskedSrc = src;
|
|
1769
1585
|
var match;
|
|
1770
|
-
var keepPrevChar, prevChar;
|
|
1586
|
+
var keepPrevChar, prevChar;
|
|
1771
1587
|
|
|
1588
|
+
// Mask out reflinks
|
|
1772
1589
|
if (this.tokens.links) {
|
|
1773
1590
|
var links = Object.keys(this.tokens.links);
|
|
1774
|
-
|
|
1775
1591
|
if (links.length > 0) {
|
|
1776
1592
|
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
|
1777
1593
|
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
|
@@ -1779,25 +1595,23 @@
|
|
|
1779
1595
|
}
|
|
1780
1596
|
}
|
|
1781
1597
|
}
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
|
|
1598
|
+
}
|
|
1599
|
+
// Mask out other blocks
|
|
1785
1600
|
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
|
1786
1601
|
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1602
|
+
}
|
|
1789
1603
|
|
|
1604
|
+
// Mask out escaped em & strong delimiters
|
|
1790
1605
|
while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) {
|
|
1791
1606
|
maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
|
|
1792
1607
|
}
|
|
1793
|
-
|
|
1794
1608
|
while (src) {
|
|
1795
1609
|
if (!keepPrevChar) {
|
|
1796
1610
|
prevChar = '';
|
|
1797
1611
|
}
|
|
1612
|
+
keepPrevChar = false;
|
|
1798
1613
|
|
|
1799
|
-
|
|
1800
|
-
|
|
1614
|
+
// extensions
|
|
1801
1615
|
if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some(function (extTokenizer) {
|
|
1802
1616
|
if (token = extTokenizer.call({
|
|
1803
1617
|
lexer: _this2
|
|
@@ -1806,148 +1620,132 @@
|
|
|
1806
1620
|
tokens.push(token);
|
|
1807
1621
|
return true;
|
|
1808
1622
|
}
|
|
1809
|
-
|
|
1810
1623
|
return false;
|
|
1811
1624
|
})) {
|
|
1812
1625
|
continue;
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1626
|
+
}
|
|
1815
1627
|
|
|
1628
|
+
// escape
|
|
1816
1629
|
if (token = this.tokenizer.escape(src)) {
|
|
1817
1630
|
src = src.substring(token.raw.length);
|
|
1818
1631
|
tokens.push(token);
|
|
1819
1632
|
continue;
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1633
|
+
}
|
|
1822
1634
|
|
|
1635
|
+
// tag
|
|
1823
1636
|
if (token = this.tokenizer.tag(src)) {
|
|
1824
1637
|
src = src.substring(token.raw.length);
|
|
1825
1638
|
lastToken = tokens[tokens.length - 1];
|
|
1826
|
-
|
|
1827
1639
|
if (lastToken && token.type === 'text' && lastToken.type === 'text') {
|
|
1828
1640
|
lastToken.raw += token.raw;
|
|
1829
1641
|
lastToken.text += token.text;
|
|
1830
1642
|
} else {
|
|
1831
1643
|
tokens.push(token);
|
|
1832
1644
|
}
|
|
1833
|
-
|
|
1834
1645
|
continue;
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1646
|
+
}
|
|
1837
1647
|
|
|
1648
|
+
// link
|
|
1838
1649
|
if (token = this.tokenizer.link(src)) {
|
|
1839
1650
|
src = src.substring(token.raw.length);
|
|
1840
1651
|
tokens.push(token);
|
|
1841
1652
|
continue;
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1653
|
+
}
|
|
1844
1654
|
|
|
1655
|
+
// reflink, nolink
|
|
1845
1656
|
if (token = this.tokenizer.reflink(src, this.tokens.links)) {
|
|
1846
1657
|
src = src.substring(token.raw.length);
|
|
1847
1658
|
lastToken = tokens[tokens.length - 1];
|
|
1848
|
-
|
|
1849
1659
|
if (lastToken && token.type === 'text' && lastToken.type === 'text') {
|
|
1850
1660
|
lastToken.raw += token.raw;
|
|
1851
1661
|
lastToken.text += token.text;
|
|
1852
1662
|
} else {
|
|
1853
1663
|
tokens.push(token);
|
|
1854
1664
|
}
|
|
1855
|
-
|
|
1856
1665
|
continue;
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1666
|
+
}
|
|
1859
1667
|
|
|
1668
|
+
// em & strong
|
|
1860
1669
|
if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
|
|
1861
1670
|
src = src.substring(token.raw.length);
|
|
1862
1671
|
tokens.push(token);
|
|
1863
1672
|
continue;
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1673
|
+
}
|
|
1866
1674
|
|
|
1675
|
+
// code
|
|
1867
1676
|
if (token = this.tokenizer.codespan(src)) {
|
|
1868
1677
|
src = src.substring(token.raw.length);
|
|
1869
1678
|
tokens.push(token);
|
|
1870
1679
|
continue;
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1680
|
+
}
|
|
1873
1681
|
|
|
1682
|
+
// br
|
|
1874
1683
|
if (token = this.tokenizer.br(src)) {
|
|
1875
1684
|
src = src.substring(token.raw.length);
|
|
1876
1685
|
tokens.push(token);
|
|
1877
1686
|
continue;
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1687
|
+
}
|
|
1880
1688
|
|
|
1689
|
+
// del (gfm)
|
|
1881
1690
|
if (token = this.tokenizer.del(src)) {
|
|
1882
1691
|
src = src.substring(token.raw.length);
|
|
1883
1692
|
tokens.push(token);
|
|
1884
1693
|
continue;
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1694
|
+
}
|
|
1887
1695
|
|
|
1696
|
+
// autolink
|
|
1888
1697
|
if (token = this.tokenizer.autolink(src, mangle)) {
|
|
1889
1698
|
src = src.substring(token.raw.length);
|
|
1890
1699
|
tokens.push(token);
|
|
1891
1700
|
continue;
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1701
|
+
}
|
|
1894
1702
|
|
|
1703
|
+
// url (gfm)
|
|
1895
1704
|
if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
|
|
1896
1705
|
src = src.substring(token.raw.length);
|
|
1897
1706
|
tokens.push(token);
|
|
1898
1707
|
continue;
|
|
1899
|
-
}
|
|
1900
|
-
// prevent inlineText consuming extensions by clipping 'src' to extension start
|
|
1901
|
-
|
|
1708
|
+
}
|
|
1902
1709
|
|
|
1710
|
+
// text
|
|
1711
|
+
// prevent inlineText consuming extensions by clipping 'src' to extension start
|
|
1903
1712
|
cutSrc = src;
|
|
1904
|
-
|
|
1905
1713
|
if (this.options.extensions && this.options.extensions.startInline) {
|
|
1906
1714
|
(function () {
|
|
1907
1715
|
var startIndex = Infinity;
|
|
1908
1716
|
var tempSrc = src.slice(1);
|
|
1909
1717
|
var tempStart = void 0;
|
|
1910
|
-
|
|
1911
1718
|
_this2.options.extensions.startInline.forEach(function (getStartIndex) {
|
|
1912
1719
|
tempStart = getStartIndex.call({
|
|
1913
1720
|
lexer: this
|
|
1914
1721
|
}, tempSrc);
|
|
1915
|
-
|
|
1916
1722
|
if (typeof tempStart === 'number' && tempStart >= 0) {
|
|
1917
1723
|
startIndex = Math.min(startIndex, tempStart);
|
|
1918
1724
|
}
|
|
1919
1725
|
});
|
|
1920
|
-
|
|
1921
1726
|
if (startIndex < Infinity && startIndex >= 0) {
|
|
1922
1727
|
cutSrc = src.substring(0, startIndex + 1);
|
|
1923
1728
|
}
|
|
1924
1729
|
})();
|
|
1925
1730
|
}
|
|
1926
|
-
|
|
1927
1731
|
if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
|
|
1928
1732
|
src = src.substring(token.raw.length);
|
|
1929
|
-
|
|
1930
1733
|
if (token.raw.slice(-1) !== '_') {
|
|
1931
1734
|
// Track prevChar before string of ____ started
|
|
1932
1735
|
prevChar = token.raw.slice(-1);
|
|
1933
1736
|
}
|
|
1934
|
-
|
|
1935
1737
|
keepPrevChar = true;
|
|
1936
1738
|
lastToken = tokens[tokens.length - 1];
|
|
1937
|
-
|
|
1938
1739
|
if (lastToken && lastToken.type === 'text') {
|
|
1939
1740
|
lastToken.raw += token.raw;
|
|
1940
1741
|
lastToken.text += token.text;
|
|
1941
1742
|
} else {
|
|
1942
1743
|
tokens.push(token);
|
|
1943
1744
|
}
|
|
1944
|
-
|
|
1945
1745
|
continue;
|
|
1946
1746
|
}
|
|
1947
|
-
|
|
1948
1747
|
if (src) {
|
|
1949
1748
|
var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
|
1950
|
-
|
|
1951
1749
|
if (this.options.silent) {
|
|
1952
1750
|
console.error(errMsg);
|
|
1953
1751
|
break;
|
|
@@ -1956,10 +1754,8 @@
|
|
|
1956
1754
|
}
|
|
1957
1755
|
}
|
|
1958
1756
|
}
|
|
1959
|
-
|
|
1960
1757
|
return tokens;
|
|
1961
1758
|
};
|
|
1962
|
-
|
|
1963
1759
|
_createClass(Lexer, null, [{
|
|
1964
1760
|
key: "rules",
|
|
1965
1761
|
get: function get() {
|
|
@@ -1969,212 +1765,175 @@
|
|
|
1969
1765
|
};
|
|
1970
1766
|
}
|
|
1971
1767
|
}]);
|
|
1972
|
-
|
|
1973
1768
|
return Lexer;
|
|
1974
1769
|
}();
|
|
1975
1770
|
|
|
1976
1771
|
/**
|
|
1977
1772
|
* Renderer
|
|
1978
1773
|
*/
|
|
1979
|
-
|
|
1980
1774
|
var Renderer = /*#__PURE__*/function () {
|
|
1981
1775
|
function Renderer(options) {
|
|
1982
1776
|
this.options = options || exports.defaults;
|
|
1983
1777
|
}
|
|
1984
|
-
|
|
1985
1778
|
var _proto = Renderer.prototype;
|
|
1986
|
-
|
|
1987
1779
|
_proto.code = function code(_code, infostring, escaped) {
|
|
1988
1780
|
var lang = (infostring || '').match(/\S*/)[0];
|
|
1989
|
-
|
|
1990
1781
|
if (this.options.highlight) {
|
|
1991
1782
|
var out = this.options.highlight(_code, lang);
|
|
1992
|
-
|
|
1993
1783
|
if (out != null && out !== _code) {
|
|
1994
1784
|
escaped = true;
|
|
1995
1785
|
_code = out;
|
|
1996
1786
|
}
|
|
1997
1787
|
}
|
|
1998
|
-
|
|
1999
1788
|
_code = _code.replace(/\n$/, '') + '\n';
|
|
2000
|
-
|
|
2001
1789
|
if (!lang) {
|
|
2002
1790
|
return '<pre><code>' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
|
|
2003
1791
|
}
|
|
2004
|
-
|
|
2005
1792
|
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
|
|
2006
1793
|
}
|
|
1794
|
+
|
|
2007
1795
|
/**
|
|
2008
1796
|
* @param {string} quote
|
|
2009
|
-
|
|
2010
|
-
;
|
|
2011
|
-
|
|
1797
|
+
*/;
|
|
2012
1798
|
_proto.blockquote = function blockquote(quote) {
|
|
2013
1799
|
return "<blockquote>\n" + quote + "</blockquote>\n";
|
|
2014
1800
|
};
|
|
2015
|
-
|
|
2016
1801
|
_proto.html = function html(_html) {
|
|
2017
1802
|
return _html;
|
|
2018
1803
|
}
|
|
1804
|
+
|
|
2019
1805
|
/**
|
|
2020
1806
|
* @param {string} text
|
|
2021
1807
|
* @param {string} level
|
|
2022
1808
|
* @param {string} raw
|
|
2023
1809
|
* @param {any} slugger
|
|
2024
|
-
|
|
2025
|
-
;
|
|
2026
|
-
|
|
1810
|
+
*/;
|
|
2027
1811
|
_proto.heading = function heading(text, level, raw, slugger) {
|
|
2028
1812
|
if (this.options.headerIds) {
|
|
2029
1813
|
var id = this.options.headerPrefix + slugger.slug(raw);
|
|
2030
1814
|
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
|
|
2031
|
-
}
|
|
2032
|
-
|
|
1815
|
+
}
|
|
2033
1816
|
|
|
1817
|
+
// ignore IDs
|
|
2034
1818
|
return "<h" + level + ">" + text + "</h" + level + ">\n";
|
|
2035
1819
|
};
|
|
2036
|
-
|
|
2037
1820
|
_proto.hr = function hr() {
|
|
2038
1821
|
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
|
2039
1822
|
};
|
|
2040
|
-
|
|
2041
1823
|
_proto.list = function list(body, ordered, start) {
|
|
2042
1824
|
var type = ordered ? 'ol' : 'ul',
|
|
2043
|
-
|
|
1825
|
+
startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
|
|
2044
1826
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
2045
1827
|
}
|
|
1828
|
+
|
|
2046
1829
|
/**
|
|
2047
1830
|
* @param {string} text
|
|
2048
|
-
|
|
2049
|
-
;
|
|
2050
|
-
|
|
1831
|
+
*/;
|
|
2051
1832
|
_proto.listitem = function listitem(text) {
|
|
2052
1833
|
return "<li>" + text + "</li>\n";
|
|
2053
1834
|
};
|
|
2054
|
-
|
|
2055
1835
|
_proto.checkbox = function checkbox(checked) {
|
|
2056
1836
|
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
|
|
2057
1837
|
}
|
|
1838
|
+
|
|
2058
1839
|
/**
|
|
2059
1840
|
* @param {string} text
|
|
2060
|
-
|
|
2061
|
-
;
|
|
2062
|
-
|
|
1841
|
+
*/;
|
|
2063
1842
|
_proto.paragraph = function paragraph(text) {
|
|
2064
1843
|
return "<p>" + text + "</p>\n";
|
|
2065
1844
|
}
|
|
1845
|
+
|
|
2066
1846
|
/**
|
|
2067
1847
|
* @param {string} header
|
|
2068
1848
|
* @param {string} body
|
|
2069
|
-
|
|
2070
|
-
;
|
|
2071
|
-
|
|
1849
|
+
*/;
|
|
2072
1850
|
_proto.table = function table(header, body) {
|
|
2073
1851
|
if (body) body = "<tbody>" + body + "</tbody>";
|
|
2074
1852
|
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
|
|
2075
1853
|
}
|
|
1854
|
+
|
|
2076
1855
|
/**
|
|
2077
1856
|
* @param {string} content
|
|
2078
|
-
|
|
2079
|
-
;
|
|
2080
|
-
|
|
1857
|
+
*/;
|
|
2081
1858
|
_proto.tablerow = function tablerow(content) {
|
|
2082
1859
|
return "<tr>\n" + content + "</tr>\n";
|
|
2083
1860
|
};
|
|
2084
|
-
|
|
2085
1861
|
_proto.tablecell = function tablecell(content, flags) {
|
|
2086
1862
|
var type = flags.header ? 'th' : 'td';
|
|
2087
1863
|
var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
|
|
2088
1864
|
return tag + content + ("</" + type + ">\n");
|
|
2089
1865
|
}
|
|
1866
|
+
|
|
2090
1867
|
/**
|
|
2091
1868
|
* span level renderer
|
|
2092
1869
|
* @param {string} text
|
|
2093
|
-
|
|
2094
|
-
;
|
|
2095
|
-
|
|
1870
|
+
*/;
|
|
2096
1871
|
_proto.strong = function strong(text) {
|
|
2097
1872
|
return "<strong>" + text + "</strong>";
|
|
2098
1873
|
}
|
|
1874
|
+
|
|
2099
1875
|
/**
|
|
2100
1876
|
* @param {string} text
|
|
2101
|
-
|
|
2102
|
-
;
|
|
2103
|
-
|
|
1877
|
+
*/;
|
|
2104
1878
|
_proto.em = function em(text) {
|
|
2105
1879
|
return "<em>" + text + "</em>";
|
|
2106
1880
|
}
|
|
1881
|
+
|
|
2107
1882
|
/**
|
|
2108
1883
|
* @param {string} text
|
|
2109
|
-
|
|
2110
|
-
;
|
|
2111
|
-
|
|
1884
|
+
*/;
|
|
2112
1885
|
_proto.codespan = function codespan(text) {
|
|
2113
1886
|
return "<code>" + text + "</code>";
|
|
2114
1887
|
};
|
|
2115
|
-
|
|
2116
1888
|
_proto.br = function br() {
|
|
2117
1889
|
return this.options.xhtml ? '<br/>' : '<br>';
|
|
2118
1890
|
}
|
|
1891
|
+
|
|
2119
1892
|
/**
|
|
2120
1893
|
* @param {string} text
|
|
2121
|
-
|
|
2122
|
-
;
|
|
2123
|
-
|
|
1894
|
+
*/;
|
|
2124
1895
|
_proto.del = function del(text) {
|
|
2125
1896
|
return "<del>" + text + "</del>";
|
|
2126
1897
|
}
|
|
1898
|
+
|
|
2127
1899
|
/**
|
|
2128
1900
|
* @param {string} href
|
|
2129
1901
|
* @param {string} title
|
|
2130
1902
|
* @param {string} text
|
|
2131
|
-
|
|
2132
|
-
;
|
|
2133
|
-
|
|
1903
|
+
*/;
|
|
2134
1904
|
_proto.link = function link(href, title, text) {
|
|
2135
1905
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
2136
|
-
|
|
2137
1906
|
if (href === null) {
|
|
2138
1907
|
return text;
|
|
2139
1908
|
}
|
|
2140
|
-
|
|
2141
1909
|
var out = '<a href="' + escape(href) + '"';
|
|
2142
|
-
|
|
2143
1910
|
if (title) {
|
|
2144
1911
|
out += ' title="' + title + '"';
|
|
2145
1912
|
}
|
|
2146
|
-
|
|
2147
1913
|
out += '>' + text + '</a>';
|
|
2148
1914
|
return out;
|
|
2149
1915
|
}
|
|
1916
|
+
|
|
2150
1917
|
/**
|
|
2151
1918
|
* @param {string} href
|
|
2152
1919
|
* @param {string} title
|
|
2153
1920
|
* @param {string} text
|
|
2154
|
-
|
|
2155
|
-
;
|
|
2156
|
-
|
|
1921
|
+
*/;
|
|
2157
1922
|
_proto.image = function image(href, title, text) {
|
|
2158
1923
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
2159
|
-
|
|
2160
1924
|
if (href === null) {
|
|
2161
1925
|
return text;
|
|
2162
1926
|
}
|
|
2163
|
-
|
|
2164
1927
|
var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
|
|
2165
|
-
|
|
2166
1928
|
if (title) {
|
|
2167
1929
|
out += " title=\"" + title + "\"";
|
|
2168
1930
|
}
|
|
2169
|
-
|
|
2170
1931
|
out += this.options.xhtml ? '/>' : '>';
|
|
2171
1932
|
return out;
|
|
2172
1933
|
};
|
|
2173
|
-
|
|
2174
1934
|
_proto.text = function text(_text) {
|
|
2175
1935
|
return _text;
|
|
2176
1936
|
};
|
|
2177
|
-
|
|
2178
1937
|
return Renderer;
|
|
2179
1938
|
}();
|
|
2180
1939
|
|
|
@@ -2184,46 +1943,35 @@
|
|
|
2184
1943
|
*/
|
|
2185
1944
|
var TextRenderer = /*#__PURE__*/function () {
|
|
2186
1945
|
function TextRenderer() {}
|
|
2187
|
-
|
|
2188
1946
|
var _proto = TextRenderer.prototype;
|
|
2189
|
-
|
|
2190
1947
|
// no need for block level renderers
|
|
2191
1948
|
_proto.strong = function strong(text) {
|
|
2192
1949
|
return text;
|
|
2193
1950
|
};
|
|
2194
|
-
|
|
2195
1951
|
_proto.em = function em(text) {
|
|
2196
1952
|
return text;
|
|
2197
1953
|
};
|
|
2198
|
-
|
|
2199
1954
|
_proto.codespan = function codespan(text) {
|
|
2200
1955
|
return text;
|
|
2201
1956
|
};
|
|
2202
|
-
|
|
2203
1957
|
_proto.del = function del(text) {
|
|
2204
1958
|
return text;
|
|
2205
1959
|
};
|
|
2206
|
-
|
|
2207
1960
|
_proto.html = function html(text) {
|
|
2208
1961
|
return text;
|
|
2209
1962
|
};
|
|
2210
|
-
|
|
2211
1963
|
_proto.text = function text(_text) {
|
|
2212
1964
|
return _text;
|
|
2213
1965
|
};
|
|
2214
|
-
|
|
2215
1966
|
_proto.link = function link(href, title, text) {
|
|
2216
1967
|
return '' + text;
|
|
2217
1968
|
};
|
|
2218
|
-
|
|
2219
1969
|
_proto.image = function image(href, title, text) {
|
|
2220
1970
|
return '' + text;
|
|
2221
1971
|
};
|
|
2222
|
-
|
|
2223
1972
|
_proto.br = function br() {
|
|
2224
1973
|
return '';
|
|
2225
1974
|
};
|
|
2226
|
-
|
|
2227
1975
|
return TextRenderer;
|
|
2228
1976
|
}();
|
|
2229
1977
|
|
|
@@ -2234,69 +1982,60 @@
|
|
|
2234
1982
|
function Slugger() {
|
|
2235
1983
|
this.seen = {};
|
|
2236
1984
|
}
|
|
1985
|
+
|
|
2237
1986
|
/**
|
|
2238
1987
|
* @param {string} value
|
|
2239
1988
|
*/
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
1989
|
var _proto = Slugger.prototype;
|
|
2243
|
-
|
|
2244
1990
|
_proto.serialize = function serialize(value) {
|
|
2245
|
-
return value.toLowerCase().trim()
|
|
2246
|
-
|
|
1991
|
+
return value.toLowerCase().trim()
|
|
1992
|
+
// remove html tags
|
|
1993
|
+
.replace(/<[!\/a-z].*?>/ig, '')
|
|
1994
|
+
// remove unwanted chars
|
|
2247
1995
|
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
|
|
2248
1996
|
}
|
|
1997
|
+
|
|
2249
1998
|
/**
|
|
2250
1999
|
* Finds the next safe (unique) slug to use
|
|
2251
2000
|
* @param {string} originalSlug
|
|
2252
2001
|
* @param {boolean} isDryRun
|
|
2253
|
-
|
|
2254
|
-
;
|
|
2255
|
-
|
|
2002
|
+
*/;
|
|
2256
2003
|
_proto.getNextSafeSlug = function getNextSafeSlug(originalSlug, isDryRun) {
|
|
2257
2004
|
var slug = originalSlug;
|
|
2258
2005
|
var occurenceAccumulator = 0;
|
|
2259
|
-
|
|
2260
2006
|
if (this.seen.hasOwnProperty(slug)) {
|
|
2261
2007
|
occurenceAccumulator = this.seen[originalSlug];
|
|
2262
|
-
|
|
2263
2008
|
do {
|
|
2264
2009
|
occurenceAccumulator++;
|
|
2265
2010
|
slug = originalSlug + '-' + occurenceAccumulator;
|
|
2266
2011
|
} while (this.seen.hasOwnProperty(slug));
|
|
2267
2012
|
}
|
|
2268
|
-
|
|
2269
2013
|
if (!isDryRun) {
|
|
2270
2014
|
this.seen[originalSlug] = occurenceAccumulator;
|
|
2271
2015
|
this.seen[slug] = 0;
|
|
2272
2016
|
}
|
|
2273
|
-
|
|
2274
2017
|
return slug;
|
|
2275
2018
|
}
|
|
2019
|
+
|
|
2276
2020
|
/**
|
|
2277
2021
|
* Convert string to unique id
|
|
2278
2022
|
* @param {object} [options]
|
|
2279
2023
|
* @param {boolean} [options.dryrun] Generates the next unique slug without
|
|
2280
2024
|
* updating the internal accumulator.
|
|
2281
|
-
|
|
2282
|
-
;
|
|
2283
|
-
|
|
2025
|
+
*/;
|
|
2284
2026
|
_proto.slug = function slug(value, options) {
|
|
2285
2027
|
if (options === void 0) {
|
|
2286
2028
|
options = {};
|
|
2287
2029
|
}
|
|
2288
|
-
|
|
2289
2030
|
var slug = this.serialize(value);
|
|
2290
2031
|
return this.getNextSafeSlug(slug, options.dryrun);
|
|
2291
2032
|
};
|
|
2292
|
-
|
|
2293
2033
|
return Slugger;
|
|
2294
2034
|
}();
|
|
2295
2035
|
|
|
2296
2036
|
/**
|
|
2297
2037
|
* Parsing & Compiling
|
|
2298
2038
|
*/
|
|
2299
|
-
|
|
2300
2039
|
var Parser = /*#__PURE__*/function () {
|
|
2301
2040
|
function Parser(options) {
|
|
2302
2041
|
this.options = options || exports.defaults;
|
|
@@ -2306,140 +2045,122 @@
|
|
|
2306
2045
|
this.textRenderer = new TextRenderer();
|
|
2307
2046
|
this.slugger = new Slugger();
|
|
2308
2047
|
}
|
|
2048
|
+
|
|
2309
2049
|
/**
|
|
2310
2050
|
* Static Parse Method
|
|
2311
2051
|
*/
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
2052
|
Parser.parse = function parse(tokens, options) {
|
|
2315
2053
|
var parser = new Parser(options);
|
|
2316
2054
|
return parser.parse(tokens);
|
|
2317
2055
|
}
|
|
2056
|
+
|
|
2318
2057
|
/**
|
|
2319
2058
|
* Static Parse Inline Method
|
|
2320
|
-
|
|
2321
|
-
;
|
|
2322
|
-
|
|
2059
|
+
*/;
|
|
2323
2060
|
Parser.parseInline = function parseInline(tokens, options) {
|
|
2324
2061
|
var parser = new Parser(options);
|
|
2325
2062
|
return parser.parseInline(tokens);
|
|
2326
2063
|
}
|
|
2064
|
+
|
|
2327
2065
|
/**
|
|
2328
2066
|
* Parse Loop
|
|
2329
|
-
|
|
2330
|
-
;
|
|
2331
|
-
|
|
2067
|
+
*/;
|
|
2332
2068
|
var _proto = Parser.prototype;
|
|
2333
|
-
|
|
2334
2069
|
_proto.parse = function parse(tokens, top) {
|
|
2335
2070
|
if (top === void 0) {
|
|
2336
2071
|
top = true;
|
|
2337
2072
|
}
|
|
2338
|
-
|
|
2339
2073
|
var out = '',
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2074
|
+
i,
|
|
2075
|
+
j,
|
|
2076
|
+
k,
|
|
2077
|
+
l2,
|
|
2078
|
+
l3,
|
|
2079
|
+
row,
|
|
2080
|
+
cell,
|
|
2081
|
+
header,
|
|
2082
|
+
body,
|
|
2083
|
+
token,
|
|
2084
|
+
ordered,
|
|
2085
|
+
start,
|
|
2086
|
+
loose,
|
|
2087
|
+
itemBody,
|
|
2088
|
+
item,
|
|
2089
|
+
checked,
|
|
2090
|
+
task,
|
|
2091
|
+
checkbox,
|
|
2092
|
+
ret;
|
|
2359
2093
|
var l = tokens.length;
|
|
2360
|
-
|
|
2361
2094
|
for (i = 0; i < l; i++) {
|
|
2362
|
-
token = tokens[i];
|
|
2095
|
+
token = tokens[i];
|
|
2363
2096
|
|
|
2097
|
+
// Run any renderer extensions
|
|
2364
2098
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2365
2099
|
ret = this.options.extensions.renderers[token.type].call({
|
|
2366
2100
|
parser: this
|
|
2367
2101
|
}, token);
|
|
2368
|
-
|
|
2369
2102
|
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
|
|
2370
2103
|
out += ret || '';
|
|
2371
2104
|
continue;
|
|
2372
2105
|
}
|
|
2373
2106
|
}
|
|
2374
|
-
|
|
2375
2107
|
switch (token.type) {
|
|
2376
2108
|
case 'space':
|
|
2377
2109
|
{
|
|
2378
2110
|
continue;
|
|
2379
2111
|
}
|
|
2380
|
-
|
|
2381
2112
|
case 'hr':
|
|
2382
2113
|
{
|
|
2383
2114
|
out += this.renderer.hr();
|
|
2384
2115
|
continue;
|
|
2385
2116
|
}
|
|
2386
|
-
|
|
2387
2117
|
case 'heading':
|
|
2388
2118
|
{
|
|
2389
2119
|
out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
|
|
2390
2120
|
continue;
|
|
2391
2121
|
}
|
|
2392
|
-
|
|
2393
2122
|
case 'code':
|
|
2394
2123
|
{
|
|
2395
2124
|
out += this.renderer.code(token.text, token.lang, token.escaped);
|
|
2396
2125
|
continue;
|
|
2397
2126
|
}
|
|
2398
|
-
|
|
2399
2127
|
case 'table':
|
|
2400
2128
|
{
|
|
2401
|
-
header = '';
|
|
2129
|
+
header = '';
|
|
2402
2130
|
|
|
2131
|
+
// header
|
|
2403
2132
|
cell = '';
|
|
2404
2133
|
l2 = token.header.length;
|
|
2405
|
-
|
|
2406
2134
|
for (j = 0; j < l2; j++) {
|
|
2407
2135
|
cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), {
|
|
2408
2136
|
header: true,
|
|
2409
2137
|
align: token.align[j]
|
|
2410
2138
|
});
|
|
2411
2139
|
}
|
|
2412
|
-
|
|
2413
2140
|
header += this.renderer.tablerow(cell);
|
|
2414
2141
|
body = '';
|
|
2415
2142
|
l2 = token.rows.length;
|
|
2416
|
-
|
|
2417
2143
|
for (j = 0; j < l2; j++) {
|
|
2418
2144
|
row = token.rows[j];
|
|
2419
2145
|
cell = '';
|
|
2420
2146
|
l3 = row.length;
|
|
2421
|
-
|
|
2422
2147
|
for (k = 0; k < l3; k++) {
|
|
2423
2148
|
cell += this.renderer.tablecell(this.parseInline(row[k].tokens), {
|
|
2424
2149
|
header: false,
|
|
2425
2150
|
align: token.align[k]
|
|
2426
2151
|
});
|
|
2427
2152
|
}
|
|
2428
|
-
|
|
2429
2153
|
body += this.renderer.tablerow(cell);
|
|
2430
2154
|
}
|
|
2431
|
-
|
|
2432
2155
|
out += this.renderer.table(header, body);
|
|
2433
2156
|
continue;
|
|
2434
2157
|
}
|
|
2435
|
-
|
|
2436
2158
|
case 'blockquote':
|
|
2437
2159
|
{
|
|
2438
2160
|
body = this.parse(token.tokens);
|
|
2439
2161
|
out += this.renderer.blockquote(body);
|
|
2440
2162
|
continue;
|
|
2441
2163
|
}
|
|
2442
|
-
|
|
2443
2164
|
case 'list':
|
|
2444
2165
|
{
|
|
2445
2166
|
ordered = token.ordered;
|
|
@@ -2447,20 +2168,16 @@
|
|
|
2447
2168
|
loose = token.loose;
|
|
2448
2169
|
l2 = token.items.length;
|
|
2449
2170
|
body = '';
|
|
2450
|
-
|
|
2451
2171
|
for (j = 0; j < l2; j++) {
|
|
2452
2172
|
item = token.items[j];
|
|
2453
2173
|
checked = item.checked;
|
|
2454
2174
|
task = item.task;
|
|
2455
2175
|
itemBody = '';
|
|
2456
|
-
|
|
2457
2176
|
if (item.task) {
|
|
2458
2177
|
checkbox = this.renderer.checkbox(checked);
|
|
2459
|
-
|
|
2460
2178
|
if (loose) {
|
|
2461
2179
|
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
|
|
2462
2180
|
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
2463
|
-
|
|
2464
2181
|
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
|
|
2465
2182
|
item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
|
|
2466
2183
|
}
|
|
@@ -2474,45 +2191,36 @@
|
|
|
2474
2191
|
itemBody += checkbox;
|
|
2475
2192
|
}
|
|
2476
2193
|
}
|
|
2477
|
-
|
|
2478
2194
|
itemBody += this.parse(item.tokens, loose);
|
|
2479
2195
|
body += this.renderer.listitem(itemBody, task, checked);
|
|
2480
2196
|
}
|
|
2481
|
-
|
|
2482
2197
|
out += this.renderer.list(body, ordered, start);
|
|
2483
2198
|
continue;
|
|
2484
2199
|
}
|
|
2485
|
-
|
|
2486
2200
|
case 'html':
|
|
2487
2201
|
{
|
|
2488
2202
|
// TODO parse inline content if parameter markdown=1
|
|
2489
2203
|
out += this.renderer.html(token.text);
|
|
2490
2204
|
continue;
|
|
2491
2205
|
}
|
|
2492
|
-
|
|
2493
2206
|
case 'paragraph':
|
|
2494
2207
|
{
|
|
2495
2208
|
out += this.renderer.paragraph(this.parseInline(token.tokens));
|
|
2496
2209
|
continue;
|
|
2497
2210
|
}
|
|
2498
|
-
|
|
2499
2211
|
case 'text':
|
|
2500
2212
|
{
|
|
2501
2213
|
body = token.tokens ? this.parseInline(token.tokens) : token.text;
|
|
2502
|
-
|
|
2503
2214
|
while (i + 1 < l && tokens[i + 1].type === 'text') {
|
|
2504
2215
|
token = tokens[++i];
|
|
2505
2216
|
body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
|
|
2506
2217
|
}
|
|
2507
|
-
|
|
2508
2218
|
out += top ? this.renderer.paragraph(body) : body;
|
|
2509
2219
|
continue;
|
|
2510
2220
|
}
|
|
2511
|
-
|
|
2512
2221
|
default:
|
|
2513
2222
|
{
|
|
2514
2223
|
var errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2515
|
-
|
|
2516
2224
|
if (this.options.silent) {
|
|
2517
2225
|
console.error(errMsg);
|
|
2518
2226
|
return;
|
|
@@ -2522,101 +2230,86 @@
|
|
|
2522
2230
|
}
|
|
2523
2231
|
}
|
|
2524
2232
|
}
|
|
2525
|
-
|
|
2526
2233
|
return out;
|
|
2527
2234
|
}
|
|
2235
|
+
|
|
2528
2236
|
/**
|
|
2529
2237
|
* Parse Inline Tokens
|
|
2530
|
-
|
|
2531
|
-
;
|
|
2532
|
-
|
|
2238
|
+
*/;
|
|
2533
2239
|
_proto.parseInline = function parseInline(tokens, renderer) {
|
|
2534
2240
|
renderer = renderer || this.renderer;
|
|
2535
2241
|
var out = '',
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2242
|
+
i,
|
|
2243
|
+
token,
|
|
2244
|
+
ret;
|
|
2539
2245
|
var l = tokens.length;
|
|
2540
|
-
|
|
2541
2246
|
for (i = 0; i < l; i++) {
|
|
2542
|
-
token = tokens[i];
|
|
2247
|
+
token = tokens[i];
|
|
2543
2248
|
|
|
2249
|
+
// Run any renderer extensions
|
|
2544
2250
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2545
2251
|
ret = this.options.extensions.renderers[token.type].call({
|
|
2546
2252
|
parser: this
|
|
2547
2253
|
}, token);
|
|
2548
|
-
|
|
2549
2254
|
if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
|
|
2550
2255
|
out += ret || '';
|
|
2551
2256
|
continue;
|
|
2552
2257
|
}
|
|
2553
2258
|
}
|
|
2554
|
-
|
|
2555
2259
|
switch (token.type) {
|
|
2556
2260
|
case 'escape':
|
|
2557
2261
|
{
|
|
2558
2262
|
out += renderer.text(token.text);
|
|
2559
2263
|
break;
|
|
2560
2264
|
}
|
|
2561
|
-
|
|
2562
2265
|
case 'html':
|
|
2563
2266
|
{
|
|
2564
2267
|
out += renderer.html(token.text);
|
|
2565
2268
|
break;
|
|
2566
2269
|
}
|
|
2567
|
-
|
|
2568
2270
|
case 'link':
|
|
2569
2271
|
{
|
|
2570
2272
|
out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
|
|
2571
2273
|
break;
|
|
2572
2274
|
}
|
|
2573
|
-
|
|
2574
2275
|
case 'image':
|
|
2575
2276
|
{
|
|
2576
2277
|
out += renderer.image(token.href, token.title, token.text);
|
|
2577
2278
|
break;
|
|
2578
2279
|
}
|
|
2579
|
-
|
|
2580
2280
|
case 'strong':
|
|
2581
2281
|
{
|
|
2582
2282
|
out += renderer.strong(this.parseInline(token.tokens, renderer));
|
|
2583
2283
|
break;
|
|
2584
2284
|
}
|
|
2585
|
-
|
|
2586
2285
|
case 'em':
|
|
2587
2286
|
{
|
|
2588
2287
|
out += renderer.em(this.parseInline(token.tokens, renderer));
|
|
2589
2288
|
break;
|
|
2590
2289
|
}
|
|
2591
|
-
|
|
2592
2290
|
case 'codespan':
|
|
2593
2291
|
{
|
|
2594
2292
|
out += renderer.codespan(token.text);
|
|
2595
2293
|
break;
|
|
2596
2294
|
}
|
|
2597
|
-
|
|
2598
2295
|
case 'br':
|
|
2599
2296
|
{
|
|
2600
2297
|
out += renderer.br();
|
|
2601
2298
|
break;
|
|
2602
2299
|
}
|
|
2603
|
-
|
|
2604
2300
|
case 'del':
|
|
2605
2301
|
{
|
|
2606
2302
|
out += renderer.del(this.parseInline(token.tokens, renderer));
|
|
2607
2303
|
break;
|
|
2608
2304
|
}
|
|
2609
|
-
|
|
2610
2305
|
case 'text':
|
|
2611
2306
|
{
|
|
2612
2307
|
out += renderer.text(token.text);
|
|
2613
2308
|
break;
|
|
2614
2309
|
}
|
|
2615
|
-
|
|
2616
2310
|
default:
|
|
2617
2311
|
{
|
|
2618
2312
|
var errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2619
|
-
|
|
2620
2313
|
if (this.options.silent) {
|
|
2621
2314
|
console.error(errMsg);
|
|
2622
2315
|
return;
|
|
@@ -2626,68 +2319,54 @@
|
|
|
2626
2319
|
}
|
|
2627
2320
|
}
|
|
2628
2321
|
}
|
|
2629
|
-
|
|
2630
2322
|
return out;
|
|
2631
2323
|
};
|
|
2632
|
-
|
|
2633
2324
|
return Parser;
|
|
2634
2325
|
}();
|
|
2635
2326
|
|
|
2636
2327
|
/**
|
|
2637
2328
|
* Marked
|
|
2638
2329
|
*/
|
|
2639
|
-
|
|
2640
2330
|
function marked(src, opt, callback) {
|
|
2641
2331
|
// throw error in case of non string input
|
|
2642
2332
|
if (typeof src === 'undefined' || src === null) {
|
|
2643
2333
|
throw new Error('marked(): input parameter is undefined or null');
|
|
2644
2334
|
}
|
|
2645
|
-
|
|
2646
2335
|
if (typeof src !== 'string') {
|
|
2647
2336
|
throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
|
2648
2337
|
}
|
|
2649
|
-
|
|
2650
2338
|
if (typeof opt === 'function') {
|
|
2651
2339
|
callback = opt;
|
|
2652
2340
|
opt = null;
|
|
2653
2341
|
}
|
|
2654
|
-
|
|
2655
2342
|
opt = merge({}, marked.defaults, opt || {});
|
|
2656
2343
|
checkSanitizeDeprecation(opt);
|
|
2657
|
-
|
|
2658
2344
|
if (callback) {
|
|
2659
2345
|
var highlight = opt.highlight;
|
|
2660
2346
|
var tokens;
|
|
2661
|
-
|
|
2662
2347
|
try {
|
|
2663
2348
|
tokens = Lexer.lex(src, opt);
|
|
2664
2349
|
} catch (e) {
|
|
2665
2350
|
return callback(e);
|
|
2666
2351
|
}
|
|
2667
|
-
|
|
2668
2352
|
var done = function done(err) {
|
|
2669
2353
|
var out;
|
|
2670
|
-
|
|
2671
2354
|
if (!err) {
|
|
2672
2355
|
try {
|
|
2673
2356
|
if (opt.walkTokens) {
|
|
2674
2357
|
marked.walkTokens(tokens, opt.walkTokens);
|
|
2675
2358
|
}
|
|
2676
|
-
|
|
2677
2359
|
out = Parser.parse(tokens, opt);
|
|
2678
2360
|
} catch (e) {
|
|
2679
2361
|
err = e;
|
|
2680
2362
|
}
|
|
2681
2363
|
}
|
|
2682
|
-
|
|
2683
2364
|
opt.highlight = highlight;
|
|
2684
2365
|
return err ? callback(err) : callback(null, out);
|
|
2685
2366
|
};
|
|
2686
|
-
|
|
2687
2367
|
if (!highlight || highlight.length < 3) {
|
|
2688
2368
|
return done();
|
|
2689
2369
|
}
|
|
2690
|
-
|
|
2691
2370
|
delete opt.highlight;
|
|
2692
2371
|
if (!tokens.length) return done();
|
|
2693
2372
|
var pending = 0;
|
|
@@ -2699,14 +2378,11 @@
|
|
|
2699
2378
|
if (err) {
|
|
2700
2379
|
return done(err);
|
|
2701
2380
|
}
|
|
2702
|
-
|
|
2703
2381
|
if (code != null && code !== token.text) {
|
|
2704
2382
|
token.text = code;
|
|
2705
2383
|
token.escaped = true;
|
|
2706
2384
|
}
|
|
2707
|
-
|
|
2708
2385
|
pending--;
|
|
2709
|
-
|
|
2710
2386
|
if (pending === 0) {
|
|
2711
2387
|
done();
|
|
2712
2388
|
}
|
|
@@ -2714,42 +2390,34 @@
|
|
|
2714
2390
|
}, 0);
|
|
2715
2391
|
}
|
|
2716
2392
|
});
|
|
2717
|
-
|
|
2718
2393
|
if (pending === 0) {
|
|
2719
2394
|
done();
|
|
2720
2395
|
}
|
|
2721
|
-
|
|
2722
2396
|
return;
|
|
2723
2397
|
}
|
|
2724
|
-
|
|
2725
2398
|
function onError(e) {
|
|
2726
2399
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2727
|
-
|
|
2728
2400
|
if (opt.silent) {
|
|
2729
2401
|
return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
|
|
2730
2402
|
}
|
|
2731
|
-
|
|
2732
2403
|
throw e;
|
|
2733
2404
|
}
|
|
2734
|
-
|
|
2735
2405
|
try {
|
|
2736
2406
|
var _tokens = Lexer.lex(src, opt);
|
|
2737
|
-
|
|
2738
2407
|
if (opt.walkTokens) {
|
|
2739
2408
|
if (opt.async) {
|
|
2740
2409
|
return Promise.all(marked.walkTokens(_tokens, opt.walkTokens)).then(function () {
|
|
2741
2410
|
return Parser.parse(_tokens, opt);
|
|
2742
2411
|
})["catch"](onError);
|
|
2743
2412
|
}
|
|
2744
|
-
|
|
2745
2413
|
marked.walkTokens(_tokens, opt.walkTokens);
|
|
2746
2414
|
}
|
|
2747
|
-
|
|
2748
2415
|
return Parser.parse(_tokens, opt);
|
|
2749
2416
|
} catch (e) {
|
|
2750
2417
|
onError(e);
|
|
2751
2418
|
}
|
|
2752
2419
|
}
|
|
2420
|
+
|
|
2753
2421
|
/**
|
|
2754
2422
|
* Options
|
|
2755
2423
|
*/
|
|
@@ -2759,9 +2427,9 @@
|
|
|
2759
2427
|
changeDefaults(marked.defaults);
|
|
2760
2428
|
return marked;
|
|
2761
2429
|
};
|
|
2762
|
-
|
|
2763
2430
|
marked.getDefaults = getDefaults;
|
|
2764
2431
|
marked.defaults = exports.defaults;
|
|
2432
|
+
|
|
2765
2433
|
/**
|
|
2766
2434
|
* Use Extension
|
|
2767
2435
|
*/
|
|
@@ -2770,7 +2438,6 @@
|
|
|
2770
2438
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2771
2439
|
args[_key] = arguments[_key];
|
|
2772
2440
|
}
|
|
2773
|
-
|
|
2774
2441
|
var opts = merge.apply(void 0, [{}].concat(args));
|
|
2775
2442
|
var extensions = marked.defaults.extensions || {
|
|
2776
2443
|
renderers: {},
|
|
@@ -2785,43 +2452,35 @@
|
|
|
2785
2452
|
if (!ext.name) {
|
|
2786
2453
|
throw new Error('extension name required');
|
|
2787
2454
|
}
|
|
2788
|
-
|
|
2789
2455
|
if (ext.renderer) {
|
|
2790
2456
|
// Renderer extensions
|
|
2791
2457
|
var prevRenderer = extensions.renderers ? extensions.renderers[ext.name] : null;
|
|
2792
|
-
|
|
2793
2458
|
if (prevRenderer) {
|
|
2794
2459
|
// Replace extension with func to run new extension but fall back if false
|
|
2795
2460
|
extensions.renderers[ext.name] = function () {
|
|
2796
2461
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2797
2462
|
args[_key2] = arguments[_key2];
|
|
2798
2463
|
}
|
|
2799
|
-
|
|
2800
2464
|
var ret = ext.renderer.apply(this, args);
|
|
2801
|
-
|
|
2802
2465
|
if (ret === false) {
|
|
2803
2466
|
ret = prevRenderer.apply(this, args);
|
|
2804
2467
|
}
|
|
2805
|
-
|
|
2806
2468
|
return ret;
|
|
2807
2469
|
};
|
|
2808
2470
|
} else {
|
|
2809
2471
|
extensions.renderers[ext.name] = ext.renderer;
|
|
2810
2472
|
}
|
|
2811
2473
|
}
|
|
2812
|
-
|
|
2813
2474
|
if (ext.tokenizer) {
|
|
2814
2475
|
// Tokenizer Extensions
|
|
2815
2476
|
if (!ext.level || ext.level !== 'block' && ext.level !== 'inline') {
|
|
2816
2477
|
throw new Error("extension level must be 'block' or 'inline'");
|
|
2817
2478
|
}
|
|
2818
|
-
|
|
2819
2479
|
if (extensions[ext.level]) {
|
|
2820
2480
|
extensions[ext.level].unshift(ext.tokenizer);
|
|
2821
2481
|
} else {
|
|
2822
2482
|
extensions[ext.level] = [ext.tokenizer];
|
|
2823
2483
|
}
|
|
2824
|
-
|
|
2825
2484
|
if (ext.start) {
|
|
2826
2485
|
// Function to check for start of token
|
|
2827
2486
|
if (ext.level === 'block') {
|
|
@@ -2839,110 +2498,89 @@
|
|
|
2839
2498
|
}
|
|
2840
2499
|
}
|
|
2841
2500
|
}
|
|
2842
|
-
|
|
2843
2501
|
if (ext.childTokens) {
|
|
2844
2502
|
// Child tokens to be visited by walkTokens
|
|
2845
2503
|
extensions.childTokens[ext.name] = ext.childTokens;
|
|
2846
2504
|
}
|
|
2847
2505
|
});
|
|
2848
|
-
}
|
|
2849
|
-
|
|
2506
|
+
}
|
|
2850
2507
|
|
|
2508
|
+
// ==-- Parse "overwrite" extensions --== //
|
|
2851
2509
|
if (pack.renderer) {
|
|
2852
2510
|
(function () {
|
|
2853
2511
|
var renderer = marked.defaults.renderer || new Renderer();
|
|
2854
|
-
|
|
2855
2512
|
var _loop = function _loop(prop) {
|
|
2856
|
-
var prevRenderer = renderer[prop];
|
|
2857
|
-
|
|
2513
|
+
var prevRenderer = renderer[prop];
|
|
2514
|
+
// Replace renderer with func to run extension, but fall back if false
|
|
2858
2515
|
renderer[prop] = function () {
|
|
2859
2516
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
2860
2517
|
args[_key3] = arguments[_key3];
|
|
2861
2518
|
}
|
|
2862
|
-
|
|
2863
2519
|
var ret = pack.renderer[prop].apply(renderer, args);
|
|
2864
|
-
|
|
2865
2520
|
if (ret === false) {
|
|
2866
2521
|
ret = prevRenderer.apply(renderer, args);
|
|
2867
2522
|
}
|
|
2868
|
-
|
|
2869
2523
|
return ret;
|
|
2870
2524
|
};
|
|
2871
2525
|
};
|
|
2872
|
-
|
|
2873
2526
|
for (var prop in pack.renderer) {
|
|
2874
2527
|
_loop(prop);
|
|
2875
2528
|
}
|
|
2876
|
-
|
|
2877
2529
|
opts.renderer = renderer;
|
|
2878
2530
|
})();
|
|
2879
2531
|
}
|
|
2880
|
-
|
|
2881
2532
|
if (pack.tokenizer) {
|
|
2882
2533
|
(function () {
|
|
2883
2534
|
var tokenizer = marked.defaults.tokenizer || new Tokenizer();
|
|
2884
|
-
|
|
2885
2535
|
var _loop2 = function _loop2(prop) {
|
|
2886
|
-
var prevTokenizer = tokenizer[prop];
|
|
2887
|
-
|
|
2536
|
+
var prevTokenizer = tokenizer[prop];
|
|
2537
|
+
// Replace tokenizer with func to run extension, but fall back if false
|
|
2888
2538
|
tokenizer[prop] = function () {
|
|
2889
2539
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
2890
2540
|
args[_key4] = arguments[_key4];
|
|
2891
2541
|
}
|
|
2892
|
-
|
|
2893
2542
|
var ret = pack.tokenizer[prop].apply(tokenizer, args);
|
|
2894
|
-
|
|
2895
2543
|
if (ret === false) {
|
|
2896
2544
|
ret = prevTokenizer.apply(tokenizer, args);
|
|
2897
2545
|
}
|
|
2898
|
-
|
|
2899
2546
|
return ret;
|
|
2900
2547
|
};
|
|
2901
2548
|
};
|
|
2902
|
-
|
|
2903
2549
|
for (var prop in pack.tokenizer) {
|
|
2904
2550
|
_loop2(prop);
|
|
2905
2551
|
}
|
|
2906
|
-
|
|
2907
2552
|
opts.tokenizer = tokenizer;
|
|
2908
2553
|
})();
|
|
2909
|
-
}
|
|
2910
|
-
|
|
2554
|
+
}
|
|
2911
2555
|
|
|
2556
|
+
// ==-- Parse WalkTokens extensions --== //
|
|
2912
2557
|
if (pack.walkTokens) {
|
|
2913
2558
|
var _walkTokens = marked.defaults.walkTokens;
|
|
2914
|
-
|
|
2915
2559
|
opts.walkTokens = function (token) {
|
|
2916
2560
|
var values = [];
|
|
2917
2561
|
values.push(pack.walkTokens.call(this, token));
|
|
2918
|
-
|
|
2919
2562
|
if (_walkTokens) {
|
|
2920
2563
|
values = values.concat(_walkTokens.call(this, token));
|
|
2921
2564
|
}
|
|
2922
|
-
|
|
2923
2565
|
return values;
|
|
2924
2566
|
};
|
|
2925
2567
|
}
|
|
2926
|
-
|
|
2927
2568
|
if (hasExtensions) {
|
|
2928
2569
|
opts.extensions = extensions;
|
|
2929
2570
|
}
|
|
2930
|
-
|
|
2931
2571
|
marked.setOptions(opts);
|
|
2932
2572
|
});
|
|
2933
2573
|
};
|
|
2574
|
+
|
|
2934
2575
|
/**
|
|
2935
2576
|
* Run callback for every token
|
|
2936
2577
|
*/
|
|
2937
2578
|
|
|
2938
|
-
|
|
2939
2579
|
marked.walkTokens = function (tokens, callback) {
|
|
2940
2580
|
var values = [];
|
|
2941
|
-
|
|
2942
2581
|
var _loop3 = function _loop3() {
|
|
2943
2582
|
var token = _step.value;
|
|
2944
2583
|
values = values.concat(callback.call(marked, token));
|
|
2945
|
-
|
|
2946
2584
|
switch (token.type) {
|
|
2947
2585
|
case 'table':
|
|
2948
2586
|
{
|
|
@@ -2950,25 +2588,20 @@
|
|
|
2950
2588
|
var cell = _step2.value;
|
|
2951
2589
|
values = values.concat(marked.walkTokens(cell.tokens, callback));
|
|
2952
2590
|
}
|
|
2953
|
-
|
|
2954
2591
|
for (var _iterator3 = _createForOfIteratorHelperLoose(token.rows), _step3; !(_step3 = _iterator3()).done;) {
|
|
2955
2592
|
var row = _step3.value;
|
|
2956
|
-
|
|
2957
2593
|
for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
|
|
2958
2594
|
var _cell = _step4.value;
|
|
2959
2595
|
values = values.concat(marked.walkTokens(_cell.tokens, callback));
|
|
2960
2596
|
}
|
|
2961
2597
|
}
|
|
2962
|
-
|
|
2963
2598
|
break;
|
|
2964
2599
|
}
|
|
2965
|
-
|
|
2966
2600
|
case 'list':
|
|
2967
2601
|
{
|
|
2968
2602
|
values = values.concat(marked.walkTokens(token.items, callback));
|
|
2969
2603
|
break;
|
|
2970
2604
|
}
|
|
2971
|
-
|
|
2972
2605
|
default:
|
|
2973
2606
|
{
|
|
2974
2607
|
if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) {
|
|
@@ -2982,55 +2615,44 @@
|
|
|
2982
2615
|
}
|
|
2983
2616
|
}
|
|
2984
2617
|
};
|
|
2985
|
-
|
|
2986
2618
|
for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
|
|
2987
2619
|
_loop3();
|
|
2988
2620
|
}
|
|
2989
|
-
|
|
2990
2621
|
return values;
|
|
2991
2622
|
};
|
|
2623
|
+
|
|
2992
2624
|
/**
|
|
2993
2625
|
* Parse Inline
|
|
2994
2626
|
* @param {string} src
|
|
2995
2627
|
*/
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
2628
|
marked.parseInline = function (src, opt) {
|
|
2999
2629
|
// throw error in case of non string input
|
|
3000
2630
|
if (typeof src === 'undefined' || src === null) {
|
|
3001
2631
|
throw new Error('marked.parseInline(): input parameter is undefined or null');
|
|
3002
2632
|
}
|
|
3003
|
-
|
|
3004
2633
|
if (typeof src !== 'string') {
|
|
3005
2634
|
throw new Error('marked.parseInline(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
|
3006
2635
|
}
|
|
3007
|
-
|
|
3008
2636
|
opt = merge({}, marked.defaults, opt || {});
|
|
3009
2637
|
checkSanitizeDeprecation(opt);
|
|
3010
|
-
|
|
3011
2638
|
try {
|
|
3012
2639
|
var tokens = Lexer.lexInline(src, opt);
|
|
3013
|
-
|
|
3014
2640
|
if (opt.walkTokens) {
|
|
3015
2641
|
marked.walkTokens(tokens, opt.walkTokens);
|
|
3016
2642
|
}
|
|
3017
|
-
|
|
3018
2643
|
return Parser.parseInline(tokens, opt);
|
|
3019
2644
|
} catch (e) {
|
|
3020
2645
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
3021
|
-
|
|
3022
2646
|
if (opt.silent) {
|
|
3023
2647
|
return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
|
|
3024
2648
|
}
|
|
3025
|
-
|
|
3026
2649
|
throw e;
|
|
3027
2650
|
}
|
|
3028
2651
|
};
|
|
2652
|
+
|
|
3029
2653
|
/**
|
|
3030
2654
|
* Expose
|
|
3031
2655
|
*/
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
2656
|
marked.Parser = Parser;
|
|
3035
2657
|
marked.parser = Parser.parse;
|
|
3036
2658
|
marked.Renderer = Renderer;
|