1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | (function (global, factory) {
|
13 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
14 | typeof define === 'function' && define.amd ? define(factory) :
|
15 | (global = global || self, global.marked = factory());
|
16 | }(this, (function () { 'use strict';
|
17 |
|
18 | function _defineProperties(target, props) {
|
19 | for (var i = 0; i < props.length; i++) {
|
20 | var descriptor = props[i];
|
21 | descriptor.enumerable = descriptor.enumerable || false;
|
22 | descriptor.configurable = true;
|
23 | if ("value" in descriptor) descriptor.writable = true;
|
24 | Object.defineProperty(target, descriptor.key, descriptor);
|
25 | }
|
26 | }
|
27 |
|
28 | function _createClass(Constructor, protoProps, staticProps) {
|
29 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
30 | if (staticProps) _defineProperties(Constructor, staticProps);
|
31 | return Constructor;
|
32 | }
|
33 |
|
34 | function createCommonjsModule(fn, module) {
|
35 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
36 | }
|
37 |
|
38 | var defaults = createCommonjsModule(function (module) {
|
39 | function getDefaults() {
|
40 | return {
|
41 | baseUrl: null,
|
42 | breaks: false,
|
43 | gfm: true,
|
44 | headerIds: true,
|
45 | headerPrefix: '',
|
46 | highlight: null,
|
47 | langPrefix: 'language-',
|
48 | mangle: true,
|
49 | pedantic: false,
|
50 | renderer: null,
|
51 | sanitize: false,
|
52 | sanitizer: null,
|
53 | silent: false,
|
54 | smartLists: false,
|
55 | smartypants: false,
|
56 | xhtml: false
|
57 | };
|
58 | }
|
59 |
|
60 | function changeDefaults(newDefaults) {
|
61 | module.exports.defaults = newDefaults;
|
62 | }
|
63 |
|
64 | module.exports = {
|
65 | defaults: getDefaults(),
|
66 | getDefaults: getDefaults,
|
67 | changeDefaults: changeDefaults
|
68 | };
|
69 | });
|
70 | var defaults_1 = defaults.defaults;
|
71 | var defaults_2 = defaults.getDefaults;
|
72 | var defaults_3 = defaults.changeDefaults;
|
73 |
|
74 | |
75 |
|
76 |
|
77 | var escapeTest = /[&<>"']/;
|
78 | var escapeReplace = /[&<>"']/g;
|
79 | var escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
|
80 | var escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
|
81 | var escapeReplacements = {
|
82 | '&': '&',
|
83 | '<': '<',
|
84 | '>': '>',
|
85 | '"': '"',
|
86 | "'": '''
|
87 | };
|
88 |
|
89 | var getEscapeReplacement = function getEscapeReplacement(ch) {
|
90 | return escapeReplacements[ch];
|
91 | };
|
92 |
|
93 | function escape(html, encode) {
|
94 | if (encode) {
|
95 | if (escapeTest.test(html)) {
|
96 | return html.replace(escapeReplace, getEscapeReplacement);
|
97 | }
|
98 | } else {
|
99 | if (escapeTestNoEncode.test(html)) {
|
100 | return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
|
101 | }
|
102 | }
|
103 |
|
104 | return html;
|
105 | }
|
106 |
|
107 | var unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
108 |
|
109 | function unescape(html) {
|
110 |
|
111 | return html.replace(unescapeTest, function (_, n) {
|
112 | n = n.toLowerCase();
|
113 | if (n === 'colon') return ':';
|
114 |
|
115 | if (n.charAt(0) === '#') {
|
116 | return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
|
117 | }
|
118 |
|
119 | return '';
|
120 | });
|
121 | }
|
122 |
|
123 | var caret = /(^|[^\[])\^/g;
|
124 |
|
125 | function edit(regex, opt) {
|
126 | regex = regex.source || regex;
|
127 | opt = opt || '';
|
128 | var obj = {
|
129 | replace: function replace(name, val) {
|
130 | val = val.source || val;
|
131 | val = val.replace(caret, '$1');
|
132 | regex = regex.replace(name, val);
|
133 | return obj;
|
134 | },
|
135 | getRegex: function getRegex() {
|
136 | return new RegExp(regex, opt);
|
137 | }
|
138 | };
|
139 | return obj;
|
140 | }
|
141 |
|
142 | var nonWordAndColonTest = /[^\w:]/g;
|
143 | var originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
|
144 |
|
145 | function cleanUrl(sanitize, base, href) {
|
146 | if (sanitize) {
|
147 | var prot;
|
148 |
|
149 | try {
|
150 | prot = decodeURIComponent(unescape(href)).replace(nonWordAndColonTest, '').toLowerCase();
|
151 | } catch (e) {
|
152 | return null;
|
153 | }
|
154 |
|
155 | if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
156 | return null;
|
157 | }
|
158 | }
|
159 |
|
160 | if (base && !originIndependentUrl.test(href)) {
|
161 | href = resolveUrl(base, href);
|
162 | }
|
163 |
|
164 | try {
|
165 | href = encodeURI(href).replace(/%25/g, '%');
|
166 | } catch (e) {
|
167 | return null;
|
168 | }
|
169 |
|
170 | return href;
|
171 | }
|
172 |
|
173 | var baseUrls = {};
|
174 | var justDomain = /^[^:]+:\/*[^/]*$/;
|
175 | var protocol = /^([^:]+:)[\s\S]*$/;
|
176 | var domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
|
177 |
|
178 | function resolveUrl(base, href) {
|
179 | if (!baseUrls[' ' + base]) {
|
180 |
|
181 |
|
182 |
|
183 | if (justDomain.test(base)) {
|
184 | baseUrls[' ' + base] = base + '/';
|
185 | } else {
|
186 | baseUrls[' ' + base] = rtrim(base, '/', true);
|
187 | }
|
188 | }
|
189 |
|
190 | base = baseUrls[' ' + base];
|
191 | var relativeBase = base.indexOf(':') === -1;
|
192 |
|
193 | if (href.substring(0, 2) === '//') {
|
194 | if (relativeBase) {
|
195 | return href;
|
196 | }
|
197 |
|
198 | return base.replace(protocol, '$1') + href;
|
199 | } else if (href.charAt(0) === '/') {
|
200 | if (relativeBase) {
|
201 | return href;
|
202 | }
|
203 |
|
204 | return base.replace(domain, '$1') + href;
|
205 | } else {
|
206 | return base + href;
|
207 | }
|
208 | }
|
209 |
|
210 | var noopTest = {
|
211 | exec: function noopTest() {}
|
212 | };
|
213 |
|
214 | function merge(obj) {
|
215 | var i = 1,
|
216 | target,
|
217 | key;
|
218 |
|
219 | for (; i < arguments.length; i++) {
|
220 | target = arguments[i];
|
221 |
|
222 | for (key in target) {
|
223 | if (Object.prototype.hasOwnProperty.call(target, key)) {
|
224 | obj[key] = target[key];
|
225 | }
|
226 | }
|
227 | }
|
228 |
|
229 | return obj;
|
230 | }
|
231 |
|
232 | function splitCells(tableRow, count) {
|
233 |
|
234 |
|
235 | var row = tableRow.replace(/\|/g, function (match, offset, str) {
|
236 | var escaped = false,
|
237 | curr = offset;
|
238 |
|
239 | while (--curr >= 0 && str[curr] === '\\') {
|
240 | escaped = !escaped;
|
241 | }
|
242 |
|
243 | if (escaped) {
|
244 |
|
245 |
|
246 | return '|';
|
247 | } else {
|
248 |
|
249 | return ' |';
|
250 | }
|
251 | }),
|
252 | cells = row.split(/ \|/);
|
253 | var i = 0;
|
254 |
|
255 | if (cells.length > count) {
|
256 | cells.splice(count);
|
257 | } else {
|
258 | while (cells.length < count) {
|
259 | cells.push('');
|
260 | }
|
261 | }
|
262 |
|
263 | for (; i < cells.length; i++) {
|
264 |
|
265 | cells[i] = cells[i].trim().replace(/\\\|/g, '|');
|
266 | }
|
267 |
|
268 | return cells;
|
269 | }
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | function rtrim(str, c, invert) {
|
275 | var l = str.length;
|
276 |
|
277 | if (l === 0) {
|
278 | return '';
|
279 | }
|
280 |
|
281 |
|
282 | var suffLen = 0;
|
283 |
|
284 | while (suffLen < l) {
|
285 | var currChar = str.charAt(l - suffLen - 1);
|
286 |
|
287 | if (currChar === c && !invert) {
|
288 | suffLen++;
|
289 | } else if (currChar !== c && invert) {
|
290 | suffLen++;
|
291 | } else {
|
292 | break;
|
293 | }
|
294 | }
|
295 |
|
296 | return str.substr(0, l - suffLen);
|
297 | }
|
298 |
|
299 | function findClosingBracket(str, b) {
|
300 | if (str.indexOf(b[1]) === -1) {
|
301 | return -1;
|
302 | }
|
303 |
|
304 | var l = str.length;
|
305 | var level = 0,
|
306 | i = 0;
|
307 |
|
308 | for (; i < l; i++) {
|
309 | if (str[i] === '\\') {
|
310 | i++;
|
311 | } else if (str[i] === b[0]) {
|
312 | level++;
|
313 | } else if (str[i] === b[1]) {
|
314 | level--;
|
315 |
|
316 | if (level < 0) {
|
317 | return i;
|
318 | }
|
319 | }
|
320 | }
|
321 |
|
322 | return -1;
|
323 | }
|
324 |
|
325 | function checkSanitizeDeprecation(opt) {
|
326 | if (opt && opt.sanitize && !opt.silent) {
|
327 | console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
|
328 | }
|
329 | }
|
330 |
|
331 | var helpers = {
|
332 | escape: escape,
|
333 | unescape: unescape,
|
334 | edit: edit,
|
335 | cleanUrl: cleanUrl,
|
336 | resolveUrl: resolveUrl,
|
337 | noopTest: noopTest,
|
338 | merge: merge,
|
339 | splitCells: splitCells,
|
340 | rtrim: rtrim,
|
341 | findClosingBracket: findClosingBracket,
|
342 | checkSanitizeDeprecation: checkSanitizeDeprecation
|
343 | };
|
344 |
|
345 | var noopTest$1 = helpers.noopTest,
|
346 | edit$1 = helpers.edit,
|
347 | merge$1 = helpers.merge;
|
348 | |
349 |
|
350 |
|
351 |
|
352 | var block = {
|
353 | newline: /^\n+/,
|
354 | code: /^( {4}[^\n]+\n*)+/,
|
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}(?:'
|
361 | + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)'
|
362 | + '|comment[^\\n]*(\\n+|$)'
|
363 | + '|<\\?[\\s\\S]*?\\?>\\n*'
|
364 | + '|<![A-Z][\\s\\S]*?>\\n*'
|
365 | + '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*'
|
366 | + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)'
|
367 | + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)'
|
368 | + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)'
|
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 |
|
375 |
|
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', '')
|
390 | .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ')
|
391 | .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)').replace('tag', block._tag)
|
392 | .getRegex();
|
393 | block.blockquote = edit$1(block.blockquote).replace('paragraph', block.paragraph).getRegex();
|
394 | |
395 |
|
396 |
|
397 |
|
398 | block.normal = merge$1({}, block);
|
399 | |
400 |
|
401 |
|
402 |
|
403 | block.gfm = merge$1({}, block.normal, {
|
404 | nptable: /^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,
|
405 | table: /^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/
|
406 | });
|
407 | |
408 |
|
409 |
|
410 |
|
411 | block.pedantic = merge$1({}, block.normal, {
|
412 | html: edit$1('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)'
|
413 | + '|<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(),
|
414 | def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
|
415 | heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
|
416 | fences: noopTest$1,
|
417 |
|
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 |
|
422 |
|
423 |
|
424 | var inline = {
|
425 | escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
|
426 | autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
|
427 | url: noopTest$1,
|
428 | tag: '^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>'
|
429 | + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>'
|
430 | + '|^<\\?[\\s\\S]*?\\?>'
|
431 | + '|^<![a-zA-Z]+\\s[\\s\\S]*?>'
|
432 | + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
|
433 |
|
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 | };
|
444 |
|
445 |
|
446 | inline._punctuation = '!"#$%&\'()*+,\\-./:;<=>?@\\[^_{|}~';
|
447 | inline.em = edit$1(inline.em).replace(/punctuation/g, inline._punctuation).getRegex();
|
448 | inline._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
|
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 |
|
461 |
|
462 |
|
463 | inline.normal = merge$1({}, inline);
|
464 | |
465 |
|
466 |
|
467 |
|
468 | inline.pedantic = merge$1({}, inline.normal, {
|
469 | strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
|
470 | em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
|
471 | link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace('label', inline._label).getRegex(),
|
472 | reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', inline._label).getRegex()
|
473 | });
|
474 | |
475 |
|
476 |
|
477 |
|
478 | inline.gfm = merge$1({}, inline.normal, {
|
479 | escape: edit$1(inline.escape).replace('])', '~|])').getRegex(),
|
480 | _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
|
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();
|
487 | |
488 |
|
489 |
|
490 |
|
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 |
|
507 |
|
508 |
|
509 | var Lexer_1 =
|
510 |
|
511 | function () {
|
512 | function Lexer(options) {
|
513 | this.tokens = [];
|
514 | this.tokens.links = Object.create(null);
|
515 | 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 | }
|
524 | |
525 |
|
526 |
|
527 |
|
528 |
|
529 | |
530 |
|
531 |
|
532 | Lexer.lex = function lex(src, options) {
|
533 | var lexer = new Lexer(options);
|
534 | return lexer.lex(src);
|
535 | };
|
536 |
|
537 | var _proto = Lexer.prototype;
|
538 |
|
539 | |
540 |
|
541 |
|
542 | _proto.lex = function lex(src) {
|
543 | src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ');
|
544 | return this.token(src, true);
|
545 | };
|
546 |
|
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 |
|
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 | }
|
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);
|
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 | }
|
581 |
|
582 | continue;
|
583 | }
|
584 |
|
585 |
|
586 | if (cap = this.rules.fences.exec(src)) {
|
587 | src = src.substring(cap[0].length);
|
588 | this.tokens.push({
|
589 | type: 'code',
|
590 | lang: cap[2] ? cap[2].trim() : cap[2],
|
591 | text: cap[3] || ''
|
592 | });
|
593 | continue;
|
594 | }
|
595 |
|
596 |
|
597 | if (cap = this.rules.heading.exec(src)) {
|
598 | src = src.substring(cap[0].length);
|
599 | this.tokens.push({
|
600 | type: 'heading',
|
601 | depth: cap[1].length,
|
602 | text: cap[2]
|
603 | });
|
604 | continue;
|
605 | }
|
606 |
|
607 |
|
608 | if (cap = this.rules.nptable.exec(src)) {
|
609 | item = {
|
610 | type: 'table',
|
611 | header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
|
612 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
613 | cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
614 | };
|
615 |
|
616 | if (item.header.length === item.align.length) {
|
617 | src = src.substring(cap[0].length);
|
618 |
|
619 | for (i = 0; i < item.align.length; i++) {
|
620 | if (/^ *-+: *$/.test(item.align[i])) {
|
621 | item.align[i] = 'right';
|
622 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
623 | item.align[i] = 'center';
|
624 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
625 | item.align[i] = 'left';
|
626 | } else {
|
627 | item.align[i] = null;
|
628 | }
|
629 | }
|
630 |
|
631 | for (i = 0; i < item.cells.length; i++) {
|
632 | item.cells[i] = splitCells$1(item.cells[i], item.header.length);
|
633 | }
|
634 |
|
635 | this.tokens.push(item);
|
636 | continue;
|
637 | }
|
638 | }
|
639 |
|
640 |
|
641 | if (cap = this.rules.hr.exec(src)) {
|
642 | src = src.substring(cap[0].length);
|
643 | this.tokens.push({
|
644 | type: 'hr'
|
645 | });
|
646 | continue;
|
647 | }
|
648 |
|
649 |
|
650 | if (cap = this.rules.blockquote.exec(src)) {
|
651 | src = src.substring(cap[0].length);
|
652 | this.tokens.push({
|
653 | type: 'blockquote_start'
|
654 | });
|
655 | cap = cap[0].replace(/^ *> ?/gm, '');
|
656 |
|
657 |
|
658 |
|
659 | this.token(cap, top);
|
660 | this.tokens.push({
|
661 | type: 'blockquote_end'
|
662 | });
|
663 | continue;
|
664 | }
|
665 |
|
666 |
|
667 | if (cap = this.rules.list.exec(src)) {
|
668 | src = src.substring(cap[0].length);
|
669 | bull = cap[2];
|
670 | isordered = bull.length > 1;
|
671 | listStart = {
|
672 | type: 'list_start',
|
673 | ordered: isordered,
|
674 | start: isordered ? +bull : '',
|
675 | loose: false
|
676 | };
|
677 | this.tokens.push(listStart);
|
678 |
|
679 | cap = cap[0].match(this.rules.item);
|
680 | listItems = [];
|
681 | next = false;
|
682 | l = cap.length;
|
683 | i = 0;
|
684 |
|
685 | for (; i < l; i++) {
|
686 | item = cap[i];
|
687 |
|
688 |
|
689 | space = item.length;
|
690 | item = item.replace(/^ *([*+-]|\d+\.) */, '');
|
691 |
|
692 |
|
693 | if (~item.indexOf('\n ')) {
|
694 | space -= item.length;
|
695 | item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
|
696 | }
|
697 |
|
698 |
|
699 |
|
700 | if (i !== l - 1) {
|
701 | b = block$1.bullet.exec(cap[i + 1])[0];
|
702 |
|
703 | if (bull.length > 1 ? b.length === 1 : b.length > 1 || this.options.smartLists && b !== bull) {
|
704 | src = cap.slice(i + 1).join('\n') + src;
|
705 | i = l - 1;
|
706 | }
|
707 | }
|
708 |
|
709 |
|
710 |
|
711 |
|
712 | loose = next || /\n\n(?!\s*$)/.test(item);
|
713 |
|
714 | if (i !== l - 1) {
|
715 | next = item.charAt(item.length - 1) === '\n';
|
716 | if (!loose) loose = next;
|
717 | }
|
718 |
|
719 | if (loose) {
|
720 | listStart.loose = true;
|
721 | }
|
722 |
|
723 |
|
724 | istask = /^\[[ xX]\] /.test(item);
|
725 | ischecked = undefined;
|
726 |
|
727 | if (istask) {
|
728 | ischecked = item[1] !== ' ';
|
729 | item = item.replace(/^\[[ xX]\] +/, '');
|
730 | }
|
731 |
|
732 | t = {
|
733 | type: 'list_item_start',
|
734 | task: istask,
|
735 | checked: ischecked,
|
736 | loose: loose
|
737 | };
|
738 | listItems.push(t);
|
739 | this.tokens.push(t);
|
740 |
|
741 | this.token(item, false);
|
742 | this.tokens.push({
|
743 | type: 'list_item_end'
|
744 | });
|
745 | }
|
746 |
|
747 | if (listStart.loose) {
|
748 | l = listItems.length;
|
749 | i = 0;
|
750 |
|
751 | for (; i < l; i++) {
|
752 | listItems[i].loose = true;
|
753 | }
|
754 | }
|
755 |
|
756 | this.tokens.push({
|
757 | type: 'list_end'
|
758 | });
|
759 | continue;
|
760 | }
|
761 |
|
762 |
|
763 | if (cap = this.rules.html.exec(src)) {
|
764 | src = src.substring(cap[0].length);
|
765 | this.tokens.push({
|
766 | type: this.options.sanitize ? 'paragraph' : 'html',
|
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 | });
|
770 | 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, ' ');
|
778 |
|
779 | if (!this.tokens.links[tag]) {
|
780 | this.tokens.links[tag] = {
|
781 | href: cap[2],
|
782 | title: cap[3]
|
783 | };
|
784 | }
|
785 |
|
786 | continue;
|
787 | }
|
788 |
|
789 |
|
790 | if (cap = this.rules.table.exec(src)) {
|
791 | item = {
|
792 | type: 'table',
|
793 | header: splitCells$1(cap[1].replace(/^ *| *\| *$/g, '')),
|
794 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
795 | cells: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
|
796 | };
|
797 |
|
798 | if (item.header.length === item.align.length) {
|
799 | src = src.substring(cap[0].length);
|
800 |
|
801 | for (i = 0; i < item.align.length; i++) {
|
802 | if (/^ *-+: *$/.test(item.align[i])) {
|
803 | item.align[i] = 'right';
|
804 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
805 | item.align[i] = 'center';
|
806 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
807 | item.align[i] = 'left';
|
808 | } else {
|
809 | item.align[i] = null;
|
810 | }
|
811 | }
|
812 |
|
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 |
|
817 | this.tokens.push(item);
|
818 | continue;
|
819 | }
|
820 | }
|
821 |
|
822 |
|
823 | if (cap = this.rules.lheading.exec(src)) {
|
824 | src = src.substring(cap[0].length);
|
825 | this.tokens.push({
|
826 | type: 'heading',
|
827 | depth: cap[2].charAt(0) === '=' ? 1 : 2,
|
828 | text: cap[1]
|
829 | });
|
830 | continue;
|
831 | }
|
832 |
|
833 |
|
834 | if (top && (cap = this.rules.paragraph.exec(src))) {
|
835 | src = src.substring(cap[0].length);
|
836 | this.tokens.push({
|
837 | type: 'paragraph',
|
838 | text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
|
839 | });
|
840 | continue;
|
841 | }
|
842 |
|
843 |
|
844 | if (cap = this.rules.text.exec(src)) {
|
845 |
|
846 | src = src.substring(cap[0].length);
|
847 | this.tokens.push({
|
848 | type: 'text',
|
849 | text: cap[0]
|
850 | });
|
851 | continue;
|
852 | }
|
853 |
|
854 | if (src) {
|
855 | throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
856 | }
|
857 | }
|
858 |
|
859 | return this.tokens;
|
860 | };
|
861 |
|
862 | _createClass(Lexer, null, [{
|
863 | key: "rules",
|
864 | get: function get() {
|
865 | return block$1;
|
866 | }
|
867 | }]);
|
868 |
|
869 | return Lexer;
|
870 | }();
|
871 |
|
872 | var defaults$2 = defaults.defaults;
|
873 | var cleanUrl$1 = helpers.cleanUrl,
|
874 | escape$2 = helpers.escape;
|
875 | |
876 |
|
877 |
|
878 |
|
879 | var Renderer_1 =
|
880 |
|
881 | function () {
|
882 | function Renderer(options) {
|
883 | this.options = options || defaults$2;
|
884 | }
|
885 |
|
886 | var _proto = Renderer.prototype;
|
887 |
|
888 | _proto.code = function code(_code, infostring, escaped) {
|
889 | var lang = (infostring || '').match(/\S*/)[0];
|
890 |
|
891 | if (this.options.highlight) {
|
892 | var out = this.options.highlight(_code, lang);
|
893 |
|
894 | if (out != null && out !== _code) {
|
895 | escaped = true;
|
896 | _code = out;
|
897 | }
|
898 | }
|
899 |
|
900 | if (!lang) {
|
901 | return '<pre><code>' + (escaped ? _code : escape$2(_code, true)) + '</code></pre>';
|
902 | }
|
903 |
|
904 | return '<pre><code class="' + this.options.langPrefix + escape$2(lang, true) + '">' + (escaped ? _code : escape$2(_code, true)) + '</code></pre>\n';
|
905 | };
|
906 |
|
907 | _proto.blockquote = function blockquote(quote) {
|
908 | return '<blockquote>\n' + quote + '</blockquote>\n';
|
909 | };
|
910 |
|
911 | _proto.html = function html(_html) {
|
912 | return _html;
|
913 | };
|
914 |
|
915 | _proto.heading = function heading(text, level, raw, slugger) {
|
916 | if (this.options.headerIds) {
|
917 | return '<h' + level + ' id="' + this.options.headerPrefix + slugger.slug(raw) + '">' + text + '</h' + level + '>\n';
|
918 | }
|
919 |
|
920 |
|
921 | return '<h' + level + '>' + text + '</h' + level + '>\n';
|
922 | };
|
923 |
|
924 | _proto.hr = function hr() {
|
925 | return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
926 | };
|
927 |
|
928 | _proto.list = function list(body, ordered, start) {
|
929 | var type = ordered ? 'ol' : 'ul',
|
930 | startatt = ordered && start !== 1 ? ' start="' + start + '"' : '';
|
931 | return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
|
932 | };
|
933 |
|
934 | _proto.listitem = function listitem(text) {
|
935 | return '<li>' + text + '</li>\n';
|
936 | };
|
937 |
|
938 | _proto.checkbox = function checkbox(checked) {
|
939 | return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox"' + (this.options.xhtml ? ' /' : '') + '> ';
|
940 | };
|
941 |
|
942 | _proto.paragraph = function paragraph(text) {
|
943 | return '<p>' + text + '</p>\n';
|
944 | };
|
945 |
|
946 | _proto.table = function table(header, body) {
|
947 | if (body) body = '<tbody>' + body + '</tbody>';
|
948 | return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
|
949 | };
|
950 |
|
951 | _proto.tablerow = function tablerow(content) {
|
952 | return '<tr>\n' + content + '</tr>\n';
|
953 | };
|
954 |
|
955 | _proto.tablecell = function tablecell(content, flags) {
|
956 | var type = flags.header ? 'th' : 'td';
|
957 | var tag = flags.align ? '<' + type + ' align="' + flags.align + '">' : '<' + type + '>';
|
958 | return tag + content + '</' + type + '>\n';
|
959 | };
|
960 |
|
961 |
|
962 | _proto.strong = function strong(text) {
|
963 | return '<strong>' + text + '</strong>';
|
964 | };
|
965 |
|
966 | _proto.em = function em(text) {
|
967 | return '<em>' + text + '</em>';
|
968 | };
|
969 |
|
970 | _proto.codespan = function codespan(text) {
|
971 | return '<code>' + text + '</code>';
|
972 | };
|
973 |
|
974 | _proto.br = function br() {
|
975 | return this.options.xhtml ? '<br/>' : '<br>';
|
976 | };
|
977 |
|
978 | _proto.del = function del(text) {
|
979 | return '<del>' + text + '</del>';
|
980 | };
|
981 |
|
982 | _proto.link = function link(href, title, text) {
|
983 | href = cleanUrl$1(this.options.sanitize, this.options.baseUrl, href);
|
984 |
|
985 | if (href === null) {
|
986 | return text;
|
987 | }
|
988 |
|
989 | var out = '<a href="' + escape$2(href) + '"';
|
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 + '"';
|
1007 |
|
1008 | if (title) {
|
1009 | 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 |
|
1025 |
|
1026 | var Slugger_1 =
|
1027 |
|
1028 | function () {
|
1029 | function Slugger() {
|
1030 | this.seen = {};
|
1031 | }
|
1032 | |
1033 |
|
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 |
|
1064 |
|
1065 |
|
1066 | var InlineLexer_1 =
|
1067 |
|
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 |
|
1093 |
|
1094 |
|
1095 |
|
1096 | |
1097 |
|
1098 |
|
1099 | InlineLexer.output = function output(src, links, options) {
|
1100 | var inline = new InlineLexer(links, options);
|
1101 | return inline.output(src);
|
1102 | }
|
1103 | |
1104 |
|
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 |
|
1121 | if (cap = this.rules.escape.exec(src)) {
|
1122 | src = src.substring(cap[0].length);
|
1123 | out += escape$3(cap[1]);
|
1124 | continue;
|
1125 | }
|
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 | }
|
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 | }
|
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 | }
|
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 | }
|
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 | }
|
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 | }
|
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 | }
|
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 | }
|
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 | }
|
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 |
|
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 | }
|
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 |
|
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 |
|
1315 |
|
1316 | ;
|
1317 |
|
1318 | _proto.smartypants = function smartypants(text) {
|
1319 | if (!this.options.smartypants) return text;
|
1320 | return text
|
1321 | .replace(/---/g, "\u2014")
|
1322 | .replace(/--/g, "\u2013")
|
1323 | .replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018")
|
1324 | .replace(/'/g, "\u2019")
|
1325 | .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201C")
|
1326 | .replace(/"/g, "\u201D")
|
1327 | .replace(/\.{3}/g, "\u2026");
|
1328 | }
|
1329 | |
1330 |
|
1331 |
|
1332 | ;
|
1333 |
|
1334 | _proto.mangle = function mangle(text) {
|
1335 | if (!this.options.mangle) return text;
|
1336 | var l = text.length;
|
1337 | var out = '',
|
1338 | i = 0,
|
1339 | ch;
|
1340 |
|
1341 | for (; i < l; i++) {
|
1342 | ch = text.charCodeAt(i);
|
1343 |
|
1344 | if (Math.random() > 0.5) {
|
1345 | ch = 'x' + ch.toString(16);
|
1346 | }
|
1347 |
|
1348 | out += '&#' + ch + ';';
|
1349 | }
|
1350 |
|
1351 | return out;
|
1352 | };
|
1353 |
|
1354 | _createClass(InlineLexer, null, [{
|
1355 | key: "rules",
|
1356 | get: function get() {
|
1357 | return inline$1;
|
1358 | }
|
1359 | }]);
|
1360 |
|
1361 | return InlineLexer;
|
1362 | }();
|
1363 |
|
1364 | |
1365 |
|
1366 |
|
1367 |
|
1368 | var TextRenderer_1 =
|
1369 |
|
1370 | function () {
|
1371 | function TextRenderer() {}
|
1372 |
|
1373 | var _proto = TextRenderer.prototype;
|
1374 |
|
1375 |
|
1376 | _proto.strong = function strong(text) {
|
1377 | return text;
|
1378 | };
|
1379 |
|
1380 | _proto.em = function em(text) {
|
1381 | return text;
|
1382 | };
|
1383 |
|
1384 | _proto.codespan = function codespan(text) {
|
1385 | return text;
|
1386 | };
|
1387 |
|
1388 | _proto.del = function del(text) {
|
1389 | return text;
|
1390 | };
|
1391 |
|
1392 | _proto.text = function text(_text) {
|
1393 | return _text;
|
1394 | };
|
1395 |
|
1396 | _proto.link = function link(href, title, text) {
|
1397 | return '' + text;
|
1398 | };
|
1399 |
|
1400 | _proto.image = function image(href, title, text) {
|
1401 | return '' + text;
|
1402 | };
|
1403 |
|
1404 | _proto.br = function br() {
|
1405 | return '';
|
1406 | };
|
1407 |
|
1408 | return TextRenderer;
|
1409 | }();
|
1410 |
|
1411 | var defaults$4 = defaults.defaults;
|
1412 | var merge$2 = helpers.merge,
|
1413 | unescape$1 = helpers.unescape;
|
1414 | |
1415 |
|
1416 |
|
1417 |
|
1418 | var Parser_1 =
|
1419 |
|
1420 | function () {
|
1421 | function Parser(options) {
|
1422 | this.tokens = [];
|
1423 | this.token = null;
|
1424 | this.options = options || defaults$4;
|
1425 | this.options.renderer = this.options.renderer || new Renderer_1();
|
1426 | this.renderer = this.options.renderer;
|
1427 | this.renderer.options = this.options;
|
1428 | this.slugger = new Slugger_1();
|
1429 | }
|
1430 | |
1431 |
|
1432 |
|
1433 |
|
1434 |
|
1435 | Parser.parse = function parse(tokens, options) {
|
1436 | var parser = new Parser(options);
|
1437 | return parser.parse(tokens);
|
1438 | };
|
1439 |
|
1440 | var _proto = Parser.prototype;
|
1441 |
|
1442 | |
1443 |
|
1444 |
|
1445 | _proto.parse = function parse(tokens) {
|
1446 | this.inline = new InlineLexer_1(tokens.links, this.options);
|
1447 |
|
1448 | this.inlineText = new InlineLexer_1(tokens.links, merge$2({}, this.options, {
|
1449 | renderer: new TextRenderer_1()
|
1450 | }));
|
1451 | this.tokens = tokens.reverse();
|
1452 | var out = '';
|
1453 |
|
1454 | while (this.next()) {
|
1455 | out += this.tok();
|
1456 | }
|
1457 |
|
1458 | return out;
|
1459 | };
|
1460 |
|
1461 | |
1462 |
|
1463 |
|
1464 | _proto.next = function next() {
|
1465 | this.token = this.tokens.pop();
|
1466 | return this.token;
|
1467 | };
|
1468 |
|
1469 | |
1470 |
|
1471 |
|
1472 | _proto.peek = function peek() {
|
1473 | return this.tokens[this.tokens.length - 1] || 0;
|
1474 | };
|
1475 |
|
1476 | |
1477 |
|
1478 |
|
1479 | _proto.parseText = function parseText() {
|
1480 | var body = this.token.text;
|
1481 |
|
1482 | while (this.peek().type === 'text') {
|
1483 | body += '\n' + this.next().text;
|
1484 | }
|
1485 |
|
1486 | return this.inline.output(body);
|
1487 | };
|
1488 |
|
1489 | |
1490 |
|
1491 |
|
1492 | _proto.tok = function tok() {
|
1493 | var body = '';
|
1494 |
|
1495 | switch (this.token.type) {
|
1496 | case 'space':
|
1497 | {
|
1498 | return '';
|
1499 | }
|
1500 |
|
1501 | case 'hr':
|
1502 | {
|
1503 | return this.renderer.hr();
|
1504 | }
|
1505 |
|
1506 | case 'heading':
|
1507 | {
|
1508 | return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, unescape$1(this.inlineText.output(this.token.text)), this.slugger);
|
1509 | }
|
1510 |
|
1511 | case 'code':
|
1512 | {
|
1513 | return this.renderer.code(this.token.text, this.token.lang, this.token.escaped);
|
1514 | }
|
1515 |
|
1516 | case 'table':
|
1517 | {
|
1518 | var header = '',
|
1519 | i,
|
1520 | row,
|
1521 | cell,
|
1522 | j;
|
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 | });
|
1531 | }
|
1532 |
|
1533 | header += this.renderer.tablerow(cell);
|
1534 |
|
1535 | for (i = 0; i < this.token.cells.length; i++) {
|
1536 | row = this.token.cells[i];
|
1537 | cell = '';
|
1538 |
|
1539 | for (j = 0; j < row.length; j++) {
|
1540 | cell += this.renderer.tablecell(this.inline.output(row[j]), {
|
1541 | header: false,
|
1542 | align: this.token.align[j]
|
1543 | });
|
1544 | }
|
1545 |
|
1546 | body += this.renderer.tablerow(cell);
|
1547 | }
|
1548 |
|
1549 | return this.renderer.table(header, body);
|
1550 | }
|
1551 |
|
1552 | case 'blockquote_start':
|
1553 | {
|
1554 | body = '';
|
1555 |
|
1556 | while (this.next().type !== 'blockquote_end') {
|
1557 | body += this.tok();
|
1558 | }
|
1559 |
|
1560 | return this.renderer.blockquote(body);
|
1561 | }
|
1562 |
|
1563 | case 'list_start':
|
1564 | {
|
1565 | body = '';
|
1566 | var ordered = this.token.ordered,
|
1567 | start = this.token.start;
|
1568 |
|
1569 | while (this.next().type !== 'list_end') {
|
1570 | body += this.tok();
|
1571 | }
|
1572 |
|
1573 | return this.renderer.list(body, ordered, start);
|
1574 | }
|
1575 |
|
1576 | case 'list_item_start':
|
1577 | {
|
1578 | body = '';
|
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 | }
|
1594 | } else {
|
1595 | body += this.renderer.checkbox(checked);
|
1596 | }
|
1597 | }
|
1598 |
|
1599 | while (this.next().type !== 'list_item_end') {
|
1600 | body += !loose && this.token.type === 'text' ? this.parseText() : this.tok();
|
1601 | }
|
1602 |
|
1603 | return this.renderer.listitem(body, task, checked);
|
1604 | }
|
1605 |
|
1606 | case 'html':
|
1607 | {
|
1608 |
|
1609 | return this.renderer.html(this.token.text);
|
1610 | }
|
1611 |
|
1612 | case 'paragraph':
|
1613 | {
|
1614 | return this.renderer.paragraph(this.inline.output(this.token.text));
|
1615 | }
|
1616 |
|
1617 | case 'text':
|
1618 | {
|
1619 | return this.renderer.paragraph(this.parseText());
|
1620 | }
|
1621 |
|
1622 | default:
|
1623 | {
|
1624 | var errMsg = 'Token with "' + this.token.type + '" type was not found.';
|
1625 |
|
1626 | if (this.options.silent) {
|
1627 | console.log(errMsg);
|
1628 | } else {
|
1629 | throw new Error(errMsg);
|
1630 | }
|
1631 | }
|
1632 | }
|
1633 | };
|
1634 |
|
1635 | return Parser;
|
1636 | }();
|
1637 |
|
1638 | var merge$3 = helpers.merge,
|
1639 | checkSanitizeDeprecation$1 = helpers.checkSanitizeDeprecation,
|
1640 | escape$4 = helpers.escape;
|
1641 | var getDefaults = defaults.getDefaults,
|
1642 | changeDefaults = defaults.changeDefaults,
|
1643 | defaults$5 = defaults.defaults;
|
1644 | |
1645 |
|
1646 |
|
1647 |
|
1648 | function marked(src, opt, callback) {
|
1649 |
|
1650 | if (typeof src === 'undefined' || src === null) {
|
1651 | throw new Error('marked(): input parameter is undefined or null');
|
1652 | }
|
1653 |
|
1654 | if (typeof src !== 'string') {
|
1655 | throw new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
1656 | }
|
1657 |
|
1658 | if (callback || typeof opt === 'function') {
|
1659 | var _ret = function () {
|
1660 | if (!callback) {
|
1661 | callback = opt;
|
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;
|
1671 |
|
1672 | try {
|
1673 | tokens = Lexer_1.lex(src, opt);
|
1674 | } catch (e) {
|
1675 | return {
|
1676 | v: callback(e)
|
1677 | };
|
1678 | }
|
1679 |
|
1680 | pending = tokens.length;
|
1681 |
|
1682 | var done = function done(err) {
|
1683 | if (err) {
|
1684 | opt.highlight = highlight;
|
1685 | return callback(err);
|
1686 | }
|
1687 |
|
1688 | var out;
|
1689 |
|
1690 | try {
|
1691 | out = Parser_1.parse(tokens, opt);
|
1692 | } catch (e) {
|
1693 | err = e;
|
1694 | }
|
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 | }
|
1705 |
|
1706 | delete opt.highlight;
|
1707 | if (!pending) return {
|
1708 | v: done()
|
1709 | };
|
1710 |
|
1711 | for (; i < tokens.length; i++) {
|
1712 | (function (token) {
|
1713 | if (token.type !== 'code') {
|
1714 | return --pending || done();
|
1715 | }
|
1716 |
|
1717 | return highlight(token.text, token.lang, function (err, code) {
|
1718 | if (err) return done(err);
|
1719 |
|
1720 | if (code == null || code === token.text) {
|
1721 | return --pending || done();
|
1722 | }
|
1723 |
|
1724 | token.text = code;
|
1725 | token.escaped = true;
|
1726 | --pending || done();
|
1727 | });
|
1728 | })(tokens[i]);
|
1729 | }
|
1730 |
|
1731 | return {
|
1732 | v: void 0
|
1733 | };
|
1734 | }();
|
1735 |
|
1736 | if (typeof _ret === "object") return _ret.v;
|
1737 | }
|
1738 |
|
1739 | try {
|
1740 | opt = merge$3({}, marked.defaults, opt || {});
|
1741 | checkSanitizeDeprecation$1(opt);
|
1742 | return Parser_1.parse(Lexer_1.lex(src, opt), opt);
|
1743 | } catch (e) {
|
1744 | e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
1745 |
|
1746 | if ((opt || marked.defaults).silent) {
|
1747 | return '<p>An error occurred:</p><pre>' + escape$4(e.message + '', true) + '</pre>';
|
1748 | }
|
1749 |
|
1750 | throw e;
|
1751 | }
|
1752 | }
|
1753 | |
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 | marked.options = marked.setOptions = function (opt) {
|
1759 | merge$3(marked.defaults, opt);
|
1760 | changeDefaults(marked.defaults);
|
1761 | return marked;
|
1762 | };
|
1763 |
|
1764 | marked.getDefaults = getDefaults;
|
1765 | marked.defaults = defaults$5;
|
1766 | |
1767 |
|
1768 |
|
1769 |
|
1770 | marked.Parser = Parser_1;
|
1771 | marked.parser = Parser_1.parse;
|
1772 | marked.Renderer = Renderer_1;
|
1773 | marked.TextRenderer = TextRenderer_1;
|
1774 | marked.Lexer = Lexer_1;
|
1775 | marked.lexer = Lexer_1.lex;
|
1776 | marked.InlineLexer = InlineLexer_1;
|
1777 | marked.inlineLexer = InlineLexer_1.output;
|
1778 | marked.Slugger = Slugger_1;
|
1779 | marked.parse = marked;
|
1780 | var marked_1 = marked;
|
1781 |
|
1782 | return marked_1;
|
1783 |
|
1784 | })));
|