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