3 * marked - a markdown parser
4 * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
5 * https://github.com/chjj/marked
12 // alert( Roo.ux.Showdown.toHtml("Markdown *rocks*.") );
14 // Note: move the sample code to the bottom of this
15 // file before uncommenting it.
22 Roo.namespace('Roo.ux');
24 Roo.ux.Showdown.toHtml = function(text) {
26 var c = new Roo.ux.Showdown.marked.setOptions({
27 renderer: new Roo.ux.Showdown.marked.Renderer(),
37 return Roo.ux.Showdown.marked(text);
42 // Wraps all "globals" so that the only thing
43 // exposed is makeHtml().
53 code: /^( {4}[^\n]+\n*)+/,
55 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
56 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
58 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
59 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
60 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
61 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
62 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
64 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
68 block.bullet = /(?:[*+-]|\d+\.)/;
69 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
70 block.item = replace(block.item, 'gm')
71 (/bull/g, block.bullet)
74 block.list = replace(block.list)
75 (/bull/g, block.bullet)
76 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
77 ('def', '\\n+(?=' + block.def.source + ')')
80 block.blockquote = replace(block.blockquote)
85 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
86 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
87 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
89 block.html = replace(block.html)
90 ('comment', /<!--[\s\S]*?-->/)
91 ('closed', /<(tag)[\s\S]+?<\/\1>/)
92 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
96 block.paragraph = replace(block.paragraph)
98 ('heading', block.heading)
99 ('lheading', block.lheading)
100 ('blockquote', block.blockquote)
101 ('tag', '<' + block._tag)
106 * Normal Block Grammar
109 block.normal = merge({}, block);
115 block.gfm = merge({}, block.normal, {
116 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
118 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
121 block.gfm.paragraph = replace(block.paragraph)
123 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
124 + block.list.source.replace('\\1', '\\3') + '|')
128 * GFM + Tables Block Grammar
131 block.tables = merge({}, block.gfm, {
132 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
133 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
140 function Lexer(options) {
142 this.tokens.links = {};
143 this.options = options || marked.defaults;
144 this.rules = block.normal;
146 if (this.options.gfm) {
147 if (this.options.tables) {
148 this.rules = block.tables;
150 this.rules = block.gfm;
165 Lexer.lex = function(src, options) {
166 var lexer = new Lexer(options);
167 return lexer.lex(src);
174 Lexer.prototype.lex = function(src) {
176 .replace(/\r\n|\r/g, '\n')
178 .replace(/\u00a0/g, ' ')
179 .replace(/\u2424/g, '\n');
181 return this.token(src, true);
188 Lexer.prototype.token = function(src, top, bq) {
189 var src = src.replace(/^ +$/gm, '')
202 if (cap = this.rules.newline.exec(src)) {
203 src = src.substring(cap[0].length);
204 if (cap[0].length > 1) {
212 if (cap = this.rules.code.exec(src)) {
213 src = src.substring(cap[0].length);
214 cap = cap[0].replace(/^ {4}/gm, '');
217 text: !this.options.pedantic
218 ? cap.replace(/\n+$/, '')
225 if (cap = this.rules.fences.exec(src)) {
226 src = src.substring(cap[0].length);
236 if (cap = this.rules.heading.exec(src)) {
237 src = src.substring(cap[0].length);
240 depth: cap[1].length,
246 // table no leading pipe (gfm)
247 if (top && (cap = this.rules.nptable.exec(src))) {
248 src = src.substring(cap[0].length);
252 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
253 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
254 cells: cap[3].replace(/\n$/, '').split('\n')
257 for (i = 0; i < item.align.length; i++) {
258 if (/^ *-+: *$/.test(item.align[i])) {
259 item.align[i] = 'right';
260 } else if (/^ *:-+: *$/.test(item.align[i])) {
261 item.align[i] = 'center';
262 } else if (/^ *:-+ *$/.test(item.align[i])) {
263 item.align[i] = 'left';
265 item.align[i] = null;
269 for (i = 0; i < item.cells.length; i++) {
270 item.cells[i] = item.cells[i].split(/ *\| */);
273 this.tokens.push(item);
279 if (cap = this.rules.lheading.exec(src)) {
280 src = src.substring(cap[0].length);
283 depth: cap[2] === '=' ? 1 : 2,
290 if (cap = this.rules.hr.exec(src)) {
291 src = src.substring(cap[0].length);
299 if (cap = this.rules.blockquote.exec(src)) {
300 src = src.substring(cap[0].length);
303 type: 'blockquote_start'
306 cap = cap[0].replace(/^ *> ?/gm, '');
308 // Pass `top` to keep the current
309 // "toplevel" state. This is exactly
310 // how markdown.pl works.
311 this.token(cap, top, true);
314 type: 'blockquote_end'
321 if (cap = this.rules.list.exec(src)) {
322 src = src.substring(cap[0].length);
327 ordered: bull.length > 1
330 // Get each top-level item.
331 cap = cap[0].match(this.rules.item);
340 // Remove the list item's bullet
341 // so it is seen as the next token.
343 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
345 // Outdent whatever the
346 // list item contains. Hacky.
347 if (~item.indexOf('\n ')) {
348 space -= item.length;
349 item = !this.options.pedantic
350 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
351 : item.replace(/^ {1,4}/gm, '');
354 // Determine whether the next list item belongs here.
355 // Backpedal if it does not belong in this list.
356 if (this.options.smartLists && i !== l - 1) {
357 b = block.bullet.exec(cap[i + 1])[0];
358 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
359 src = cap.slice(i + 1).join('\n') + src;
364 // Determine whether item is loose or not.
365 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
366 // for discount behavior.
367 loose = next || /\n\n(?!\s*$)/.test(item);
369 next = item.charAt(item.length - 1) === '\n';
370 if (!loose) loose = next;
380 this.token(item, false, bq);
383 type: 'list_item_end'
395 if (cap = this.rules.html.exec(src)) {
396 src = src.substring(cap[0].length);
398 type: this.options.sanitize
401 pre: !this.options.sanitizer
402 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
409 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
410 src = src.substring(cap[0].length);
411 this.tokens.links[cap[1].toLowerCase()] = {
419 if (top && (cap = this.rules.table.exec(src))) {
420 src = src.substring(cap[0].length);
424 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
425 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
426 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
429 for (i = 0; i < item.align.length; i++) {
430 if (/^ *-+: *$/.test(item.align[i])) {
431 item.align[i] = 'right';
432 } else if (/^ *:-+: *$/.test(item.align[i])) {
433 item.align[i] = 'center';
434 } else if (/^ *:-+ *$/.test(item.align[i])) {
435 item.align[i] = 'left';
437 item.align[i] = null;
441 for (i = 0; i < item.cells.length; i++) {
442 item.cells[i] = item.cells[i]
443 .replace(/^ *\| *| *\| *$/g, '')
447 this.tokens.push(item);
452 // top-level paragraph
453 if (top && (cap = this.rules.paragraph.exec(src))) {
454 src = src.substring(cap[0].length);
457 text: cap[1].charAt(cap[1].length - 1) === '\n'
458 ? cap[1].slice(0, -1)
465 if (cap = this.rules.text.exec(src)) {
466 // Top-level should never reach here.
467 src = src.substring(cap[0].length);
477 Error('Infinite loop on byte: ' + src.charCodeAt(0));
485 * Inline-Level Grammar
489 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
490 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
492 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
493 link: /^!?\[(inside)\]\(href\)/,
494 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
495 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
496 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
497 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
498 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
499 br: /^ {2,}\n(?!\s*$)/,
501 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
504 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
505 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
507 inline.link = replace(inline.link)
508 ('inside', inline._inside)
509 ('href', inline._href)
512 inline.reflink = replace(inline.reflink)
513 ('inside', inline._inside)
517 * Normal Inline Grammar
520 inline.normal = merge({}, inline);
523 * Pedantic Inline Grammar
526 inline.pedantic = merge({}, inline.normal, {
527 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
528 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
535 inline.gfm = merge({}, inline.normal, {
536 escape: replace(inline.escape)('])', '~|])')(),
537 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
538 del: /^~~(?=\S)([\s\S]*?\S)~~/,
539 text: replace(inline.text)
546 * GFM + Line Breaks Inline Grammar
549 inline.breaks = merge({}, inline.gfm, {
550 br: replace(inline.br)('{2,}', '*')(),
551 text: replace(inline.gfm.text)('{2,}', '*')()
555 * Inline Lexer & Compiler
558 function InlineLexer(links, options) {
559 this.options = options || marked.defaults;
561 this.rules = inline.normal;
562 this.renderer = this.options.renderer || new Renderer;
563 this.renderer.options = this.options;
567 Error('Tokens array requires a `links` property.');
570 if (this.options.gfm) {
571 if (this.options.breaks) {
572 this.rules = inline.breaks;
574 this.rules = inline.gfm;
576 } else if (this.options.pedantic) {
577 this.rules = inline.pedantic;
582 * Expose Inline Rules
585 InlineLexer.rules = inline;
588 * Static Lexing/Compiling Method
591 InlineLexer.output = function(src, links, options) {
592 var inline = new InlineLexer(links, options);
593 return inline.output(src);
600 InlineLexer.prototype.output = function(src) {
609 if (cap = this.rules.escape.exec(src)) {
610 src = src.substring(cap[0].length);
616 if (cap = this.rules.autolink.exec(src)) {
617 src = src.substring(cap[0].length);
618 if (cap[2] === '@') {
619 text = cap[1].charAt(6) === ':'
620 ? this.mangle(cap[1].substring(7))
621 : this.mangle(cap[1]);
622 href = this.mangle('mailto:') + text;
624 text = escape(cap[1]);
627 out += this.renderer.link(href, null, text);
632 if (!this.inLink && (cap = this.rules.url.exec(src))) {
633 src = src.substring(cap[0].length);
634 text = escape(cap[1]);
636 out += this.renderer.link(href, null, text);
641 if (cap = this.rules.tag.exec(src)) {
642 if (!this.inLink && /^<a /i.test(cap[0])) {
644 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
647 src = src.substring(cap[0].length);
648 out += this.options.sanitize
649 ? this.options.sanitizer
650 ? this.options.sanitizer(cap[0])
657 if (cap = this.rules.link.exec(src)) {
658 src = src.substring(cap[0].length);
660 out += this.outputLink(cap, {
669 if ((cap = this.rules.reflink.exec(src))
670 || (cap = this.rules.nolink.exec(src))) {
671 src = src.substring(cap[0].length);
672 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
673 link = this.links[link.toLowerCase()];
674 if (!link || !link.href) {
675 out += cap[0].charAt(0);
676 src = cap[0].substring(1) + src;
680 out += this.outputLink(cap, link);
686 if (cap = this.rules.strong.exec(src)) {
687 src = src.substring(cap[0].length);
688 out += this.renderer.strong(this.output(cap[2] || cap[1]));
693 if (cap = this.rules.em.exec(src)) {
694 src = src.substring(cap[0].length);
695 out += this.renderer.em(this.output(cap[2] || cap[1]));
700 if (cap = this.rules.code.exec(src)) {
701 src = src.substring(cap[0].length);
702 out += this.renderer.codespan(escape(cap[2], true));
707 if (cap = this.rules.br.exec(src)) {
708 src = src.substring(cap[0].length);
709 out += this.renderer.br();
714 if (cap = this.rules.del.exec(src)) {
715 src = src.substring(cap[0].length);
716 out += this.renderer.del(this.output(cap[1]));
721 if (cap = this.rules.text.exec(src)) {
722 src = src.substring(cap[0].length);
723 out += this.renderer.text(escape(this.smartypants(cap[0])));
729 Error('Infinite loop on byte: ' + src.charCodeAt(0));
740 InlineLexer.prototype.outputLink = function(cap, link) {
741 var href = escape(link.href)
742 , title = link.title ? escape(link.title) : null;
744 return cap[0].charAt(0) !== '!'
745 ? this.renderer.link(href, title, this.output(cap[1]))
746 : this.renderer.image(href, title, escape(cap[1]));
750 * Smartypants Transformations
753 InlineLexer.prototype.smartypants = function(text) {
754 if (!this.options.smartypants) return text;
757 .replace(/---/g, '\u2014')
759 .replace(/--/g, '\u2013')
761 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
762 // closing singles & apostrophes
763 .replace(/'/g, '\u2019')
765 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
767 .replace(/"/g, '\u201d')
769 .replace(/\.{3}/g, '\u2026');
776 InlineLexer.prototype.mangle = function(text) {
777 if (!this.options.mangle) return text;
784 ch = text.charCodeAt(i);
785 if (Math.random() > 0.5) {
786 ch = 'x' + ch.toString(16);
788 out += '&#' + ch + ';';
798 function Renderer(options) {
799 this.options = options || {};
802 Renderer.prototype.code = function(code, lang, escaped) {
803 if (this.options.highlight) {
804 var out = this.options.highlight(code, lang);
805 if (out != null && out !== code) {
814 + (escaped ? code : escape(code, true))
818 return '<pre><code class="'
819 + this.options.langPrefix
822 + (escaped ? code : escape(code, true))
823 + '\n</code></pre>\n';
826 Renderer.prototype.blockquote = function(quote) {
827 return '<blockquote>\n' + quote + '</blockquote>\n';
830 Renderer.prototype.html = function(html) {
834 Renderer.prototype.heading = function(text, level, raw) {
838 + this.options.headerPrefix
839 + raw.toLowerCase().replace(/[^\w]+/g, '-')
847 Renderer.prototype.hr = function() {
848 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
851 Renderer.prototype.list = function(body, ordered) {
852 var type = ordered ? 'ol' : 'ul';
853 return '<' + type + '>\n' + body + '</' + type + '>\n';
856 Renderer.prototype.listitem = function(text) {
857 return '<li>' + text + '</li>\n';
860 Renderer.prototype.paragraph = function(text) {
861 return '<p>' + text + '</p>\n';
864 Renderer.prototype.table = function(header, body) {
875 Renderer.prototype.tablerow = function(content) {
876 return '<tr>\n' + content + '</tr>\n';
879 Renderer.prototype.tablecell = function(content, flags) {
880 var type = flags.header ? 'th' : 'td';
881 var tag = flags.align
882 ? '<' + type + ' style="text-align:' + flags.align + '">'
884 return tag + content + '</' + type + '>\n';
887 // span level renderer
888 Renderer.prototype.strong = function(text) {
889 return '<strong>' + text + '</strong>';
892 Renderer.prototype.em = function(text) {
893 return '<em>' + text + '</em>';
896 Renderer.prototype.codespan = function(text) {
897 return '<code>' + text + '</code>';
900 Renderer.prototype.br = function() {
901 return this.options.xhtml ? '<br/>' : '<br>';
904 Renderer.prototype.del = function(text) {
905 return '<del>' + text + '</del>';
908 Renderer.prototype.link = function(href, title, text) {
909 if (this.options.sanitize) {
911 var prot = decodeURIComponent(unescape(href))
912 .replace(/[^\w:]/g, '')
917 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
921 var out = '<a href="' + href + '"';
923 out += ' title="' + title + '"';
925 out += '>' + text + '</a>';
929 Renderer.prototype.image = function(href, title, text) {
930 var out = '<img src="' + href + '" alt="' + text + '"';
932 out += ' title="' + title + '"';
934 out += this.options.xhtml ? '/>' : '>';
938 Renderer.prototype.text = function(text) {
943 * Parsing & Compiling
946 function Parser(options) {
949 this.options = options || marked.defaults;
950 this.options.renderer = this.options.renderer || new Renderer;
951 this.renderer = this.options.renderer;
952 this.renderer.options = this.options;
956 * Static Parse Method
959 Parser.parse = function(src, options, renderer) {
960 var parser = new Parser(options, renderer);
961 return parser.parse(src);
968 Parser.prototype.parse = function(src) {
969 this.inline = new InlineLexer(src.links, this.options, this.renderer);
970 this.tokens = src.reverse();
973 while (this.next()) {
984 Parser.prototype.next = function() {
985 return this.token = this.tokens.pop();
992 Parser.prototype.peek = function() {
993 return this.tokens[this.tokens.length - 1] || 0;
1000 Parser.prototype.parseText = function() {
1001 var body = this.token.text;
1003 while (this.peek().type === 'text') {
1004 body += '\n' + this.next().text;
1007 return this.inline.output(body);
1011 * Parse Current Token
1014 Parser.prototype.tok = function() {
1015 switch (this.token.type) {
1020 return this.renderer.hr();
1023 return this.renderer.heading(
1024 this.inline.output(this.token.text),
1029 return this.renderer.code(this.token.text,
1031 this.token.escaped);
1044 for (i = 0; i < this.token.header.length; i++) {
1045 flags = { header: true, align: this.token.align[i] };
1046 cell += this.renderer.tablecell(
1047 this.inline.output(this.token.header[i]),
1048 { header: true, align: this.token.align[i] }
1051 header += this.renderer.tablerow(cell);
1053 for (i = 0; i < this.token.cells.length; i++) {
1054 row = this.token.cells[i];
1057 for (j = 0; j < row.length; j++) {
1058 cell += this.renderer.tablecell(
1059 this.inline.output(row[j]),
1060 { header: false, align: this.token.align[j] }
1064 body += this.renderer.tablerow(cell);
1066 return this.renderer.table(header, body);
1068 case 'blockquote_start': {
1071 while (this.next().type !== 'blockquote_end') {
1075 return this.renderer.blockquote(body);
1077 case 'list_start': {
1079 , ordered = this.token.ordered;
1081 while (this.next().type !== 'list_end') {
1085 return this.renderer.list(body, ordered);
1087 case 'list_item_start': {
1090 while (this.next().type !== 'list_item_end') {
1091 body += this.token.type === 'text'
1096 return this.renderer.listitem(body);
1098 case 'loose_item_start': {
1101 while (this.next().type !== 'list_item_end') {
1105 return this.renderer.listitem(body);
1108 var html = !this.token.pre && !this.options.pedantic
1109 ? this.inline.output(this.token.text)
1111 return this.renderer.html(html);
1114 return this.renderer.paragraph(this.inline.output(this.token.text));
1117 return this.renderer.paragraph(this.parseText());
1126 function escape(html, encode) {
1128 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
1129 .replace(/</g, '<')
1130 .replace(/>/g, '>')
1131 .replace(/"/g, '"')
1132 .replace(/'/g, ''');
1135 function unescape(html) {
1136 // explicitly match decimal, hex, and named HTML entities
1137 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
1138 n = n.toLowerCase();
1139 if (n === 'colon') return ':';
1140 if (n.charAt(0) === '#') {
1141 return n.charAt(1) === 'x'
1142 ? String.fromCharCode(parseInt(n.substring(2), 16))
1143 : String.fromCharCode(+n.substring(1));
1149 function replace(regex, opt) {
1150 regex = regex.source;
1152 return function self(name, val) {
1153 if (!name) return new RegExp(regex, opt);
1154 val = val.source || val;
1155 val = val.replace(/(^|[^\[])\^/g, '$1');
1156 regex = regex.replace(name, val);
1164 function merge(obj) {
1169 for (; i < arguments.length; i++) {
1170 target = arguments[i];
1171 for (key in target) {
1172 if (Object.prototype.hasOwnProperty.call(target, key)) {
1173 obj[key] = target[key];
1186 function marked(src, opt, callback) {
1187 if (callback || typeof opt === 'function') {
1193 opt = merge({}, marked.defaults, opt || {});
1195 var highlight = opt.highlight
1201 tokens = Lexer.lex(src, opt)
1206 pending = tokens.length;
1208 var done = function(err) {
1210 opt.highlight = highlight;
1211 return callback(err);
1217 out = Parser.parse(tokens, opt);
1222 opt.highlight = highlight;
1226 : callback(null, out);
1229 if (!highlight || highlight.length < 3) {
1233 delete opt.highlight;
1235 if (!pending) return done();
1237 for (; i < tokens.length; i++) {
1239 if (token.type !== 'code') {
1240 return --pending || done();
1242 return highlight(token.text, token.lang, function(err, code) {
1243 if (err) return done(err);
1244 if (code == null || code === token.text) {
1245 return --pending || done();
1248 token.escaped = true;
1249 --pending || done();
1257 if (opt) opt = merge({}, marked.defaults, opt);
1258 return Parser.parse(Lexer.lex(src, opt), opt);
1260 e.message += '\nPlease report this to https://github.com/chjj/marked.';
1261 if ((opt || marked.defaults).silent) {
1262 return '<p>An error occured:</p><pre>'
1263 + escape(e.message + '', true)
1275 marked.setOptions = function(opt) {
1276 merge(marked.defaults, opt);
1291 langPrefix: 'lang-',
1294 renderer: new Renderer,
1302 marked.Parser = Parser;
1303 marked.parser = Parser.parse;
1305 marked.Renderer = Renderer;
1307 marked.Lexer = Lexer;
1308 marked.lexer = Lexer.lex;
1310 marked.InlineLexer = InlineLexer;
1311 marked.inlineLexer = InlineLexer.output;
1313 marked.parse = marked;
1315 Roo.ux.Showdown.marked = marked;