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