marked 4.1.1 → 4.2.1
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 +273 -646
- package/lib/marked.esm.js +14 -9
- package/lib/marked.umd.js +273 -646
- package/marked.min.js +1 -1
- package/package.json +12 -11
- package/src/Lexer.js +2 -1
- package/src/Tokenizer.js +6 -4
- package/src/rules.js +6 -4
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,45 +926,42 @@
|
|
|
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);
|
|
932
|
+
var raw = src.slice(0, lLength + match.index + (match[0].length - rDelim.length) + rLength);
|
|
1061
933
|
|
|
934
|
+
// Create `em` if smallest delimiter has odd char count. *a***
|
|
1062
935
|
if (Math.min(lLength, rLength) % 2) {
|
|
1063
|
-
var _text =
|
|
1064
|
-
|
|
936
|
+
var _text = raw.slice(1, -1);
|
|
1065
937
|
return {
|
|
1066
938
|
type: 'em',
|
|
1067
|
-
raw:
|
|
939
|
+
raw: raw,
|
|
1068
940
|
text: _text,
|
|
1069
941
|
tokens: this.lexer.inlineTokens(_text)
|
|
1070
942
|
};
|
|
1071
|
-
}
|
|
1072
|
-
|
|
943
|
+
}
|
|
1073
944
|
|
|
1074
|
-
|
|
945
|
+
// Create 'strong' if smallest delimiter has even char count. **a***
|
|
946
|
+
var text = raw.slice(2, -2);
|
|
1075
947
|
return {
|
|
1076
948
|
type: 'strong',
|
|
1077
|
-
raw:
|
|
949
|
+
raw: raw,
|
|
1078
950
|
text: text,
|
|
1079
951
|
tokens: this.lexer.inlineTokens(text)
|
|
1080
952
|
};
|
|
1081
953
|
}
|
|
1082
954
|
}
|
|
1083
955
|
};
|
|
1084
|
-
|
|
1085
956
|
_proto.codespan = function codespan(src) {
|
|
1086
957
|
var cap = this.rules.inline.code.exec(src);
|
|
1087
|
-
|
|
1088
958
|
if (cap) {
|
|
1089
959
|
var text = cap[2].replace(/\n/g, ' ');
|
|
1090
960
|
var hasNonSpaceChars = /[^ ]/.test(text);
|
|
1091
961
|
var hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
|
|
1092
|
-
|
|
1093
962
|
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
|
|
1094
963
|
text = text.substring(1, text.length - 1);
|
|
1095
964
|
}
|
|
1096
|
-
|
|
1097
965
|
text = escape(text, true);
|
|
1098
966
|
return {
|
|
1099
967
|
type: 'codespan',
|
|
@@ -1102,10 +970,8 @@
|
|
|
1102
970
|
};
|
|
1103
971
|
}
|
|
1104
972
|
};
|
|
1105
|
-
|
|
1106
973
|
_proto.br = function br(src) {
|
|
1107
974
|
var cap = this.rules.inline.br.exec(src);
|
|
1108
|
-
|
|
1109
975
|
if (cap) {
|
|
1110
976
|
return {
|
|
1111
977
|
type: 'br',
|
|
@@ -1113,10 +979,8 @@
|
|
|
1113
979
|
};
|
|
1114
980
|
}
|
|
1115
981
|
};
|
|
1116
|
-
|
|
1117
982
|
_proto.del = function del(src) {
|
|
1118
983
|
var cap = this.rules.inline.del.exec(src);
|
|
1119
|
-
|
|
1120
984
|
if (cap) {
|
|
1121
985
|
return {
|
|
1122
986
|
type: 'del',
|
|
@@ -1126,13 +990,10 @@
|
|
|
1126
990
|
};
|
|
1127
991
|
}
|
|
1128
992
|
};
|
|
1129
|
-
|
|
1130
993
|
_proto.autolink = function autolink(src, mangle) {
|
|
1131
994
|
var cap = this.rules.inline.autolink.exec(src);
|
|
1132
|
-
|
|
1133
995
|
if (cap) {
|
|
1134
996
|
var text, href;
|
|
1135
|
-
|
|
1136
997
|
if (cap[2] === '@') {
|
|
1137
998
|
text = escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
|
|
1138
999
|
href = 'mailto:' + text;
|
|
@@ -1140,7 +1001,6 @@
|
|
|
1140
1001
|
text = escape(cap[1]);
|
|
1141
1002
|
href = text;
|
|
1142
1003
|
}
|
|
1143
|
-
|
|
1144
1004
|
return {
|
|
1145
1005
|
type: 'link',
|
|
1146
1006
|
raw: cap[0],
|
|
@@ -1154,34 +1014,27 @@
|
|
|
1154
1014
|
};
|
|
1155
1015
|
}
|
|
1156
1016
|
};
|
|
1157
|
-
|
|
1158
1017
|
_proto.url = function url(src, mangle) {
|
|
1159
1018
|
var cap;
|
|
1160
|
-
|
|
1161
1019
|
if (cap = this.rules.inline.url.exec(src)) {
|
|
1162
1020
|
var text, href;
|
|
1163
|
-
|
|
1164
1021
|
if (cap[2] === '@') {
|
|
1165
1022
|
text = escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
|
|
1166
1023
|
href = 'mailto:' + text;
|
|
1167
1024
|
} else {
|
|
1168
1025
|
// do extended autolink path validation
|
|
1169
1026
|
var prevCapZero;
|
|
1170
|
-
|
|
1171
1027
|
do {
|
|
1172
1028
|
prevCapZero = cap[0];
|
|
1173
1029
|
cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
|
|
1174
1030
|
} while (prevCapZero !== cap[0]);
|
|
1175
|
-
|
|
1176
1031
|
text = escape(cap[0]);
|
|
1177
|
-
|
|
1178
1032
|
if (cap[1] === 'www.') {
|
|
1179
1033
|
href = 'http://' + text;
|
|
1180
1034
|
} else {
|
|
1181
1035
|
href = text;
|
|
1182
1036
|
}
|
|
1183
1037
|
}
|
|
1184
|
-
|
|
1185
1038
|
return {
|
|
1186
1039
|
type: 'link',
|
|
1187
1040
|
raw: cap[0],
|
|
@@ -1195,19 +1048,15 @@
|
|
|
1195
1048
|
};
|
|
1196
1049
|
}
|
|
1197
1050
|
};
|
|
1198
|
-
|
|
1199
1051
|
_proto.inlineText = function inlineText(src, smartypants) {
|
|
1200
1052
|
var cap = this.rules.inline.text.exec(src);
|
|
1201
|
-
|
|
1202
1053
|
if (cap) {
|
|
1203
1054
|
var text;
|
|
1204
|
-
|
|
1205
1055
|
if (this.lexer.state.inRawBlock) {
|
|
1206
1056
|
text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0];
|
|
1207
1057
|
} else {
|
|
1208
1058
|
text = escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
|
|
1209
1059
|
}
|
|
1210
|
-
|
|
1211
1060
|
return {
|
|
1212
1061
|
type: 'text',
|
|
1213
1062
|
raw: cap[0],
|
|
@@ -1215,14 +1064,12 @@
|
|
|
1215
1064
|
};
|
|
1216
1065
|
}
|
|
1217
1066
|
};
|
|
1218
|
-
|
|
1219
1067
|
return Tokenizer;
|
|
1220
1068
|
}();
|
|
1221
1069
|
|
|
1222
1070
|
/**
|
|
1223
1071
|
* Block-Level Grammar
|
|
1224
1072
|
*/
|
|
1225
|
-
|
|
1226
1073
|
var block = {
|
|
1227
1074
|
newline: /^(?: *(?:\n|$))+/,
|
|
1228
1075
|
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
@@ -1263,11 +1110,13 @@
|
|
|
1263
1110
|
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
|
|
1264
1111
|
.getRegex();
|
|
1265
1112
|
block.blockquote = edit(block.blockquote).replace('paragraph', block.paragraph).getRegex();
|
|
1113
|
+
|
|
1266
1114
|
/**
|
|
1267
1115
|
* Normal Block Grammar
|
|
1268
1116
|
*/
|
|
1269
1117
|
|
|
1270
1118
|
block.normal = merge({}, block);
|
|
1119
|
+
|
|
1271
1120
|
/**
|
|
1272
1121
|
* GFM Block Grammar
|
|
1273
1122
|
*/
|
|
@@ -1276,8 +1125,8 @@
|
|
|
1276
1125
|
table: '^ *([^\\n ].*\\|.*)\\n' // Header
|
|
1277
1126
|
+ ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' // Align
|
|
1278
1127
|
+ '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
|
1279
|
-
|
|
1280
1128
|
});
|
|
1129
|
+
|
|
1281
1130
|
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
1131
|
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
1283
1132
|
.getRegex();
|
|
@@ -1299,10 +1148,10 @@
|
|
|
1299
1148
|
// fences not supported
|
|
1300
1149
|
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
1150
|
});
|
|
1151
|
+
|
|
1302
1152
|
/**
|
|
1303
1153
|
* Inline-Level Grammar
|
|
1304
1154
|
*/
|
|
1305
|
-
|
|
1306
1155
|
var inline = {
|
|
1307
1156
|
escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
|
|
1308
1157
|
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
|
@@ -1320,24 +1169,28 @@
|
|
|
1320
1169
|
emStrong: {
|
|
1321
1170
|
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
|
|
1322
1171
|
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
|
|
1323
|
-
// () Skip orphan inside strong
|
|
1324
|
-
rDelimAst: /^[^_
|
|
1325
|
-
rDelimUnd: /^[^_
|
|
1326
|
-
|
|
1172
|
+
// () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
|
|
1173
|
+
rDelimAst: /^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,
|
|
1174
|
+
rDelimUnd: /^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
|
|
1327
1175
|
},
|
|
1176
|
+
|
|
1328
1177
|
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
1329
1178
|
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
1330
1179
|
del: noopTest,
|
|
1331
1180
|
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
|
|
1332
1181
|
punctuation: /^([\spunctuation])/
|
|
1333
|
-
};
|
|
1334
|
-
// without * and _ to handle the different emphasis markers * and _
|
|
1182
|
+
};
|
|
1335
1183
|
|
|
1184
|
+
// list of punctuation marks from CommonMark spec
|
|
1185
|
+
// without * and _ to handle the different emphasis markers * and _
|
|
1336
1186
|
inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
|
|
1337
|
-
inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1187
|
+
inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1338
1188
|
|
|
1189
|
+
// sequences em should skip over [title](link), `code`, <html>
|
|
1339
1190
|
inline.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
|
|
1340
|
-
|
|
1191
|
+
// lookbehind is not available on Safari as of version 16
|
|
1192
|
+
// inline.escapedEmSt = /(?<=(?:^|[^\\)(?:\\[^])*)\\[*_]/g;
|
|
1193
|
+
inline.escapedEmSt = /(?:^|[^\\])(?:\\\\)*\\[*_]/g;
|
|
1341
1194
|
inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
|
|
1342
1195
|
inline.emStrong.lDelim = edit(inline.emStrong.lDelim).replace(/punct/g, inline._punctuation).getRegex();
|
|
1343
1196
|
inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'g').replace(/punct/g, inline._punctuation).getRegex();
|
|
@@ -1355,11 +1208,13 @@
|
|
|
1355
1208
|
inline.reflink = edit(inline.reflink).replace('label', inline._label).replace('ref', block._label).getRegex();
|
|
1356
1209
|
inline.nolink = edit(inline.nolink).replace('ref', block._label).getRegex();
|
|
1357
1210
|
inline.reflinkSearch = edit(inline.reflinkSearch, 'g').replace('reflink', inline.reflink).replace('nolink', inline.nolink).getRegex();
|
|
1211
|
+
|
|
1358
1212
|
/**
|
|
1359
1213
|
* Normal Inline Grammar
|
|
1360
1214
|
*/
|
|
1361
1215
|
|
|
1362
1216
|
inline.normal = merge({}, inline);
|
|
1217
|
+
|
|
1363
1218
|
/**
|
|
1364
1219
|
* Pedantic Inline Grammar
|
|
1365
1220
|
*/
|
|
@@ -1380,6 +1235,7 @@
|
|
|
1380
1235
|
link: edit(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
|
|
1381
1236
|
reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
|
|
1382
1237
|
});
|
|
1238
|
+
|
|
1383
1239
|
/**
|
|
1384
1240
|
* GFM Inline Grammar
|
|
1385
1241
|
*/
|
|
@@ -1406,46 +1262,46 @@
|
|
|
1406
1262
|
* smartypants text replacement
|
|
1407
1263
|
* @param {string} text
|
|
1408
1264
|
*/
|
|
1409
|
-
|
|
1410
1265
|
function smartypants(text) {
|
|
1411
|
-
return text
|
|
1412
|
-
|
|
1413
|
-
.replace(
|
|
1414
|
-
|
|
1415
|
-
.replace(
|
|
1416
|
-
|
|
1417
|
-
.replace(/"/g, "\
|
|
1266
|
+
return text
|
|
1267
|
+
// em-dashes
|
|
1268
|
+
.replace(/---/g, "\u2014")
|
|
1269
|
+
// en-dashes
|
|
1270
|
+
.replace(/--/g, "\u2013")
|
|
1271
|
+
// opening singles
|
|
1272
|
+
.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018")
|
|
1273
|
+
// closing singles & apostrophes
|
|
1274
|
+
.replace(/'/g, "\u2019")
|
|
1275
|
+
// opening doubles
|
|
1276
|
+
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C")
|
|
1277
|
+
// closing doubles
|
|
1278
|
+
.replace(/"/g, "\u201D")
|
|
1279
|
+
// ellipses
|
|
1418
1280
|
.replace(/\.{3}/g, "\u2026");
|
|
1419
1281
|
}
|
|
1282
|
+
|
|
1420
1283
|
/**
|
|
1421
1284
|
* mangle email addresses
|
|
1422
1285
|
* @param {string} text
|
|
1423
1286
|
*/
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
1287
|
function mangle(text) {
|
|
1427
1288
|
var out = '',
|
|
1428
|
-
|
|
1429
|
-
|
|
1289
|
+
i,
|
|
1290
|
+
ch;
|
|
1430
1291
|
var l = text.length;
|
|
1431
|
-
|
|
1432
1292
|
for (i = 0; i < l; i++) {
|
|
1433
1293
|
ch = text.charCodeAt(i);
|
|
1434
|
-
|
|
1435
1294
|
if (Math.random() > 0.5) {
|
|
1436
1295
|
ch = 'x' + ch.toString(16);
|
|
1437
1296
|
}
|
|
1438
|
-
|
|
1439
1297
|
out += '&#' + ch + ';';
|
|
1440
1298
|
}
|
|
1441
|
-
|
|
1442
1299
|
return out;
|
|
1443
1300
|
}
|
|
1301
|
+
|
|
1444
1302
|
/**
|
|
1445
1303
|
* Block Lexer
|
|
1446
1304
|
*/
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
1305
|
var Lexer = /*#__PURE__*/function () {
|
|
1450
1306
|
function Lexer(options) {
|
|
1451
1307
|
this.tokens = [];
|
|
@@ -1465,27 +1321,23 @@
|
|
|
1465
1321
|
block: block.normal,
|
|
1466
1322
|
inline: inline.normal
|
|
1467
1323
|
};
|
|
1468
|
-
|
|
1469
1324
|
if (this.options.pedantic) {
|
|
1470
1325
|
rules.block = block.pedantic;
|
|
1471
1326
|
rules.inline = inline.pedantic;
|
|
1472
1327
|
} else if (this.options.gfm) {
|
|
1473
1328
|
rules.block = block.gfm;
|
|
1474
|
-
|
|
1475
1329
|
if (this.options.breaks) {
|
|
1476
1330
|
rules.inline = inline.breaks;
|
|
1477
1331
|
} else {
|
|
1478
1332
|
rules.inline = inline.gfm;
|
|
1479
1333
|
}
|
|
1480
1334
|
}
|
|
1481
|
-
|
|
1482
1335
|
this.tokenizer.rules = rules;
|
|
1483
1336
|
}
|
|
1337
|
+
|
|
1484
1338
|
/**
|
|
1485
1339
|
* Expose Rules
|
|
1486
1340
|
*/
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
1341
|
/**
|
|
1490
1342
|
* Static Lex Method
|
|
1491
1343
|
*/
|
|
@@ -1493,45 +1345,37 @@
|
|
|
1493
1345
|
var lexer = new Lexer(options);
|
|
1494
1346
|
return lexer.lex(src);
|
|
1495
1347
|
}
|
|
1348
|
+
|
|
1496
1349
|
/**
|
|
1497
1350
|
* Static Lex Inline Method
|
|
1498
|
-
|
|
1499
|
-
;
|
|
1500
|
-
|
|
1351
|
+
*/;
|
|
1501
1352
|
Lexer.lexInline = function lexInline(src, options) {
|
|
1502
1353
|
var lexer = new Lexer(options);
|
|
1503
1354
|
return lexer.inlineTokens(src);
|
|
1504
1355
|
}
|
|
1356
|
+
|
|
1505
1357
|
/**
|
|
1506
1358
|
* Preprocessing
|
|
1507
|
-
|
|
1508
|
-
;
|
|
1509
|
-
|
|
1359
|
+
*/;
|
|
1510
1360
|
var _proto = Lexer.prototype;
|
|
1511
|
-
|
|
1512
1361
|
_proto.lex = function lex(src) {
|
|
1513
1362
|
src = src.replace(/\r\n|\r/g, '\n');
|
|
1514
1363
|
this.blockTokens(src, this.tokens);
|
|
1515
1364
|
var next;
|
|
1516
|
-
|
|
1517
1365
|
while (next = this.inlineQueue.shift()) {
|
|
1518
1366
|
this.inlineTokens(next.src, next.tokens);
|
|
1519
1367
|
}
|
|
1520
|
-
|
|
1521
1368
|
return this.tokens;
|
|
1522
1369
|
}
|
|
1370
|
+
|
|
1523
1371
|
/**
|
|
1524
1372
|
* Lexing
|
|
1525
|
-
|
|
1526
|
-
;
|
|
1527
|
-
|
|
1373
|
+
*/;
|
|
1528
1374
|
_proto.blockTokens = function blockTokens(src, tokens) {
|
|
1529
1375
|
var _this = this;
|
|
1530
|
-
|
|
1531
1376
|
if (tokens === void 0) {
|
|
1532
1377
|
tokens = [];
|
|
1533
1378
|
}
|
|
1534
|
-
|
|
1535
1379
|
if (this.options.pedantic) {
|
|
1536
1380
|
src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
|
|
1537
1381
|
} else {
|
|
@@ -1539,9 +1383,7 @@
|
|
|
1539
1383
|
return leading + ' '.repeat(tabs.length);
|
|
1540
1384
|
});
|
|
1541
1385
|
}
|
|
1542
|
-
|
|
1543
1386
|
var token, lastToken, cutSrc, lastParagraphClipped;
|
|
1544
|
-
|
|
1545
1387
|
while (src) {
|
|
1546
1388
|
if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some(function (extTokenizer) {
|
|
1547
1389
|
if (token = extTokenizer.call({
|
|
@@ -1551,16 +1393,14 @@
|
|
|
1551
1393
|
tokens.push(token);
|
|
1552
1394
|
return true;
|
|
1553
1395
|
}
|
|
1554
|
-
|
|
1555
1396
|
return false;
|
|
1556
1397
|
})) {
|
|
1557
1398
|
continue;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1399
|
+
}
|
|
1560
1400
|
|
|
1401
|
+
// newline
|
|
1561
1402
|
if (token = this.tokenizer.space(src)) {
|
|
1562
1403
|
src = src.substring(token.raw.length);
|
|
1563
|
-
|
|
1564
1404
|
if (token.raw.length === 1 && tokens.length > 0) {
|
|
1565
1405
|
// if there's a single \n as a spacer, it's terminating the last line,
|
|
1566
1406
|
// so move it there so that we don't get unecessary paragraph tags
|
|
@@ -1568,15 +1408,14 @@
|
|
|
1568
1408
|
} else {
|
|
1569
1409
|
tokens.push(token);
|
|
1570
1410
|
}
|
|
1571
|
-
|
|
1572
1411
|
continue;
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1412
|
+
}
|
|
1575
1413
|
|
|
1414
|
+
// code
|
|
1576
1415
|
if (token = this.tokenizer.code(src)) {
|
|
1577
1416
|
src = src.substring(token.raw.length);
|
|
1578
|
-
lastToken = tokens[tokens.length - 1];
|
|
1579
|
-
|
|
1417
|
+
lastToken = tokens[tokens.length - 1];
|
|
1418
|
+
// An indented code block cannot interrupt a paragraph.
|
|
1580
1419
|
if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
|
|
1581
1420
|
lastToken.raw += '\n' + token.raw;
|
|
1582
1421
|
lastToken.text += '\n' + token.text;
|
|
@@ -1584,57 +1423,55 @@
|
|
|
1584
1423
|
} else {
|
|
1585
1424
|
tokens.push(token);
|
|
1586
1425
|
}
|
|
1587
|
-
|
|
1588
1426
|
continue;
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1427
|
+
}
|
|
1591
1428
|
|
|
1429
|
+
// fences
|
|
1592
1430
|
if (token = this.tokenizer.fences(src)) {
|
|
1593
1431
|
src = src.substring(token.raw.length);
|
|
1594
1432
|
tokens.push(token);
|
|
1595
1433
|
continue;
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1434
|
+
}
|
|
1598
1435
|
|
|
1436
|
+
// heading
|
|
1599
1437
|
if (token = this.tokenizer.heading(src)) {
|
|
1600
1438
|
src = src.substring(token.raw.length);
|
|
1601
1439
|
tokens.push(token);
|
|
1602
1440
|
continue;
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1441
|
+
}
|
|
1605
1442
|
|
|
1443
|
+
// hr
|
|
1606
1444
|
if (token = this.tokenizer.hr(src)) {
|
|
1607
1445
|
src = src.substring(token.raw.length);
|
|
1608
1446
|
tokens.push(token);
|
|
1609
1447
|
continue;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1448
|
+
}
|
|
1612
1449
|
|
|
1450
|
+
// blockquote
|
|
1613
1451
|
if (token = this.tokenizer.blockquote(src)) {
|
|
1614
1452
|
src = src.substring(token.raw.length);
|
|
1615
1453
|
tokens.push(token);
|
|
1616
1454
|
continue;
|
|
1617
|
-
}
|
|
1618
|
-
|
|
1455
|
+
}
|
|
1619
1456
|
|
|
1457
|
+
// list
|
|
1620
1458
|
if (token = this.tokenizer.list(src)) {
|
|
1621
1459
|
src = src.substring(token.raw.length);
|
|
1622
1460
|
tokens.push(token);
|
|
1623
1461
|
continue;
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1462
|
+
}
|
|
1626
1463
|
|
|
1464
|
+
// html
|
|
1627
1465
|
if (token = this.tokenizer.html(src)) {
|
|
1628
1466
|
src = src.substring(token.raw.length);
|
|
1629
1467
|
tokens.push(token);
|
|
1630
1468
|
continue;
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1469
|
+
}
|
|
1633
1470
|
|
|
1471
|
+
// def
|
|
1634
1472
|
if (token = this.tokenizer.def(src)) {
|
|
1635
1473
|
src = src.substring(token.raw.length);
|
|
1636
1474
|
lastToken = tokens[tokens.length - 1];
|
|
1637
|
-
|
|
1638
1475
|
if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
|
|
1639
1476
|
lastToken.raw += '\n' + token.raw;
|
|
1640
1477
|
lastToken.text += '\n' + token.raw;
|
|
@@ -1645,53 +1482,46 @@
|
|
|
1645
1482
|
title: token.title
|
|
1646
1483
|
};
|
|
1647
1484
|
}
|
|
1648
|
-
|
|
1649
1485
|
continue;
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1486
|
+
}
|
|
1652
1487
|
|
|
1488
|
+
// table (gfm)
|
|
1653
1489
|
if (token = this.tokenizer.table(src)) {
|
|
1654
1490
|
src = src.substring(token.raw.length);
|
|
1655
1491
|
tokens.push(token);
|
|
1656
1492
|
continue;
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1493
|
+
}
|
|
1659
1494
|
|
|
1495
|
+
// lheading
|
|
1660
1496
|
if (token = this.tokenizer.lheading(src)) {
|
|
1661
1497
|
src = src.substring(token.raw.length);
|
|
1662
1498
|
tokens.push(token);
|
|
1663
1499
|
continue;
|
|
1664
|
-
}
|
|
1665
|
-
// prevent paragraph consuming extensions by clipping 'src' to extension start
|
|
1666
|
-
|
|
1500
|
+
}
|
|
1667
1501
|
|
|
1502
|
+
// top-level paragraph
|
|
1503
|
+
// prevent paragraph consuming extensions by clipping 'src' to extension start
|
|
1668
1504
|
cutSrc = src;
|
|
1669
|
-
|
|
1670
1505
|
if (this.options.extensions && this.options.extensions.startBlock) {
|
|
1671
1506
|
(function () {
|
|
1672
1507
|
var startIndex = Infinity;
|
|
1673
1508
|
var tempSrc = src.slice(1);
|
|
1674
1509
|
var tempStart = void 0;
|
|
1675
|
-
|
|
1676
1510
|
_this.options.extensions.startBlock.forEach(function (getStartIndex) {
|
|
1677
1511
|
tempStart = getStartIndex.call({
|
|
1678
1512
|
lexer: this
|
|
1679
1513
|
}, tempSrc);
|
|
1680
|
-
|
|
1681
1514
|
if (typeof tempStart === 'number' && tempStart >= 0) {
|
|
1682
1515
|
startIndex = Math.min(startIndex, tempStart);
|
|
1683
1516
|
}
|
|
1684
1517
|
});
|
|
1685
|
-
|
|
1686
1518
|
if (startIndex < Infinity && startIndex >= 0) {
|
|
1687
1519
|
cutSrc = src.substring(0, startIndex + 1);
|
|
1688
1520
|
}
|
|
1689
1521
|
})();
|
|
1690
1522
|
}
|
|
1691
|
-
|
|
1692
1523
|
if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
|
|
1693
1524
|
lastToken = tokens[tokens.length - 1];
|
|
1694
|
-
|
|
1695
1525
|
if (lastParagraphClipped && lastToken.type === 'paragraph') {
|
|
1696
1526
|
lastToken.raw += '\n' + token.raw;
|
|
1697
1527
|
lastToken.text += '\n' + token.text;
|
|
@@ -1700,17 +1530,15 @@
|
|
|
1700
1530
|
} else {
|
|
1701
1531
|
tokens.push(token);
|
|
1702
1532
|
}
|
|
1703
|
-
|
|
1704
1533
|
lastParagraphClipped = cutSrc.length !== src.length;
|
|
1705
1534
|
src = src.substring(token.raw.length);
|
|
1706
1535
|
continue;
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1536
|
+
}
|
|
1709
1537
|
|
|
1538
|
+
// text
|
|
1710
1539
|
if (token = this.tokenizer.text(src)) {
|
|
1711
1540
|
src = src.substring(token.raw.length);
|
|
1712
1541
|
lastToken = tokens[tokens.length - 1];
|
|
1713
|
-
|
|
1714
1542
|
if (lastToken && lastToken.type === 'text') {
|
|
1715
1543
|
lastToken.raw += '\n' + token.raw;
|
|
1716
1544
|
lastToken.text += '\n' + token.text;
|
|
@@ -1719,13 +1547,10 @@
|
|
|
1719
1547
|
} else {
|
|
1720
1548
|
tokens.push(token);
|
|
1721
1549
|
}
|
|
1722
|
-
|
|
1723
1550
|
continue;
|
|
1724
1551
|
}
|
|
1725
|
-
|
|
1726
1552
|
if (src) {
|
|
1727
1553
|
var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
|
1728
|
-
|
|
1729
1554
|
if (this.options.silent) {
|
|
1730
1555
|
console.error(errMsg);
|
|
1731
1556
|
break;
|
|
@@ -1734,43 +1559,38 @@
|
|
|
1734
1559
|
}
|
|
1735
1560
|
}
|
|
1736
1561
|
}
|
|
1737
|
-
|
|
1738
1562
|
this.state.top = true;
|
|
1739
1563
|
return tokens;
|
|
1740
1564
|
};
|
|
1741
|
-
|
|
1742
1565
|
_proto.inline = function inline(src, tokens) {
|
|
1743
1566
|
if (tokens === void 0) {
|
|
1744
1567
|
tokens = [];
|
|
1745
1568
|
}
|
|
1746
|
-
|
|
1747
1569
|
this.inlineQueue.push({
|
|
1748
1570
|
src: src,
|
|
1749
1571
|
tokens: tokens
|
|
1750
1572
|
});
|
|
1751
1573
|
return tokens;
|
|
1752
1574
|
}
|
|
1575
|
+
|
|
1753
1576
|
/**
|
|
1754
1577
|
* Lexing/Compiling
|
|
1755
|
-
|
|
1756
|
-
;
|
|
1757
|
-
|
|
1578
|
+
*/;
|
|
1758
1579
|
_proto.inlineTokens = function inlineTokens(src, tokens) {
|
|
1759
1580
|
var _this2 = this;
|
|
1760
|
-
|
|
1761
1581
|
if (tokens === void 0) {
|
|
1762
1582
|
tokens = [];
|
|
1763
1583
|
}
|
|
1584
|
+
var token, lastToken, cutSrc;
|
|
1764
1585
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1586
|
+
// String with links masked to avoid interference with em and strong
|
|
1767
1587
|
var maskedSrc = src;
|
|
1768
1588
|
var match;
|
|
1769
|
-
var keepPrevChar, prevChar;
|
|
1589
|
+
var keepPrevChar, prevChar;
|
|
1770
1590
|
|
|
1591
|
+
// Mask out reflinks
|
|
1771
1592
|
if (this.tokens.links) {
|
|
1772
1593
|
var links = Object.keys(this.tokens.links);
|
|
1773
|
-
|
|
1774
1594
|
if (links.length > 0) {
|
|
1775
1595
|
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
|
1776
1596
|
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
|
@@ -1778,25 +1598,24 @@
|
|
|
1778
1598
|
}
|
|
1779
1599
|
}
|
|
1780
1600
|
}
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
|
|
1601
|
+
}
|
|
1602
|
+
// Mask out other blocks
|
|
1784
1603
|
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
|
1785
1604
|
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1605
|
+
}
|
|
1788
1606
|
|
|
1607
|
+
// Mask out escaped em & strong delimiters
|
|
1789
1608
|
while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) {
|
|
1790
|
-
maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
|
|
1609
|
+
maskedSrc = maskedSrc.slice(0, match.index + match[0].length - 2) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex);
|
|
1610
|
+
this.tokenizer.rules.inline.escapedEmSt.lastIndex--;
|
|
1791
1611
|
}
|
|
1792
|
-
|
|
1793
1612
|
while (src) {
|
|
1794
1613
|
if (!keepPrevChar) {
|
|
1795
1614
|
prevChar = '';
|
|
1796
1615
|
}
|
|
1616
|
+
keepPrevChar = false;
|
|
1797
1617
|
|
|
1798
|
-
|
|
1799
|
-
|
|
1618
|
+
// extensions
|
|
1800
1619
|
if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some(function (extTokenizer) {
|
|
1801
1620
|
if (token = extTokenizer.call({
|
|
1802
1621
|
lexer: _this2
|
|
@@ -1805,148 +1624,132 @@
|
|
|
1805
1624
|
tokens.push(token);
|
|
1806
1625
|
return true;
|
|
1807
1626
|
}
|
|
1808
|
-
|
|
1809
1627
|
return false;
|
|
1810
1628
|
})) {
|
|
1811
1629
|
continue;
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1630
|
+
}
|
|
1814
1631
|
|
|
1632
|
+
// escape
|
|
1815
1633
|
if (token = this.tokenizer.escape(src)) {
|
|
1816
1634
|
src = src.substring(token.raw.length);
|
|
1817
1635
|
tokens.push(token);
|
|
1818
1636
|
continue;
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1637
|
+
}
|
|
1821
1638
|
|
|
1639
|
+
// tag
|
|
1822
1640
|
if (token = this.tokenizer.tag(src)) {
|
|
1823
1641
|
src = src.substring(token.raw.length);
|
|
1824
1642
|
lastToken = tokens[tokens.length - 1];
|
|
1825
|
-
|
|
1826
1643
|
if (lastToken && token.type === 'text' && lastToken.type === 'text') {
|
|
1827
1644
|
lastToken.raw += token.raw;
|
|
1828
1645
|
lastToken.text += token.text;
|
|
1829
1646
|
} else {
|
|
1830
1647
|
tokens.push(token);
|
|
1831
1648
|
}
|
|
1832
|
-
|
|
1833
1649
|
continue;
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1650
|
+
}
|
|
1836
1651
|
|
|
1652
|
+
// link
|
|
1837
1653
|
if (token = this.tokenizer.link(src)) {
|
|
1838
1654
|
src = src.substring(token.raw.length);
|
|
1839
1655
|
tokens.push(token);
|
|
1840
1656
|
continue;
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1657
|
+
}
|
|
1843
1658
|
|
|
1659
|
+
// reflink, nolink
|
|
1844
1660
|
if (token = this.tokenizer.reflink(src, this.tokens.links)) {
|
|
1845
1661
|
src = src.substring(token.raw.length);
|
|
1846
1662
|
lastToken = tokens[tokens.length - 1];
|
|
1847
|
-
|
|
1848
1663
|
if (lastToken && token.type === 'text' && lastToken.type === 'text') {
|
|
1849
1664
|
lastToken.raw += token.raw;
|
|
1850
1665
|
lastToken.text += token.text;
|
|
1851
1666
|
} else {
|
|
1852
1667
|
tokens.push(token);
|
|
1853
1668
|
}
|
|
1854
|
-
|
|
1855
1669
|
continue;
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1670
|
+
}
|
|
1858
1671
|
|
|
1672
|
+
// em & strong
|
|
1859
1673
|
if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
|
|
1860
1674
|
src = src.substring(token.raw.length);
|
|
1861
1675
|
tokens.push(token);
|
|
1862
1676
|
continue;
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1677
|
+
}
|
|
1865
1678
|
|
|
1679
|
+
// code
|
|
1866
1680
|
if (token = this.tokenizer.codespan(src)) {
|
|
1867
1681
|
src = src.substring(token.raw.length);
|
|
1868
1682
|
tokens.push(token);
|
|
1869
1683
|
continue;
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1684
|
+
}
|
|
1872
1685
|
|
|
1686
|
+
// br
|
|
1873
1687
|
if (token = this.tokenizer.br(src)) {
|
|
1874
1688
|
src = src.substring(token.raw.length);
|
|
1875
1689
|
tokens.push(token);
|
|
1876
1690
|
continue;
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1691
|
+
}
|
|
1879
1692
|
|
|
1693
|
+
// del (gfm)
|
|
1880
1694
|
if (token = this.tokenizer.del(src)) {
|
|
1881
1695
|
src = src.substring(token.raw.length);
|
|
1882
1696
|
tokens.push(token);
|
|
1883
1697
|
continue;
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1698
|
+
}
|
|
1886
1699
|
|
|
1700
|
+
// autolink
|
|
1887
1701
|
if (token = this.tokenizer.autolink(src, mangle)) {
|
|
1888
1702
|
src = src.substring(token.raw.length);
|
|
1889
1703
|
tokens.push(token);
|
|
1890
1704
|
continue;
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1705
|
+
}
|
|
1893
1706
|
|
|
1707
|
+
// url (gfm)
|
|
1894
1708
|
if (!this.state.inLink && (token = this.tokenizer.url(src, mangle))) {
|
|
1895
1709
|
src = src.substring(token.raw.length);
|
|
1896
1710
|
tokens.push(token);
|
|
1897
1711
|
continue;
|
|
1898
|
-
}
|
|
1899
|
-
// prevent inlineText consuming extensions by clipping 'src' to extension start
|
|
1900
|
-
|
|
1712
|
+
}
|
|
1901
1713
|
|
|
1714
|
+
// text
|
|
1715
|
+
// prevent inlineText consuming extensions by clipping 'src' to extension start
|
|
1902
1716
|
cutSrc = src;
|
|
1903
|
-
|
|
1904
1717
|
if (this.options.extensions && this.options.extensions.startInline) {
|
|
1905
1718
|
(function () {
|
|
1906
1719
|
var startIndex = Infinity;
|
|
1907
1720
|
var tempSrc = src.slice(1);
|
|
1908
1721
|
var tempStart = void 0;
|
|
1909
|
-
|
|
1910
1722
|
_this2.options.extensions.startInline.forEach(function (getStartIndex) {
|
|
1911
1723
|
tempStart = getStartIndex.call({
|
|
1912
1724
|
lexer: this
|
|
1913
1725
|
}, tempSrc);
|
|
1914
|
-
|
|
1915
1726
|
if (typeof tempStart === 'number' && tempStart >= 0) {
|
|
1916
1727
|
startIndex = Math.min(startIndex, tempStart);
|
|
1917
1728
|
}
|
|
1918
1729
|
});
|
|
1919
|
-
|
|
1920
1730
|
if (startIndex < Infinity && startIndex >= 0) {
|
|
1921
1731
|
cutSrc = src.substring(0, startIndex + 1);
|
|
1922
1732
|
}
|
|
1923
1733
|
})();
|
|
1924
1734
|
}
|
|
1925
|
-
|
|
1926
1735
|
if (token = this.tokenizer.inlineText(cutSrc, smartypants)) {
|
|
1927
1736
|
src = src.substring(token.raw.length);
|
|
1928
|
-
|
|
1929
1737
|
if (token.raw.slice(-1) !== '_') {
|
|
1930
1738
|
// Track prevChar before string of ____ started
|
|
1931
1739
|
prevChar = token.raw.slice(-1);
|
|
1932
1740
|
}
|
|
1933
|
-
|
|
1934
1741
|
keepPrevChar = true;
|
|
1935
1742
|
lastToken = tokens[tokens.length - 1];
|
|
1936
|
-
|
|
1937
1743
|
if (lastToken && lastToken.type === 'text') {
|
|
1938
1744
|
lastToken.raw += token.raw;
|
|
1939
1745
|
lastToken.text += token.text;
|
|
1940
1746
|
} else {
|
|
1941
1747
|
tokens.push(token);
|
|
1942
1748
|
}
|
|
1943
|
-
|
|
1944
1749
|
continue;
|
|
1945
1750
|
}
|
|
1946
|
-
|
|
1947
1751
|
if (src) {
|
|
1948
1752
|
var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
|
1949
|
-
|
|
1950
1753
|
if (this.options.silent) {
|
|
1951
1754
|
console.error(errMsg);
|
|
1952
1755
|
break;
|
|
@@ -1955,10 +1758,8 @@
|
|
|
1955
1758
|
}
|
|
1956
1759
|
}
|
|
1957
1760
|
}
|
|
1958
|
-
|
|
1959
1761
|
return tokens;
|
|
1960
1762
|
};
|
|
1961
|
-
|
|
1962
1763
|
_createClass(Lexer, null, [{
|
|
1963
1764
|
key: "rules",
|
|
1964
1765
|
get: function get() {
|
|
@@ -1968,212 +1769,175 @@
|
|
|
1968
1769
|
};
|
|
1969
1770
|
}
|
|
1970
1771
|
}]);
|
|
1971
|
-
|
|
1972
1772
|
return Lexer;
|
|
1973
1773
|
}();
|
|
1974
1774
|
|
|
1975
1775
|
/**
|
|
1976
1776
|
* Renderer
|
|
1977
1777
|
*/
|
|
1978
|
-
|
|
1979
1778
|
var Renderer = /*#__PURE__*/function () {
|
|
1980
1779
|
function Renderer(options) {
|
|
1981
1780
|
this.options = options || exports.defaults;
|
|
1982
1781
|
}
|
|
1983
|
-
|
|
1984
1782
|
var _proto = Renderer.prototype;
|
|
1985
|
-
|
|
1986
1783
|
_proto.code = function code(_code, infostring, escaped) {
|
|
1987
1784
|
var lang = (infostring || '').match(/\S*/)[0];
|
|
1988
|
-
|
|
1989
1785
|
if (this.options.highlight) {
|
|
1990
1786
|
var out = this.options.highlight(_code, lang);
|
|
1991
|
-
|
|
1992
1787
|
if (out != null && out !== _code) {
|
|
1993
1788
|
escaped = true;
|
|
1994
1789
|
_code = out;
|
|
1995
1790
|
}
|
|
1996
1791
|
}
|
|
1997
|
-
|
|
1998
1792
|
_code = _code.replace(/\n$/, '') + '\n';
|
|
1999
|
-
|
|
2000
1793
|
if (!lang) {
|
|
2001
1794
|
return '<pre><code>' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
|
|
2002
1795
|
}
|
|
2003
|
-
|
|
2004
1796
|
return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? _code : escape(_code, true)) + '</code></pre>\n';
|
|
2005
1797
|
}
|
|
1798
|
+
|
|
2006
1799
|
/**
|
|
2007
1800
|
* @param {string} quote
|
|
2008
|
-
|
|
2009
|
-
;
|
|
2010
|
-
|
|
1801
|
+
*/;
|
|
2011
1802
|
_proto.blockquote = function blockquote(quote) {
|
|
2012
1803
|
return "<blockquote>\n" + quote + "</blockquote>\n";
|
|
2013
1804
|
};
|
|
2014
|
-
|
|
2015
1805
|
_proto.html = function html(_html) {
|
|
2016
1806
|
return _html;
|
|
2017
1807
|
}
|
|
1808
|
+
|
|
2018
1809
|
/**
|
|
2019
1810
|
* @param {string} text
|
|
2020
1811
|
* @param {string} level
|
|
2021
1812
|
* @param {string} raw
|
|
2022
1813
|
* @param {any} slugger
|
|
2023
|
-
|
|
2024
|
-
;
|
|
2025
|
-
|
|
1814
|
+
*/;
|
|
2026
1815
|
_proto.heading = function heading(text, level, raw, slugger) {
|
|
2027
1816
|
if (this.options.headerIds) {
|
|
2028
1817
|
var id = this.options.headerPrefix + slugger.slug(raw);
|
|
2029
1818
|
return "<h" + level + " id=\"" + id + "\">" + text + "</h" + level + ">\n";
|
|
2030
|
-
}
|
|
2031
|
-
|
|
1819
|
+
}
|
|
2032
1820
|
|
|
1821
|
+
// ignore IDs
|
|
2033
1822
|
return "<h" + level + ">" + text + "</h" + level + ">\n";
|
|
2034
1823
|
};
|
|
2035
|
-
|
|
2036
1824
|
_proto.hr = function hr() {
|
|
2037
1825
|
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
|
2038
1826
|
};
|
|
2039
|
-
|
|
2040
1827
|
_proto.list = function list(body, ordered, start) {
|
|
2041
1828
|
var type = ordered ? 'ol' : 'ul',
|
|
2042
|
-
|
|
1829
|
+
startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
|
|
2043
1830
|
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
|
2044
1831
|
}
|
|
1832
|
+
|
|
2045
1833
|
/**
|
|
2046
1834
|
* @param {string} text
|
|
2047
|
-
|
|
2048
|
-
;
|
|
2049
|
-
|
|
1835
|
+
*/;
|
|
2050
1836
|
_proto.listitem = function listitem(text) {
|
|
2051
1837
|
return "<li>" + text + "</li>\n";
|
|
2052
1838
|
};
|
|
2053
|
-
|
|
2054
1839
|
_proto.checkbox = function checkbox(checked) {
|
|
2055
1840
|
return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
|
|
2056
1841
|
}
|
|
1842
|
+
|
|
2057
1843
|
/**
|
|
2058
1844
|
* @param {string} text
|
|
2059
|
-
|
|
2060
|
-
;
|
|
2061
|
-
|
|
1845
|
+
*/;
|
|
2062
1846
|
_proto.paragraph = function paragraph(text) {
|
|
2063
1847
|
return "<p>" + text + "</p>\n";
|
|
2064
1848
|
}
|
|
1849
|
+
|
|
2065
1850
|
/**
|
|
2066
1851
|
* @param {string} header
|
|
2067
1852
|
* @param {string} body
|
|
2068
|
-
|
|
2069
|
-
;
|
|
2070
|
-
|
|
1853
|
+
*/;
|
|
2071
1854
|
_proto.table = function table(header, body) {
|
|
2072
1855
|
if (body) body = "<tbody>" + body + "</tbody>";
|
|
2073
1856
|
return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
|
|
2074
1857
|
}
|
|
1858
|
+
|
|
2075
1859
|
/**
|
|
2076
1860
|
* @param {string} content
|
|
2077
|
-
|
|
2078
|
-
;
|
|
2079
|
-
|
|
1861
|
+
*/;
|
|
2080
1862
|
_proto.tablerow = function tablerow(content) {
|
|
2081
1863
|
return "<tr>\n" + content + "</tr>\n";
|
|
2082
1864
|
};
|
|
2083
|
-
|
|
2084
1865
|
_proto.tablecell = function tablecell(content, flags) {
|
|
2085
1866
|
var type = flags.header ? 'th' : 'td';
|
|
2086
1867
|
var tag = flags.align ? "<" + type + " align=\"" + flags.align + "\">" : "<" + type + ">";
|
|
2087
1868
|
return tag + content + ("</" + type + ">\n");
|
|
2088
1869
|
}
|
|
1870
|
+
|
|
2089
1871
|
/**
|
|
2090
1872
|
* span level renderer
|
|
2091
1873
|
* @param {string} text
|
|
2092
|
-
|
|
2093
|
-
;
|
|
2094
|
-
|
|
1874
|
+
*/;
|
|
2095
1875
|
_proto.strong = function strong(text) {
|
|
2096
1876
|
return "<strong>" + text + "</strong>";
|
|
2097
1877
|
}
|
|
1878
|
+
|
|
2098
1879
|
/**
|
|
2099
1880
|
* @param {string} text
|
|
2100
|
-
|
|
2101
|
-
;
|
|
2102
|
-
|
|
1881
|
+
*/;
|
|
2103
1882
|
_proto.em = function em(text) {
|
|
2104
1883
|
return "<em>" + text + "</em>";
|
|
2105
1884
|
}
|
|
1885
|
+
|
|
2106
1886
|
/**
|
|
2107
1887
|
* @param {string} text
|
|
2108
|
-
|
|
2109
|
-
;
|
|
2110
|
-
|
|
1888
|
+
*/;
|
|
2111
1889
|
_proto.codespan = function codespan(text) {
|
|
2112
1890
|
return "<code>" + text + "</code>";
|
|
2113
1891
|
};
|
|
2114
|
-
|
|
2115
1892
|
_proto.br = function br() {
|
|
2116
1893
|
return this.options.xhtml ? '<br/>' : '<br>';
|
|
2117
1894
|
}
|
|
1895
|
+
|
|
2118
1896
|
/**
|
|
2119
1897
|
* @param {string} text
|
|
2120
|
-
|
|
2121
|
-
;
|
|
2122
|
-
|
|
1898
|
+
*/;
|
|
2123
1899
|
_proto.del = function del(text) {
|
|
2124
1900
|
return "<del>" + text + "</del>";
|
|
2125
1901
|
}
|
|
1902
|
+
|
|
2126
1903
|
/**
|
|
2127
1904
|
* @param {string} href
|
|
2128
1905
|
* @param {string} title
|
|
2129
1906
|
* @param {string} text
|
|
2130
|
-
|
|
2131
|
-
;
|
|
2132
|
-
|
|
1907
|
+
*/;
|
|
2133
1908
|
_proto.link = function link(href, title, text) {
|
|
2134
1909
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
2135
|
-
|
|
2136
1910
|
if (href === null) {
|
|
2137
1911
|
return text;
|
|
2138
1912
|
}
|
|
2139
|
-
|
|
2140
1913
|
var out = '<a href="' + escape(href) + '"';
|
|
2141
|
-
|
|
2142
1914
|
if (title) {
|
|
2143
1915
|
out += ' title="' + title + '"';
|
|
2144
1916
|
}
|
|
2145
|
-
|
|
2146
1917
|
out += '>' + text + '</a>';
|
|
2147
1918
|
return out;
|
|
2148
1919
|
}
|
|
1920
|
+
|
|
2149
1921
|
/**
|
|
2150
1922
|
* @param {string} href
|
|
2151
1923
|
* @param {string} title
|
|
2152
1924
|
* @param {string} text
|
|
2153
|
-
|
|
2154
|
-
;
|
|
2155
|
-
|
|
1925
|
+
*/;
|
|
2156
1926
|
_proto.image = function image(href, title, text) {
|
|
2157
1927
|
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
|
|
2158
|
-
|
|
2159
1928
|
if (href === null) {
|
|
2160
1929
|
return text;
|
|
2161
1930
|
}
|
|
2162
|
-
|
|
2163
1931
|
var out = "<img src=\"" + href + "\" alt=\"" + text + "\"";
|
|
2164
|
-
|
|
2165
1932
|
if (title) {
|
|
2166
1933
|
out += " title=\"" + title + "\"";
|
|
2167
1934
|
}
|
|
2168
|
-
|
|
2169
1935
|
out += this.options.xhtml ? '/>' : '>';
|
|
2170
1936
|
return out;
|
|
2171
1937
|
};
|
|
2172
|
-
|
|
2173
1938
|
_proto.text = function text(_text) {
|
|
2174
1939
|
return _text;
|
|
2175
1940
|
};
|
|
2176
|
-
|
|
2177
1941
|
return Renderer;
|
|
2178
1942
|
}();
|
|
2179
1943
|
|
|
@@ -2183,46 +1947,35 @@
|
|
|
2183
1947
|
*/
|
|
2184
1948
|
var TextRenderer = /*#__PURE__*/function () {
|
|
2185
1949
|
function TextRenderer() {}
|
|
2186
|
-
|
|
2187
1950
|
var _proto = TextRenderer.prototype;
|
|
2188
|
-
|
|
2189
1951
|
// no need for block level renderers
|
|
2190
1952
|
_proto.strong = function strong(text) {
|
|
2191
1953
|
return text;
|
|
2192
1954
|
};
|
|
2193
|
-
|
|
2194
1955
|
_proto.em = function em(text) {
|
|
2195
1956
|
return text;
|
|
2196
1957
|
};
|
|
2197
|
-
|
|
2198
1958
|
_proto.codespan = function codespan(text) {
|
|
2199
1959
|
return text;
|
|
2200
1960
|
};
|
|
2201
|
-
|
|
2202
1961
|
_proto.del = function del(text) {
|
|
2203
1962
|
return text;
|
|
2204
1963
|
};
|
|
2205
|
-
|
|
2206
1964
|
_proto.html = function html(text) {
|
|
2207
1965
|
return text;
|
|
2208
1966
|
};
|
|
2209
|
-
|
|
2210
1967
|
_proto.text = function text(_text) {
|
|
2211
1968
|
return _text;
|
|
2212
1969
|
};
|
|
2213
|
-
|
|
2214
1970
|
_proto.link = function link(href, title, text) {
|
|
2215
1971
|
return '' + text;
|
|
2216
1972
|
};
|
|
2217
|
-
|
|
2218
1973
|
_proto.image = function image(href, title, text) {
|
|
2219
1974
|
return '' + text;
|
|
2220
1975
|
};
|
|
2221
|
-
|
|
2222
1976
|
_proto.br = function br() {
|
|
2223
1977
|
return '';
|
|
2224
1978
|
};
|
|
2225
|
-
|
|
2226
1979
|
return TextRenderer;
|
|
2227
1980
|
}();
|
|
2228
1981
|
|
|
@@ -2233,69 +1986,60 @@
|
|
|
2233
1986
|
function Slugger() {
|
|
2234
1987
|
this.seen = {};
|
|
2235
1988
|
}
|
|
1989
|
+
|
|
2236
1990
|
/**
|
|
2237
1991
|
* @param {string} value
|
|
2238
1992
|
*/
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
1993
|
var _proto = Slugger.prototype;
|
|
2242
|
-
|
|
2243
1994
|
_proto.serialize = function serialize(value) {
|
|
2244
|
-
return value.toLowerCase().trim()
|
|
2245
|
-
|
|
1995
|
+
return value.toLowerCase().trim()
|
|
1996
|
+
// remove html tags
|
|
1997
|
+
.replace(/<[!\/a-z].*?>/ig, '')
|
|
1998
|
+
// remove unwanted chars
|
|
2246
1999
|
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
|
|
2247
2000
|
}
|
|
2001
|
+
|
|
2248
2002
|
/**
|
|
2249
2003
|
* Finds the next safe (unique) slug to use
|
|
2250
2004
|
* @param {string} originalSlug
|
|
2251
2005
|
* @param {boolean} isDryRun
|
|
2252
|
-
|
|
2253
|
-
;
|
|
2254
|
-
|
|
2006
|
+
*/;
|
|
2255
2007
|
_proto.getNextSafeSlug = function getNextSafeSlug(originalSlug, isDryRun) {
|
|
2256
2008
|
var slug = originalSlug;
|
|
2257
2009
|
var occurenceAccumulator = 0;
|
|
2258
|
-
|
|
2259
2010
|
if (this.seen.hasOwnProperty(slug)) {
|
|
2260
2011
|
occurenceAccumulator = this.seen[originalSlug];
|
|
2261
|
-
|
|
2262
2012
|
do {
|
|
2263
2013
|
occurenceAccumulator++;
|
|
2264
2014
|
slug = originalSlug + '-' + occurenceAccumulator;
|
|
2265
2015
|
} while (this.seen.hasOwnProperty(slug));
|
|
2266
2016
|
}
|
|
2267
|
-
|
|
2268
2017
|
if (!isDryRun) {
|
|
2269
2018
|
this.seen[originalSlug] = occurenceAccumulator;
|
|
2270
2019
|
this.seen[slug] = 0;
|
|
2271
2020
|
}
|
|
2272
|
-
|
|
2273
2021
|
return slug;
|
|
2274
2022
|
}
|
|
2023
|
+
|
|
2275
2024
|
/**
|
|
2276
2025
|
* Convert string to unique id
|
|
2277
2026
|
* @param {object} [options]
|
|
2278
2027
|
* @param {boolean} [options.dryrun] Generates the next unique slug without
|
|
2279
2028
|
* updating the internal accumulator.
|
|
2280
|
-
|
|
2281
|
-
;
|
|
2282
|
-
|
|
2029
|
+
*/;
|
|
2283
2030
|
_proto.slug = function slug(value, options) {
|
|
2284
2031
|
if (options === void 0) {
|
|
2285
2032
|
options = {};
|
|
2286
2033
|
}
|
|
2287
|
-
|
|
2288
2034
|
var slug = this.serialize(value);
|
|
2289
2035
|
return this.getNextSafeSlug(slug, options.dryrun);
|
|
2290
2036
|
};
|
|
2291
|
-
|
|
2292
2037
|
return Slugger;
|
|
2293
2038
|
}();
|
|
2294
2039
|
|
|
2295
2040
|
/**
|
|
2296
2041
|
* Parsing & Compiling
|
|
2297
2042
|
*/
|
|
2298
|
-
|
|
2299
2043
|
var Parser = /*#__PURE__*/function () {
|
|
2300
2044
|
function Parser(options) {
|
|
2301
2045
|
this.options = options || exports.defaults;
|
|
@@ -2305,140 +2049,122 @@
|
|
|
2305
2049
|
this.textRenderer = new TextRenderer();
|
|
2306
2050
|
this.slugger = new Slugger();
|
|
2307
2051
|
}
|
|
2052
|
+
|
|
2308
2053
|
/**
|
|
2309
2054
|
* Static Parse Method
|
|
2310
2055
|
*/
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
2056
|
Parser.parse = function parse(tokens, options) {
|
|
2314
2057
|
var parser = new Parser(options);
|
|
2315
2058
|
return parser.parse(tokens);
|
|
2316
2059
|
}
|
|
2060
|
+
|
|
2317
2061
|
/**
|
|
2318
2062
|
* Static Parse Inline Method
|
|
2319
|
-
|
|
2320
|
-
;
|
|
2321
|
-
|
|
2063
|
+
*/;
|
|
2322
2064
|
Parser.parseInline = function parseInline(tokens, options) {
|
|
2323
2065
|
var parser = new Parser(options);
|
|
2324
2066
|
return parser.parseInline(tokens);
|
|
2325
2067
|
}
|
|
2068
|
+
|
|
2326
2069
|
/**
|
|
2327
2070
|
* Parse Loop
|
|
2328
|
-
|
|
2329
|
-
;
|
|
2330
|
-
|
|
2071
|
+
*/;
|
|
2331
2072
|
var _proto = Parser.prototype;
|
|
2332
|
-
|
|
2333
2073
|
_proto.parse = function parse(tokens, top) {
|
|
2334
2074
|
if (top === void 0) {
|
|
2335
2075
|
top = true;
|
|
2336
2076
|
}
|
|
2337
|
-
|
|
2338
2077
|
var out = '',
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2078
|
+
i,
|
|
2079
|
+
j,
|
|
2080
|
+
k,
|
|
2081
|
+
l2,
|
|
2082
|
+
l3,
|
|
2083
|
+
row,
|
|
2084
|
+
cell,
|
|
2085
|
+
header,
|
|
2086
|
+
body,
|
|
2087
|
+
token,
|
|
2088
|
+
ordered,
|
|
2089
|
+
start,
|
|
2090
|
+
loose,
|
|
2091
|
+
itemBody,
|
|
2092
|
+
item,
|
|
2093
|
+
checked,
|
|
2094
|
+
task,
|
|
2095
|
+
checkbox,
|
|
2096
|
+
ret;
|
|
2358
2097
|
var l = tokens.length;
|
|
2359
|
-
|
|
2360
2098
|
for (i = 0; i < l; i++) {
|
|
2361
|
-
token = tokens[i];
|
|
2099
|
+
token = tokens[i];
|
|
2362
2100
|
|
|
2101
|
+
// Run any renderer extensions
|
|
2363
2102
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2364
2103
|
ret = this.options.extensions.renderers[token.type].call({
|
|
2365
2104
|
parser: this
|
|
2366
2105
|
}, token);
|
|
2367
|
-
|
|
2368
2106
|
if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(token.type)) {
|
|
2369
2107
|
out += ret || '';
|
|
2370
2108
|
continue;
|
|
2371
2109
|
}
|
|
2372
2110
|
}
|
|
2373
|
-
|
|
2374
2111
|
switch (token.type) {
|
|
2375
2112
|
case 'space':
|
|
2376
2113
|
{
|
|
2377
2114
|
continue;
|
|
2378
2115
|
}
|
|
2379
|
-
|
|
2380
2116
|
case 'hr':
|
|
2381
2117
|
{
|
|
2382
2118
|
out += this.renderer.hr();
|
|
2383
2119
|
continue;
|
|
2384
2120
|
}
|
|
2385
|
-
|
|
2386
2121
|
case 'heading':
|
|
2387
2122
|
{
|
|
2388
2123
|
out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
|
|
2389
2124
|
continue;
|
|
2390
2125
|
}
|
|
2391
|
-
|
|
2392
2126
|
case 'code':
|
|
2393
2127
|
{
|
|
2394
2128
|
out += this.renderer.code(token.text, token.lang, token.escaped);
|
|
2395
2129
|
continue;
|
|
2396
2130
|
}
|
|
2397
|
-
|
|
2398
2131
|
case 'table':
|
|
2399
2132
|
{
|
|
2400
|
-
header = '';
|
|
2133
|
+
header = '';
|
|
2401
2134
|
|
|
2135
|
+
// header
|
|
2402
2136
|
cell = '';
|
|
2403
2137
|
l2 = token.header.length;
|
|
2404
|
-
|
|
2405
2138
|
for (j = 0; j < l2; j++) {
|
|
2406
2139
|
cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), {
|
|
2407
2140
|
header: true,
|
|
2408
2141
|
align: token.align[j]
|
|
2409
2142
|
});
|
|
2410
2143
|
}
|
|
2411
|
-
|
|
2412
2144
|
header += this.renderer.tablerow(cell);
|
|
2413
2145
|
body = '';
|
|
2414
2146
|
l2 = token.rows.length;
|
|
2415
|
-
|
|
2416
2147
|
for (j = 0; j < l2; j++) {
|
|
2417
2148
|
row = token.rows[j];
|
|
2418
2149
|
cell = '';
|
|
2419
2150
|
l3 = row.length;
|
|
2420
|
-
|
|
2421
2151
|
for (k = 0; k < l3; k++) {
|
|
2422
2152
|
cell += this.renderer.tablecell(this.parseInline(row[k].tokens), {
|
|
2423
2153
|
header: false,
|
|
2424
2154
|
align: token.align[k]
|
|
2425
2155
|
});
|
|
2426
2156
|
}
|
|
2427
|
-
|
|
2428
2157
|
body += this.renderer.tablerow(cell);
|
|
2429
2158
|
}
|
|
2430
|
-
|
|
2431
2159
|
out += this.renderer.table(header, body);
|
|
2432
2160
|
continue;
|
|
2433
2161
|
}
|
|
2434
|
-
|
|
2435
2162
|
case 'blockquote':
|
|
2436
2163
|
{
|
|
2437
2164
|
body = this.parse(token.tokens);
|
|
2438
2165
|
out += this.renderer.blockquote(body);
|
|
2439
2166
|
continue;
|
|
2440
2167
|
}
|
|
2441
|
-
|
|
2442
2168
|
case 'list':
|
|
2443
2169
|
{
|
|
2444
2170
|
ordered = token.ordered;
|
|
@@ -2446,20 +2172,16 @@
|
|
|
2446
2172
|
loose = token.loose;
|
|
2447
2173
|
l2 = token.items.length;
|
|
2448
2174
|
body = '';
|
|
2449
|
-
|
|
2450
2175
|
for (j = 0; j < l2; j++) {
|
|
2451
2176
|
item = token.items[j];
|
|
2452
2177
|
checked = item.checked;
|
|
2453
2178
|
task = item.task;
|
|
2454
2179
|
itemBody = '';
|
|
2455
|
-
|
|
2456
2180
|
if (item.task) {
|
|
2457
2181
|
checkbox = this.renderer.checkbox(checked);
|
|
2458
|
-
|
|
2459
2182
|
if (loose) {
|
|
2460
2183
|
if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
|
|
2461
2184
|
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
2462
|
-
|
|
2463
2185
|
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
|
|
2464
2186
|
item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
|
|
2465
2187
|
}
|
|
@@ -2473,45 +2195,36 @@
|
|
|
2473
2195
|
itemBody += checkbox;
|
|
2474
2196
|
}
|
|
2475
2197
|
}
|
|
2476
|
-
|
|
2477
2198
|
itemBody += this.parse(item.tokens, loose);
|
|
2478
2199
|
body += this.renderer.listitem(itemBody, task, checked);
|
|
2479
2200
|
}
|
|
2480
|
-
|
|
2481
2201
|
out += this.renderer.list(body, ordered, start);
|
|
2482
2202
|
continue;
|
|
2483
2203
|
}
|
|
2484
|
-
|
|
2485
2204
|
case 'html':
|
|
2486
2205
|
{
|
|
2487
2206
|
// TODO parse inline content if parameter markdown=1
|
|
2488
2207
|
out += this.renderer.html(token.text);
|
|
2489
2208
|
continue;
|
|
2490
2209
|
}
|
|
2491
|
-
|
|
2492
2210
|
case 'paragraph':
|
|
2493
2211
|
{
|
|
2494
2212
|
out += this.renderer.paragraph(this.parseInline(token.tokens));
|
|
2495
2213
|
continue;
|
|
2496
2214
|
}
|
|
2497
|
-
|
|
2498
2215
|
case 'text':
|
|
2499
2216
|
{
|
|
2500
2217
|
body = token.tokens ? this.parseInline(token.tokens) : token.text;
|
|
2501
|
-
|
|
2502
2218
|
while (i + 1 < l && tokens[i + 1].type === 'text') {
|
|
2503
2219
|
token = tokens[++i];
|
|
2504
2220
|
body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
|
|
2505
2221
|
}
|
|
2506
|
-
|
|
2507
2222
|
out += top ? this.renderer.paragraph(body) : body;
|
|
2508
2223
|
continue;
|
|
2509
2224
|
}
|
|
2510
|
-
|
|
2511
2225
|
default:
|
|
2512
2226
|
{
|
|
2513
2227
|
var errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2514
|
-
|
|
2515
2228
|
if (this.options.silent) {
|
|
2516
2229
|
console.error(errMsg);
|
|
2517
2230
|
return;
|
|
@@ -2521,101 +2234,86 @@
|
|
|
2521
2234
|
}
|
|
2522
2235
|
}
|
|
2523
2236
|
}
|
|
2524
|
-
|
|
2525
2237
|
return out;
|
|
2526
2238
|
}
|
|
2239
|
+
|
|
2527
2240
|
/**
|
|
2528
2241
|
* Parse Inline Tokens
|
|
2529
|
-
|
|
2530
|
-
;
|
|
2531
|
-
|
|
2242
|
+
*/;
|
|
2532
2243
|
_proto.parseInline = function parseInline(tokens, renderer) {
|
|
2533
2244
|
renderer = renderer || this.renderer;
|
|
2534
2245
|
var out = '',
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2246
|
+
i,
|
|
2247
|
+
token,
|
|
2248
|
+
ret;
|
|
2538
2249
|
var l = tokens.length;
|
|
2539
|
-
|
|
2540
2250
|
for (i = 0; i < l; i++) {
|
|
2541
|
-
token = tokens[i];
|
|
2251
|
+
token = tokens[i];
|
|
2542
2252
|
|
|
2253
|
+
// Run any renderer extensions
|
|
2543
2254
|
if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
|
|
2544
2255
|
ret = this.options.extensions.renderers[token.type].call({
|
|
2545
2256
|
parser: this
|
|
2546
2257
|
}, token);
|
|
2547
|
-
|
|
2548
2258
|
if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
|
|
2549
2259
|
out += ret || '';
|
|
2550
2260
|
continue;
|
|
2551
2261
|
}
|
|
2552
2262
|
}
|
|
2553
|
-
|
|
2554
2263
|
switch (token.type) {
|
|
2555
2264
|
case 'escape':
|
|
2556
2265
|
{
|
|
2557
2266
|
out += renderer.text(token.text);
|
|
2558
2267
|
break;
|
|
2559
2268
|
}
|
|
2560
|
-
|
|
2561
2269
|
case 'html':
|
|
2562
2270
|
{
|
|
2563
2271
|
out += renderer.html(token.text);
|
|
2564
2272
|
break;
|
|
2565
2273
|
}
|
|
2566
|
-
|
|
2567
2274
|
case 'link':
|
|
2568
2275
|
{
|
|
2569
2276
|
out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
|
|
2570
2277
|
break;
|
|
2571
2278
|
}
|
|
2572
|
-
|
|
2573
2279
|
case 'image':
|
|
2574
2280
|
{
|
|
2575
2281
|
out += renderer.image(token.href, token.title, token.text);
|
|
2576
2282
|
break;
|
|
2577
2283
|
}
|
|
2578
|
-
|
|
2579
2284
|
case 'strong':
|
|
2580
2285
|
{
|
|
2581
2286
|
out += renderer.strong(this.parseInline(token.tokens, renderer));
|
|
2582
2287
|
break;
|
|
2583
2288
|
}
|
|
2584
|
-
|
|
2585
2289
|
case 'em':
|
|
2586
2290
|
{
|
|
2587
2291
|
out += renderer.em(this.parseInline(token.tokens, renderer));
|
|
2588
2292
|
break;
|
|
2589
2293
|
}
|
|
2590
|
-
|
|
2591
2294
|
case 'codespan':
|
|
2592
2295
|
{
|
|
2593
2296
|
out += renderer.codespan(token.text);
|
|
2594
2297
|
break;
|
|
2595
2298
|
}
|
|
2596
|
-
|
|
2597
2299
|
case 'br':
|
|
2598
2300
|
{
|
|
2599
2301
|
out += renderer.br();
|
|
2600
2302
|
break;
|
|
2601
2303
|
}
|
|
2602
|
-
|
|
2603
2304
|
case 'del':
|
|
2604
2305
|
{
|
|
2605
2306
|
out += renderer.del(this.parseInline(token.tokens, renderer));
|
|
2606
2307
|
break;
|
|
2607
2308
|
}
|
|
2608
|
-
|
|
2609
2309
|
case 'text':
|
|
2610
2310
|
{
|
|
2611
2311
|
out += renderer.text(token.text);
|
|
2612
2312
|
break;
|
|
2613
2313
|
}
|
|
2614
|
-
|
|
2615
2314
|
default:
|
|
2616
2315
|
{
|
|
2617
2316
|
var errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2618
|
-
|
|
2619
2317
|
if (this.options.silent) {
|
|
2620
2318
|
console.error(errMsg);
|
|
2621
2319
|
return;
|
|
@@ -2625,68 +2323,54 @@
|
|
|
2625
2323
|
}
|
|
2626
2324
|
}
|
|
2627
2325
|
}
|
|
2628
|
-
|
|
2629
2326
|
return out;
|
|
2630
2327
|
};
|
|
2631
|
-
|
|
2632
2328
|
return Parser;
|
|
2633
2329
|
}();
|
|
2634
2330
|
|
|
2635
2331
|
/**
|
|
2636
2332
|
* Marked
|
|
2637
2333
|
*/
|
|
2638
|
-
|
|
2639
2334
|
function marked(src, opt, callback) {
|
|
2640
2335
|
// throw error in case of non string input
|
|
2641
2336
|
if (typeof src === 'undefined' || src === null) {
|
|
2642
2337
|
throw new Error('marked(): input parameter is undefined or null');
|
|
2643
2338
|
}
|
|
2644
|
-
|
|
2645
2339
|
if (typeof src !== 'string') {
|
|
2646
2340
|
throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
|
2647
2341
|
}
|
|
2648
|
-
|
|
2649
2342
|
if (typeof opt === 'function') {
|
|
2650
2343
|
callback = opt;
|
|
2651
2344
|
opt = null;
|
|
2652
2345
|
}
|
|
2653
|
-
|
|
2654
2346
|
opt = merge({}, marked.defaults, opt || {});
|
|
2655
2347
|
checkSanitizeDeprecation(opt);
|
|
2656
|
-
|
|
2657
2348
|
if (callback) {
|
|
2658
2349
|
var highlight = opt.highlight;
|
|
2659
2350
|
var tokens;
|
|
2660
|
-
|
|
2661
2351
|
try {
|
|
2662
2352
|
tokens = Lexer.lex(src, opt);
|
|
2663
2353
|
} catch (e) {
|
|
2664
2354
|
return callback(e);
|
|
2665
2355
|
}
|
|
2666
|
-
|
|
2667
2356
|
var done = function done(err) {
|
|
2668
2357
|
var out;
|
|
2669
|
-
|
|
2670
2358
|
if (!err) {
|
|
2671
2359
|
try {
|
|
2672
2360
|
if (opt.walkTokens) {
|
|
2673
2361
|
marked.walkTokens(tokens, opt.walkTokens);
|
|
2674
2362
|
}
|
|
2675
|
-
|
|
2676
2363
|
out = Parser.parse(tokens, opt);
|
|
2677
2364
|
} catch (e) {
|
|
2678
2365
|
err = e;
|
|
2679
2366
|
}
|
|
2680
2367
|
}
|
|
2681
|
-
|
|
2682
2368
|
opt.highlight = highlight;
|
|
2683
2369
|
return err ? callback(err) : callback(null, out);
|
|
2684
2370
|
};
|
|
2685
|
-
|
|
2686
2371
|
if (!highlight || highlight.length < 3) {
|
|
2687
2372
|
return done();
|
|
2688
2373
|
}
|
|
2689
|
-
|
|
2690
2374
|
delete opt.highlight;
|
|
2691
2375
|
if (!tokens.length) return done();
|
|
2692
2376
|
var pending = 0;
|
|
@@ -2698,14 +2382,11 @@
|
|
|
2698
2382
|
if (err) {
|
|
2699
2383
|
return done(err);
|
|
2700
2384
|
}
|
|
2701
|
-
|
|
2702
2385
|
if (code != null && code !== token.text) {
|
|
2703
2386
|
token.text = code;
|
|
2704
2387
|
token.escaped = true;
|
|
2705
2388
|
}
|
|
2706
|
-
|
|
2707
2389
|
pending--;
|
|
2708
|
-
|
|
2709
2390
|
if (pending === 0) {
|
|
2710
2391
|
done();
|
|
2711
2392
|
}
|
|
@@ -2713,42 +2394,34 @@
|
|
|
2713
2394
|
}, 0);
|
|
2714
2395
|
}
|
|
2715
2396
|
});
|
|
2716
|
-
|
|
2717
2397
|
if (pending === 0) {
|
|
2718
2398
|
done();
|
|
2719
2399
|
}
|
|
2720
|
-
|
|
2721
2400
|
return;
|
|
2722
2401
|
}
|
|
2723
|
-
|
|
2724
2402
|
function onError(e) {
|
|
2725
2403
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
2726
|
-
|
|
2727
2404
|
if (opt.silent) {
|
|
2728
2405
|
return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
|
|
2729
2406
|
}
|
|
2730
|
-
|
|
2731
2407
|
throw e;
|
|
2732
2408
|
}
|
|
2733
|
-
|
|
2734
2409
|
try {
|
|
2735
2410
|
var _tokens = Lexer.lex(src, opt);
|
|
2736
|
-
|
|
2737
2411
|
if (opt.walkTokens) {
|
|
2738
2412
|
if (opt.async) {
|
|
2739
2413
|
return Promise.all(marked.walkTokens(_tokens, opt.walkTokens)).then(function () {
|
|
2740
2414
|
return Parser.parse(_tokens, opt);
|
|
2741
2415
|
})["catch"](onError);
|
|
2742
2416
|
}
|
|
2743
|
-
|
|
2744
2417
|
marked.walkTokens(_tokens, opt.walkTokens);
|
|
2745
2418
|
}
|
|
2746
|
-
|
|
2747
2419
|
return Parser.parse(_tokens, opt);
|
|
2748
2420
|
} catch (e) {
|
|
2749
2421
|
onError(e);
|
|
2750
2422
|
}
|
|
2751
2423
|
}
|
|
2424
|
+
|
|
2752
2425
|
/**
|
|
2753
2426
|
* Options
|
|
2754
2427
|
*/
|
|
@@ -2758,9 +2431,9 @@
|
|
|
2758
2431
|
changeDefaults(marked.defaults);
|
|
2759
2432
|
return marked;
|
|
2760
2433
|
};
|
|
2761
|
-
|
|
2762
2434
|
marked.getDefaults = getDefaults;
|
|
2763
2435
|
marked.defaults = exports.defaults;
|
|
2436
|
+
|
|
2764
2437
|
/**
|
|
2765
2438
|
* Use Extension
|
|
2766
2439
|
*/
|
|
@@ -2769,7 +2442,6 @@
|
|
|
2769
2442
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2770
2443
|
args[_key] = arguments[_key];
|
|
2771
2444
|
}
|
|
2772
|
-
|
|
2773
2445
|
var opts = merge.apply(void 0, [{}].concat(args));
|
|
2774
2446
|
var extensions = marked.defaults.extensions || {
|
|
2775
2447
|
renderers: {},
|
|
@@ -2784,43 +2456,35 @@
|
|
|
2784
2456
|
if (!ext.name) {
|
|
2785
2457
|
throw new Error('extension name required');
|
|
2786
2458
|
}
|
|
2787
|
-
|
|
2788
2459
|
if (ext.renderer) {
|
|
2789
2460
|
// Renderer extensions
|
|
2790
2461
|
var prevRenderer = extensions.renderers ? extensions.renderers[ext.name] : null;
|
|
2791
|
-
|
|
2792
2462
|
if (prevRenderer) {
|
|
2793
2463
|
// Replace extension with func to run new extension but fall back if false
|
|
2794
2464
|
extensions.renderers[ext.name] = function () {
|
|
2795
2465
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2796
2466
|
args[_key2] = arguments[_key2];
|
|
2797
2467
|
}
|
|
2798
|
-
|
|
2799
2468
|
var ret = ext.renderer.apply(this, args);
|
|
2800
|
-
|
|
2801
2469
|
if (ret === false) {
|
|
2802
2470
|
ret = prevRenderer.apply(this, args);
|
|
2803
2471
|
}
|
|
2804
|
-
|
|
2805
2472
|
return ret;
|
|
2806
2473
|
};
|
|
2807
2474
|
} else {
|
|
2808
2475
|
extensions.renderers[ext.name] = ext.renderer;
|
|
2809
2476
|
}
|
|
2810
2477
|
}
|
|
2811
|
-
|
|
2812
2478
|
if (ext.tokenizer) {
|
|
2813
2479
|
// Tokenizer Extensions
|
|
2814
2480
|
if (!ext.level || ext.level !== 'block' && ext.level !== 'inline') {
|
|
2815
2481
|
throw new Error("extension level must be 'block' or 'inline'");
|
|
2816
2482
|
}
|
|
2817
|
-
|
|
2818
2483
|
if (extensions[ext.level]) {
|
|
2819
2484
|
extensions[ext.level].unshift(ext.tokenizer);
|
|
2820
2485
|
} else {
|
|
2821
2486
|
extensions[ext.level] = [ext.tokenizer];
|
|
2822
2487
|
}
|
|
2823
|
-
|
|
2824
2488
|
if (ext.start) {
|
|
2825
2489
|
// Function to check for start of token
|
|
2826
2490
|
if (ext.level === 'block') {
|
|
@@ -2838,110 +2502,89 @@
|
|
|
2838
2502
|
}
|
|
2839
2503
|
}
|
|
2840
2504
|
}
|
|
2841
|
-
|
|
2842
2505
|
if (ext.childTokens) {
|
|
2843
2506
|
// Child tokens to be visited by walkTokens
|
|
2844
2507
|
extensions.childTokens[ext.name] = ext.childTokens;
|
|
2845
2508
|
}
|
|
2846
2509
|
});
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2510
|
+
}
|
|
2849
2511
|
|
|
2512
|
+
// ==-- Parse "overwrite" extensions --== //
|
|
2850
2513
|
if (pack.renderer) {
|
|
2851
2514
|
(function () {
|
|
2852
2515
|
var renderer = marked.defaults.renderer || new Renderer();
|
|
2853
|
-
|
|
2854
2516
|
var _loop = function _loop(prop) {
|
|
2855
|
-
var prevRenderer = renderer[prop];
|
|
2856
|
-
|
|
2517
|
+
var prevRenderer = renderer[prop];
|
|
2518
|
+
// Replace renderer with func to run extension, but fall back if false
|
|
2857
2519
|
renderer[prop] = function () {
|
|
2858
2520
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
2859
2521
|
args[_key3] = arguments[_key3];
|
|
2860
2522
|
}
|
|
2861
|
-
|
|
2862
2523
|
var ret = pack.renderer[prop].apply(renderer, args);
|
|
2863
|
-
|
|
2864
2524
|
if (ret === false) {
|
|
2865
2525
|
ret = prevRenderer.apply(renderer, args);
|
|
2866
2526
|
}
|
|
2867
|
-
|
|
2868
2527
|
return ret;
|
|
2869
2528
|
};
|
|
2870
2529
|
};
|
|
2871
|
-
|
|
2872
2530
|
for (var prop in pack.renderer) {
|
|
2873
2531
|
_loop(prop);
|
|
2874
2532
|
}
|
|
2875
|
-
|
|
2876
2533
|
opts.renderer = renderer;
|
|
2877
2534
|
})();
|
|
2878
2535
|
}
|
|
2879
|
-
|
|
2880
2536
|
if (pack.tokenizer) {
|
|
2881
2537
|
(function () {
|
|
2882
2538
|
var tokenizer = marked.defaults.tokenizer || new Tokenizer();
|
|
2883
|
-
|
|
2884
2539
|
var _loop2 = function _loop2(prop) {
|
|
2885
|
-
var prevTokenizer = tokenizer[prop];
|
|
2886
|
-
|
|
2540
|
+
var prevTokenizer = tokenizer[prop];
|
|
2541
|
+
// Replace tokenizer with func to run extension, but fall back if false
|
|
2887
2542
|
tokenizer[prop] = function () {
|
|
2888
2543
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
2889
2544
|
args[_key4] = arguments[_key4];
|
|
2890
2545
|
}
|
|
2891
|
-
|
|
2892
2546
|
var ret = pack.tokenizer[prop].apply(tokenizer, args);
|
|
2893
|
-
|
|
2894
2547
|
if (ret === false) {
|
|
2895
2548
|
ret = prevTokenizer.apply(tokenizer, args);
|
|
2896
2549
|
}
|
|
2897
|
-
|
|
2898
2550
|
return ret;
|
|
2899
2551
|
};
|
|
2900
2552
|
};
|
|
2901
|
-
|
|
2902
2553
|
for (var prop in pack.tokenizer) {
|
|
2903
2554
|
_loop2(prop);
|
|
2904
2555
|
}
|
|
2905
|
-
|
|
2906
2556
|
opts.tokenizer = tokenizer;
|
|
2907
2557
|
})();
|
|
2908
|
-
}
|
|
2909
|
-
|
|
2558
|
+
}
|
|
2910
2559
|
|
|
2560
|
+
// ==-- Parse WalkTokens extensions --== //
|
|
2911
2561
|
if (pack.walkTokens) {
|
|
2912
2562
|
var _walkTokens = marked.defaults.walkTokens;
|
|
2913
|
-
|
|
2914
2563
|
opts.walkTokens = function (token) {
|
|
2915
2564
|
var values = [];
|
|
2916
2565
|
values.push(pack.walkTokens.call(this, token));
|
|
2917
|
-
|
|
2918
2566
|
if (_walkTokens) {
|
|
2919
2567
|
values = values.concat(_walkTokens.call(this, token));
|
|
2920
2568
|
}
|
|
2921
|
-
|
|
2922
2569
|
return values;
|
|
2923
2570
|
};
|
|
2924
2571
|
}
|
|
2925
|
-
|
|
2926
2572
|
if (hasExtensions) {
|
|
2927
2573
|
opts.extensions = extensions;
|
|
2928
2574
|
}
|
|
2929
|
-
|
|
2930
2575
|
marked.setOptions(opts);
|
|
2931
2576
|
});
|
|
2932
2577
|
};
|
|
2578
|
+
|
|
2933
2579
|
/**
|
|
2934
2580
|
* Run callback for every token
|
|
2935
2581
|
*/
|
|
2936
2582
|
|
|
2937
|
-
|
|
2938
2583
|
marked.walkTokens = function (tokens, callback) {
|
|
2939
2584
|
var values = [];
|
|
2940
|
-
|
|
2941
2585
|
var _loop3 = function _loop3() {
|
|
2942
2586
|
var token = _step.value;
|
|
2943
2587
|
values = values.concat(callback.call(marked, token));
|
|
2944
|
-
|
|
2945
2588
|
switch (token.type) {
|
|
2946
2589
|
case 'table':
|
|
2947
2590
|
{
|
|
@@ -2949,25 +2592,20 @@
|
|
|
2949
2592
|
var cell = _step2.value;
|
|
2950
2593
|
values = values.concat(marked.walkTokens(cell.tokens, callback));
|
|
2951
2594
|
}
|
|
2952
|
-
|
|
2953
2595
|
for (var _iterator3 = _createForOfIteratorHelperLoose(token.rows), _step3; !(_step3 = _iterator3()).done;) {
|
|
2954
2596
|
var row = _step3.value;
|
|
2955
|
-
|
|
2956
2597
|
for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
|
|
2957
2598
|
var _cell = _step4.value;
|
|
2958
2599
|
values = values.concat(marked.walkTokens(_cell.tokens, callback));
|
|
2959
2600
|
}
|
|
2960
2601
|
}
|
|
2961
|
-
|
|
2962
2602
|
break;
|
|
2963
2603
|
}
|
|
2964
|
-
|
|
2965
2604
|
case 'list':
|
|
2966
2605
|
{
|
|
2967
2606
|
values = values.concat(marked.walkTokens(token.items, callback));
|
|
2968
2607
|
break;
|
|
2969
2608
|
}
|
|
2970
|
-
|
|
2971
2609
|
default:
|
|
2972
2610
|
{
|
|
2973
2611
|
if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) {
|
|
@@ -2981,55 +2619,44 @@
|
|
|
2981
2619
|
}
|
|
2982
2620
|
}
|
|
2983
2621
|
};
|
|
2984
|
-
|
|
2985
2622
|
for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
|
|
2986
2623
|
_loop3();
|
|
2987
2624
|
}
|
|
2988
|
-
|
|
2989
2625
|
return values;
|
|
2990
2626
|
};
|
|
2627
|
+
|
|
2991
2628
|
/**
|
|
2992
2629
|
* Parse Inline
|
|
2993
2630
|
* @param {string} src
|
|
2994
2631
|
*/
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
2632
|
marked.parseInline = function (src, opt) {
|
|
2998
2633
|
// throw error in case of non string input
|
|
2999
2634
|
if (typeof src === 'undefined' || src === null) {
|
|
3000
2635
|
throw new Error('marked.parseInline(): input parameter is undefined or null');
|
|
3001
2636
|
}
|
|
3002
|
-
|
|
3003
2637
|
if (typeof src !== 'string') {
|
|
3004
2638
|
throw new Error('marked.parseInline(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
|
3005
2639
|
}
|
|
3006
|
-
|
|
3007
2640
|
opt = merge({}, marked.defaults, opt || {});
|
|
3008
2641
|
checkSanitizeDeprecation(opt);
|
|
3009
|
-
|
|
3010
2642
|
try {
|
|
3011
2643
|
var tokens = Lexer.lexInline(src, opt);
|
|
3012
|
-
|
|
3013
2644
|
if (opt.walkTokens) {
|
|
3014
2645
|
marked.walkTokens(tokens, opt.walkTokens);
|
|
3015
2646
|
}
|
|
3016
|
-
|
|
3017
2647
|
return Parser.parseInline(tokens, opt);
|
|
3018
2648
|
} catch (e) {
|
|
3019
2649
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
3020
|
-
|
|
3021
2650
|
if (opt.silent) {
|
|
3022
2651
|
return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
|
|
3023
2652
|
}
|
|
3024
|
-
|
|
3025
2653
|
throw e;
|
|
3026
2654
|
}
|
|
3027
2655
|
};
|
|
2656
|
+
|
|
3028
2657
|
/**
|
|
3029
2658
|
* Expose
|
|
3030
2659
|
*/
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
2660
|
marked.Parser = Parser;
|
|
3034
2661
|
marked.parser = Parser.parse;
|
|
3035
2662
|
marked.Renderer = Renderer;
|