marked 0.8.1 → 1.1.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/README.md +1 -1
- package/lib/marked.esm.js +1475 -845
- package/lib/marked.js +1825 -1022
- package/marked.min.js +1 -1
- package/package.json +18 -16
- package/src/Lexer.js +334 -281
- package/src/Parser.js +206 -157
- package/src/Renderer.js +21 -21
- package/src/Slugger.js +4 -1
- package/src/TextRenderer.js +4 -0
- package/src/Tokenizer.js +659 -0
- package/src/defaults.js +2 -0
- package/src/marked.js +128 -44
- package/src/rules.js +81 -10
- package/src/InlineLexer.js +0 -293
package/lib/marked.js
CHANGED
|
@@ -31,6 +31,48 @@
|
|
|
31
31
|
return Constructor;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
35
|
+
if (!o) return;
|
|
36
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
37
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
38
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
39
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
40
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function _arrayLikeToArray(arr, len) {
|
|
44
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
45
|
+
|
|
46
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
47
|
+
|
|
48
|
+
return arr2;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
52
|
+
var it;
|
|
53
|
+
|
|
54
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
55
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
56
|
+
if (it) o = it;
|
|
57
|
+
var i = 0;
|
|
58
|
+
return function () {
|
|
59
|
+
if (i >= o.length) return {
|
|
60
|
+
done: true
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
done: false,
|
|
64
|
+
value: o[i++]
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
it = o[Symbol.iterator]();
|
|
73
|
+
return it.next.bind(it);
|
|
74
|
+
}
|
|
75
|
+
|
|
34
76
|
function createCommonjsModule(fn, module) {
|
|
35
77
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
36
78
|
}
|
|
@@ -53,6 +95,8 @@
|
|
|
53
95
|
silent: false,
|
|
54
96
|
smartLists: false,
|
|
55
97
|
smartypants: false,
|
|
98
|
+
tokenizer: null,
|
|
99
|
+
walkTokens: null,
|
|
56
100
|
xhtml: false
|
|
57
101
|
};
|
|
58
102
|
}
|
|
@@ -342,557 +386,1418 @@
|
|
|
342
386
|
checkSanitizeDeprecation: checkSanitizeDeprecation
|
|
343
387
|
};
|
|
344
388
|
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
var block = {
|
|
353
|
-
newline: /^\n+/,
|
|
354
|
-
code: /^( {4}[^\n]+\n*)+/,
|
|
355
|
-
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
|
|
356
|
-
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
|
357
|
-
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
|
|
358
|
-
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
|
359
|
-
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
|
360
|
-
html: '^ {0,3}(?:' // optional indentation
|
|
361
|
-
+ '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
|
|
362
|
-
+ '|comment[^\\n]*(\\n+|$)' // (2)
|
|
363
|
-
+ '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
|
|
364
|
-
+ '|<![A-Z][\\s\\S]*?>\\n*' // (4)
|
|
365
|
-
+ '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
|
|
366
|
-
+ '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
|
|
367
|
-
+ '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
|
|
368
|
-
+ '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
|
|
369
|
-
+ ')',
|
|
370
|
-
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
|
|
371
|
-
nptable: noopTest$1,
|
|
372
|
-
table: noopTest$1,
|
|
373
|
-
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
374
|
-
// regex template, placeholders will be replaced according to different paragraph
|
|
375
|
-
// interruption rules of commonmark and the original markdown spec:
|
|
376
|
-
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
|
|
377
|
-
text: /^[^\n]+/
|
|
378
|
-
};
|
|
379
|
-
block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
|
|
380
|
-
block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
|
|
381
|
-
block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
|
|
382
|
-
block.bullet = /(?:[*+-]|\d{1,9}\.)/;
|
|
383
|
-
block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
|
|
384
|
-
block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
|
|
385
|
-
block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
|
|
386
|
-
block._tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr' + '|track|ul';
|
|
387
|
-
block._comment = /<!--(?!-?>)[\s\S]*?-->/;
|
|
388
|
-
block.html = edit$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
389
|
-
block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
|
|
390
|
-
.replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
391
|
-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
|
|
392
|
-
.getRegex();
|
|
393
|
-
block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
|
|
394
|
-
/**
|
|
395
|
-
* Normal Block Grammar
|
|
396
|
-
*/
|
|
389
|
+
var defaults$1 = defaults.defaults;
|
|
390
|
+
var rtrim$1 = helpers.rtrim,
|
|
391
|
+
splitCells$1 = helpers.splitCells,
|
|
392
|
+
_escape = helpers.escape,
|
|
393
|
+
findClosingBracket$1 = helpers.findClosingBracket;
|
|
397
394
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
395
|
+
function outputLink(cap, link, raw) {
|
|
396
|
+
var href = link.href;
|
|
397
|
+
var title = link.title ? _escape(link.title) : null;
|
|
398
|
+
var text = cap[1].replace(/\\([\[\]])/g, '$1');
|
|
402
399
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
400
|
+
if (cap[0].charAt(0) !== '!') {
|
|
401
|
+
return {
|
|
402
|
+
type: 'link',
|
|
403
|
+
raw: raw,
|
|
404
|
+
href: href,
|
|
405
|
+
title: title,
|
|
406
|
+
text: text
|
|
407
|
+
};
|
|
408
|
+
} else {
|
|
409
|
+
return {
|
|
410
|
+
type: 'image',
|
|
411
|
+
raw: raw,
|
|
412
|
+
href: href,
|
|
413
|
+
title: title,
|
|
414
|
+
text: _escape(text)
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
411
418
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
415
|
-
.getRegex();
|
|
416
|
-
block.gfm.table = edit$1(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
|
|
417
|
-
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
418
|
-
.getRegex();
|
|
419
|
-
/**
|
|
420
|
-
* Pedantic grammar (original John Gruber's loose markdown specification)
|
|
421
|
-
*/
|
|
419
|
+
function indentCodeCompensation(raw, text) {
|
|
420
|
+
var matchIndentToCode = raw.match(/^(\s+)(?:```)/);
|
|
422
421
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
427
|
-
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
|
|
428
|
-
fences: noopTest$1,
|
|
429
|
-
// fences not supported
|
|
430
|
-
paragraph: edit$1(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()
|
|
431
|
-
});
|
|
432
|
-
/**
|
|
433
|
-
* Inline-Level Grammar
|
|
434
|
-
*/
|
|
422
|
+
if (matchIndentToCode === null) {
|
|
423
|
+
return text;
|
|
424
|
+
}
|
|
435
425
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
url: noopTest$1,
|
|
440
|
-
tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
|
|
441
|
-
+ '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
|
|
442
|
-
+ '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
|
|
443
|
-
+ '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
|
|
444
|
-
+ '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
|
|
445
|
-
// CDATA section
|
|
446
|
-
link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
|
|
447
|
-
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
|
|
448
|
-
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
|
|
449
|
-
strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
|
|
450
|
-
em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
|
|
451
|
-
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
452
|
-
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
453
|
-
del: noopTest$1,
|
|
454
|
-
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
|
|
455
|
-
}; // list of punctuation marks from common mark spec
|
|
456
|
-
// without ` and ] to workaround Rule 17 (inline code blocks/links)
|
|
426
|
+
var indentToCode = matchIndentToCode[1];
|
|
427
|
+
return text.split('\n').map(function (node) {
|
|
428
|
+
var matchIndentInNode = node.match(/^\s+/);
|
|
457
429
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
|
|
462
|
-
inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
|
|
463
|
-
inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
|
|
464
|
-
inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
|
|
465
|
-
inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex();
|
|
466
|
-
inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
|
|
467
|
-
inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
|
|
468
|
-
inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
|
|
469
|
-
inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
|
|
470
|
-
inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
|
|
471
|
-
/**
|
|
472
|
-
* Normal Inline Grammar
|
|
473
|
-
*/
|
|
430
|
+
if (matchIndentInNode === null) {
|
|
431
|
+
return node;
|
|
432
|
+
}
|
|
474
433
|
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Pedantic Inline Grammar
|
|
478
|
-
*/
|
|
434
|
+
var indentInNode = matchIndentInNode[0];
|
|
479
435
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
|
|
484
|
-
reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
|
|
485
|
-
});
|
|
486
|
-
/**
|
|
487
|
-
* GFM Inline Grammar
|
|
488
|
-
*/
|
|
436
|
+
if (indentInNode.length >= indentToCode.length) {
|
|
437
|
+
return node.slice(indentToCode.length);
|
|
438
|
+
}
|
|
489
439
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
|
|
494
|
-
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
|
|
495
|
-
del: /^~+(?=\S)([\s\S]*?\S)~+/,
|
|
496
|
-
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
|
|
497
|
-
});
|
|
498
|
-
inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
|
|
440
|
+
return node;
|
|
441
|
+
}).join('\n');
|
|
442
|
+
}
|
|
499
443
|
/**
|
|
500
|
-
*
|
|
444
|
+
* Tokenizer
|
|
501
445
|
*/
|
|
502
446
|
|
|
503
|
-
inline.breaks = merge$1({}, inline.gfm, {
|
|
504
|
-
br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
|
|
505
|
-
text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
|
|
506
|
-
});
|
|
507
|
-
var rules = {
|
|
508
|
-
block: block,
|
|
509
|
-
inline: inline
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
var defaults$1 = defaults.defaults;
|
|
513
|
-
var block$1 = rules.block;
|
|
514
|
-
var rtrim$1 = helpers.rtrim,
|
|
515
|
-
splitCells$1 = helpers.splitCells,
|
|
516
|
-
escape$1 = helpers.escape;
|
|
517
|
-
/**
|
|
518
|
-
* Block Lexer
|
|
519
|
-
*/
|
|
520
447
|
|
|
521
|
-
var
|
|
522
|
-
|
|
523
|
-
function () {
|
|
524
|
-
function Lexer(options) {
|
|
525
|
-
this.tokens = [];
|
|
526
|
-
this.tokens.links = Object.create(null);
|
|
448
|
+
var Tokenizer_1 = /*#__PURE__*/function () {
|
|
449
|
+
function Tokenizer(options) {
|
|
527
450
|
this.options = options || defaults$1;
|
|
528
|
-
this.rules = block$1.normal;
|
|
529
|
-
|
|
530
|
-
if (this.options.pedantic) {
|
|
531
|
-
this.rules = block$1.pedantic;
|
|
532
|
-
} else if (this.options.gfm) {
|
|
533
|
-
this.rules = block$1.gfm;
|
|
534
|
-
}
|
|
535
451
|
}
|
|
536
|
-
/**
|
|
537
|
-
* Expose Block Rules
|
|
538
|
-
*/
|
|
539
452
|
|
|
453
|
+
var _proto = Tokenizer.prototype;
|
|
540
454
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
*/
|
|
544
|
-
Lexer.lex = function lex(src, options) {
|
|
545
|
-
var lexer = new Lexer(options);
|
|
546
|
-
return lexer.lex(src);
|
|
547
|
-
};
|
|
455
|
+
_proto.space = function space(src) {
|
|
456
|
+
var cap = this.rules.block.newline.exec(src);
|
|
548
457
|
|
|
549
|
-
|
|
458
|
+
if (cap) {
|
|
459
|
+
if (cap[0].length > 1) {
|
|
460
|
+
return {
|
|
461
|
+
type: 'space',
|
|
462
|
+
raw: cap[0]
|
|
463
|
+
};
|
|
464
|
+
}
|
|
550
465
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
|
|
556
|
-
return this.token(src, true);
|
|
466
|
+
return {
|
|
467
|
+
raw: '\n'
|
|
468
|
+
};
|
|
469
|
+
}
|
|
557
470
|
};
|
|
558
471
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
*/
|
|
562
|
-
_proto.token = function token(src, top) {
|
|
563
|
-
src = src.replace(/^ +$/gm, '');
|
|
564
|
-
var next, loose, cap, bull, b, item, listStart, listItems, t, space, i, tag, l, isordered, istask, ischecked;
|
|
472
|
+
_proto.code = function code(src, tokens) {
|
|
473
|
+
var cap = this.rules.block.code.exec(src);
|
|
565
474
|
|
|
566
|
-
|
|
567
|
-
//
|
|
568
|
-
if (cap = this.rules.newline.exec(src)) {
|
|
569
|
-
src = src.substring(cap[0].length);
|
|
475
|
+
if (cap) {
|
|
476
|
+
var lastToken = tokens[tokens.length - 1]; // An indented code block cannot interrupt a paragraph.
|
|
570
477
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
}
|
|
478
|
+
if (lastToken && lastToken.type === 'paragraph') {
|
|
479
|
+
return {
|
|
480
|
+
raw: cap[0],
|
|
481
|
+
text: cap[0].trimRight()
|
|
482
|
+
};
|
|
483
|
+
}
|
|
577
484
|
|
|
485
|
+
var text = cap[0].replace(/^ {4}/gm, '');
|
|
486
|
+
return {
|
|
487
|
+
type: 'code',
|
|
488
|
+
raw: cap[0],
|
|
489
|
+
codeBlockStyle: 'indented',
|
|
490
|
+
text: !this.options.pedantic ? rtrim$1(text, '\n') : text
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
};
|
|
578
494
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
src = src.substring(cap[0].length); // An indented code block cannot interrupt a paragraph.
|
|
495
|
+
_proto.fences = function fences(src) {
|
|
496
|
+
var cap = this.rules.block.fences.exec(src);
|
|
582
497
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
498
|
+
if (cap) {
|
|
499
|
+
var raw = cap[0];
|
|
500
|
+
var text = indentCodeCompensation(raw, cap[3] || '');
|
|
501
|
+
return {
|
|
502
|
+
type: 'code',
|
|
503
|
+
raw: raw,
|
|
504
|
+
lang: cap[2] ? cap[2].trim() : cap[2],
|
|
505
|
+
text: text
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
};
|
|
593
509
|
|
|
594
|
-
|
|
595
|
-
|
|
510
|
+
_proto.heading = function heading(src) {
|
|
511
|
+
var cap = this.rules.block.heading.exec(src);
|
|
596
512
|
|
|
513
|
+
if (cap) {
|
|
514
|
+
return {
|
|
515
|
+
type: 'heading',
|
|
516
|
+
raw: cap[0],
|
|
517
|
+
depth: cap[1].length,
|
|
518
|
+
text: cap[2]
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
};
|
|
597
522
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
this.tokens.push({
|
|
601
|
-
type: 'code',
|
|
602
|
-
lang: cap[2] ? cap[2].trim() : cap[2],
|
|
603
|
-
text: cap[3] || ''
|
|
604
|
-
});
|
|
605
|
-
continue;
|
|
606
|
-
} // heading
|
|
523
|
+
_proto.nptable = function nptable(src) {
|
|
524
|
+
var cap = this.rules.block.nptable.exec(src);
|
|
607
525
|
|
|
526
|
+
if (cap) {
|
|
527
|
+
var item = {
|
|
528
|
+
type: 'table',
|
|
529
|
+
header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
|
|
530
|
+
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
|
531
|
+
cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : [],
|
|
532
|
+
raw: cap[0]
|
|
533
|
+
};
|
|
608
534
|
|
|
609
|
-
if (
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
535
|
+
if (item.header.length === item.align.length) {
|
|
536
|
+
var l = item.align.length;
|
|
537
|
+
var i;
|
|
538
|
+
|
|
539
|
+
for (i = 0; i < l; i++) {
|
|
540
|
+
if (/^ *-+: *$/.test(item.align[i])) {
|
|
541
|
+
item.align[i] = 'right';
|
|
542
|
+
} else if (/^ *:-+: *$/.test(item.align[i])) {
|
|
543
|
+
item.align[i] = 'center';
|
|
544
|
+
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
|
545
|
+
item.align[i] = 'left';
|
|
546
|
+
} else {
|
|
547
|
+
item.align[i] = null;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
618
550
|
|
|
551
|
+
l = item.cells.length;
|
|
619
552
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
|
|
624
|
-
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
|
625
|
-
cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
|
626
|
-
};
|
|
553
|
+
for (i = 0; i < l; i++) {
|
|
554
|
+
item.cells[i] = splitCells$1(item.cells[i], item.header.length);
|
|
555
|
+
}
|
|
627
556
|
|
|
628
|
-
|
|
629
|
-
|
|
557
|
+
return item;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
};
|
|
630
561
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
562
|
+
_proto.hr = function hr(src) {
|
|
563
|
+
var cap = this.rules.block.hr.exec(src);
|
|
564
|
+
|
|
565
|
+
if (cap) {
|
|
566
|
+
return {
|
|
567
|
+
type: 'hr',
|
|
568
|
+
raw: cap[0]
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
_proto.blockquote = function blockquote(src) {
|
|
574
|
+
var cap = this.rules.block.blockquote.exec(src);
|
|
575
|
+
|
|
576
|
+
if (cap) {
|
|
577
|
+
var text = cap[0].replace(/^ *> ?/gm, '');
|
|
578
|
+
return {
|
|
579
|
+
type: 'blockquote',
|
|
580
|
+
raw: cap[0],
|
|
581
|
+
text: text
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
_proto.list = function list(src) {
|
|
587
|
+
var cap = this.rules.block.list.exec(src);
|
|
588
|
+
|
|
589
|
+
if (cap) {
|
|
590
|
+
var raw = cap[0];
|
|
591
|
+
var bull = cap[2];
|
|
592
|
+
var isordered = bull.length > 1;
|
|
593
|
+
var isparen = bull[bull.length - 1] === ')';
|
|
594
|
+
var list = {
|
|
595
|
+
type: 'list',
|
|
596
|
+
raw: raw,
|
|
597
|
+
ordered: isordered,
|
|
598
|
+
start: isordered ? +bull.slice(0, -1) : '',
|
|
599
|
+
loose: false,
|
|
600
|
+
items: []
|
|
601
|
+
}; // Get each top-level item.
|
|
602
|
+
|
|
603
|
+
var itemMatch = cap[0].match(this.rules.block.item);
|
|
604
|
+
var next = false,
|
|
605
|
+
item,
|
|
606
|
+
space,
|
|
607
|
+
b,
|
|
608
|
+
addBack,
|
|
609
|
+
loose,
|
|
610
|
+
istask,
|
|
611
|
+
ischecked;
|
|
612
|
+
var l = itemMatch.length;
|
|
613
|
+
|
|
614
|
+
for (var i = 0; i < l; i++) {
|
|
615
|
+
item = itemMatch[i];
|
|
616
|
+
raw = item; // Remove the list item's bullet
|
|
617
|
+
// so it is seen as the next token.
|
|
618
|
+
|
|
619
|
+
space = item.length;
|
|
620
|
+
item = item.replace(/^ *([*+-]|\d+[.)]) */, ''); // Outdent whatever the
|
|
621
|
+
// list item contains. Hacky.
|
|
622
|
+
|
|
623
|
+
if (~item.indexOf('\n ')) {
|
|
624
|
+
space -= item.length;
|
|
625
|
+
item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
|
|
626
|
+
} // Determine whether the next list item belongs here.
|
|
627
|
+
// Backpedal if it does not belong in this list.
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
if (i !== l - 1) {
|
|
631
|
+
b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
|
|
632
|
+
|
|
633
|
+
if (isordered ? b.length === 1 || !isparen && b[b.length - 1] === ')' : b.length > 1 || this.options.smartLists && b !== bull) {
|
|
634
|
+
addBack = itemMatch.slice(i + 1).join('\n');
|
|
635
|
+
list.raw = list.raw.substring(0, list.raw.length - addBack.length);
|
|
636
|
+
i = l - 1;
|
|
637
|
+
}
|
|
638
|
+
} // Determine whether item is loose or not.
|
|
639
|
+
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
|
640
|
+
// for discount behavior.
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
loose = next || /\n\n(?!\s*$)/.test(item);
|
|
644
|
+
|
|
645
|
+
if (i !== l - 1) {
|
|
646
|
+
next = item.charAt(item.length - 1) === '\n';
|
|
647
|
+
if (!loose) loose = next;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
if (loose) {
|
|
651
|
+
list.loose = true;
|
|
652
|
+
} // Check for task list items
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
istask = /^\[[ xX]\] /.test(item);
|
|
656
|
+
ischecked = undefined;
|
|
657
|
+
|
|
658
|
+
if (istask) {
|
|
659
|
+
ischecked = item[1] !== ' ';
|
|
660
|
+
item = item.replace(/^\[[ xX]\] +/, '');
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
list.items.push({
|
|
664
|
+
type: 'list_item',
|
|
665
|
+
raw: raw,
|
|
666
|
+
task: istask,
|
|
667
|
+
checked: ischecked,
|
|
668
|
+
loose: loose,
|
|
669
|
+
text: item
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return list;
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
_proto.html = function html(src) {
|
|
678
|
+
var cap = this.rules.block.html.exec(src);
|
|
679
|
+
|
|
680
|
+
if (cap) {
|
|
681
|
+
return {
|
|
682
|
+
type: this.options.sanitize ? 'paragraph' : 'html',
|
|
683
|
+
raw: cap[0],
|
|
684
|
+
pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
|
685
|
+
text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
_proto.def = function def(src) {
|
|
691
|
+
var cap = this.rules.block.def.exec(src);
|
|
692
|
+
|
|
693
|
+
if (cap) {
|
|
694
|
+
if (cap[3]) cap[3] = cap[3].substring(1, cap[3].length - 1);
|
|
695
|
+
var tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
|
|
696
|
+
return {
|
|
697
|
+
tag: tag,
|
|
698
|
+
raw: cap[0],
|
|
699
|
+
href: cap[2],
|
|
700
|
+
title: cap[3]
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
_proto.table = function table(src) {
|
|
706
|
+
var cap = this.rules.block.table.exec(src);
|
|
707
|
+
|
|
708
|
+
if (cap) {
|
|
709
|
+
var item = {
|
|
710
|
+
type: 'table',
|
|
711
|
+
header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
|
|
712
|
+
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
|
713
|
+
cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
if (item.header.length === item.align.length) {
|
|
717
|
+
item.raw = cap[0];
|
|
718
|
+
var l = item.align.length;
|
|
719
|
+
var i;
|
|
720
|
+
|
|
721
|
+
for (i = 0; i < l; i++) {
|
|
722
|
+
if (/^ *-+: *$/.test(item.align[i])) {
|
|
723
|
+
item.align[i] = 'right';
|
|
724
|
+
} else if (/^ *:-+: *$/.test(item.align[i])) {
|
|
725
|
+
item.align[i] = 'center';
|
|
726
|
+
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
|
727
|
+
item.align[i] = 'left';
|
|
728
|
+
} else {
|
|
729
|
+
item.align[i] = null;
|
|
641
730
|
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
l = item.cells.length;
|
|
734
|
+
|
|
735
|
+
for (i = 0; i < l; i++) {
|
|
736
|
+
item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
return item;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
_proto.lheading = function lheading(src) {
|
|
745
|
+
var cap = this.rules.block.lheading.exec(src);
|
|
746
|
+
|
|
747
|
+
if (cap) {
|
|
748
|
+
return {
|
|
749
|
+
type: 'heading',
|
|
750
|
+
raw: cap[0],
|
|
751
|
+
depth: cap[2].charAt(0) === '=' ? 1 : 2,
|
|
752
|
+
text: cap[1]
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
_proto.paragraph = function paragraph(src) {
|
|
758
|
+
var cap = this.rules.block.paragraph.exec(src);
|
|
759
|
+
|
|
760
|
+
if (cap) {
|
|
761
|
+
return {
|
|
762
|
+
type: 'paragraph',
|
|
763
|
+
raw: cap[0],
|
|
764
|
+
text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
_proto.text = function text(src, tokens) {
|
|
770
|
+
var cap = this.rules.block.text.exec(src);
|
|
771
|
+
|
|
772
|
+
if (cap) {
|
|
773
|
+
var lastToken = tokens[tokens.length - 1];
|
|
774
|
+
|
|
775
|
+
if (lastToken && lastToken.type === 'text') {
|
|
776
|
+
return {
|
|
777
|
+
raw: cap[0],
|
|
778
|
+
text: cap[0]
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
return {
|
|
783
|
+
type: 'text',
|
|
784
|
+
raw: cap[0],
|
|
785
|
+
text: cap[0]
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
_proto.escape = function escape(src) {
|
|
791
|
+
var cap = this.rules.inline.escape.exec(src);
|
|
792
|
+
|
|
793
|
+
if (cap) {
|
|
794
|
+
return {
|
|
795
|
+
type: 'escape',
|
|
796
|
+
raw: cap[0],
|
|
797
|
+
text: _escape(cap[1])
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
_proto.tag = function tag(src, inLink, inRawBlock) {
|
|
803
|
+
var cap = this.rules.inline.tag.exec(src);
|
|
804
|
+
|
|
805
|
+
if (cap) {
|
|
806
|
+
if (!inLink && /^<a /i.test(cap[0])) {
|
|
807
|
+
inLink = true;
|
|
808
|
+
} else if (inLink && /^<\/a>/i.test(cap[0])) {
|
|
809
|
+
inLink = false;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
if (!inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
813
|
+
inRawBlock = true;
|
|
814
|
+
} else if (inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
815
|
+
inRawBlock = false;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return {
|
|
819
|
+
type: this.options.sanitize ? 'text' : 'html',
|
|
820
|
+
raw: cap[0],
|
|
821
|
+
inLink: inLink,
|
|
822
|
+
inRawBlock: inRawBlock,
|
|
823
|
+
text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0]
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
_proto.link = function link(src) {
|
|
829
|
+
var cap = this.rules.inline.link.exec(src);
|
|
830
|
+
|
|
831
|
+
if (cap) {
|
|
832
|
+
var lastParenIndex = findClosingBracket$1(cap[2], '()');
|
|
833
|
+
|
|
834
|
+
if (lastParenIndex > -1) {
|
|
835
|
+
var start = cap[0].indexOf('!') === 0 ? 5 : 4;
|
|
836
|
+
var linkLen = start + cap[1].length + lastParenIndex;
|
|
837
|
+
cap[2] = cap[2].substring(0, lastParenIndex);
|
|
838
|
+
cap[0] = cap[0].substring(0, linkLen).trim();
|
|
839
|
+
cap[3] = '';
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
var href = cap[2];
|
|
843
|
+
var title = '';
|
|
844
|
+
|
|
845
|
+
if (this.options.pedantic) {
|
|
846
|
+
var link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
|
|
847
|
+
|
|
848
|
+
if (link) {
|
|
849
|
+
href = link[1];
|
|
850
|
+
title = link[3];
|
|
851
|
+
} else {
|
|
852
|
+
title = '';
|
|
853
|
+
}
|
|
854
|
+
} else {
|
|
855
|
+
title = cap[3] ? cap[3].slice(1, -1) : '';
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
|
|
859
|
+
var token = outputLink(cap, {
|
|
860
|
+
href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
|
|
861
|
+
title: title ? title.replace(this.rules.inline._escapes, '$1') : title
|
|
862
|
+
}, cap[0]);
|
|
863
|
+
return token;
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
_proto.reflink = function reflink(src, links) {
|
|
868
|
+
var cap;
|
|
869
|
+
|
|
870
|
+
if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
|
|
871
|
+
var link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
|
872
|
+
link = links[link.toLowerCase()];
|
|
873
|
+
|
|
874
|
+
if (!link || !link.href) {
|
|
875
|
+
var text = cap[0].charAt(0);
|
|
876
|
+
return {
|
|
877
|
+
type: 'text',
|
|
878
|
+
raw: text,
|
|
879
|
+
text: text
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
var token = outputLink(cap, link, cap[0]);
|
|
884
|
+
return token;
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
_proto.strong = function strong(src, maskedSrc, prevChar) {
|
|
889
|
+
if (prevChar === void 0) {
|
|
890
|
+
prevChar = '';
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
var match = this.rules.inline.strong.start.exec(src);
|
|
894
|
+
|
|
895
|
+
if (match && (!match[1] || match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar)))) {
|
|
896
|
+
maskedSrc = maskedSrc.slice(-1 * src.length);
|
|
897
|
+
var endReg = match[0] === '**' ? this.rules.inline.strong.endAst : this.rules.inline.strong.endUnd;
|
|
898
|
+
endReg.lastIndex = 0;
|
|
899
|
+
var cap;
|
|
900
|
+
|
|
901
|
+
while ((match = endReg.exec(maskedSrc)) != null) {
|
|
902
|
+
cap = this.rules.inline.strong.middle.exec(maskedSrc.slice(0, match.index + 3));
|
|
903
|
+
|
|
904
|
+
if (cap) {
|
|
905
|
+
return {
|
|
906
|
+
type: 'strong',
|
|
907
|
+
raw: src.slice(0, cap[0].length),
|
|
908
|
+
text: src.slice(2, cap[0].length - 2)
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
_proto.em = function em(src, maskedSrc, prevChar) {
|
|
916
|
+
if (prevChar === void 0) {
|
|
917
|
+
prevChar = '';
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
var match = this.rules.inline.em.start.exec(src);
|
|
921
|
+
|
|
922
|
+
if (match && (!match[1] || match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar)))) {
|
|
923
|
+
maskedSrc = maskedSrc.slice(-1 * src.length);
|
|
924
|
+
var endReg = match[0] === '*' ? this.rules.inline.em.endAst : this.rules.inline.em.endUnd;
|
|
925
|
+
endReg.lastIndex = 0;
|
|
926
|
+
var cap;
|
|
927
|
+
|
|
928
|
+
while ((match = endReg.exec(maskedSrc)) != null) {
|
|
929
|
+
cap = this.rules.inline.em.middle.exec(maskedSrc.slice(0, match.index + 2));
|
|
930
|
+
|
|
931
|
+
if (cap) {
|
|
932
|
+
return {
|
|
933
|
+
type: 'em',
|
|
934
|
+
raw: src.slice(0, cap[0].length),
|
|
935
|
+
text: src.slice(1, cap[0].length - 1)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
_proto.codespan = function codespan(src) {
|
|
943
|
+
var cap = this.rules.inline.code.exec(src);
|
|
944
|
+
|
|
945
|
+
if (cap) {
|
|
946
|
+
var text = cap[2].replace(/\n/g, ' ');
|
|
947
|
+
var hasNonSpaceChars = /[^ ]/.test(text);
|
|
948
|
+
var hasSpaceCharsOnBothEnds = text.startsWith(' ') && text.endsWith(' ');
|
|
949
|
+
|
|
950
|
+
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
|
|
951
|
+
text = text.substring(1, text.length - 1);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
text = _escape(text, true);
|
|
955
|
+
return {
|
|
956
|
+
type: 'codespan',
|
|
957
|
+
raw: cap[0],
|
|
958
|
+
text: text
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
_proto.br = function br(src) {
|
|
964
|
+
var cap = this.rules.inline.br.exec(src);
|
|
965
|
+
|
|
966
|
+
if (cap) {
|
|
967
|
+
return {
|
|
968
|
+
type: 'br',
|
|
969
|
+
raw: cap[0]
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
_proto.del = function del(src) {
|
|
975
|
+
var cap = this.rules.inline.del.exec(src);
|
|
976
|
+
|
|
977
|
+
if (cap) {
|
|
978
|
+
return {
|
|
979
|
+
type: 'del',
|
|
980
|
+
raw: cap[0],
|
|
981
|
+
text: cap[1]
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
_proto.autolink = function autolink(src, mangle) {
|
|
987
|
+
var cap = this.rules.inline.autolink.exec(src);
|
|
988
|
+
|
|
989
|
+
if (cap) {
|
|
990
|
+
var text, href;
|
|
991
|
+
|
|
992
|
+
if (cap[2] === '@') {
|
|
993
|
+
text = _escape(this.options.mangle ? mangle(cap[1]) : cap[1]);
|
|
994
|
+
href = 'mailto:' + text;
|
|
995
|
+
} else {
|
|
996
|
+
text = _escape(cap[1]);
|
|
997
|
+
href = text;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
return {
|
|
1001
|
+
type: 'link',
|
|
1002
|
+
raw: cap[0],
|
|
1003
|
+
text: text,
|
|
1004
|
+
href: href,
|
|
1005
|
+
tokens: [{
|
|
1006
|
+
type: 'text',
|
|
1007
|
+
raw: text,
|
|
1008
|
+
text: text
|
|
1009
|
+
}]
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
_proto.url = function url(src, mangle) {
|
|
1015
|
+
var cap;
|
|
1016
|
+
|
|
1017
|
+
if (cap = this.rules.inline.url.exec(src)) {
|
|
1018
|
+
var text, href;
|
|
1019
|
+
|
|
1020
|
+
if (cap[2] === '@') {
|
|
1021
|
+
text = _escape(this.options.mangle ? mangle(cap[0]) : cap[0]);
|
|
1022
|
+
href = 'mailto:' + text;
|
|
1023
|
+
} else {
|
|
1024
|
+
// do extended autolink path validation
|
|
1025
|
+
var prevCapZero;
|
|
1026
|
+
|
|
1027
|
+
do {
|
|
1028
|
+
prevCapZero = cap[0];
|
|
1029
|
+
cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
|
|
1030
|
+
} while (prevCapZero !== cap[0]);
|
|
1031
|
+
|
|
1032
|
+
text = _escape(cap[0]);
|
|
1033
|
+
|
|
1034
|
+
if (cap[1] === 'www.') {
|
|
1035
|
+
href = 'http://' + text;
|
|
1036
|
+
} else {
|
|
1037
|
+
href = text;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
return {
|
|
1042
|
+
type: 'link',
|
|
1043
|
+
raw: cap[0],
|
|
1044
|
+
text: text,
|
|
1045
|
+
href: href,
|
|
1046
|
+
tokens: [{
|
|
1047
|
+
type: 'text',
|
|
1048
|
+
raw: text,
|
|
1049
|
+
text: text
|
|
1050
|
+
}]
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
_proto.inlineText = function inlineText(src, inRawBlock, smartypants) {
|
|
1056
|
+
var cap = this.rules.inline.text.exec(src);
|
|
1057
|
+
|
|
1058
|
+
if (cap) {
|
|
1059
|
+
var text;
|
|
1060
|
+
|
|
1061
|
+
if (inRawBlock) {
|
|
1062
|
+
text = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : _escape(cap[0]) : cap[0];
|
|
1063
|
+
} else {
|
|
1064
|
+
text = _escape(this.options.smartypants ? smartypants(cap[0]) : cap[0]);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
return {
|
|
1068
|
+
type: 'text',
|
|
1069
|
+
raw: cap[0],
|
|
1070
|
+
text: text
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
|
|
1075
|
+
return Tokenizer;
|
|
1076
|
+
}();
|
|
1077
|
+
|
|
1078
|
+
var noopTest$1 = helpers.noopTest,
|
|
1079
|
+
edit$1 = helpers.edit,
|
|
1080
|
+
merge$1 = helpers.merge;
|
|
1081
|
+
/**
|
|
1082
|
+
* Block-Level Grammar
|
|
1083
|
+
*/
|
|
1084
|
+
|
|
1085
|
+
var block = {
|
|
1086
|
+
newline: /^\n+/,
|
|
1087
|
+
code: /^( {4}[^\n]+\n*)+/,
|
|
1088
|
+
fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,
|
|
1089
|
+
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
|
|
1090
|
+
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
|
|
1091
|
+
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
|
|
1092
|
+
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
|
1093
|
+
html: '^ {0,3}(?:' // optional indentation
|
|
1094
|
+
+ '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
|
|
1095
|
+
+ '|comment[^\\n]*(\\n+|$)' // (2)
|
|
1096
|
+
+ '|<\\?[\\s\\S]*?\\?>\\n*' // (3)
|
|
1097
|
+
+ '|<![A-Z][\\s\\S]*?>\\n*' // (4)
|
|
1098
|
+
+ '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5)
|
|
1099
|
+
+ '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
|
|
1100
|
+
+ '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
|
|
1101
|
+
+ '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
|
|
1102
|
+
+ ')',
|
|
1103
|
+
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
|
|
1104
|
+
nptable: noopTest$1,
|
|
1105
|
+
table: noopTest$1,
|
|
1106
|
+
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
1107
|
+
// regex template, placeholders will be replaced according to different paragraph
|
|
1108
|
+
// interruption rules of commonmark and the original markdown spec:
|
|
1109
|
+
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,
|
|
1110
|
+
text: /^[^\n]+/
|
|
1111
|
+
};
|
|
1112
|
+
block._label = /(?!\s*\])(?:\\[\[\]]|[^\[\]])+/;
|
|
1113
|
+
block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
|
|
1114
|
+
block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
|
|
1115
|
+
block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
|
1116
|
+
block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
|
|
1117
|
+
block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
|
|
1118
|
+
block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
|
|
1119
|
+
block._tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr' + '|track|ul';
|
|
1120
|
+
block._comment = /<!--(?!-?>)[\s\S]*?-->/;
|
|
1121
|
+
block.html = edit$1(block.html, 'i').replace('comment', block._comment).replace('tag', block._tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
1122
|
+
block.paragraph = edit$1(block._paragraph).replace('hr', block.hr).replace('heading', ' {0,3}#{1,6} ').replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
|
|
1123
|
+
.replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
|
|
1124
|
+
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
|
|
1125
|
+
.getRegex();
|
|
1126
|
+
block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
|
|
1127
|
+
/**
|
|
1128
|
+
* Normal Block Grammar
|
|
1129
|
+
*/
|
|
1130
|
+
|
|
1131
|
+
block.normal = merge$1({}, block);
|
|
1132
|
+
/**
|
|
1133
|
+
* GFM Block Grammar
|
|
1134
|
+
*/
|
|
1135
|
+
|
|
1136
|
+
block.gfm = merge$1({}, block.normal, {
|
|
1137
|
+
nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
|
|
1138
|
+
+ ' *([-:]+ *\\|[-| :]*)' // Align
|
|
1139
|
+
+ '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
|
|
1140
|
+
// Cells
|
|
1141
|
+
table: '^ *\\|(.+)\\n' // Header
|
|
1142
|
+
+ ' *\\|?( *[-:]+[-| :]*)' // Align
|
|
1143
|
+
+ '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
|
1144
|
+
|
|
1145
|
+
});
|
|
1146
|
+
block.gfm.nptable = edit$1(block.gfm.nptable).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
|
|
1147
|
+
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
1148
|
+
.getRegex();
|
|
1149
|
+
block.gfm.table = edit$1(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
|
|
1150
|
+
.replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
|
|
1151
|
+
.getRegex();
|
|
1152
|
+
/**
|
|
1153
|
+
* Pedantic grammar (original John Gruber's loose markdown specification)
|
|
1154
|
+
*/
|
|
642
1155
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
1156
|
+
block.pedantic = merge$1({}, block.normal, {
|
|
1157
|
+
html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
|
|
1158
|
+
+ '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))').replace('comment', block._comment).replace(/tag/g, '(?!(?:' + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub' + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)' + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b').getRegex(),
|
|
1159
|
+
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
|
1160
|
+
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
|
|
1161
|
+
fences: noopTest$1,
|
|
1162
|
+
// fences not supported
|
|
1163
|
+
paragraph: edit$1(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()
|
|
1164
|
+
});
|
|
1165
|
+
/**
|
|
1166
|
+
* Inline-Level Grammar
|
|
1167
|
+
*/
|
|
1168
|
+
|
|
1169
|
+
var inline = {
|
|
1170
|
+
escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
|
|
1171
|
+
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
|
1172
|
+
url: noopTest$1,
|
|
1173
|
+
tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
|
|
1174
|
+
+ '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
|
|
1175
|
+
+ '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
|
|
1176
|
+
+ '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
|
|
1177
|
+
+ '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
|
|
1178
|
+
// CDATA section
|
|
1179
|
+
link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
|
|
1180
|
+
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
|
|
1181
|
+
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
|
|
1182
|
+
reflinkSearch: 'reflink|nolink(?!\\()',
|
|
1183
|
+
strong: {
|
|
1184
|
+
start: /^(?:(\*\*(?=[*punctuation]))|\*\*)(?![\s])|__/,
|
|
1185
|
+
// (1) returns if starts w/ punctuation
|
|
1186
|
+
middle: /^\*\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*\*$|^__(?![\s])((?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?)__$/,
|
|
1187
|
+
endAst: /[^punctuation\s]\*\*(?!\*)|[punctuation]\*\*(?!\*)(?:(?=[punctuation\s]|$))/,
|
|
1188
|
+
// last char can't be punct, or final * must also be followed by punct (or endline)
|
|
1189
|
+
endUnd: /[^\s]__(?!_)(?:(?=[punctuation\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
|
1190
|
+
|
|
1191
|
+
},
|
|
1192
|
+
em: {
|
|
1193
|
+
start: /^(?:(\*(?=[punctuation]))|\*)(?![*\s])|_/,
|
|
1194
|
+
// (1) returns if starts w/ punctuation
|
|
1195
|
+
middle: /^\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?_$/,
|
|
1196
|
+
endAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation\s]|$))/,
|
|
1197
|
+
// last char can't be punct, or final * must also be followed by punct (or endline)
|
|
1198
|
+
endUnd: /[^\s]_(?!_)(?:(?=[punctuation\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
|
1199
|
+
|
|
1200
|
+
},
|
|
1201
|
+
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
1202
|
+
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
1203
|
+
del: noopTest$1,
|
|
1204
|
+
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/,
|
|
1205
|
+
punctuation: /^([\s*punctuation])/
|
|
1206
|
+
}; // list of punctuation marks from common mark spec
|
|
1207
|
+
// without * and _ to workaround cases with double emphasis
|
|
1208
|
+
|
|
1209
|
+
inline._punctuation = '!"#$%&\'()+\\-.,/:;<=>?@\\[\\]`^{|}~';
|
|
1210
|
+
inline.punctuation = edit$1(inline.punctuation).replace(/punctuation/g, inline._punctuation).getRegex(); // sequences em should skip over [title](link), `code`, <html>
|
|
1211
|
+
|
|
1212
|
+
inline._blockSkip = '\\[[^\\]]*?\\]\\([^\\)]*?\\)|`[^`]*?`|<[^>]*?>';
|
|
1213
|
+
inline._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*';
|
|
1214
|
+
inline.em.start = edit$1(inline.em.start).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1215
|
+
inline.em.middle = edit$1(inline.em.middle).replace(/punctuation/g, inline._punctuation).replace(/overlapSkip/g, inline._overlapSkip).getRegex();
|
|
1216
|
+
inline.em.endAst = edit$1(inline.em.endAst, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1217
|
+
inline.em.endUnd = edit$1(inline.em.endUnd, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1218
|
+
inline.strong.start = edit$1(inline.strong.start).replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1219
|
+
inline.strong.middle = edit$1(inline.strong.middle).replace(/punctuation/g, inline._punctuation).replace(/blockSkip/g, inline._blockSkip).getRegex();
|
|
1220
|
+
inline.strong.endAst = edit$1(inline.strong.endAst, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1221
|
+
inline.strong.endUnd = edit$1(inline.strong.endUnd, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
|
1222
|
+
inline.blockSkip = edit$1(inline._blockSkip, 'g').getRegex();
|
|
1223
|
+
inline.overlapSkip = edit$1(inline._overlapSkip, 'g').getRegex();
|
|
1224
|
+
inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
|
|
1225
|
+
inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
|
|
1226
|
+
inline._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
|
|
1227
|
+
inline.autolink = edit$1(inline.autolink).replace('scheme', inline._scheme).replace('email', inline._email).getRegex();
|
|
1228
|
+
inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
|
|
1229
|
+
inline.tag = edit$1(inline.tag).replace('comment', block._comment).replace('attribute', inline._attribute).getRegex();
|
|
1230
|
+
inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
|
|
1231
|
+
inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
|
|
1232
|
+
inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
|
|
1233
|
+
inline.link = edit$1(inline.link).replace('label', inline._label).replace('href', inline._href).replace('title', inline._title).getRegex();
|
|
1234
|
+
inline.reflink = edit$1(inline.reflink).replace('label', inline._label).getRegex();
|
|
1235
|
+
inline.reflinkSearch = edit$1(inline.reflinkSearch, 'g').replace('reflink', inline.reflink).replace('nolink', inline.nolink).getRegex();
|
|
1236
|
+
/**
|
|
1237
|
+
* Normal Inline Grammar
|
|
1238
|
+
*/
|
|
1239
|
+
|
|
1240
|
+
inline.normal = merge$1({}, inline);
|
|
1241
|
+
/**
|
|
1242
|
+
* Pedantic Inline Grammar
|
|
1243
|
+
*/
|
|
1244
|
+
|
|
1245
|
+
inline.pedantic = merge$1({}, inline.normal, {
|
|
1246
|
+
strong: {
|
|
1247
|
+
start: /^__|\*\*/,
|
|
1248
|
+
middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
|
|
1249
|
+
endAst: /\*\*(?!\*)/g,
|
|
1250
|
+
endUnd: /__(?!_)/g
|
|
1251
|
+
},
|
|
1252
|
+
em: {
|
|
1253
|
+
start: /^_|\*/,
|
|
1254
|
+
middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
|
|
1255
|
+
endAst: /\*(?!\*)/g,
|
|
1256
|
+
endUnd: /_(?!_)/g
|
|
1257
|
+
},
|
|
1258
|
+
link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
|
|
1259
|
+
reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
|
|
1260
|
+
});
|
|
1261
|
+
/**
|
|
1262
|
+
* GFM Inline Grammar
|
|
1263
|
+
*/
|
|
1264
|
+
|
|
1265
|
+
inline.gfm = merge$1({}, inline.normal, {
|
|
1266
|
+
escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
|
|
1267
|
+
_extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
|
|
1268
|
+
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
|
|
1269
|
+
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
|
|
1270
|
+
del: /^~+(?=\S)([\s\S]*?\S)~+/,
|
|
1271
|
+
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
|
|
1272
|
+
});
|
|
1273
|
+
inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
|
|
1274
|
+
/**
|
|
1275
|
+
* GFM + Line Breaks Inline Grammar
|
|
1276
|
+
*/
|
|
1277
|
+
|
|
1278
|
+
inline.breaks = merge$1({}, inline.gfm, {
|
|
1279
|
+
br: edit$1(inline.br).replace('{2,}', '*').getRegex(),
|
|
1280
|
+
text: edit$1(inline.gfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
|
|
1281
|
+
});
|
|
1282
|
+
var rules = {
|
|
1283
|
+
block: block,
|
|
1284
|
+
inline: inline
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
var defaults$2 = defaults.defaults;
|
|
1288
|
+
var block$1 = rules.block,
|
|
1289
|
+
inline$1 = rules.inline;
|
|
1290
|
+
/**
|
|
1291
|
+
* smartypants text replacement
|
|
1292
|
+
*/
|
|
1293
|
+
|
|
1294
|
+
function smartypants(text) {
|
|
1295
|
+
return text // em-dashes
|
|
1296
|
+
.replace(/---/g, "\u2014") // en-dashes
|
|
1297
|
+
.replace(/--/g, "\u2013") // opening singles
|
|
1298
|
+
.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
|
|
1299
|
+
.replace(/'/g, "\u2019") // opening doubles
|
|
1300
|
+
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
|
|
1301
|
+
.replace(/"/g, "\u201D") // ellipses
|
|
1302
|
+
.replace(/\.{3}/g, "\u2026");
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* mangle email addresses
|
|
1306
|
+
*/
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
function mangle(text) {
|
|
1310
|
+
var out = '',
|
|
1311
|
+
i,
|
|
1312
|
+
ch;
|
|
1313
|
+
var l = text.length;
|
|
1314
|
+
|
|
1315
|
+
for (i = 0; i < l; i++) {
|
|
1316
|
+
ch = text.charCodeAt(i);
|
|
1317
|
+
|
|
1318
|
+
if (Math.random() > 0.5) {
|
|
1319
|
+
ch = 'x' + ch.toString(16);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
out += '&#' + ch + ';';
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
return out;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Block Lexer
|
|
1329
|
+
*/
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
var Lexer_1 = /*#__PURE__*/function () {
|
|
1333
|
+
function Lexer(options) {
|
|
1334
|
+
this.tokens = [];
|
|
1335
|
+
this.tokens.links = Object.create(null);
|
|
1336
|
+
this.options = options || defaults$2;
|
|
1337
|
+
this.options.tokenizer = this.options.tokenizer || new Tokenizer_1();
|
|
1338
|
+
this.tokenizer = this.options.tokenizer;
|
|
1339
|
+
this.tokenizer.options = this.options;
|
|
1340
|
+
var rules = {
|
|
1341
|
+
block: block$1.normal,
|
|
1342
|
+
inline: inline$1.normal
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
if (this.options.pedantic) {
|
|
1346
|
+
rules.block = block$1.pedantic;
|
|
1347
|
+
rules.inline = inline$1.pedantic;
|
|
1348
|
+
} else if (this.options.gfm) {
|
|
1349
|
+
rules.block = block$1.gfm;
|
|
1350
|
+
|
|
1351
|
+
if (this.options.breaks) {
|
|
1352
|
+
rules.inline = inline$1.breaks;
|
|
1353
|
+
} else {
|
|
1354
|
+
rules.inline = inline$1.gfm;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
this.tokenizer.rules = rules;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Expose Rules
|
|
1362
|
+
*/
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Static Lex Method
|
|
1367
|
+
*/
|
|
1368
|
+
Lexer.lex = function lex(src, options) {
|
|
1369
|
+
var lexer = new Lexer(options);
|
|
1370
|
+
return lexer.lex(src);
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Preprocessing
|
|
1374
|
+
*/
|
|
1375
|
+
;
|
|
1376
|
+
|
|
1377
|
+
var _proto = Lexer.prototype;
|
|
1378
|
+
|
|
1379
|
+
_proto.lex = function lex(src) {
|
|
1380
|
+
src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
|
|
1381
|
+
this.blockTokens(src, this.tokens, true);
|
|
1382
|
+
this.inline(this.tokens);
|
|
1383
|
+
return this.tokens;
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Lexing
|
|
1387
|
+
*/
|
|
1388
|
+
;
|
|
1389
|
+
|
|
1390
|
+
_proto.blockTokens = function blockTokens(src, tokens, top) {
|
|
1391
|
+
if (tokens === void 0) {
|
|
1392
|
+
tokens = [];
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
if (top === void 0) {
|
|
1396
|
+
top = true;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
src = src.replace(/^ +$/gm, '');
|
|
1400
|
+
var token, i, l, lastToken;
|
|
1401
|
+
|
|
1402
|
+
while (src) {
|
|
1403
|
+
// newline
|
|
1404
|
+
if (token = this.tokenizer.space(src)) {
|
|
1405
|
+
src = src.substring(token.raw.length);
|
|
646
1406
|
|
|
647
|
-
|
|
648
|
-
|
|
1407
|
+
if (token.type) {
|
|
1408
|
+
tokens.push(token);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
continue;
|
|
1412
|
+
} // code
|
|
1413
|
+
|
|
1414
|
+
|
|
1415
|
+
if (token = this.tokenizer.code(src, tokens)) {
|
|
1416
|
+
src = src.substring(token.raw.length);
|
|
1417
|
+
|
|
1418
|
+
if (token.type) {
|
|
1419
|
+
tokens.push(token);
|
|
1420
|
+
} else {
|
|
1421
|
+
lastToken = tokens[tokens.length - 1];
|
|
1422
|
+
lastToken.raw += '\n' + token.raw;
|
|
1423
|
+
lastToken.text += '\n' + token.text;
|
|
649
1424
|
}
|
|
1425
|
+
|
|
1426
|
+
continue;
|
|
1427
|
+
} // fences
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
if (token = this.tokenizer.fences(src)) {
|
|
1431
|
+
src = src.substring(token.raw.length);
|
|
1432
|
+
tokens.push(token);
|
|
1433
|
+
continue;
|
|
1434
|
+
} // heading
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
if (token = this.tokenizer.heading(src)) {
|
|
1438
|
+
src = src.substring(token.raw.length);
|
|
1439
|
+
tokens.push(token);
|
|
1440
|
+
continue;
|
|
1441
|
+
} // table no leading pipe (gfm)
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
if (token = this.tokenizer.nptable(src)) {
|
|
1445
|
+
src = src.substring(token.raw.length);
|
|
1446
|
+
tokens.push(token);
|
|
1447
|
+
continue;
|
|
650
1448
|
} // hr
|
|
651
1449
|
|
|
652
1450
|
|
|
653
|
-
if (
|
|
654
|
-
src = src.substring(
|
|
655
|
-
|
|
656
|
-
type: 'hr'
|
|
657
|
-
});
|
|
1451
|
+
if (token = this.tokenizer.hr(src)) {
|
|
1452
|
+
src = src.substring(token.raw.length);
|
|
1453
|
+
tokens.push(token);
|
|
658
1454
|
continue;
|
|
659
1455
|
} // blockquote
|
|
660
1456
|
|
|
661
1457
|
|
|
662
|
-
if (
|
|
663
|
-
src = src.substring(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
});
|
|
667
|
-
cap = cap[0].replace(/^ *> ?/gm, ''); // Pass `top` to keep the current
|
|
668
|
-
// "toplevel" state. This is exactly
|
|
669
|
-
// how markdown.pl works.
|
|
670
|
-
|
|
671
|
-
this.token(cap, top);
|
|
672
|
-
this.tokens.push({
|
|
673
|
-
type: 'blockquote_end'
|
|
674
|
-
});
|
|
1458
|
+
if (token = this.tokenizer.blockquote(src)) {
|
|
1459
|
+
src = src.substring(token.raw.length);
|
|
1460
|
+
token.tokens = this.blockTokens(token.text, [], top);
|
|
1461
|
+
tokens.push(token);
|
|
675
1462
|
continue;
|
|
676
1463
|
} // list
|
|
677
1464
|
|
|
678
1465
|
|
|
679
|
-
if (
|
|
680
|
-
src = src.substring(
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
1466
|
+
if (token = this.tokenizer.list(src)) {
|
|
1467
|
+
src = src.substring(token.raw.length);
|
|
1468
|
+
l = token.items.length;
|
|
1469
|
+
|
|
1470
|
+
for (i = 0; i < l; i++) {
|
|
1471
|
+
token.items[i].tokens = this.blockTokens(token.items[i].text, [], false);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
tokens.push(token);
|
|
1475
|
+
continue;
|
|
1476
|
+
} // html
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
if (token = this.tokenizer.html(src)) {
|
|
1480
|
+
src = src.substring(token.raw.length);
|
|
1481
|
+
tokens.push(token);
|
|
1482
|
+
continue;
|
|
1483
|
+
} // def
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
if (top && (token = this.tokenizer.def(src))) {
|
|
1487
|
+
src = src.substring(token.raw.length);
|
|
1488
|
+
|
|
1489
|
+
if (!this.tokens.links[token.tag]) {
|
|
1490
|
+
this.tokens.links[token.tag] = {
|
|
1491
|
+
href: token.href,
|
|
1492
|
+
title: token.title
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
continue;
|
|
1497
|
+
} // table (gfm)
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
if (token = this.tokenizer.table(src)) {
|
|
1501
|
+
src = src.substring(token.raw.length);
|
|
1502
|
+
tokens.push(token);
|
|
1503
|
+
continue;
|
|
1504
|
+
} // lheading
|
|
1505
|
+
|
|
1506
|
+
|
|
1507
|
+
if (token = this.tokenizer.lheading(src)) {
|
|
1508
|
+
src = src.substring(token.raw.length);
|
|
1509
|
+
tokens.push(token);
|
|
1510
|
+
continue;
|
|
1511
|
+
} // top-level paragraph
|
|
1512
|
+
|
|
1513
|
+
|
|
1514
|
+
if (top && (token = this.tokenizer.paragraph(src))) {
|
|
1515
|
+
src = src.substring(token.raw.length);
|
|
1516
|
+
tokens.push(token);
|
|
1517
|
+
continue;
|
|
1518
|
+
} // text
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
if (token = this.tokenizer.text(src, tokens)) {
|
|
1522
|
+
src = src.substring(token.raw.length);
|
|
1523
|
+
|
|
1524
|
+
if (token.type) {
|
|
1525
|
+
tokens.push(token);
|
|
1526
|
+
} else {
|
|
1527
|
+
lastToken = tokens[tokens.length - 1];
|
|
1528
|
+
lastToken.raw += '\n' + token.raw;
|
|
1529
|
+
lastToken.text += '\n' + token.text;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
continue;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
if (src) {
|
|
1536
|
+
var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
|
1537
|
+
|
|
1538
|
+
if (this.options.silent) {
|
|
1539
|
+
console.error(errMsg);
|
|
1540
|
+
break;
|
|
1541
|
+
} else {
|
|
1542
|
+
throw new Error(errMsg);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
return tokens;
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
_proto.inline = function inline(tokens) {
|
|
1551
|
+
var i, j, k, l2, row, token;
|
|
1552
|
+
var l = tokens.length;
|
|
1553
|
+
|
|
1554
|
+
for (i = 0; i < l; i++) {
|
|
1555
|
+
token = tokens[i];
|
|
1556
|
+
|
|
1557
|
+
switch (token.type) {
|
|
1558
|
+
case 'paragraph':
|
|
1559
|
+
case 'text':
|
|
1560
|
+
case 'heading':
|
|
1561
|
+
{
|
|
1562
|
+
token.tokens = [];
|
|
1563
|
+
this.inlineTokens(token.text, token.tokens);
|
|
1564
|
+
break;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
case 'table':
|
|
1568
|
+
{
|
|
1569
|
+
token.tokens = {
|
|
1570
|
+
header: [],
|
|
1571
|
+
cells: []
|
|
1572
|
+
}; // header
|
|
690
1573
|
|
|
691
|
-
|
|
692
|
-
listItems = [];
|
|
693
|
-
next = false;
|
|
694
|
-
l = cap.length;
|
|
695
|
-
i = 0;
|
|
1574
|
+
l2 = token.header.length;
|
|
696
1575
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
1576
|
+
for (j = 0; j < l2; j++) {
|
|
1577
|
+
token.tokens.header[j] = [];
|
|
1578
|
+
this.inlineTokens(token.header[j], token.tokens.header[j]);
|
|
1579
|
+
} // cells
|
|
700
1580
|
|
|
701
|
-
space = item.length;
|
|
702
|
-
item = item.replace(/^ *([*+-]|\d+\.) */, ''); // Outdent whatever the
|
|
703
|
-
// list item contains. Hacky.
|
|
704
1581
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1582
|
+
l2 = token.cells.length;
|
|
1583
|
+
|
|
1584
|
+
for (j = 0; j < l2; j++) {
|
|
1585
|
+
row = token.cells[j];
|
|
1586
|
+
token.tokens.cells[j] = [];
|
|
1587
|
+
|
|
1588
|
+
for (k = 0; k < row.length; k++) {
|
|
1589
|
+
token.tokens.cells[j][k] = [];
|
|
1590
|
+
this.inlineTokens(row[k], token.tokens.cells[j][k]);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
710
1596
|
|
|
1597
|
+
case 'blockquote':
|
|
1598
|
+
{
|
|
1599
|
+
this.inline(token.tokens);
|
|
1600
|
+
break;
|
|
1601
|
+
}
|
|
711
1602
|
|
|
712
|
-
|
|
713
|
-
|
|
1603
|
+
case 'list':
|
|
1604
|
+
{
|
|
1605
|
+
l2 = token.items.length;
|
|
714
1606
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
i = l - 1;
|
|
1607
|
+
for (j = 0; j < l2; j++) {
|
|
1608
|
+
this.inline(token.items[j].tokens);
|
|
718
1609
|
}
|
|
719
|
-
} // Determine whether item is loose or not.
|
|
720
|
-
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
|
721
|
-
// for discount behavior.
|
|
722
1610
|
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
return tokens;
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Lexing/Compiling
|
|
1620
|
+
*/
|
|
1621
|
+
;
|
|
1622
|
+
|
|
1623
|
+
_proto.inlineTokens = function inlineTokens(src, tokens, inLink, inRawBlock, prevChar) {
|
|
1624
|
+
if (tokens === void 0) {
|
|
1625
|
+
tokens = [];
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
if (inLink === void 0) {
|
|
1629
|
+
inLink = false;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
if (inRawBlock === void 0) {
|
|
1633
|
+
inRawBlock = false;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
if (prevChar === void 0) {
|
|
1637
|
+
prevChar = '';
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
var token; // String with links masked to avoid interference with em and strong
|
|
1641
|
+
|
|
1642
|
+
var maskedSrc = src;
|
|
1643
|
+
var match; // Mask out reflinks
|
|
723
1644
|
|
|
724
|
-
|
|
1645
|
+
if (this.tokens.links) {
|
|
1646
|
+
var links = Object.keys(this.tokens.links);
|
|
725
1647
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
1648
|
+
if (links.length > 0) {
|
|
1649
|
+
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
|
1650
|
+
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
|
1651
|
+
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
|
729
1652
|
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
} // Mask out other blocks
|
|
730
1656
|
|
|
731
|
-
if (loose) {
|
|
732
|
-
listStart.loose = true;
|
|
733
|
-
} // Check for task list items
|
|
734
1657
|
|
|
1658
|
+
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
|
1659
|
+
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
1660
|
+
}
|
|
735
1661
|
|
|
736
|
-
|
|
737
|
-
|
|
1662
|
+
while (src) {
|
|
1663
|
+
// escape
|
|
1664
|
+
if (token = this.tokenizer.escape(src)) {
|
|
1665
|
+
src = src.substring(token.raw.length);
|
|
1666
|
+
tokens.push(token);
|
|
1667
|
+
continue;
|
|
1668
|
+
} // tag
|
|
738
1669
|
|
|
739
|
-
if (istask) {
|
|
740
|
-
ischecked = item[1] !== ' ';
|
|
741
|
-
item = item.replace(/^\[[ xX]\] +/, '');
|
|
742
|
-
}
|
|
743
1670
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
this.tokens.push(t); // Recurse.
|
|
1671
|
+
if (token = this.tokenizer.tag(src, inLink, inRawBlock)) {
|
|
1672
|
+
src = src.substring(token.raw.length);
|
|
1673
|
+
inLink = token.inLink;
|
|
1674
|
+
inRawBlock = token.inRawBlock;
|
|
1675
|
+
tokens.push(token);
|
|
1676
|
+
continue;
|
|
1677
|
+
} // link
|
|
752
1678
|
|
|
753
|
-
this.token(item, false);
|
|
754
|
-
this.tokens.push({
|
|
755
|
-
type: 'list_item_end'
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
1679
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
i = 0;
|
|
1680
|
+
if (token = this.tokenizer.link(src)) {
|
|
1681
|
+
src = src.substring(token.raw.length);
|
|
762
1682
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}
|
|
1683
|
+
if (token.type === 'link') {
|
|
1684
|
+
token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
|
|
766
1685
|
}
|
|
767
1686
|
|
|
768
|
-
|
|
769
|
-
type: 'list_end'
|
|
770
|
-
});
|
|
1687
|
+
tokens.push(token);
|
|
771
1688
|
continue;
|
|
772
|
-
} //
|
|
1689
|
+
} // reflink, nolink
|
|
773
1690
|
|
|
774
1691
|
|
|
775
|
-
if (
|
|
776
|
-
src = src.substring(
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
1692
|
+
if (token = this.tokenizer.reflink(src, this.tokens.links)) {
|
|
1693
|
+
src = src.substring(token.raw.length);
|
|
1694
|
+
|
|
1695
|
+
if (token.type === 'link') {
|
|
1696
|
+
token.tokens = this.inlineTokens(token.text, [], true, inRawBlock);
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
tokens.push(token);
|
|
782
1700
|
continue;
|
|
783
|
-
} //
|
|
1701
|
+
} // strong
|
|
784
1702
|
|
|
785
1703
|
|
|
786
|
-
if (
|
|
787
|
-
src = src.substring(
|
|
788
|
-
|
|
789
|
-
|
|
1704
|
+
if (token = this.tokenizer.strong(src, maskedSrc, prevChar)) {
|
|
1705
|
+
src = src.substring(token.raw.length);
|
|
1706
|
+
token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
|
|
1707
|
+
tokens.push(token);
|
|
1708
|
+
continue;
|
|
1709
|
+
} // em
|
|
790
1710
|
|
|
791
|
-
if (!this.tokens.links[tag]) {
|
|
792
|
-
this.tokens.links[tag] = {
|
|
793
|
-
href: cap[2],
|
|
794
|
-
title: cap[3]
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
1711
|
|
|
1712
|
+
if (token = this.tokenizer.em(src, maskedSrc, prevChar)) {
|
|
1713
|
+
src = src.substring(token.raw.length);
|
|
1714
|
+
token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
|
|
1715
|
+
tokens.push(token);
|
|
798
1716
|
continue;
|
|
799
|
-
} //
|
|
1717
|
+
} // code
|
|
800
1718
|
|
|
801
1719
|
|
|
802
|
-
if (
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
|
808
|
-
};
|
|
1720
|
+
if (token = this.tokenizer.codespan(src)) {
|
|
1721
|
+
src = src.substring(token.raw.length);
|
|
1722
|
+
tokens.push(token);
|
|
1723
|
+
continue;
|
|
1724
|
+
} // br
|
|
809
1725
|
|
|
810
|
-
if (item.header.length === item.align.length) {
|
|
811
|
-
src = src.substring(cap[0].length);
|
|
812
1726
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
|
819
|
-
item.align[i] = 'left';
|
|
820
|
-
} else {
|
|
821
|
-
item.align[i] = null;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
1727
|
+
if (token = this.tokenizer.br(src)) {
|
|
1728
|
+
src = src.substring(token.raw.length);
|
|
1729
|
+
tokens.push(token);
|
|
1730
|
+
continue;
|
|
1731
|
+
} // del (gfm)
|
|
824
1732
|
|
|
825
|
-
for (i = 0; i < item.cells.length; i++) {
|
|
826
|
-
item.cells[i] = splitCells$1(item.cells[i].replace(/^ *\| *| *\| *$/g, ''), item.header.length);
|
|
827
|
-
}
|
|
828
1733
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1734
|
+
if (token = this.tokenizer.del(src)) {
|
|
1735
|
+
src = src.substring(token.raw.length);
|
|
1736
|
+
token.tokens = this.inlineTokens(token.text, [], inLink, inRawBlock);
|
|
1737
|
+
tokens.push(token);
|
|
1738
|
+
continue;
|
|
1739
|
+
} // autolink
|
|
833
1740
|
|
|
834
1741
|
|
|
835
|
-
if (
|
|
836
|
-
src = src.substring(
|
|
837
|
-
|
|
838
|
-
type: 'heading',
|
|
839
|
-
depth: cap[2].charAt(0) === '=' ? 1 : 2,
|
|
840
|
-
text: cap[1]
|
|
841
|
-
});
|
|
1742
|
+
if (token = this.tokenizer.autolink(src, mangle)) {
|
|
1743
|
+
src = src.substring(token.raw.length);
|
|
1744
|
+
tokens.push(token);
|
|
842
1745
|
continue;
|
|
843
|
-
} //
|
|
1746
|
+
} // url (gfm)
|
|
844
1747
|
|
|
845
1748
|
|
|
846
|
-
if (
|
|
847
|
-
src = src.substring(
|
|
848
|
-
|
|
849
|
-
type: 'paragraph',
|
|
850
|
-
text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
|
|
851
|
-
});
|
|
1749
|
+
if (!inLink && (token = this.tokenizer.url(src, mangle))) {
|
|
1750
|
+
src = src.substring(token.raw.length);
|
|
1751
|
+
tokens.push(token);
|
|
852
1752
|
continue;
|
|
853
1753
|
} // text
|
|
854
1754
|
|
|
855
1755
|
|
|
856
|
-
if (
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
type: 'text',
|
|
861
|
-
text: cap[0]
|
|
862
|
-
});
|
|
1756
|
+
if (token = this.tokenizer.inlineText(src, inRawBlock, smartypants)) {
|
|
1757
|
+
src = src.substring(token.raw.length);
|
|
1758
|
+
prevChar = token.raw.slice(-1);
|
|
1759
|
+
tokens.push(token);
|
|
863
1760
|
continue;
|
|
864
1761
|
}
|
|
865
1762
|
|
|
866
1763
|
if (src) {
|
|
867
|
-
|
|
1764
|
+
var errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
|
|
1765
|
+
|
|
1766
|
+
if (this.options.silent) {
|
|
1767
|
+
console.error(errMsg);
|
|
1768
|
+
break;
|
|
1769
|
+
} else {
|
|
1770
|
+
throw new Error(errMsg);
|
|
1771
|
+
}
|
|
868
1772
|
}
|
|
869
1773
|
}
|
|
870
1774
|
|
|
871
|
-
return
|
|
1775
|
+
return tokens;
|
|
872
1776
|
};
|
|
873
1777
|
|
|
874
1778
|
_createClass(Lexer, null, [{
|
|
875
1779
|
key: "rules",
|
|
876
1780
|
get: function get() {
|
|
877
|
-
return
|
|
1781
|
+
return {
|
|
1782
|
+
block: block$1,
|
|
1783
|
+
inline: inline$1
|
|
1784
|
+
};
|
|
878
1785
|
}
|
|
879
1786
|
}]);
|
|
880
1787
|
|
|
881
1788
|
return Lexer;
|
|
882
1789
|
}();
|
|
883
1790
|
|
|
884
|
-
var defaults$
|
|
1791
|
+
var defaults$3 = defaults.defaults;
|
|
885
1792
|
var cleanUrl$1 = helpers.cleanUrl,
|
|
886
|
-
escape$
|
|
1793
|
+
escape$1 = helpers.escape;
|
|
887
1794
|
/**
|
|
888
1795
|
* Renderer
|
|
889
1796
|
*/
|
|
890
1797
|
|
|
891
|
-
var Renderer_1 =
|
|
892
|
-
/*#__PURE__*/
|
|
893
|
-
function () {
|
|
1798
|
+
var Renderer_1 = /*#__PURE__*/function () {
|
|
894
1799
|
function Renderer(options) {
|
|
895
|
-
this.options = options || defaults$
|
|
1800
|
+
this.options = options || defaults$3;
|
|
896
1801
|
}
|
|
897
1802
|
|
|
898
1803
|
var _proto = Renderer.prototype;
|
|
@@ -910,10 +1815,10 @@
|
|
|
910
1815
|
}
|
|
911
1816
|
|
|
912
1817
|
if (!lang) {
|
|
913
|
-
return '<pre><code>' + (escaped ? _code : escape$
|
|
1818
|
+
return '<pre><code>' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
|
|
914
1819
|
}
|
|
915
1820
|
|
|
916
|
-
return '<pre><code class="' + this.options.langPrefix + escape$
|
|
1821
|
+
return '<pre><code class="' + this.options.langPrefix + escape$1(lang, true) + '">' + (escaped ? _code : escape$1(_code, true)) + '</code></pre>\n';
|
|
917
1822
|
};
|
|
918
1823
|
|
|
919
1824
|
_proto.blockquote = function blockquote(quote) {
|
|
@@ -968,9 +1873,9 @@
|
|
|
968
1873
|
var type = flags.header ? 'th' : 'td';
|
|
969
1874
|
var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
|
|
970
1875
|
return tag + content + '</' + type + '>\n';
|
|
971
|
-
}
|
|
1876
|
+
} // span level renderer
|
|
1877
|
+
;
|
|
972
1878
|
|
|
973
|
-
// span level renderer
|
|
974
1879
|
_proto.strong = function strong(text) {
|
|
975
1880
|
return '<strong>' + text + '</strong>';
|
|
976
1881
|
};
|
|
@@ -998,388 +1903,45 @@
|
|
|
998
1903
|
return text;
|
|
999
1904
|
}
|
|
1000
1905
|
|
|
1001
|
-
var out = '<a href="' + escape$
|
|
1002
|
-
|
|
1003
|
-
if (title) {
|
|
1004
|
-
out += ' title="' + title + '"';
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
out += '>' + text + '</a>';
|
|
1008
|
-
return out;
|
|
1009
|
-
};
|
|
1010
|
-
|
|
1011
|
-
_proto.image = function image(href, title, text) {
|
|
1012
|
-
href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
|
|
1013
|
-
|
|
1014
|
-
if (href === null) {
|
|
1015
|
-
return text;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
var out = '<img src="' + href + '" alt="' + text + '"';
|
|
1019
|
-
|
|
1020
|
-
if (title) {
|
|
1021
|
-
out += ' title="' + title + '"';
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
out += this.options.xhtml ? '/>' : '>';
|
|
1025
|
-
return out;
|
|
1026
|
-
};
|
|
1027
|
-
|
|
1028
|
-
_proto.text = function text(_text) {
|
|
1029
|
-
return _text;
|
|
1030
|
-
};
|
|
1031
|
-
|
|
1032
|
-
return Renderer;
|
|
1033
|
-
}();
|
|
1034
|
-
|
|
1035
|
-
/**
|
|
1036
|
-
* Slugger generates header id
|
|
1037
|
-
*/
|
|
1038
|
-
var Slugger_1 =
|
|
1039
|
-
/*#__PURE__*/
|
|
1040
|
-
function () {
|
|
1041
|
-
function Slugger() {
|
|
1042
|
-
this.seen = {};
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Convert string to unique id
|
|
1046
|
-
*/
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
var _proto = Slugger.prototype;
|
|
1050
|
-
|
|
1051
|
-
_proto.slug = function slug(value) {
|
|
1052
|
-
var slug = value.toLowerCase().trim().replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
|
|
1053
|
-
|
|
1054
|
-
if (this.seen.hasOwnProperty(slug)) {
|
|
1055
|
-
var originalSlug = slug;
|
|
1056
|
-
|
|
1057
|
-
do {
|
|
1058
|
-
this.seen[originalSlug]++;
|
|
1059
|
-
slug = originalSlug + '-' + this.seen[originalSlug];
|
|
1060
|
-
} while (this.seen.hasOwnProperty(slug));
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
this.seen[slug] = 0;
|
|
1064
|
-
return slug;
|
|
1065
|
-
};
|
|
1066
|
-
|
|
1067
|
-
return Slugger;
|
|
1068
|
-
}();
|
|
1069
|
-
|
|
1070
|
-
var defaults$3 = defaults.defaults;
|
|
1071
|
-
var inline$1 = rules.inline;
|
|
1072
|
-
var findClosingBracket$1 = helpers.findClosingBracket,
|
|
1073
|
-
escape$3 = helpers.escape;
|
|
1074
|
-
/**
|
|
1075
|
-
* Inline Lexer & Compiler
|
|
1076
|
-
*/
|
|
1077
|
-
|
|
1078
|
-
var InlineLexer_1 =
|
|
1079
|
-
/*#__PURE__*/
|
|
1080
|
-
function () {
|
|
1081
|
-
function InlineLexer(links, options) {
|
|
1082
|
-
this.options = options || defaults$3;
|
|
1083
|
-
this.links = links;
|
|
1084
|
-
this.rules = inline$1.normal;
|
|
1085
|
-
this.options.renderer = this.options.renderer || new Renderer_1();
|
|
1086
|
-
this.renderer = this.options.renderer;
|
|
1087
|
-
this.renderer.options = this.options;
|
|
1088
|
-
|
|
1089
|
-
if (!this.links) {
|
|
1090
|
-
throw new Error('Tokens array requires a `links` property.');
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
if (this.options.pedantic) {
|
|
1094
|
-
this.rules = inline$1.pedantic;
|
|
1095
|
-
} else if (this.options.gfm) {
|
|
1096
|
-
if (this.options.breaks) {
|
|
1097
|
-
this.rules = inline$1.breaks;
|
|
1098
|
-
} else {
|
|
1099
|
-
this.rules = inline$1.gfm;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
/**
|
|
1104
|
-
* Expose Inline Rules
|
|
1105
|
-
*/
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
/**
|
|
1109
|
-
* Static Lexing/Compiling Method
|
|
1110
|
-
*/
|
|
1111
|
-
InlineLexer.output = function output(src, links, options) {
|
|
1112
|
-
var inline = new InlineLexer(links, options);
|
|
1113
|
-
return inline.output(src);
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Lexing/Compiling
|
|
1117
|
-
*/
|
|
1118
|
-
;
|
|
1119
|
-
|
|
1120
|
-
var _proto = InlineLexer.prototype;
|
|
1121
|
-
|
|
1122
|
-
_proto.output = function output(src) {
|
|
1123
|
-
var out = '',
|
|
1124
|
-
link,
|
|
1125
|
-
text,
|
|
1126
|
-
href,
|
|
1127
|
-
title,
|
|
1128
|
-
cap,
|
|
1129
|
-
prevCapZero;
|
|
1130
|
-
|
|
1131
|
-
while (src) {
|
|
1132
|
-
// escape
|
|
1133
|
-
if (cap = this.rules.escape.exec(src)) {
|
|
1134
|
-
src = src.substring(cap[0].length);
|
|
1135
|
-
out += escape$3(cap[1]);
|
|
1136
|
-
continue;
|
|
1137
|
-
} // tag
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
if (cap = this.rules.tag.exec(src)) {
|
|
1141
|
-
if (!this.inLink && /^<a /i.test(cap[0])) {
|
|
1142
|
-
this.inLink = true;
|
|
1143
|
-
} else if (this.inLink && /^<\/a>/i.test(cap[0])) {
|
|
1144
|
-
this.inLink = false;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
if (!this.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
1148
|
-
this.inRawBlock = true;
|
|
1149
|
-
} else if (this.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
|
|
1150
|
-
this.inRawBlock = false;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
src = src.substring(cap[0].length);
|
|
1154
|
-
out += this.renderer.html(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]);
|
|
1155
|
-
continue;
|
|
1156
|
-
} // link
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
if (cap = this.rules.link.exec(src)) {
|
|
1160
|
-
var lastParenIndex = findClosingBracket$1(cap[2], '()');
|
|
1161
|
-
|
|
1162
|
-
if (lastParenIndex > -1) {
|
|
1163
|
-
var start = cap[0].indexOf('!') === 0 ? 5 : 4;
|
|
1164
|
-
var linkLen = start + cap[1].length + lastParenIndex;
|
|
1165
|
-
cap[2] = cap[2].substring(0, lastParenIndex);
|
|
1166
|
-
cap[0] = cap[0].substring(0, linkLen).trim();
|
|
1167
|
-
cap[3] = '';
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
src = src.substring(cap[0].length);
|
|
1171
|
-
this.inLink = true;
|
|
1172
|
-
href = cap[2];
|
|
1173
|
-
|
|
1174
|
-
if (this.options.pedantic) {
|
|
1175
|
-
link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
|
|
1176
|
-
|
|
1177
|
-
if (link) {
|
|
1178
|
-
href = link[1];
|
|
1179
|
-
title = link[3];
|
|
1180
|
-
} else {
|
|
1181
|
-
title = '';
|
|
1182
|
-
}
|
|
1183
|
-
} else {
|
|
1184
|
-
title = cap[3] ? cap[3].slice(1, -1) : '';
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
href = href.trim().replace(/^<([\s\S]*)>$/, '$1');
|
|
1188
|
-
out += this.outputLink(cap, {
|
|
1189
|
-
href: InlineLexer.escapes(href),
|
|
1190
|
-
title: InlineLexer.escapes(title)
|
|
1191
|
-
});
|
|
1192
|
-
this.inLink = false;
|
|
1193
|
-
continue;
|
|
1194
|
-
} // reflink, nolink
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
if ((cap = this.rules.reflink.exec(src)) || (cap = this.rules.nolink.exec(src))) {
|
|
1198
|
-
src = src.substring(cap[0].length);
|
|
1199
|
-
link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
|
1200
|
-
link = this.links[link.toLowerCase()];
|
|
1201
|
-
|
|
1202
|
-
if (!link || !link.href) {
|
|
1203
|
-
out += cap[0].charAt(0);
|
|
1204
|
-
src = cap[0].substring(1) + src;
|
|
1205
|
-
continue;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
this.inLink = true;
|
|
1209
|
-
out += this.outputLink(cap, link);
|
|
1210
|
-
this.inLink = false;
|
|
1211
|
-
continue;
|
|
1212
|
-
} // strong
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
if (cap = this.rules.strong.exec(src)) {
|
|
1216
|
-
src = src.substring(cap[0].length);
|
|
1217
|
-
out += this.renderer.strong(this.output(cap[4] || cap[3] || cap[2] || cap[1]));
|
|
1218
|
-
continue;
|
|
1219
|
-
} // em
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
if (cap = this.rules.em.exec(src)) {
|
|
1223
|
-
src = src.substring(cap[0].length);
|
|
1224
|
-
out += this.renderer.em(this.output(cap[6] || cap[5] || cap[4] || cap[3] || cap[2] || cap[1]));
|
|
1225
|
-
continue;
|
|
1226
|
-
} // code
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
if (cap = this.rules.code.exec(src)) {
|
|
1230
|
-
src = src.substring(cap[0].length);
|
|
1231
|
-
out += this.renderer.codespan(escape$3(cap[2].trim(), true));
|
|
1232
|
-
continue;
|
|
1233
|
-
} // br
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
if (cap = this.rules.br.exec(src)) {
|
|
1237
|
-
src = src.substring(cap[0].length);
|
|
1238
|
-
out += this.renderer.br();
|
|
1239
|
-
continue;
|
|
1240
|
-
} // del (gfm)
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
if (cap = this.rules.del.exec(src)) {
|
|
1244
|
-
src = src.substring(cap[0].length);
|
|
1245
|
-
out += this.renderer.del(this.output(cap[1]));
|
|
1246
|
-
continue;
|
|
1247
|
-
} // autolink
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
if (cap = this.rules.autolink.exec(src)) {
|
|
1251
|
-
src = src.substring(cap[0].length);
|
|
1252
|
-
|
|
1253
|
-
if (cap[2] === '@') {
|
|
1254
|
-
text = escape$3(this.mangle(cap[1]));
|
|
1255
|
-
href = 'mailto:' + text;
|
|
1256
|
-
} else {
|
|
1257
|
-
text = escape$3(cap[1]);
|
|
1258
|
-
href = text;
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
out += this.renderer.link(href, null, text);
|
|
1262
|
-
continue;
|
|
1263
|
-
} // url (gfm)
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
if (!this.inLink && (cap = this.rules.url.exec(src))) {
|
|
1267
|
-
if (cap[2] === '@') {
|
|
1268
|
-
text = escape$3(cap[0]);
|
|
1269
|
-
href = 'mailto:' + text;
|
|
1270
|
-
} else {
|
|
1271
|
-
// do extended autolink path validation
|
|
1272
|
-
do {
|
|
1273
|
-
prevCapZero = cap[0];
|
|
1274
|
-
cap[0] = this.rules._backpedal.exec(cap[0])[0];
|
|
1275
|
-
} while (prevCapZero !== cap[0]);
|
|
1276
|
-
|
|
1277
|
-
text = escape$3(cap[0]);
|
|
1278
|
-
|
|
1279
|
-
if (cap[1] === 'www.') {
|
|
1280
|
-
href = 'http://' + text;
|
|
1281
|
-
} else {
|
|
1282
|
-
href = text;
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
src = src.substring(cap[0].length);
|
|
1287
|
-
out += this.renderer.link(href, null, text);
|
|
1288
|
-
continue;
|
|
1289
|
-
} // text
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
if (cap = this.rules.text.exec(src)) {
|
|
1293
|
-
src = src.substring(cap[0].length);
|
|
1294
|
-
|
|
1295
|
-
if (this.inRawBlock) {
|
|
1296
|
-
out += this.renderer.text(this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape$3(cap[0]) : cap[0]);
|
|
1297
|
-
} else {
|
|
1298
|
-
out += this.renderer.text(escape$3(this.smartypants(cap[0])));
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
continue;
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
if (src) {
|
|
1305
|
-
throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
return out;
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
|
-
InlineLexer.escapes = function escapes(text) {
|
|
1313
|
-
return text ? text.replace(InlineLexer.rules._escapes, '$1') : text;
|
|
1314
|
-
}
|
|
1315
|
-
/**
|
|
1316
|
-
* Compile Link
|
|
1317
|
-
*/
|
|
1318
|
-
;
|
|
1906
|
+
var out = '<a href="' + escape$1(href) + '"';
|
|
1319
1907
|
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) : this.renderer.image(href, title, escape$3(cap[1]));
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* Smartypants Transformations
|
|
1327
|
-
*/
|
|
1328
|
-
;
|
|
1908
|
+
if (title) {
|
|
1909
|
+
out += ' title="' + title + '"';
|
|
1910
|
+
}
|
|
1329
1911
|
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
.replace(/---/g, "\u2014") // en-dashes
|
|
1334
|
-
.replace(/--/g, "\u2013") // opening singles
|
|
1335
|
-
.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018") // closing singles & apostrophes
|
|
1336
|
-
.replace(/'/g, "\u2019") // opening doubles
|
|
1337
|
-
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C") // closing doubles
|
|
1338
|
-
.replace(/"/g, "\u201D") // ellipses
|
|
1339
|
-
.replace(/\.{3}/g, "\u2026");
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Mangle Links
|
|
1343
|
-
*/
|
|
1344
|
-
;
|
|
1912
|
+
out += '>' + text + '</a>';
|
|
1913
|
+
return out;
|
|
1914
|
+
};
|
|
1345
1915
|
|
|
1346
|
-
_proto.
|
|
1347
|
-
|
|
1348
|
-
var l = text.length;
|
|
1349
|
-
var out = '',
|
|
1350
|
-
i = 0,
|
|
1351
|
-
ch;
|
|
1916
|
+
_proto.image = function image(href, title, text) {
|
|
1917
|
+
href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
|
|
1352
1918
|
|
|
1353
|
-
|
|
1354
|
-
|
|
1919
|
+
if (href === null) {
|
|
1920
|
+
return text;
|
|
1921
|
+
}
|
|
1355
1922
|
|
|
1356
|
-
|
|
1357
|
-
ch = 'x' + ch.toString(16);
|
|
1358
|
-
}
|
|
1923
|
+
var out = '<img src="' + href + '" alt="' + text + '"';
|
|
1359
1924
|
|
|
1360
|
-
|
|
1925
|
+
if (title) {
|
|
1926
|
+
out += ' title="' + title + '"';
|
|
1361
1927
|
}
|
|
1362
1928
|
|
|
1929
|
+
out += this.options.xhtml ? '/>' : '>';
|
|
1363
1930
|
return out;
|
|
1364
1931
|
};
|
|
1365
1932
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
return inline$1;
|
|
1370
|
-
}
|
|
1371
|
-
}]);
|
|
1933
|
+
_proto.text = function text(_text) {
|
|
1934
|
+
return _text;
|
|
1935
|
+
};
|
|
1372
1936
|
|
|
1373
|
-
return
|
|
1937
|
+
return Renderer;
|
|
1374
1938
|
}();
|
|
1375
1939
|
|
|
1376
1940
|
/**
|
|
1377
1941
|
* TextRenderer
|
|
1378
1942
|
* returns only the textual part of the token
|
|
1379
1943
|
*/
|
|
1380
|
-
var TextRenderer_1 =
|
|
1381
|
-
/*#__PURE__*/
|
|
1382
|
-
function () {
|
|
1944
|
+
var TextRenderer_1 = /*#__PURE__*/function () {
|
|
1383
1945
|
function TextRenderer() {}
|
|
1384
1946
|
|
|
1385
1947
|
var _proto = TextRenderer.prototype;
|
|
@@ -1401,6 +1963,10 @@
|
|
|
1401
1963
|
return text;
|
|
1402
1964
|
};
|
|
1403
1965
|
|
|
1966
|
+
_proto.html = function html(text) {
|
|
1967
|
+
return text;
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1404
1970
|
_proto.text = function text(_text) {
|
|
1405
1971
|
return _text;
|
|
1406
1972
|
};
|
|
@@ -1420,23 +1986,54 @@
|
|
|
1420
1986
|
return TextRenderer;
|
|
1421
1987
|
}();
|
|
1422
1988
|
|
|
1989
|
+
/**
|
|
1990
|
+
* Slugger generates header id
|
|
1991
|
+
*/
|
|
1992
|
+
var Slugger_1 = /*#__PURE__*/function () {
|
|
1993
|
+
function Slugger() {
|
|
1994
|
+
this.seen = {};
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* Convert string to unique id
|
|
1998
|
+
*/
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
var _proto = Slugger.prototype;
|
|
2002
|
+
|
|
2003
|
+
_proto.slug = function slug(value) {
|
|
2004
|
+
var slug = value.toLowerCase().trim() // remove html tags
|
|
2005
|
+
.replace(/<[!\/a-z].*?>/ig, '') // remove unwanted chars
|
|
2006
|
+
.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, '').replace(/\s/g, '-');
|
|
2007
|
+
|
|
2008
|
+
if (this.seen.hasOwnProperty(slug)) {
|
|
2009
|
+
var originalSlug = slug;
|
|
2010
|
+
|
|
2011
|
+
do {
|
|
2012
|
+
this.seen[originalSlug]++;
|
|
2013
|
+
slug = originalSlug + '-' + this.seen[originalSlug];
|
|
2014
|
+
} while (this.seen.hasOwnProperty(slug));
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
this.seen[slug] = 0;
|
|
2018
|
+
return slug;
|
|
2019
|
+
};
|
|
2020
|
+
|
|
2021
|
+
return Slugger;
|
|
2022
|
+
}();
|
|
2023
|
+
|
|
1423
2024
|
var defaults$4 = defaults.defaults;
|
|
1424
|
-
var
|
|
1425
|
-
unescape$1 = helpers.unescape;
|
|
2025
|
+
var unescape$1 = helpers.unescape;
|
|
1426
2026
|
/**
|
|
1427
2027
|
* Parsing & Compiling
|
|
1428
2028
|
*/
|
|
1429
2029
|
|
|
1430
|
-
var Parser_1 =
|
|
1431
|
-
/*#__PURE__*/
|
|
1432
|
-
function () {
|
|
2030
|
+
var Parser_1 = /*#__PURE__*/function () {
|
|
1433
2031
|
function Parser(options) {
|
|
1434
|
-
this.tokens = [];
|
|
1435
|
-
this.token = null;
|
|
1436
2032
|
this.options = options || defaults$4;
|
|
1437
2033
|
this.options.renderer = this.options.renderer || new Renderer_1();
|
|
1438
2034
|
this.renderer = this.options.renderer;
|
|
1439
2035
|
this.renderer.options = this.options;
|
|
2036
|
+
this.textRenderer = new TextRenderer_1();
|
|
1440
2037
|
this.slugger = new Slugger_1();
|
|
1441
2038
|
}
|
|
1442
2039
|
/**
|
|
@@ -1447,209 +2044,295 @@
|
|
|
1447
2044
|
Parser.parse = function parse(tokens, options) {
|
|
1448
2045
|
var parser = new Parser(options);
|
|
1449
2046
|
return parser.parse(tokens);
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
var _proto = Parser.prototype;
|
|
1453
|
-
|
|
2047
|
+
}
|
|
1454
2048
|
/**
|
|
1455
2049
|
* Parse Loop
|
|
1456
2050
|
*/
|
|
1457
|
-
|
|
1458
|
-
this.inline = new InlineLexer_1(tokens.links, this.options); // use an InlineLexer with a TextRenderer to extract pure text
|
|
2051
|
+
;
|
|
1459
2052
|
|
|
1460
|
-
|
|
1461
|
-
renderer: new TextRenderer_1()
|
|
1462
|
-
}));
|
|
1463
|
-
this.tokens = tokens.reverse();
|
|
1464
|
-
var out = '';
|
|
2053
|
+
var _proto = Parser.prototype;
|
|
1465
2054
|
|
|
1466
|
-
|
|
1467
|
-
|
|
2055
|
+
_proto.parse = function parse(tokens, top) {
|
|
2056
|
+
if (top === void 0) {
|
|
2057
|
+
top = true;
|
|
1468
2058
|
}
|
|
1469
2059
|
|
|
1470
|
-
|
|
1471
|
-
|
|
2060
|
+
var out = '',
|
|
2061
|
+
i,
|
|
2062
|
+
j,
|
|
2063
|
+
k,
|
|
2064
|
+
l2,
|
|
2065
|
+
l3,
|
|
2066
|
+
row,
|
|
2067
|
+
cell,
|
|
2068
|
+
header,
|
|
2069
|
+
body,
|
|
2070
|
+
token,
|
|
2071
|
+
ordered,
|
|
2072
|
+
start,
|
|
2073
|
+
loose,
|
|
2074
|
+
itemBody,
|
|
2075
|
+
item,
|
|
2076
|
+
checked,
|
|
2077
|
+
task,
|
|
2078
|
+
checkbox;
|
|
2079
|
+
var l = tokens.length;
|
|
2080
|
+
|
|
2081
|
+
for (i = 0; i < l; i++) {
|
|
2082
|
+
token = tokens[i];
|
|
2083
|
+
|
|
2084
|
+
switch (token.type) {
|
|
2085
|
+
case 'space':
|
|
2086
|
+
{
|
|
2087
|
+
continue;
|
|
2088
|
+
}
|
|
1472
2089
|
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
return this.token;
|
|
1479
|
-
};
|
|
2090
|
+
case 'hr':
|
|
2091
|
+
{
|
|
2092
|
+
out += this.renderer.hr();
|
|
2093
|
+
continue;
|
|
2094
|
+
}
|
|
1480
2095
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
};
|
|
2096
|
+
case 'heading':
|
|
2097
|
+
{
|
|
2098
|
+
out += this.renderer.heading(this.parseInline(token.tokens), token.depth, unescape$1(this.parseInline(token.tokens, this.textRenderer)), this.slugger);
|
|
2099
|
+
continue;
|
|
2100
|
+
}
|
|
1487
2101
|
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
2102
|
+
case 'code':
|
|
2103
|
+
{
|
|
2104
|
+
out += this.renderer.code(token.text, token.lang, token.escaped);
|
|
2105
|
+
continue;
|
|
2106
|
+
}
|
|
1493
2107
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
2108
|
+
case 'table':
|
|
2109
|
+
{
|
|
2110
|
+
header = ''; // header
|
|
1497
2111
|
|
|
1498
|
-
|
|
1499
|
-
|
|
2112
|
+
cell = '';
|
|
2113
|
+
l2 = token.header.length;
|
|
1500
2114
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
2115
|
+
for (j = 0; j < l2; j++) {
|
|
2116
|
+
cell += this.renderer.tablecell(this.parseInline(token.tokens.header[j]), {
|
|
2117
|
+
header: true,
|
|
2118
|
+
align: token.align[j]
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
1506
2121
|
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
return '';
|
|
1511
|
-
}
|
|
2122
|
+
header += this.renderer.tablerow(cell);
|
|
2123
|
+
body = '';
|
|
2124
|
+
l2 = token.cells.length;
|
|
1512
2125
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
2126
|
+
for (j = 0; j < l2; j++) {
|
|
2127
|
+
row = token.tokens.cells[j];
|
|
2128
|
+
cell = '';
|
|
2129
|
+
l3 = row.length;
|
|
1517
2130
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
2131
|
+
for (k = 0; k < l3; k++) {
|
|
2132
|
+
cell += this.renderer.tablecell(this.parseInline(row[k]), {
|
|
2133
|
+
header: false,
|
|
2134
|
+
align: token.align[k]
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
1522
2137
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
return this.renderer.code(this.token.text, this.token.lang, this.token.escaped);
|
|
1526
|
-
}
|
|
2138
|
+
body += this.renderer.tablerow(cell);
|
|
2139
|
+
}
|
|
1527
2140
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
var header = '',
|
|
1531
|
-
i,
|
|
1532
|
-
row,
|
|
1533
|
-
cell,
|
|
1534
|
-
j; // header
|
|
1535
|
-
|
|
1536
|
-
cell = '';
|
|
1537
|
-
|
|
1538
|
-
for (i = 0; i < this.token.header.length; i++) {
|
|
1539
|
-
cell += this.renderer.tablecell(this.inline.output(this.token.header[i]), {
|
|
1540
|
-
header: true,
|
|
1541
|
-
align: this.token.align[i]
|
|
1542
|
-
});
|
|
2141
|
+
out += this.renderer.table(header, body);
|
|
2142
|
+
continue;
|
|
1543
2143
|
}
|
|
1544
2144
|
|
|
1545
|
-
|
|
2145
|
+
case 'blockquote':
|
|
2146
|
+
{
|
|
2147
|
+
body = this.parse(token.tokens);
|
|
2148
|
+
out += this.renderer.blockquote(body);
|
|
2149
|
+
continue;
|
|
2150
|
+
}
|
|
1546
2151
|
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
2152
|
+
case 'list':
|
|
2153
|
+
{
|
|
2154
|
+
ordered = token.ordered;
|
|
2155
|
+
start = token.start;
|
|
2156
|
+
loose = token.loose;
|
|
2157
|
+
l2 = token.items.length;
|
|
2158
|
+
body = '';
|
|
2159
|
+
|
|
2160
|
+
for (j = 0; j < l2; j++) {
|
|
2161
|
+
item = token.items[j];
|
|
2162
|
+
checked = item.checked;
|
|
2163
|
+
task = item.task;
|
|
2164
|
+
itemBody = '';
|
|
2165
|
+
|
|
2166
|
+
if (item.task) {
|
|
2167
|
+
checkbox = this.renderer.checkbox(checked);
|
|
2168
|
+
|
|
2169
|
+
if (loose) {
|
|
2170
|
+
if (item.tokens.length > 0 && item.tokens[0].type === 'text') {
|
|
2171
|
+
item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
|
|
2172
|
+
|
|
2173
|
+
if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
|
|
2174
|
+
item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
|
|
2175
|
+
}
|
|
2176
|
+
} else {
|
|
2177
|
+
item.tokens.unshift({
|
|
2178
|
+
type: 'text',
|
|
2179
|
+
text: checkbox
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
} else {
|
|
2183
|
+
itemBody += checkbox;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
1550
2186
|
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
header: false,
|
|
1554
|
-
align: this.token.align[j]
|
|
1555
|
-
});
|
|
2187
|
+
itemBody += this.parse(item.tokens, loose);
|
|
2188
|
+
body += this.renderer.listitem(itemBody, task, checked);
|
|
1556
2189
|
}
|
|
1557
2190
|
|
|
1558
|
-
|
|
2191
|
+
out += this.renderer.list(body, ordered, start);
|
|
2192
|
+
continue;
|
|
1559
2193
|
}
|
|
1560
2194
|
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
2195
|
+
case 'html':
|
|
2196
|
+
{
|
|
2197
|
+
// TODO parse inline content if parameter markdown=1
|
|
2198
|
+
out += this.renderer.html(token.text);
|
|
2199
|
+
continue;
|
|
2200
|
+
}
|
|
1567
2201
|
|
|
1568
|
-
|
|
1569
|
-
|
|
2202
|
+
case 'paragraph':
|
|
2203
|
+
{
|
|
2204
|
+
out += this.renderer.paragraph(this.parseInline(token.tokens));
|
|
2205
|
+
continue;
|
|
1570
2206
|
}
|
|
1571
2207
|
|
|
1572
|
-
|
|
1573
|
-
|
|
2208
|
+
case 'text':
|
|
2209
|
+
{
|
|
2210
|
+
body = token.tokens ? this.parseInline(token.tokens) : token.text;
|
|
1574
2211
|
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
start = this.token.start;
|
|
2212
|
+
while (i + 1 < l && tokens[i + 1].type === 'text') {
|
|
2213
|
+
token = tokens[++i];
|
|
2214
|
+
body += '\n' + (token.tokens ? this.parseInline(token.tokens) : token.text);
|
|
2215
|
+
}
|
|
1580
2216
|
|
|
1581
|
-
|
|
1582
|
-
|
|
2217
|
+
out += top ? this.renderer.paragraph(body) : body;
|
|
2218
|
+
continue;
|
|
1583
2219
|
}
|
|
1584
2220
|
|
|
1585
|
-
|
|
1586
|
-
|
|
2221
|
+
default:
|
|
2222
|
+
{
|
|
2223
|
+
var errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
1587
2224
|
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
var loose = this.token.loose;
|
|
1592
|
-
var checked = this.token.checked;
|
|
1593
|
-
var task = this.token.task;
|
|
1594
|
-
|
|
1595
|
-
if (this.token.task) {
|
|
1596
|
-
if (loose) {
|
|
1597
|
-
if (this.peek().type === 'text') {
|
|
1598
|
-
var nextToken = this.peek();
|
|
1599
|
-
nextToken.text = this.renderer.checkbox(checked) + ' ' + nextToken.text;
|
|
1600
|
-
} else {
|
|
1601
|
-
this.tokens.push({
|
|
1602
|
-
type: 'text',
|
|
1603
|
-
text: this.renderer.checkbox(checked)
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
2225
|
+
if (this.options.silent) {
|
|
2226
|
+
console.error(errMsg);
|
|
2227
|
+
return;
|
|
1606
2228
|
} else {
|
|
1607
|
-
|
|
2229
|
+
throw new Error(errMsg);
|
|
1608
2230
|
}
|
|
1609
2231
|
}
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
return out;
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Parse Inline Tokens
|
|
2239
|
+
*/
|
|
2240
|
+
;
|
|
2241
|
+
|
|
2242
|
+
_proto.parseInline = function parseInline(tokens, renderer) {
|
|
2243
|
+
renderer = renderer || this.renderer;
|
|
2244
|
+
var out = '',
|
|
2245
|
+
i,
|
|
2246
|
+
token;
|
|
2247
|
+
var l = tokens.length;
|
|
2248
|
+
|
|
2249
|
+
for (i = 0; i < l; i++) {
|
|
2250
|
+
token = tokens[i];
|
|
2251
|
+
|
|
2252
|
+
switch (token.type) {
|
|
2253
|
+
case 'escape':
|
|
2254
|
+
{
|
|
2255
|
+
out += renderer.text(token.text);
|
|
2256
|
+
break;
|
|
2257
|
+
}
|
|
1610
2258
|
|
|
1611
|
-
|
|
1612
|
-
|
|
2259
|
+
case 'html':
|
|
2260
|
+
{
|
|
2261
|
+
out += renderer.html(token.text);
|
|
2262
|
+
break;
|
|
1613
2263
|
}
|
|
1614
2264
|
|
|
1615
|
-
|
|
1616
|
-
|
|
2265
|
+
case 'link':
|
|
2266
|
+
{
|
|
2267
|
+
out += renderer.link(token.href, token.title, this.parseInline(token.tokens, renderer));
|
|
2268
|
+
break;
|
|
2269
|
+
}
|
|
1617
2270
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
2271
|
+
case 'image':
|
|
2272
|
+
{
|
|
2273
|
+
out += renderer.image(token.href, token.title, token.text);
|
|
2274
|
+
break;
|
|
2275
|
+
}
|
|
1623
2276
|
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
2277
|
+
case 'strong':
|
|
2278
|
+
{
|
|
2279
|
+
out += renderer.strong(this.parseInline(token.tokens, renderer));
|
|
2280
|
+
break;
|
|
2281
|
+
}
|
|
1628
2282
|
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
2283
|
+
case 'em':
|
|
2284
|
+
{
|
|
2285
|
+
out += renderer.em(this.parseInline(token.tokens, renderer));
|
|
2286
|
+
break;
|
|
2287
|
+
}
|
|
1633
2288
|
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
2289
|
+
case 'codespan':
|
|
2290
|
+
{
|
|
2291
|
+
out += renderer.codespan(token.text);
|
|
2292
|
+
break;
|
|
2293
|
+
}
|
|
1637
2294
|
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
2295
|
+
case 'br':
|
|
2296
|
+
{
|
|
2297
|
+
out += renderer.br();
|
|
2298
|
+
break;
|
|
1642
2299
|
}
|
|
1643
|
-
|
|
2300
|
+
|
|
2301
|
+
case 'del':
|
|
2302
|
+
{
|
|
2303
|
+
out += renderer.del(this.parseInline(token.tokens, renderer));
|
|
2304
|
+
break;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
case 'text':
|
|
2308
|
+
{
|
|
2309
|
+
out += renderer.text(token.text);
|
|
2310
|
+
break;
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
default:
|
|
2314
|
+
{
|
|
2315
|
+
var errMsg = 'Token with "' + token.type + '" type was not found.';
|
|
2316
|
+
|
|
2317
|
+
if (this.options.silent) {
|
|
2318
|
+
console.error(errMsg);
|
|
2319
|
+
return;
|
|
2320
|
+
} else {
|
|
2321
|
+
throw new Error(errMsg);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
1644
2325
|
}
|
|
2326
|
+
|
|
2327
|
+
return out;
|
|
1645
2328
|
};
|
|
1646
2329
|
|
|
1647
2330
|
return Parser;
|
|
1648
2331
|
}();
|
|
1649
2332
|
|
|
1650
|
-
var merge$
|
|
2333
|
+
var merge$2 = helpers.merge,
|
|
1651
2334
|
checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
|
|
1652
|
-
escape$
|
|
2335
|
+
escape$2 = helpers.escape;
|
|
1653
2336
|
var getDefaults = defaults.getDefaults,
|
|
1654
2337
|
changeDefaults = defaults.changeDefaults,
|
|
1655
2338
|
defaults$5 = defaults.defaults;
|
|
@@ -1667,96 +2350,90 @@
|
|
|
1667
2350
|
throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
|
1668
2351
|
}
|
|
1669
2352
|
|
|
1670
|
-
if (
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
opt = null;
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
opt = merge$3({}, marked.defaults, opt || {});
|
|
1678
|
-
checkSanitizeDeprecation$1(opt);
|
|
1679
|
-
var highlight = opt.highlight;
|
|
1680
|
-
var tokens,
|
|
1681
|
-
pending,
|
|
1682
|
-
i = 0;
|
|
2353
|
+
if (typeof opt === 'function') {
|
|
2354
|
+
callback = opt;
|
|
2355
|
+
opt = null;
|
|
2356
|
+
}
|
|
1683
2357
|
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
} catch (e) {
|
|
1687
|
-
return {
|
|
1688
|
-
v: callback(e)
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
2358
|
+
opt = merge$2({}, marked.defaults, opt || {});
|
|
2359
|
+
checkSanitizeDeprecation$1(opt);
|
|
1691
2360
|
|
|
1692
|
-
|
|
2361
|
+
if (callback) {
|
|
2362
|
+
var highlight = opt.highlight;
|
|
2363
|
+
var tokens;
|
|
1693
2364
|
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
2365
|
+
try {
|
|
2366
|
+
tokens = Lexer_1.lex(src, opt);
|
|
2367
|
+
} catch (e) {
|
|
2368
|
+
return callback(e);
|
|
2369
|
+
}
|
|
1699
2370
|
|
|
1700
|
-
|
|
2371
|
+
var done = function done(err) {
|
|
2372
|
+
var out;
|
|
1701
2373
|
|
|
2374
|
+
if (!err) {
|
|
1702
2375
|
try {
|
|
1703
2376
|
out = Parser_1.parse(tokens, opt);
|
|
1704
2377
|
} catch (e) {
|
|
1705
2378
|
err = e;
|
|
1706
2379
|
}
|
|
1707
|
-
|
|
1708
|
-
opt.highlight = highlight;
|
|
1709
|
-
return err ? callback(err) : callback(null, out);
|
|
1710
|
-
};
|
|
1711
|
-
|
|
1712
|
-
if (!highlight || highlight.length < 3) {
|
|
1713
|
-
return {
|
|
1714
|
-
v: done()
|
|
1715
|
-
};
|
|
1716
2380
|
}
|
|
1717
2381
|
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
};
|
|
2382
|
+
opt.highlight = highlight;
|
|
2383
|
+
return err ? callback(err) : callback(null, out);
|
|
2384
|
+
};
|
|
1722
2385
|
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
return --pending || done();
|
|
1727
|
-
}
|
|
2386
|
+
if (!highlight || highlight.length < 3) {
|
|
2387
|
+
return done();
|
|
2388
|
+
}
|
|
1728
2389
|
|
|
1729
|
-
|
|
1730
|
-
|
|
2390
|
+
delete opt.highlight;
|
|
2391
|
+
if (!tokens.length) return done();
|
|
2392
|
+
var pending = 0;
|
|
2393
|
+
marked.walkTokens(tokens, function (token) {
|
|
2394
|
+
if (token.type === 'code') {
|
|
2395
|
+
pending++;
|
|
2396
|
+
setTimeout(function () {
|
|
2397
|
+
highlight(token.text, token.lang, function (err, code) {
|
|
2398
|
+
if (err) {
|
|
2399
|
+
return done(err);
|
|
2400
|
+
}
|
|
1731
2401
|
|
|
1732
|
-
if (code
|
|
1733
|
-
|
|
2402
|
+
if (code != null && code !== token.text) {
|
|
2403
|
+
token.text = code;
|
|
2404
|
+
token.escaped = true;
|
|
1734
2405
|
}
|
|
1735
2406
|
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
2407
|
+
pending--;
|
|
2408
|
+
|
|
2409
|
+
if (pending === 0) {
|
|
2410
|
+
done();
|
|
2411
|
+
}
|
|
1739
2412
|
});
|
|
1740
|
-
})
|
|
2413
|
+
}, 0);
|
|
1741
2414
|
}
|
|
2415
|
+
});
|
|
1742
2416
|
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
}();
|
|
2417
|
+
if (pending === 0) {
|
|
2418
|
+
done();
|
|
2419
|
+
}
|
|
1747
2420
|
|
|
1748
|
-
|
|
2421
|
+
return;
|
|
1749
2422
|
}
|
|
1750
2423
|
|
|
1751
2424
|
try {
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
2425
|
+
var _tokens = Lexer_1.lex(src, opt);
|
|
2426
|
+
|
|
2427
|
+
if (opt.walkTokens) {
|
|
2428
|
+
marked.walkTokens(_tokens, opt.walkTokens);
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
return Parser_1.parse(_tokens, opt);
|
|
1755
2432
|
} catch (e) {
|
|
1756
2433
|
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
|
1757
2434
|
|
|
1758
|
-
if (
|
|
1759
|
-
return '<p>An error occurred:</p><pre>' + escape$
|
|
2435
|
+
if (opt.silent) {
|
|
2436
|
+
return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
|
|
1760
2437
|
}
|
|
1761
2438
|
|
|
1762
2439
|
throw e;
|
|
@@ -1768,25 +2445,151 @@
|
|
|
1768
2445
|
|
|
1769
2446
|
|
|
1770
2447
|
marked.options = marked.setOptions = function (opt) {
|
|
1771
|
-
merge$
|
|
2448
|
+
merge$2(marked.defaults, opt);
|
|
1772
2449
|
changeDefaults(marked.defaults);
|
|
1773
2450
|
return marked;
|
|
1774
2451
|
};
|
|
1775
2452
|
|
|
1776
2453
|
marked.getDefaults = getDefaults;
|
|
1777
2454
|
marked.defaults = defaults$5;
|
|
2455
|
+
/**
|
|
2456
|
+
* Use Extension
|
|
2457
|
+
*/
|
|
2458
|
+
|
|
2459
|
+
marked.use = function (extension) {
|
|
2460
|
+
var opts = merge$2({}, extension);
|
|
2461
|
+
|
|
2462
|
+
if (extension.renderer) {
|
|
2463
|
+
(function () {
|
|
2464
|
+
var renderer = marked.defaults.renderer || new Renderer_1();
|
|
2465
|
+
|
|
2466
|
+
var _loop = function _loop(prop) {
|
|
2467
|
+
var prevRenderer = renderer[prop];
|
|
2468
|
+
|
|
2469
|
+
renderer[prop] = function () {
|
|
2470
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2471
|
+
args[_key] = arguments[_key];
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
var ret = extension.renderer[prop].apply(renderer, args);
|
|
2475
|
+
|
|
2476
|
+
if (ret === false) {
|
|
2477
|
+
ret = prevRenderer.apply(renderer, args);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
return ret;
|
|
2481
|
+
};
|
|
2482
|
+
};
|
|
2483
|
+
|
|
2484
|
+
for (var prop in extension.renderer) {
|
|
2485
|
+
_loop(prop);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
opts.renderer = renderer;
|
|
2489
|
+
})();
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
if (extension.tokenizer) {
|
|
2493
|
+
(function () {
|
|
2494
|
+
var tokenizer = marked.defaults.tokenizer || new Tokenizer_1();
|
|
2495
|
+
|
|
2496
|
+
var _loop2 = function _loop2(prop) {
|
|
2497
|
+
var prevTokenizer = tokenizer[prop];
|
|
2498
|
+
|
|
2499
|
+
tokenizer[prop] = function () {
|
|
2500
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2501
|
+
args[_key2] = arguments[_key2];
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
var ret = extension.tokenizer[prop].apply(tokenizer, args);
|
|
2505
|
+
|
|
2506
|
+
if (ret === false) {
|
|
2507
|
+
ret = prevTokenizer.apply(tokenizer, args);
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
return ret;
|
|
2511
|
+
};
|
|
2512
|
+
};
|
|
2513
|
+
|
|
2514
|
+
for (var prop in extension.tokenizer) {
|
|
2515
|
+
_loop2(prop);
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
opts.tokenizer = tokenizer;
|
|
2519
|
+
})();
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
if (extension.walkTokens) {
|
|
2523
|
+
var walkTokens = marked.defaults.walkTokens;
|
|
2524
|
+
|
|
2525
|
+
opts.walkTokens = function (token) {
|
|
2526
|
+
extension.walkTokens(token);
|
|
2527
|
+
|
|
2528
|
+
if (walkTokens) {
|
|
2529
|
+
walkTokens(token);
|
|
2530
|
+
}
|
|
2531
|
+
};
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
marked.setOptions(opts);
|
|
2535
|
+
};
|
|
2536
|
+
/**
|
|
2537
|
+
* Run callback for every token
|
|
2538
|
+
*/
|
|
2539
|
+
|
|
2540
|
+
|
|
2541
|
+
marked.walkTokens = function (tokens, callback) {
|
|
2542
|
+
for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
|
|
2543
|
+
var token = _step.value;
|
|
2544
|
+
callback(token);
|
|
2545
|
+
|
|
2546
|
+
switch (token.type) {
|
|
2547
|
+
case 'table':
|
|
2548
|
+
{
|
|
2549
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(token.tokens.header), _step2; !(_step2 = _iterator2()).done;) {
|
|
2550
|
+
var cell = _step2.value;
|
|
2551
|
+
marked.walkTokens(cell, callback);
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(token.tokens.cells), _step3; !(_step3 = _iterator3()).done;) {
|
|
2555
|
+
var row = _step3.value;
|
|
2556
|
+
|
|
2557
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
|
|
2558
|
+
var _cell = _step4.value;
|
|
2559
|
+
marked.walkTokens(_cell, callback);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
break;
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
case 'list':
|
|
2567
|
+
{
|
|
2568
|
+
marked.walkTokens(token.items, callback);
|
|
2569
|
+
break;
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
default:
|
|
2573
|
+
{
|
|
2574
|
+
if (token.tokens) {
|
|
2575
|
+
marked.walkTokens(token.tokens, callback);
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
};
|
|
1778
2581
|
/**
|
|
1779
2582
|
* Expose
|
|
1780
2583
|
*/
|
|
1781
2584
|
|
|
2585
|
+
|
|
1782
2586
|
marked.Parser = Parser_1;
|
|
1783
2587
|
marked.parser = Parser_1.parse;
|
|
1784
2588
|
marked.Renderer = Renderer_1;
|
|
1785
2589
|
marked.TextRenderer = TextRenderer_1;
|
|
1786
2590
|
marked.Lexer = Lexer_1;
|
|
1787
2591
|
marked.lexer = Lexer_1.lex;
|
|
1788
|
-
marked.
|
|
1789
|
-
marked.inlineLexer = InlineLexer_1.output;
|
|
2592
|
+
marked.Tokenizer = Tokenizer_1;
|
|
1790
2593
|
marked.Slugger = Slugger_1;
|
|
1791
2594
|
marked.parse = marked;
|
|
1792
2595
|
var marked_1 = marked;
|