1 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | ;(function () {
|
10 |
|
11 | |
12 |
|
13 |
|
14 |
|
15 | var block = {
|
16 | newline: /^\n+/,
|
17 | code: /^( {4}[^\n]+\n*)+/,
|
18 | fences: noop,
|
19 | hr: /^( *[-*_]){3,} *(?:\n+|$)/,
|
20 | heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
|
21 | nptable: noop,
|
22 | lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
|
23 | blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
|
24 | list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
25 | html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
|
26 | def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
|
27 | table: noop,
|
28 | paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
|
29 | text: /^[^\n]+/
|
30 | };
|
31 |
|
32 | block.bullet = /(?:[*+-]|\d+\.)/;
|
33 | block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
|
34 | block.item = replace(block.item, 'gm')(/bull/g, block.bullet)();
|
35 |
|
36 | block.list = replace(block.list)(/bull/g, block.bullet)('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')('def', '\\n+(?=' + block.def.source + ')')();
|
37 |
|
38 | block.blockquote = replace(block.blockquote)('def', block.def)();
|
39 |
|
40 | block._tag = '(?!(?:' + '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';
|
41 |
|
42 | block.html = replace(block.html)('comment', /<!--[\s\S]*?-->/)('closed', /<(tag)[\s\S]+?<\/\1>/)('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g, block._tag)();
|
43 |
|
44 | block.paragraph = replace(block.paragraph)('hr', block.hr)('heading', block.heading)('lheading', block.lheading)('blockquote', block.blockquote)('tag', '<' + block._tag)('def', block.def)();
|
45 |
|
46 | /**
|
47 | * Normal Block Grammar
|
48 | */
|
49 |
|
50 | block.normal = merge({}, block);
|
51 |
|
52 | /**
|
53 | * GFM Block Grammar
|
54 | */
|
55 |
|
56 | block.gfm = merge({}, block.normal, {
|
57 | fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
|
58 | paragraph: /^/,
|
59 | heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
|
60 | });
|
61 |
|
62 | block.gfm.paragraph = replace(block.paragraph)('(?!', '(?!' + block.gfm.fences.source.replace('\\1', '\\2') + '|' + block.list.source.replace('\\1', '\\3') + '|')();
|
63 |
|
64 | /**
|
65 | * GFM + Tables Block Grammar
|
66 | */
|
67 |
|
68 | block.tables = merge({}, block.gfm, {
|
69 | nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
|
70 | table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
|
71 | });
|
72 |
|
73 | /**
|
74 | * Block Lexer
|
75 | */
|
76 |
|
77 | function Lexer(options) {
|
78 | this.tokens = [];
|
79 | this.tokens.links = {};
|
80 | this.options = options || marked.defaults;
|
81 | this.rules = block.normal;
|
82 |
|
83 | if (this.options.gfm) {
|
84 | if (this.options.tables) {
|
85 | this.rules = block.tables;
|
86 | } else {
|
87 | this.rules = block.gfm;
|
88 | }
|
89 | }
|
90 | }
|
91 |
|
92 | /**
|
93 | * Expose Block Rules
|
94 | */
|
95 |
|
96 | Lexer.rules = block;
|
97 |
|
98 | /**
|
99 | * Static Lex Method
|
100 | */
|
101 |
|
102 | Lexer.lex = function (src, options) {
|
103 | var lexer = new Lexer(options);
|
104 | return lexer.lex(src);
|
105 | };
|
106 |
|
107 | /**
|
108 | * Preprocessing
|
109 | */
|
110 |
|
111 | Lexer.prototype.lex = function (src) {
|
112 | src = src.replace(/\r\n|\r/g, '\n').replace(/\t/g, ' ').replace(/\u00a0/g, ' ').replace(/\u2424/g, '\n');
|
113 |
|
114 | return this.token(src, true);
|
115 | };
|
116 |
|
117 | /**
|
118 | * Lexing
|
119 | */
|
120 |
|
121 | Lexer.prototype.token = function (src, top, bq) {
|
122 | var src = src.replace(/^ +$/gm, ''),
|
123 | next,
|
124 | loose,
|
125 | cap,
|
126 | bull,
|
127 | b,
|
128 | item,
|
129 | space,
|
130 | i,
|
131 | l;
|
132 |
|
133 | while (src) {
|
134 | // newline
|
135 | if (cap = this.rules.newline.exec(src)) {
|
136 | src = src.substring(cap[0].length);
|
137 | if (cap[0].length > 1) {
|
138 | this.tokens.push({
|
139 | type: 'space'
|
140 | });
|
141 | }
|
142 | }
|
143 |
|
144 | // code
|
145 | if (cap = this.rules.code.exec(src)) {
|
146 | src = src.substring(cap[0].length);
|
147 | cap = cap[0].replace(/^ {4}/gm, '');
|
148 | this.tokens.push({
|
149 | type: 'code',
|
150 | text: !this.options.pedantic ? cap.replace(/\n+$/, '') : cap
|
151 | });
|
152 | continue;
|
153 | }
|
154 |
|
155 | // fences (gfm)
|
156 | if (cap = this.rules.fences.exec(src)) {
|
157 | src = src.substring(cap[0].length);
|
158 | this.tokens.push({
|
159 | type: 'code',
|
160 | lang: cap[2],
|
161 | text: cap[3] || ''
|
162 | });
|
163 | continue;
|
164 | }
|
165 |
|
166 | // heading
|
167 | if (cap = this.rules.heading.exec(src)) {
|
168 | src = src.substring(cap[0].length);
|
169 | this.tokens.push({
|
170 | type: 'heading',
|
171 | depth: cap[1].length,
|
172 | text: cap[2]
|
173 | });
|
174 | continue;
|
175 | }
|
176 |
|
177 | // table no leading pipe (gfm)
|
178 | if (top && (cap = this.rules.nptable.exec(src))) {
|
179 | src = src.substring(cap[0].length);
|
180 |
|
181 | item = {
|
182 | type: 'table',
|
183 | header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
184 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
185 | cells: cap[3].replace(/\n$/, '').split('\n')
|
186 | };
|
187 |
|
188 | for (i = 0; i < item.align.length; i++) {
|
189 | if (/^ *-+: *$/.test(item.align[i])) {
|
190 | item.align[i] = 'right';
|
191 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
192 | item.align[i] = 'center';
|
193 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
194 | item.align[i] = 'left';
|
195 | } else {
|
196 | item.align[i] = null;
|
197 | }
|
198 | }
|
199 |
|
200 | for (i = 0; i < item.cells.length; i++) {
|
201 | item.cells[i] = item.cells[i].split(/ *\| */);
|
202 | }
|
203 |
|
204 | this.tokens.push(item);
|
205 |
|
206 | continue;
|
207 | }
|
208 |
|
209 | // lheading
|
210 | if (cap = this.rules.lheading.exec(src)) {
|
211 | src = src.substring(cap[0].length);
|
212 | this.tokens.push({
|
213 | type: 'heading',
|
214 | depth: cap[2] === '=' ? 1 : 2,
|
215 | text: cap[1]
|
216 | });
|
217 | continue;
|
218 | }
|
219 |
|
220 | // hr
|
221 | if (cap = this.rules.hr.exec(src)) {
|
222 | src = src.substring(cap[0].length);
|
223 | this.tokens.push({
|
224 | type: 'hr'
|
225 | });
|
226 | continue;
|
227 | }
|
228 |
|
229 | // blockquote
|
230 | if (cap = this.rules.blockquote.exec(src)) {
|
231 | src = src.substring(cap[0].length);
|
232 |
|
233 | this.tokens.push({
|
234 | type: 'blockquote_start'
|
235 | });
|
236 |
|
237 | cap = cap[0].replace(/^ *> ?/gm, '');
|
238 |
|
239 | // Pass `top` to keep the current
|
240 | // "toplevel" state. This is exactly
|
241 | // how markdown.pl works.
|
242 | this.token(cap, top, true);
|
243 |
|
244 | this.tokens.push({
|
245 | type: 'blockquote_end'
|
246 | });
|
247 |
|
248 | continue;
|
249 | }
|
250 |
|
251 | // list
|
252 | if (cap = this.rules.list.exec(src)) {
|
253 | src = src.substring(cap[0].length);
|
254 | bull = cap[2];
|
255 |
|
256 | this.tokens.push({
|
257 | type: 'list_start',
|
258 | ordered: bull.length > 1
|
259 | });
|
260 |
|
261 | // Get each top-level item.
|
262 | cap = cap[0].match(this.rules.item);
|
263 |
|
264 | next = false;
|
265 | l = cap.length;
|
266 | i = 0;
|
267 |
|
268 | for (; i < l; i++) {
|
269 | item = cap[i];
|
270 |
|
271 | // Remove the list item's bullet
|
272 | // so it is seen as the next token.
|
273 | space = item.length;
|
274 | item = item.replace(/^ *([*+-]|\d+\.) +/, '');
|
275 |
|
276 | // Outdent whatever the
|
277 | // list item contains. Hacky.
|
278 | if (~item.indexOf('\n ')) {
|
279 | space -= item.length;
|
280 | item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
|
281 | }
|
282 |
|
283 | // Determine whether the next list item belongs here.
|
284 | // Backpedal if it does not belong in this list.
|
285 | if (this.options.smartLists && i !== l - 1) {
|
286 | b = block.bullet.exec(cap[i + 1])[0];
|
287 | if (bull !== b && !(bull.length > 1 && b.length > 1)) {
|
288 | src = cap.slice(i + 1).join('\n') + src;
|
289 | i = l - 1;
|
290 | }
|
291 | }
|
292 |
|
293 | // Determine whether item is loose or not.
|
294 | // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
295 | // for discount behavior.
|
296 | loose = next || /\n\n(?!\s*$)/.test(item);
|
297 | if (i !== l - 1) {
|
298 | next = item.charAt(item.length - 1) === '\n';
|
299 | if (!loose) loose = next;
|
300 | }
|
301 |
|
302 | this.tokens.push({
|
303 | type: loose ? 'loose_item_start' : 'list_item_start'
|
304 | });
|
305 |
|
306 | // Recurse.
|
307 | this.token(item, false, bq);
|
308 |
|
309 | this.tokens.push({
|
310 | type: 'list_item_end'
|
311 | });
|
312 | }
|
313 |
|
314 | this.tokens.push({
|
315 | type: 'list_end'
|
316 | });
|
317 |
|
318 | continue;
|
319 | }
|
320 |
|
321 | // html
|
322 | if (cap = this.rules.html.exec(src)) {
|
323 | src = src.substring(cap[0].length);
|
324 | this.tokens.push({
|
325 | type: this.options.sanitize ? 'paragraph' : 'html',
|
326 | pre: !this.options.sanitizer && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
327 | text: cap[0]
|
328 | });
|
329 | continue;
|
330 | }
|
331 |
|
332 | // def
|
333 | if (!bq && top && (cap = this.rules.def.exec(src))) {
|
334 | src = src.substring(cap[0].length);
|
335 | this.tokens.links[cap[1].toLowerCase()] = {
|
336 | href: cap[2],
|
337 | title: cap[3]
|
338 | };
|
339 | continue;
|
340 | }
|
341 |
|
342 | // table (gfm)
|
343 | if (top && (cap = this.rules.table.exec(src))) {
|
344 | src = src.substring(cap[0].length);
|
345 |
|
346 | item = {
|
347 | type: 'table',
|
348 | header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
349 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
350 | cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
|
351 | };
|
352 |
|
353 | for (i = 0; i < item.align.length; i++) {
|
354 | if (/^ *-+: *$/.test(item.align[i])) {
|
355 | item.align[i] = 'right';
|
356 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
357 | item.align[i] = 'center';
|
358 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
359 | item.align[i] = 'left';
|
360 | } else {
|
361 | item.align[i] = null;
|
362 | }
|
363 | }
|
364 |
|
365 | for (i = 0; i < item.cells.length; i++) {
|
366 | item.cells[i] = item.cells[i].replace(/^ *\| *| *\| *$/g, '').split(/ *\| */);
|
367 | }
|
368 |
|
369 | this.tokens.push(item);
|
370 |
|
371 | continue;
|
372 | }
|
373 |
|
374 | // top-level paragraph
|
375 | if (top && (cap = this.rules.paragraph.exec(src))) {
|
376 | src = src.substring(cap[0].length);
|
377 | this.tokens.push({
|
378 | type: 'paragraph',
|
379 | text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1]
|
380 | });
|
381 | continue;
|
382 | }
|
383 |
|
384 | // text
|
385 | if (cap = this.rules.text.exec(src)) {
|
386 | // Top-level should never reach here.
|
387 | src = src.substring(cap[0].length);
|
388 | this.tokens.push({
|
389 | type: 'text',
|
390 | text: cap[0]
|
391 | });
|
392 | continue;
|
393 | }
|
394 |
|
395 | if (src) {
|
396 | throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
397 | }
|
398 | }
|
399 |
|
400 | return this.tokens;
|
401 | };
|
402 |
|
403 | /**
|
404 | * Inline-Level Grammar
|
405 | */
|
406 |
|
407 | var inline = {
|
408 | escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
|
409 | autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
410 | url: noop,
|
411 | tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
|
412 | link: /^!?\[(inside)\]\(href\)/,
|
413 | reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
|
414 | nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
415 | strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
|
416 | em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
|
417 | code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
|
418 | br: /^ {2,}\n(?!\s*$)/,
|
419 | del: noop,
|
420 | text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
|
421 | };
|
422 |
|
423 | inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
|
424 | inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
|
425 |
|
426 | inline.link = replace(inline.link)('inside', inline._inside)('href', inline._href)();
|
427 |
|
428 | inline.reflink = replace(inline.reflink)('inside', inline._inside)();
|
429 |
|
430 | /**
|
431 | * Normal Inline Grammar
|
432 | */
|
433 |
|
434 | inline.normal = merge({}, inline);
|
435 |
|
436 | /**
|
437 | * Pedantic Inline Grammar
|
438 | */
|
439 |
|
440 | inline.pedantic = merge({}, inline.normal, {
|
441 | strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
|
442 | em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
|
443 | });
|
444 |
|
445 | /**
|
446 | * GFM Inline Grammar
|
447 | */
|
448 |
|
449 | inline.gfm = merge({}, inline.normal, {
|
450 | escape: replace(inline.escape)('])', '~|])')(),
|
451 | url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
|
452 | del: /^~~(?=\S)([\s\S]*?\S)~~/,
|
453 | text: replace(inline.text)(']|', '~]|')('|', '|https?://|')()
|
454 | });
|
455 |
|
456 | /**
|
457 | * GFM + Line Breaks Inline Grammar
|
458 | */
|
459 |
|
460 | inline.breaks = merge({}, inline.gfm, {
|
461 | br: replace(inline.br)('{2,}', '*')(),
|
462 | text: replace(inline.gfm.text)('{2,}', '*')()
|
463 | });
|
464 |
|
465 | /**
|
466 | * Inline Lexer & Compiler
|
467 | */
|
468 |
|
469 | function InlineLexer(links, options) {
|
470 | this.options = options || marked.defaults;
|
471 | this.links = links;
|
472 | this.rules = inline.normal;
|
473 | this.renderer = this.options.renderer || new Renderer();
|
474 | this.renderer.options = this.options;
|
475 |
|
476 | if (!this.links) {
|
477 | throw new Error('Tokens array requires a `links` property.');
|
478 | }
|
479 |
|
480 | if (this.options.gfm) {
|
481 | if (this.options.breaks) {
|
482 | this.rules = inline.breaks;
|
483 | } else {
|
484 | this.rules = inline.gfm;
|
485 | }
|
486 | } else if (this.options.pedantic) {
|
487 | this.rules = inline.pedantic;
|
488 | }
|
489 | }
|
490 |
|
491 | /**
|
492 | * Expose Inline Rules
|
493 | */
|
494 |
|
495 | InlineLexer.rules = inline;
|
496 |
|
497 | /**
|
498 | * Static Lexing/Compiling Method
|
499 | */
|
500 |
|
501 | InlineLexer.output = function (src, links, options) {
|
502 | var inline = new InlineLexer(links, options);
|
503 | return inline.output(src);
|
504 | };
|
505 |
|
506 | /**
|
507 | * Lexing/Compiling
|
508 | */
|
509 |
|
510 | InlineLexer.prototype.output = function (src) {
|
511 | var out = '',
|
512 | link,
|
513 | text,
|
514 | href,
|
515 | cap;
|
516 |
|
517 | while (src) {
|
518 | // escape
|
519 | if (cap = this.rules.escape.exec(src)) {
|
520 | src = src.substring(cap[0].length);
|
521 | out += cap[1];
|
522 | continue;
|
523 | }
|
524 |
|
525 | // autolink
|
526 | if (cap = this.rules.autolink.exec(src)) {
|
527 | src = src.substring(cap[0].length);
|
528 | if (cap[2] === '@') {
|
529 | text = cap[1].charAt(6) === ':' ? this.mangle(cap[1].substring(7)) : this.mangle(cap[1]);
|
530 | href = this.mangle('mailto:') + text;
|
531 | } else {
|
532 | text = escape(cap[1]);
|
533 | href = text;
|
534 | }
|
535 | out += this.renderer.link(href, null, text);
|
536 | continue;
|
537 | }
|
538 |
|
539 | // url (gfm)
|
540 | if (!this.inLink && (cap = this.rules.url.exec(src))) {
|
541 | src = src.substring(cap[0].length);
|
542 | text = escape(cap[1]);
|
543 | href = text;
|
544 | out += this.renderer.link(href, null, text);
|
545 | continue;
|
546 | }
|
547 |
|
548 | // tag
|
549 | if (cap = this.rules.tag.exec(src)) {
|
550 | if (!this.inLink && /^<a /i.test(cap[0])) {
|
551 | this.inLink = true;
|
552 | } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
|
553 | this.inLink = false;
|
554 | }
|
555 | src = src.substring(cap[0].length);
|
556 | out += this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]) : cap[0];
|
557 | continue;
|
558 | }
|
559 |
|
560 | // link
|
561 | if (cap = this.rules.link.exec(src)) {
|
562 | src = src.substring(cap[0].length);
|
563 | this.inLink = true;
|
564 | out += this.outputLink(cap, {
|
565 | href: cap[2],
|
566 | title: cap[3]
|
567 | });
|
568 | this.inLink = false;
|
569 | continue;
|
570 | }
|
571 |
|
572 | // reflink, nolink
|
573 | if ((cap = this.rules.reflink.exec(src)) || (cap = this.rules.nolink.exec(src))) {
|
574 | src = src.substring(cap[0].length);
|
575 | link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
576 | link = this.links[link.toLowerCase()];
|
577 | if (!link || !link.href) {
|
578 | out += cap[0].charAt(0);
|
579 | src = cap[0].substring(1) + src;
|
580 | continue;
|
581 | }
|
582 | this.inLink = true;
|
583 | out += this.outputLink(cap, link);
|
584 | this.inLink = false;
|
585 | continue;
|
586 | }
|
587 |
|
588 | // strong
|
589 | if (cap = this.rules.strong.exec(src)) {
|
590 | src = src.substring(cap[0].length);
|
591 | out += this.renderer.strong(this.output(cap[2] || cap[1]));
|
592 | continue;
|
593 | }
|
594 |
|
595 | // em
|
596 | if (cap = this.rules.em.exec(src)) {
|
597 | src = src.substring(cap[0].length);
|
598 | out += this.renderer.em(this.output(cap[2] || cap[1]));
|
599 | continue;
|
600 | }
|
601 |
|
602 | // code
|
603 | if (cap = this.rules.code.exec(src)) {
|
604 | src = src.substring(cap[0].length);
|
605 | out += this.renderer.codespan(escape(cap[2], true));
|
606 | continue;
|
607 | }
|
608 |
|
609 | // br
|
610 | if (cap = this.rules.br.exec(src)) {
|
611 | src = src.substring(cap[0].length);
|
612 | out += this.renderer.br();
|
613 | continue;
|
614 | }
|
615 |
|
616 | // del (gfm)
|
617 | if (cap = this.rules.del.exec(src)) {
|
618 | src = src.substring(cap[0].length);
|
619 | out += this.renderer.del(this.output(cap[1]));
|
620 | continue;
|
621 | }
|
622 |
|
623 | // text
|
624 | if (cap = this.rules.text.exec(src)) {
|
625 | src = src.substring(cap[0].length);
|
626 | out += this.renderer.text(escape(this.smartypants(cap[0])));
|
627 | continue;
|
628 | }
|
629 |
|
630 | if (src) {
|
631 | throw new Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
632 | }
|
633 | }
|
634 |
|
635 | return out;
|
636 | };
|
637 |
|
638 | /**
|
639 | * Compile Link
|
640 | */
|
641 |
|
642 | InlineLexer.prototype.outputLink = function (cap, link) {
|
643 | var href = escape(link.href),
|
644 | title = link.title ? escape(link.title) : null;
|
645 |
|
646 | return cap[0].charAt(0) !== '!' ? this.renderer.link(href, title, this.output(cap[1])) : this.renderer.image(href, title, escape(cap[1]));
|
647 | };
|
648 |
|
649 | /**
|
650 | * Smartypants Transformations
|
651 | */
|
652 |
|
653 | InlineLexer.prototype.smartypants = function (text) {
|
654 | if (!this.options.smartypants) return text;
|
655 | return text
|
656 | // em-dashes
|
657 | .replace(/---/g, '\u2014')
|
658 | // en-dashes
|
659 | .replace(/--/g, '\u2013')
|
660 | // opening singles
|
661 | .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
|
662 | // closing singles & apostrophes
|
663 | .replace(/'/g, '\u2019')
|
664 | // opening doubles
|
665 | .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201C')
|
666 | // closing doubles
|
667 | .replace(/"/g, '\u201D')
|
668 | // ellipses
|
669 | .replace(/\.{3}/g, '\u2026');
|
670 | };
|
671 |
|
672 | /**
|
673 | * Mangle Links
|
674 | */
|
675 |
|
676 | InlineLexer.prototype.mangle = function (text) {
|
677 | if (!this.options.mangle) return text;
|
678 | var out = '',
|
679 | l = text.length,
|
680 | i = 0,
|
681 | ch;
|
682 |
|
683 | for (; i < l; i++) {
|
684 | ch = text.charCodeAt(i);
|
685 | if (Math.random() > 0.5) {
|
686 | ch = 'x' + ch.toString(16);
|
687 | }
|
688 | out += '&#' + ch + ';';
|
689 | }
|
690 |
|
691 | return out;
|
692 | };
|
693 |
|
694 | /**
|
695 | * Renderer
|
696 | */
|
697 |
|
698 | function Renderer(options) {
|
699 | this.options = options || {};
|
700 | }
|
701 |
|
702 | Renderer.prototype.code = function (code, lang, escaped) {
|
703 | if (this.options.highlight) {
|
704 | var out = this.options.highlight(code, lang);
|
705 | if (out != null && out !== code) {
|
706 | escaped = true;
|
707 | code = out;
|
708 | }
|
709 | }
|
710 |
|
711 | if (!lang) {
|
712 | return '<pre><code>' + (escaped ? code : escape(code, true)) + '\n</code></pre>';
|
713 | }
|
714 |
|
715 | return '<pre><code class="' + this.options.langPrefix + escape(lang, true) + '">' + (escaped ? code : escape(code, true)) + '\n</code></pre>\n';
|
716 | };
|
717 |
|
718 | Renderer.prototype.blockquote = function (quote) {
|
719 | return '<blockquote>\n' + quote + '</blockquote>\n';
|
720 | };
|
721 |
|
722 | Renderer.prototype.html = function (html) {
|
723 | return html;
|
724 | };
|
725 |
|
726 | Renderer.prototype.heading = function (text, level, raw) {
|
727 | return '<h' + level + ' id="' + this.options.headerPrefix + raw.toLowerCase().replace(/[^\w]+/g, '-') + '">' + text + '</h' + level + '>\n';
|
728 | };
|
729 |
|
730 | Renderer.prototype.hr = function () {
|
731 | return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
732 | };
|
733 |
|
734 | Renderer.prototype.list = function (body, ordered) {
|
735 | var type = ordered ? 'ol' : 'ul';
|
736 | return '<' + type + '>\n' + body + '</' + type + '>\n';
|
737 | };
|
738 |
|
739 | Renderer.prototype.listitem = function (text) {
|
740 | return '<li>' + text + '</li>\n';
|
741 | };
|
742 |
|
743 | Renderer.prototype.paragraph = function (text) {
|
744 | return '<p>' + text + '</p>\n';
|
745 | };
|
746 |
|
747 | Renderer.prototype.table = function (header, body) {
|
748 | return '<table>\n' + '<thead>\n' + header + '</thead>\n' + '<tbody>\n' + body + '</tbody>\n' + '</table>\n';
|
749 | };
|
750 |
|
751 | Renderer.prototype.tablerow = function (content) {
|
752 | return '<tr>\n' + content + '</tr>\n';
|
753 | };
|
754 |
|
755 | Renderer.prototype.tablecell = function (content, flags) {
|
756 | var type = flags.header ? 'th' : 'td';
|
757 | var tag = flags.align ? '<' + type + ' style="text-align:' + flags.align + '">' : '<' + type + '>';
|
758 | return tag + content + '</' + type + '>\n';
|
759 | };
|
760 |
|
761 | // span level renderer
|
762 | Renderer.prototype.strong = function (text) {
|
763 | return '<strong>' + text + '</strong>';
|
764 | };
|
765 |
|
766 | Renderer.prototype.em = function (text) {
|
767 | return '<em>' + text + '</em>';
|
768 | };
|
769 |
|
770 | Renderer.prototype.codespan = function (text) {
|
771 | return '<code>' + text + '</code>';
|
772 | };
|
773 |
|
774 | Renderer.prototype.br = function () {
|
775 | return this.options.xhtml ? '<br/>' : '<br>';
|
776 | };
|
777 |
|
778 | Renderer.prototype.del = function (text) {
|
779 | return '<del>' + text + '</del>';
|
780 | };
|
781 |
|
782 | Renderer.prototype.link = function (href, title, text) {
|
783 | if (this.options.sanitize) {
|
784 | try {
|
785 | var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, '').toLowerCase();
|
786 | } catch (e) {
|
787 | return '';
|
788 | }
|
789 | if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
|
790 | return '';
|
791 | }
|
792 | }
|
793 | var out = '<a href="' + href + '"';
|
794 | if (title) {
|
795 | out += ' title="' + title + '"';
|
796 | }
|
797 | out += '>' + text + '</a>';
|
798 | return out;
|
799 | };
|
800 |
|
801 | Renderer.prototype.image = function (href, title, text) {
|
802 | var out = '<img src="' + href + '" alt="' + text + '"';
|
803 | if (title) {
|
804 | out += ' title="' + title + '"';
|
805 | }
|
806 | out += this.options.xhtml ? '/>' : '>';
|
807 | return out;
|
808 | };
|
809 |
|
810 | Renderer.prototype.text = function (text) {
|
811 | return text;
|
812 | };
|
813 |
|
814 | /**
|
815 | * Parsing & Compiling
|
816 | */
|
817 |
|
818 | function Parser(options) {
|
819 | this.tokens = [];
|
820 | this.token = null;
|
821 | this.options = options || marked.defaults;
|
822 | this.options.renderer = this.options.renderer || new Renderer();
|
823 | this.renderer = this.options.renderer;
|
824 | this.renderer.options = this.options;
|
825 | }
|
826 |
|
827 | /**
|
828 | * Static Parse Method
|
829 | */
|
830 |
|
831 | Parser.parse = function (src, options, renderer) {
|
832 | var parser = new Parser(options, renderer);
|
833 | return parser.parse(src);
|
834 | };
|
835 |
|
836 | /**
|
837 | * Parse Loop
|
838 | */
|
839 |
|
840 | Parser.prototype.parse = function (src) {
|
841 | this.inline = new InlineLexer(src.links, this.options, this.renderer);
|
842 | this.tokens = src.reverse();
|
843 |
|
844 | var out = '';
|
845 | while (this.next()) {
|
846 | out += this.tok();
|
847 | }
|
848 |
|
849 | return out;
|
850 | };
|
851 |
|
852 | /**
|
853 | * Next Token
|
854 | */
|
855 |
|
856 | Parser.prototype.next = function () {
|
857 | return this.token = this.tokens.pop();
|
858 | };
|
859 |
|
860 | /**
|
861 | * Preview Next Token
|
862 | */
|
863 |
|
864 | Parser.prototype.peek = function () {
|
865 | return this.tokens[this.tokens.length - 1] || 0;
|
866 | };
|
867 |
|
868 | /**
|
869 | * Parse Text Tokens
|
870 | */
|
871 |
|
872 | Parser.prototype.parseText = function () {
|
873 | var body = this.token.text;
|
874 |
|
875 | while (this.peek().type === 'text') {
|
876 | body += '\n' + this.next().text;
|
877 | }
|
878 |
|
879 | return this.inline.output(body);
|
880 | };
|
881 |
|
882 | /**
|
883 | * Parse Current Token
|
884 | */
|
885 |
|
886 | Parser.prototype.tok = function () {
|
887 | switch (this.token.type) {
|
888 | case 'space':
|
889 | {
|
890 | return '';
|
891 | }
|
892 | case 'hr':
|
893 | {
|
894 | return this.renderer.hr();
|
895 | }
|
896 | case 'heading':
|
897 | {
|
898 | return this.renderer.heading(this.inline.output(this.token.text), this.token.depth, this.token.text);
|
899 | }
|
900 | case 'code':
|
901 | {
|
902 | return this.renderer.code(this.token.text, this.token.lang, this.token.escaped);
|
903 | }
|
904 | case 'table':
|
905 | {
|
906 | var header = '',
|
907 | body = '',
|
908 | i,
|
909 | row,
|
910 | cell,
|
911 | flags,
|
912 | j;
|
913 |
|
914 | // header
|
915 | cell = '';
|
916 | for (i = 0; i < this.token.header.length; i++) {
|
917 | flags = { header: true, align: this.token.align[i] };
|
918 | cell += this.renderer.tablecell(this.inline.output(this.token.header[i]), { header: true, align: this.token.align[i] });
|
919 | }
|
920 | header += this.renderer.tablerow(cell);
|
921 |
|
922 | for (i = 0; i < this.token.cells.length; i++) {
|
923 | row = this.token.cells[i];
|
924 |
|
925 | cell = '';
|
926 | for (j = 0; j < row.length; j++) {
|
927 | cell += this.renderer.tablecell(this.inline.output(row[j]), { header: false, align: this.token.align[j] });
|
928 | }
|
929 |
|
930 | body += this.renderer.tablerow(cell);
|
931 | }
|
932 | return this.renderer.table(header, body);
|
933 | }
|
934 | case 'blockquote_start':
|
935 | {
|
936 | var body = '';
|
937 |
|
938 | while (this.next().type !== 'blockquote_end') {
|
939 | body += this.tok();
|
940 | }
|
941 |
|
942 | return this.renderer.blockquote(body);
|
943 | }
|
944 | case 'list_start':
|
945 | {
|
946 | var body = '',
|
947 | ordered = this.token.ordered;
|
948 |
|
949 | while (this.next().type !== 'list_end') {
|
950 | body += this.tok();
|
951 | }
|
952 |
|
953 | return this.renderer.list(body, ordered);
|
954 | }
|
955 | case 'list_item_start':
|
956 | {
|
957 | var body = '';
|
958 |
|
959 | while (this.next().type !== 'list_item_end') {
|
960 | body += this.token.type === 'text' ? this.parseText() : this.tok();
|
961 | }
|
962 |
|
963 | return this.renderer.listitem(body);
|
964 | }
|
965 | case 'loose_item_start':
|
966 | {
|
967 | var body = '';
|
968 |
|
969 | while (this.next().type !== 'list_item_end') {
|
970 | body += this.tok();
|
971 | }
|
972 |
|
973 | return this.renderer.listitem(body);
|
974 | }
|
975 | case 'html':
|
976 | {
|
977 | var html = !this.token.pre && !this.options.pedantic ? this.inline.output(this.token.text) : this.token.text;
|
978 | return this.renderer.html(html);
|
979 | }
|
980 | case 'paragraph':
|
981 | {
|
982 | return this.renderer.paragraph(this.inline.output(this.token.text));
|
983 | }
|
984 | case 'text':
|
985 | {
|
986 | return this.renderer.paragraph(this.parseText());
|
987 | }
|
988 | }
|
989 | };
|
990 |
|
991 | /**
|
992 | * Helpers
|
993 | */
|
994 |
|
995 | function escape(html, encode) {
|
996 | return html.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
997 | }
|
998 |
|
999 | function unescape(html) {
|
1000 | // explicitly match decimal, hex, and named HTML entities
|
1001 | return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function (_, n) {
|
1002 | n = n.toLowerCase();
|
1003 | if (n === 'colon') return ':';
|
1004 | if (n.charAt(0) === '#') {
|
1005 | return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1));
|
1006 | }
|
1007 | return '';
|
1008 | });
|
1009 | }
|
1010 |
|
1011 | function replace(regex, opt) {
|
1012 | regex = regex.source;
|
1013 | opt = opt || '';
|
1014 | return function self(name, val) {
|
1015 | if (!name) return new RegExp(regex, opt);
|
1016 | val = val.source || val;
|
1017 | val = val.replace(/(^|[^\[])\^/g, '$1');
|
1018 | regex = regex.replace(name, val);
|
1019 | return self;
|
1020 | };
|
1021 | }
|
1022 |
|
1023 | function noop() {}
|
1024 | noop.exec = noop;
|
1025 |
|
1026 | function merge(obj) {
|
1027 | var i = 1,
|
1028 | target,
|
1029 | key;
|
1030 |
|
1031 | for (; i < arguments.length; i++) {
|
1032 | target = arguments[i];
|
1033 | for (key in target) {
|
1034 | if (Object.prototype.hasOwnProperty.call(target, key)) {
|
1035 | obj[key] = target[key];
|
1036 | }
|
1037 | }
|
1038 | }
|
1039 |
|
1040 | return obj;
|
1041 | }
|
1042 |
|
1043 | /**
|
1044 | * Marked
|
1045 | */
|
1046 |
|
1047 | function marked(src, opt, callback) {
|
1048 | if (callback || typeof opt === 'function') {
|
1049 | if (!callback) {
|
1050 | callback = opt;
|
1051 | opt = null;
|
1052 | }
|
1053 |
|
1054 | opt = merge({}, marked.defaults, opt || {});
|
1055 |
|
1056 | var highlight = opt.highlight,
|
1057 | tokens,
|
1058 | pending,
|
1059 | i = 0;
|
1060 |
|
1061 | try {
|
1062 | tokens = Lexer.lex(src, opt);
|
1063 | } catch (e) {
|
1064 | return callback(e);
|
1065 | }
|
1066 |
|
1067 | pending = tokens.length;
|
1068 |
|
1069 | var done = function done(err) {
|
1070 | if (err) {
|
1071 | opt.highlight = highlight;
|
1072 | return callback(err);
|
1073 | }
|
1074 |
|
1075 | var out;
|
1076 |
|
1077 | try {
|
1078 | out = Parser.parse(tokens, opt);
|
1079 | } catch (e) {
|
1080 | err = e;
|
1081 | }
|
1082 |
|
1083 | opt.highlight = highlight;
|
1084 |
|
1085 | return err ? callback(err) : callback(null, out);
|
1086 | };
|
1087 |
|
1088 | if (!highlight || highlight.length < 3) {
|
1089 | return done();
|
1090 | }
|
1091 |
|
1092 | delete opt.highlight;
|
1093 |
|
1094 | if (!pending) return done();
|
1095 |
|
1096 | for (; i < tokens.length; i++) {
|
1097 | (function (token) {
|
1098 | if (token.type !== 'code') {
|
1099 | return --pending || done();
|
1100 | }
|
1101 | return highlight(token.text, token.lang, function (err, code) {
|
1102 | if (err) return done(err);
|
1103 | if (code == null || code === token.text) {
|
1104 | return --pending || done();
|
1105 | }
|
1106 | token.text = code;
|
1107 | token.escaped = true;
|
1108 | --pending || done();
|
1109 | });
|
1110 | })(tokens[i]);
|
1111 | }
|
1112 |
|
1113 | return;
|
1114 | }
|
1115 | try {
|
1116 | if (opt) opt = merge({}, marked.defaults, opt);
|
1117 | return Parser.parse(Lexer.lex(src, opt), opt);
|
1118 | } catch (e) {
|
1119 | e.message += '\nPlease report this to https://github.com/chjj/marked.';
|
1120 | if ((opt || marked.defaults).silent) {
|
1121 | return '<p>An error occured:</p><pre>' + escape(e.message + '', true) + '</pre>';
|
1122 | }
|
1123 | throw e;
|
1124 | }
|
1125 | }
|
1126 |
|
1127 | /**
|
1128 | * Options
|
1129 | */
|
1130 |
|
1131 | marked.options = marked.setOptions = function (opt) {
|
1132 | merge(marked.defaults, opt);
|
1133 | return marked;
|
1134 | };
|
1135 |
|
1136 | marked.defaults = {
|
1137 | gfm: true,
|
1138 | tables: true,
|
1139 | breaks: false,
|
1140 | pedantic: false,
|
1141 | sanitize: false,
|
1142 | sanitizer: null,
|
1143 | mangle: true,
|
1144 | smartLists: false,
|
1145 | silent: false,
|
1146 | highlight: null,
|
1147 | langPrefix: 'lang-',
|
1148 | smartypants: false,
|
1149 | headerPrefix: '',
|
1150 | renderer: new Renderer(),
|
1151 | xhtml: false
|
1152 | };
|
1153 |
|
1154 | /**
|
1155 | * Expose
|
1156 | */
|
1157 |
|
1158 | marked.Parser = Parser;
|
1159 | marked.parser = Parser.parse;
|
1160 |
|
1161 | marked.Renderer = Renderer;
|
1162 |
|
1163 | marked.Lexer = Lexer;
|
1164 | marked.lexer = Lexer.lex;
|
1165 |
|
1166 | marked.InlineLexer = InlineLexer;
|
1167 | marked.inlineLexer = InlineLexer.output;
|
1168 |
|
1169 | marked.parse = marked;
|
1170 |
|
1171 | if (typeof module !== 'undefined' && (typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
|
1172 | module.exports = marked;
|
1173 | } else if (typeof define === 'function' && define.amd) {
|
1174 | define(function () {
|
1175 | return marked;
|
1176 | });
|
1177 | } else {
|
1178 | this.marked = marked;
|
1179 | }
|
1180 | }).call(function () {
|
1181 | return this || (typeof window !== 'undefined' ? window : global);
|
1182 | }());
|
1183 | ;
|
1184 |
|
1185 | var _temp = function () {
|
1186 | if (typeof __REACT_HOT_LOADER__ === 'undefined') {
|
1187 | return;
|
1188 | }
|
1189 | }();
|
1190 |
|
1191 | ; |
\ | No newline at end of file |