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