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) {
25 var c = new Roo.ux.Showdown.converter();
26 return c.makeHtml(text);
31 // Wraps all "globals" so that the only thing
32 // exposed is makeHtml().
42 code: /^( {4}[^\n]+\n*)+/,
44 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
45 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
47 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
48 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
49 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
50 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
51 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
53 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
57 block.bullet = /(?:[*+-]|\d+\.)/;
58 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
59 block.item = replace(block.item, 'gm')
60 (/bull/g, block.bullet)
63 block.list = replace(block.list)
64 (/bull/g, block.bullet)
65 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
66 ('def', '\\n+(?=' + block.def.source + ')')
69 block.blockquote = replace(block.blockquote)
74 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
75 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
76 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
78 block.html = replace(block.html)
79 ('comment', /<!--[\s\S]*?-->/)
80 ('closed', /<(tag)[\s\S]+?<\/\1>/)
81 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
85 block.paragraph = replace(block.paragraph)
87 ('heading', block.heading)
88 ('lheading', block.lheading)
89 ('blockquote', block.blockquote)
90 ('tag', '<' + block._tag)
95 * Normal Block Grammar
98 block.normal = merge({}, block);
104 block.gfm = merge({}, block.normal, {
105 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
107 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
110 block.gfm.paragraph = replace(block.paragraph)
112 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
113 + block.list.source.replace('\\1', '\\3') + '|')
117 * GFM + Tables Block Grammar
120 block.tables = merge({}, block.gfm, {
121 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
122 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
129 function Lexer(options) {
131 this.tokens.links = {};
132 this.options = options || marked.defaults;
133 this.rules = block.normal;
135 if (this.options.gfm) {
136 if (this.options.tables) {
137 this.rules = block.tables;
139 this.rules = block.gfm;
154 Lexer.lex = function(src, options) {
155 var lexer = new Lexer(options);
156 return lexer.lex(src);
163 Lexer.prototype.lex = function(src) {
165 .replace(/\r\n|\r/g, '\n')
167 .replace(/\u00a0/g, ' ')
168 .replace(/\u2424/g, '\n');
170 return this.token(src, true);
177 Lexer.prototype.token = function(src, top, bq) {
178 var src = src.replace(/^ +$/gm, '')
191 if (cap = this.rules.newline.exec(src)) {
192 src = src.substring(cap[0].length);
193 if (cap[0].length > 1) {
201 if (cap = this.rules.code.exec(src)) {
202 src = src.substring(cap[0].length);
203 cap = cap[0].replace(/^ {4}/gm, '');
206 text: !this.options.pedantic
207 ? cap.replace(/\n+$/, '')
214 if (cap = this.rules.fences.exec(src)) {
215 src = src.substring(cap[0].length);
225 if (cap = this.rules.heading.exec(src)) {
226 src = src.substring(cap[0].length);
229 depth: cap[1].length,
235 // table no leading pipe (gfm)
236 if (top && (cap = this.rules.nptable.exec(src))) {
237 src = src.substring(cap[0].length);
241 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
242 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
243 cells: cap[3].replace(/\n$/, '').split('\n')
246 for (i = 0; i < item.align.length; i++) {
247 if (/^ *-+: *$/.test(item.align[i])) {
248 item.align[i] = 'right';
249 } else if (/^ *:-+: *$/.test(item.align[i])) {
250 item.align[i] = 'center';
251 } else if (/^ *:-+ *$/.test(item.align[i])) {
252 item.align[i] = 'left';
254 item.align[i] = null;
258 for (i = 0; i < item.cells.length; i++) {
259 item.cells[i] = item.cells[i].split(/ *\| */);
262 this.tokens.push(item);
268 if (cap = this.rules.lheading.exec(src)) {
269 src = src.substring(cap[0].length);
272 depth: cap[2] === '=' ? 1 : 2,
279 if (cap = this.rules.hr.exec(src)) {
280 src = src.substring(cap[0].length);
288 if (cap = this.rules.blockquote.exec(src)) {
289 src = src.substring(cap[0].length);
292 type: 'blockquote_start'
295 cap = cap[0].replace(/^ *> ?/gm, '');
297 // Pass `top` to keep the current
298 // "toplevel" state. This is exactly
299 // how markdown.pl works.
300 this.token(cap, top, true);
303 type: 'blockquote_end'
310 if (cap = this.rules.list.exec(src)) {
311 src = src.substring(cap[0].length);
316 ordered: bull.length > 1
319 // Get each top-level item.
320 cap = cap[0].match(this.rules.item);
329 // Remove the list item's bullet
330 // so it is seen as the next token.
332 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
334 // Outdent whatever the
335 // list item contains. Hacky.
336 if (~item.indexOf('\n ')) {
337 space -= item.length;
338 item = !this.options.pedantic
339 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
340 : item.replace(/^ {1,4}/gm, '');
343 // Determine whether the next list item belongs here.
344 // Backpedal if it does not belong in this list.
345 if (this.options.smartLists && i !== l - 1) {
346 b = block.bullet.exec(cap[i + 1])[0];
347 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
348 src = cap.slice(i + 1).join('\n') + src;
353 // Determine whether item is loose or not.
354 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
355 // for discount behavior.
356 loose = next || /\n\n(?!\s*$)/.test(item);
358 next = item.charAt(item.length - 1) === '\n';
359 if (!loose) loose = next;
369 this.token(item, false, bq);
372 type: 'list_item_end'
384 if (cap = this.rules.html.exec(src)) {
385 src = src.substring(cap[0].length);
387 type: this.options.sanitize
390 pre: !this.options.sanitizer
391 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
398 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
399 src = src.substring(cap[0].length);
400 this.tokens.links[cap[1].toLowerCase()] = {
408 if (top && (cap = this.rules.table.exec(src))) {
409 src = src.substring(cap[0].length);
413 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
414 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
415 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
418 for (i = 0; i < item.align.length; i++) {
419 if (/^ *-+: *$/.test(item.align[i])) {
420 item.align[i] = 'right';
421 } else if (/^ *:-+: *$/.test(item.align[i])) {
422 item.align[i] = 'center';
423 } else if (/^ *:-+ *$/.test(item.align[i])) {
424 item.align[i] = 'left';
426 item.align[i] = null;
430 for (i = 0; i < item.cells.length; i++) {
431 item.cells[i] = item.cells[i]
432 .replace(/^ *\| *| *\| *$/g, '')
436 this.tokens.push(item);
441 // top-level paragraph
442 if (top && (cap = this.rules.paragraph.exec(src))) {
443 src = src.substring(cap[0].length);
446 text: cap[1].charAt(cap[1].length - 1) === '\n'
447 ? cap[1].slice(0, -1)
454 if (cap = this.rules.text.exec(src)) {
455 // Top-level should never reach here.
456 src = src.substring(cap[0].length);
466 Error('Infinite loop on byte: ' + src.charCodeAt(0));
474 * Inline-Level Grammar
478 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
479 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
481 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
482 link: /^!?\[(inside)\]\(href\)/,
483 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
484 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
485 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
486 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
487 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
488 br: /^ {2,}\n(?!\s*$)/,
490 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
493 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
494 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
496 inline.link = replace(inline.link)
497 ('inside', inline._inside)
498 ('href', inline._href)
501 inline.reflink = replace(inline.reflink)
502 ('inside', inline._inside)
506 * Normal Inline Grammar
509 inline.normal = merge({}, inline);
512 * Pedantic Inline Grammar
515 inline.pedantic = merge({}, inline.normal, {
516 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
517 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
524 inline.gfm = merge({}, inline.normal, {
525 escape: replace(inline.escape)('])', '~|])')(),
526 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
527 del: /^~~(?=\S)([\s\S]*?\S)~~/,
528 text: replace(inline.text)
535 * GFM + Line Breaks Inline Grammar
538 inline.breaks = merge({}, inline.gfm, {
539 br: replace(inline.br)('{2,}', '*')(),
540 text: replace(inline.gfm.text)('{2,}', '*')()
544 * Inline Lexer & Compiler
547 function InlineLexer(links, options) {
548 this.options = options || marked.defaults;
550 this.rules = inline.normal;
551 this.renderer = this.options.renderer || new Renderer;
552 this.renderer.options = this.options;
556 Error('Tokens array requires a `links` property.');
559 if (this.options.gfm) {
560 if (this.options.breaks) {
561 this.rules = inline.breaks;
563 this.rules = inline.gfm;
565 } else if (this.options.pedantic) {
566 this.rules = inline.pedantic;
571 * Expose Inline Rules
574 InlineLexer.rules = inline;
577 * Static Lexing/Compiling Method
580 InlineLexer.output = function(src, links, options) {
581 var inline = new InlineLexer(links, options);
582 return inline.output(src);
589 InlineLexer.prototype.output = function(src) {
598 if (cap = this.rules.escape.exec(src)) {
599 src = src.substring(cap[0].length);
605 if (cap = this.rules.autolink.exec(src)) {
606 src = src.substring(cap[0].length);
607 if (cap[2] === '@') {
608 text = cap[1].charAt(6) === ':'
609 ? this.mangle(cap[1].substring(7))
610 : this.mangle(cap[1]);
611 href = this.mangle('mailto:') + text;
613 text = escape(cap[1]);
616 out += this.renderer.link(href, null, text);
621 if (!this.inLink && (cap = this.rules.url.exec(src))) {
622 src = src.substring(cap[0].length);
623 text = escape(cap[1]);
625 out += this.renderer.link(href, null, text);
630 if (cap = this.rules.tag.exec(src)) {
631 if (!this.inLink && /^<a /i.test(cap[0])) {
633 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
636 src = src.substring(cap[0].length);
637 out += this.options.sanitize
638 ? this.options.sanitizer
639 ? this.options.sanitizer(cap[0])
646 if (cap = this.rules.link.exec(src)) {
647 src = src.substring(cap[0].length);
649 out += this.outputLink(cap, {
658 if ((cap = this.rules.reflink.exec(src))
659 || (cap = this.rules.nolink.exec(src))) {
660 src = src.substring(cap[0].length);
661 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
662 link = this.links[link.toLowerCase()];
663 if (!link || !link.href) {
664 out += cap[0].charAt(0);
665 src = cap[0].substring(1) + src;
669 out += this.outputLink(cap, link);
675 if (cap = this.rules.strong.exec(src)) {
676 src = src.substring(cap[0].length);
677 out += this.renderer.strong(this.output(cap[2] || cap[1]));
682 if (cap = this.rules.em.exec(src)) {
683 src = src.substring(cap[0].length);
684 out += this.renderer.em(this.output(cap[2] || cap[1]));
689 if (cap = this.rules.code.exec(src)) {
690 src = src.substring(cap[0].length);
691 out += this.renderer.codespan(escape(cap[2], true));
696 if (cap = this.rules.br.exec(src)) {
697 src = src.substring(cap[0].length);
698 out += this.renderer.br();
703 if (cap = this.rules.del.exec(src)) {
704 src = src.substring(cap[0].length);
705 out += this.renderer.del(this.output(cap[1]));
710 if (cap = this.rules.text.exec(src)) {
711 src = src.substring(cap[0].length);
712 out += this.renderer.text(escape(this.smartypants(cap[0])));
718 Error('Infinite loop on byte: ' + src.charCodeAt(0));
729 InlineLexer.prototype.outputLink = function(cap, link) {
730 var href = escape(link.href)
731 , title = link.title ? escape(link.title) : null;
733 return cap[0].charAt(0) !== '!'
734 ? this.renderer.link(href, title, this.output(cap[1]))
735 : this.renderer.image(href, title, escape(cap[1]));
739 * Smartypants Transformations
742 InlineLexer.prototype.smartypants = function(text) {
743 if (!this.options.smartypants) return text;
746 .replace(/---/g, '\u2014')
748 .replace(/--/g, '\u2013')
750 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
751 // closing singles & apostrophes
752 .replace(/'/g, '\u2019')
754 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
756 .replace(/"/g, '\u201d')
758 .replace(/\.{3}/g, '\u2026');
765 InlineLexer.prototype.mangle = function(text) {
766 if (!this.options.mangle) return text;
773 ch = text.charCodeAt(i);
774 if (Math.random() > 0.5) {
775 ch = 'x' + ch.toString(16);
777 out += '&#' + ch + ';';
787 function Renderer(options) {
788 this.options = options || {};
791 Renderer.prototype.code = function(code, lang, escaped) {
792 if (this.options.highlight) {
793 var out = this.options.highlight(code, lang);
794 if (out != null && out !== code) {
802 + (escaped ? code : escape(code, true))
806 return '<pre><code class="'
807 + this.options.langPrefix
810 + (escaped ? code : escape(code, true))
811 + '\n</code></pre>\n';
814 Renderer.prototype.blockquote = function(quote) {
815 return '<blockquote>\n' + quote + '</blockquote>\n';
818 Renderer.prototype.html = function(html) {
822 Renderer.prototype.heading = function(text, level, raw) {
826 + this.options.headerPrefix
827 + raw.toLowerCase().replace(/[^\w]+/g, '-')
835 Renderer.prototype.hr = function() {
836 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
839 Renderer.prototype.list = function(body, ordered) {
840 var type = ordered ? 'ol' : 'ul';
841 return '<' + type + '>\n' + body + '</' + type + '>\n';
844 Renderer.prototype.listitem = function(text) {
845 return '<li>' + text + '</li>\n';
848 Renderer.prototype.paragraph = function(text) {
849 return '<p>' + text + '</p>\n';
852 Renderer.prototype.table = function(header, body) {
863 Renderer.prototype.tablerow = function(content) {
864 return '<tr>\n' + content + '</tr>\n';
867 Renderer.prototype.tablecell = function(content, flags) {
868 var type = flags.header ? 'th' : 'td';
869 var tag = flags.align
870 ? '<' + type + ' style="text-align:' + flags.align + '">'
872 return tag + content + '</' + type + '>\n';
875 // span level renderer
876 Renderer.prototype.strong = function(text) {
877 return '<strong>' + text + '</strong>';
880 Renderer.prototype.em = function(text) {
881 return '<em>' + text + '</em>';
884 Renderer.prototype.codespan = function(text) {
885 return '<code>' + text + '</code>';
888 Renderer.prototype.br = function() {
889 return this.options.xhtml ? '<br/>' : '<br>';
892 Renderer.prototype.del = function(text) {
893 return '<del>' + text + '</del>';
896 Renderer.prototype.link = function(href, title, text) {
897 if (this.options.sanitize) {
899 var prot = decodeURIComponent(unescape(href))
900 .replace(/[^\w:]/g, '')
905 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
909 var out = '<a href="' + href + '"';
911 out += ' title="' + title + '"';
913 out += '>' + text + '</a>';
917 Renderer.prototype.image = function(href, title, text) {
918 var out = '<img src="' + href + '" alt="' + text + '"';
920 out += ' title="' + title + '"';
922 out += this.options.xhtml ? '/>' : '>';
926 Renderer.prototype.text = function(text) {
931 * Parsing & Compiling
934 function Parser(options) {
937 this.options = options || marked.defaults;
938 this.options.renderer = this.options.renderer || new Renderer;
939 this.renderer = this.options.renderer;
940 this.renderer.options = this.options;
944 * Static Parse Method
947 Parser.parse = function(src, options, renderer) {
948 var parser = new Parser(options, renderer);
949 return parser.parse(src);
956 Parser.prototype.parse = function(src) {
957 this.inline = new InlineLexer(src.links, this.options, this.renderer);
958 this.tokens = src.reverse();
961 while (this.next()) {
972 Parser.prototype.next = function() {
973 return this.token = this.tokens.pop();
980 Parser.prototype.peek = function() {
981 return this.tokens[this.tokens.length - 1] || 0;
988 Parser.prototype.parseText = function() {
989 var body = this.token.text;
991 while (this.peek().type === 'text') {
992 body += '\n' + this.next().text;
995 return this.inline.output(body);
999 * Parse Current Token
1002 Parser.prototype.tok = function() {
1003 switch (this.token.type) {
1008 return this.renderer.hr();
1011 return this.renderer.heading(
1012 this.inline.output(this.token.text),
1017 return this.renderer.code(this.token.text,
1019 this.token.escaped);
1032 for (i = 0; i < this.token.header.length; i++) {
1033 flags = { header: true, align: this.token.align[i] };
1034 cell += this.renderer.tablecell(
1035 this.inline.output(this.token.header[i]),
1036 { header: true, align: this.token.align[i] }
1039 header += this.renderer.tablerow(cell);
1041 for (i = 0; i < this.token.cells.length; i++) {
1042 row = this.token.cells[i];
1045 for (j = 0; j < row.length; j++) {
1046 cell += this.renderer.tablecell(
1047 this.inline.output(row[j]),
1048 { header: false, align: this.token.align[j] }
1052 body += this.renderer.tablerow(cell);
1054 return this.renderer.table(header, body);
1056 case 'blockquote_start': {
1059 while (this.next().type !== 'blockquote_end') {
1063 return this.renderer.blockquote(body);
1065 case 'list_start': {
1067 , ordered = this.token.ordered;
1069 while (this.next().type !== 'list_end') {
1073 return this.renderer.list(body, ordered);
1075 case 'list_item_start': {
1078 while (this.next().type !== 'list_item_end') {
1079 body += this.token.type === 'text'
1084 return this.renderer.listitem(body);
1086 case 'loose_item_start': {
1089 while (this.next().type !== 'list_item_end') {
1093 return this.renderer.listitem(body);
1096 var html = !this.token.pre && !this.options.pedantic
1097 ? this.inline.output(this.token.text)
1099 return this.renderer.html(html);
1102 return this.renderer.paragraph(this.inline.output(this.token.text));
1105 return this.renderer.paragraph(this.parseText());
1114 function escape(html, encode) {
1116 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
1117 .replace(/</g, '<')
1118 .replace(/>/g, '>')
1119 .replace(/"/g, '"')
1120 .replace(/'/g, ''');
1123 function unescape(html) {
1124 // explicitly match decimal, hex, and named HTML entities
1125 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
1126 n = n.toLowerCase();
1127 if (n === 'colon') return ':';
1128 if (n.charAt(0) === '#') {
1129 return n.charAt(1) === 'x'
1130 ? String.fromCharCode(parseInt(n.substring(2), 16))
1131 : String.fromCharCode(+n.substring(1));
1137 function replace(regex, opt) {
1138 regex = regex.source;
1140 return function self(name, val) {
1141 if (!name) return new RegExp(regex, opt);
1142 val = val.source || val;
1143 val = val.replace(/(^|[^\[])\^/g, '$1');
1144 regex = regex.replace(name, val);
1152 function merge(obj) {
1157 for (; i < arguments.length; i++) {
1158 target = arguments[i];
1159 for (key in target) {
1160 if (Object.prototype.hasOwnProperty.call(target, key)) {
1161 obj[key] = target[key];
1174 function marked(src, opt, callback) {
1175 if (callback || typeof opt === 'function') {
1181 opt = merge({}, marked.defaults, opt || {});
1183 var highlight = opt.highlight
1189 tokens = Lexer.lex(src, opt)
1194 pending = tokens.length;
1196 var done = function(err) {
1198 opt.highlight = highlight;
1199 return callback(err);
1205 out = Parser.parse(tokens, opt);
1210 opt.highlight = highlight;
1214 : callback(null, out);
1217 if (!highlight || highlight.length < 3) {
1221 delete opt.highlight;
1223 if (!pending) return done();
1225 for (; i < tokens.length; i++) {
1227 if (token.type !== 'code') {
1228 return --pending || done();
1230 return highlight(token.text, token.lang, function(err, code) {
1231 if (err) return done(err);
1232 if (code == null || code === token.text) {
1233 return --pending || done();
1236 token.escaped = true;
1237 --pending || done();
1245 if (opt) opt = merge({}, marked.defaults, opt);
1246 return Parser.parse(Lexer.lex(src, opt), opt);
1248 e.message += '\nPlease report this to https://github.com/chjj/marked.';
1249 if ((opt || marked.defaults).silent) {
1250 return '<p>An error occured:</p><pre>'
1251 + escape(e.message + '', true)
1263 marked.setOptions = function(opt) {
1264 merge(marked.defaults, opt);
1279 langPrefix: 'lang-',
1282 renderer: new Renderer,
1290 marked.Parser = Parser;
1291 marked.parser = Parser.parse;
1293 marked.Renderer = Renderer;
1295 marked.Lexer = Lexer;
1296 marked.lexer = Lexer.lex;
1298 marked.InlineLexer = InlineLexer;
1299 marked.inlineLexer = InlineLexer.output;
1301 marked.parse = marked;
1303 Roo.ux.Showdown.marked = marked;