3 * marked - a markdown parser
4 * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
5 * https://github.com/chjj/marked
11 * Roo.Markdown - is a very crude wrapper around marked..
15 * alert( Roo.Markdown.toHtml("Markdown *rocks*.") );
17 * Note: move the sample code to the bottom of this
18 * file before uncommenting it.
23 Roo.Markdown.toHtml = function(text) {
25 var c = new Roo.Markdown.marked.setOptions({
26 renderer: new Roo.Markdown.marked.Renderer(),
36 return Roo.Markdown.marked(text);
41 // Wraps all "globals" so that the only thing
42 // exposed is makeHtml().
52 code: /^( {4}[^\n]+\n*)+/,
54 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
55 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
57 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
58 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
59 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
60 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
61 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
63 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
67 block.bullet = /(?:[*+-]|\d+\.)/;
68 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
69 block.item = replace(block.item, 'gm')
70 (/bull/g, block.bullet)
73 block.list = replace(block.list)
74 (/bull/g, block.bullet)
75 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
76 ('def', '\\n+(?=' + block.def.source + ')')
79 block.blockquote = replace(block.blockquote)
84 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
85 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
86 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
88 block.html = replace(block.html)
89 ('comment', /<!--[\s\S]*?-->/)
90 ('closed', /<(tag)[\s\S]+?<\/\1>/)
91 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
95 block.paragraph = replace(block.paragraph)
97 ('heading', block.heading)
98 ('lheading', block.lheading)
99 ('blockquote', block.blockquote)
100 ('tag', '<' + block._tag)
105 * Normal Block Grammar
108 block.normal = merge({}, block);
114 block.gfm = merge({}, block.normal, {
115 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
117 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
120 block.gfm.paragraph = replace(block.paragraph)
122 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
123 + block.list.source.replace('\\1', '\\3') + '|')
127 * GFM + Tables Block Grammar
130 block.tables = merge({}, block.gfm, {
131 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
132 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
139 function Lexer(options) {
141 this.tokens.links = {};
142 this.options = options || marked.defaults;
143 this.rules = block.normal;
145 if (this.options.gfm) {
146 if (this.options.tables) {
147 this.rules = block.tables;
149 this.rules = block.gfm;
164 Lexer.lex = function(src, options) {
165 var lexer = new Lexer(options);
166 return lexer.lex(src);
173 Lexer.prototype.lex = function(src) {
175 .replace(/\r\n|\r/g, '\n')
177 .replace(/\u00a0/g, ' ')
178 .replace(/\u2424/g, '\n');
180 return this.token(src, true);
187 Lexer.prototype.token = function(src, top, bq) {
188 var src = src.replace(/^ +$/gm, '')
201 if (cap = this.rules.newline.exec(src)) {
202 src = src.substring(cap[0].length);
203 if (cap[0].length > 1) {
211 if (cap = this.rules.code.exec(src)) {
212 src = src.substring(cap[0].length);
213 cap = cap[0].replace(/^ {4}/gm, '');
216 text: !this.options.pedantic
217 ? cap.replace(/\n+$/, '')
224 if (cap = this.rules.fences.exec(src)) {
225 src = src.substring(cap[0].length);
235 if (cap = this.rules.heading.exec(src)) {
236 src = src.substring(cap[0].length);
239 depth: cap[1].length,
245 // table no leading pipe (gfm)
246 if (top && (cap = this.rules.nptable.exec(src))) {
247 src = src.substring(cap[0].length);
251 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
252 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
253 cells: cap[3].replace(/\n$/, '').split('\n')
256 for (i = 0; i < item.align.length; i++) {
257 if (/^ *-+: *$/.test(item.align[i])) {
258 item.align[i] = 'right';
259 } else if (/^ *:-+: *$/.test(item.align[i])) {
260 item.align[i] = 'center';
261 } else if (/^ *:-+ *$/.test(item.align[i])) {
262 item.align[i] = 'left';
264 item.align[i] = null;
268 for (i = 0; i < item.cells.length; i++) {
269 item.cells[i] = item.cells[i].split(/ *\| */);
272 this.tokens.push(item);
278 if (cap = this.rules.lheading.exec(src)) {
279 src = src.substring(cap[0].length);
282 depth: cap[2] === '=' ? 1 : 2,
289 if (cap = this.rules.hr.exec(src)) {
290 src = src.substring(cap[0].length);
298 if (cap = this.rules.blockquote.exec(src)) {
299 src = src.substring(cap[0].length);
302 type: 'blockquote_start'
305 cap = cap[0].replace(/^ *> ?/gm, '');
307 // Pass `top` to keep the current
308 // "toplevel" state. This is exactly
309 // how markdown.pl works.
310 this.token(cap, top, true);
313 type: 'blockquote_end'
320 if (cap = this.rules.list.exec(src)) {
321 src = src.substring(cap[0].length);
326 ordered: bull.length > 1
329 // Get each top-level item.
330 cap = cap[0].match(this.rules.item);
339 // Remove the list item's bullet
340 // so it is seen as the next token.
342 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
344 // Outdent whatever the
345 // list item contains. Hacky.
346 if (~item.indexOf('\n ')) {
347 space -= item.length;
348 item = !this.options.pedantic
349 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
350 : item.replace(/^ {1,4}/gm, '');
353 // Determine whether the next list item belongs here.
354 // Backpedal if it does not belong in this list.
355 if (this.options.smartLists && i !== l - 1) {
356 b = block.bullet.exec(cap[i + 1])[0];
357 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
358 src = cap.slice(i + 1).join('\n') + src;
363 // Determine whether item is loose or not.
364 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
365 // for discount behavior.
366 loose = next || /\n\n(?!\s*$)/.test(item);
368 next = item.charAt(item.length - 1) === '\n';
369 if (!loose) loose = next;
379 this.token(item, false, bq);
382 type: 'list_item_end'
394 if (cap = this.rules.html.exec(src)) {
395 src = src.substring(cap[0].length);
397 type: this.options.sanitize
400 pre: !this.options.sanitizer
401 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
408 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
409 src = src.substring(cap[0].length);
410 this.tokens.links[cap[1].toLowerCase()] = {
418 if (top && (cap = this.rules.table.exec(src))) {
419 src = src.substring(cap[0].length);
423 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
424 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
425 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
428 for (i = 0; i < item.align.length; i++) {
429 if (/^ *-+: *$/.test(item.align[i])) {
430 item.align[i] = 'right';
431 } else if (/^ *:-+: *$/.test(item.align[i])) {
432 item.align[i] = 'center';
433 } else if (/^ *:-+ *$/.test(item.align[i])) {
434 item.align[i] = 'left';
436 item.align[i] = null;
440 for (i = 0; i < item.cells.length; i++) {
441 item.cells[i] = item.cells[i]
442 .replace(/^ *\| *| *\| *$/g, '')
446 this.tokens.push(item);
451 // top-level paragraph
452 if (top && (cap = this.rules.paragraph.exec(src))) {
453 src = src.substring(cap[0].length);
456 text: cap[1].charAt(cap[1].length - 1) === '\n'
457 ? cap[1].slice(0, -1)
464 if (cap = this.rules.text.exec(src)) {
465 // Top-level should never reach here.
466 src = src.substring(cap[0].length);
476 Error('Infinite loop on byte: ' + src.charCodeAt(0));
484 * Inline-Level Grammar
488 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
489 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
491 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
492 link: /^!?\[(inside)\]\(href\)/,
493 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
494 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
495 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
496 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
497 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
498 br: /^ {2,}\n(?!\s*$)/,
500 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
503 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
504 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
506 inline.link = replace(inline.link)
507 ('inside', inline._inside)
508 ('href', inline._href)
511 inline.reflink = replace(inline.reflink)
512 ('inside', inline._inside)
516 * Normal Inline Grammar
519 inline.normal = merge({}, inline);
522 * Pedantic Inline Grammar
525 inline.pedantic = merge({}, inline.normal, {
526 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
527 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
534 inline.gfm = merge({}, inline.normal, {
535 escape: replace(inline.escape)('])', '~|])')(),
536 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
537 del: /^~~(?=\S)([\s\S]*?\S)~~/,
538 text: replace(inline.text)
545 * GFM + Line Breaks Inline Grammar
548 inline.breaks = merge({}, inline.gfm, {
549 br: replace(inline.br)('{2,}', '*')(),
550 text: replace(inline.gfm.text)('{2,}', '*')()
554 * Inline Lexer & Compiler
557 function InlineLexer(links, options) {
558 this.options = options || marked.defaults;
560 this.rules = inline.normal;
561 this.renderer = this.options.renderer || new Renderer;
562 this.renderer.options = this.options;
566 Error('Tokens array requires a `links` property.');
569 if (this.options.gfm) {
570 if (this.options.breaks) {
571 this.rules = inline.breaks;
573 this.rules = inline.gfm;
575 } else if (this.options.pedantic) {
576 this.rules = inline.pedantic;
581 * Expose Inline Rules
584 InlineLexer.rules = inline;
587 * Static Lexing/Compiling Method
590 InlineLexer.output = function(src, links, options) {
591 var inline = new InlineLexer(links, options);
592 return inline.output(src);
599 InlineLexer.prototype.output = function(src) {
608 if (cap = this.rules.escape.exec(src)) {
609 src = src.substring(cap[0].length);
615 if (cap = this.rules.autolink.exec(src)) {
616 src = src.substring(cap[0].length);
617 if (cap[2] === '@') {
618 text = cap[1].charAt(6) === ':'
619 ? this.mangle(cap[1].substring(7))
620 : this.mangle(cap[1]);
621 href = this.mangle('mailto:') + text;
623 text = escape(cap[1]);
626 out += this.renderer.link(href, null, text);
631 if (!this.inLink && (cap = this.rules.url.exec(src))) {
632 src = src.substring(cap[0].length);
633 text = escape(cap[1]);
635 out += this.renderer.link(href, null, text);
640 if (cap = this.rules.tag.exec(src)) {
641 if (!this.inLink && /^<a /i.test(cap[0])) {
643 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
646 src = src.substring(cap[0].length);
647 out += this.options.sanitize
648 ? this.options.sanitizer
649 ? this.options.sanitizer(cap[0])
656 if (cap = this.rules.link.exec(src)) {
657 src = src.substring(cap[0].length);
659 out += this.outputLink(cap, {
668 if ((cap = this.rules.reflink.exec(src))
669 || (cap = this.rules.nolink.exec(src))) {
670 src = src.substring(cap[0].length);
671 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
672 link = this.links[link.toLowerCase()];
673 if (!link || !link.href) {
674 out += cap[0].charAt(0);
675 src = cap[0].substring(1) + src;
679 out += this.outputLink(cap, link);
685 if (cap = this.rules.strong.exec(src)) {
686 src = src.substring(cap[0].length);
687 out += this.renderer.strong(this.output(cap[2] || cap[1]));
692 if (cap = this.rules.em.exec(src)) {
693 src = src.substring(cap[0].length);
694 out += this.renderer.em(this.output(cap[2] || cap[1]));
699 if (cap = this.rules.code.exec(src)) {
700 src = src.substring(cap[0].length);
701 out += this.renderer.codespan(escape(cap[2], true));
706 if (cap = this.rules.br.exec(src)) {
707 src = src.substring(cap[0].length);
708 out += this.renderer.br();
713 if (cap = this.rules.del.exec(src)) {
714 src = src.substring(cap[0].length);
715 out += this.renderer.del(this.output(cap[1]));
720 if (cap = this.rules.text.exec(src)) {
721 src = src.substring(cap[0].length);
722 out += this.renderer.text(escape(this.smartypants(cap[0])));
728 Error('Infinite loop on byte: ' + src.charCodeAt(0));
739 InlineLexer.prototype.outputLink = function(cap, link) {
740 var href = escape(link.href)
741 , title = link.title ? escape(link.title) : null;
743 return cap[0].charAt(0) !== '!'
744 ? this.renderer.link(href, title, this.output(cap[1]))
745 : this.renderer.image(href, title, escape(cap[1]));
749 * Smartypants Transformations
752 InlineLexer.prototype.smartypants = function(text) {
753 if (!this.options.smartypants) return text;
756 .replace(/---/g, '\u2014')
758 .replace(/--/g, '\u2013')
760 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
761 // closing singles & apostrophes
762 .replace(/'/g, '\u2019')
764 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
766 .replace(/"/g, '\u201d')
768 .replace(/\.{3}/g, '\u2026');
775 InlineLexer.prototype.mangle = function(text) {
776 if (!this.options.mangle) return text;
783 ch = text.charCodeAt(i);
784 if (Math.random() > 0.5) {
785 ch = 'x' + ch.toString(16);
787 out += '&#' + ch + ';';
797 function Renderer(options) {
798 this.options = options || {};
801 Renderer.prototype.code = function(code, lang, escaped) {
802 if (this.options.highlight) {
803 var out = this.options.highlight(code, lang);
804 if (out != null && out !== code) {
809 // hack!!! - it's already escapeD?
815 + (escaped ? code : escape(code, true))
819 return '<pre><code class="'
820 + this.options.langPrefix
823 + (escaped ? code : escape(code, true))
824 + '\n</code></pre>\n';
827 Renderer.prototype.blockquote = function(quote) {
828 return '<blockquote>\n' + quote + '</blockquote>\n';
831 Renderer.prototype.html = function(html) {
835 Renderer.prototype.heading = function(text, level, raw) {
839 + this.options.headerPrefix
840 + raw.toLowerCase().replace(/[^\w]+/g, '-')
848 Renderer.prototype.hr = function() {
849 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
852 Renderer.prototype.list = function(body, ordered) {
853 var type = ordered ? 'ol' : 'ul';
854 return '<' + type + '>\n' + body + '</' + type + '>\n';
857 Renderer.prototype.listitem = function(text) {
858 return '<li>' + text + '</li>\n';
861 Renderer.prototype.paragraph = function(text) {
862 return '<p>' + text + '</p>\n';
865 Renderer.prototype.table = function(header, body) {
876 Renderer.prototype.tablerow = function(content) {
877 return '<tr>\n' + content + '</tr>\n';
880 Renderer.prototype.tablecell = function(content, flags) {
881 var type = flags.header ? 'th' : 'td';
882 var tag = flags.align
883 ? '<' + type + ' style="text-align:' + flags.align + '">'
885 return tag + content + '</' + type + '>\n';
888 // span level renderer
889 Renderer.prototype.strong = function(text) {
890 return '<strong>' + text + '</strong>';
893 Renderer.prototype.em = function(text) {
894 return '<em>' + text + '</em>';
897 Renderer.prototype.codespan = function(text) {
898 return '<code>' + text + '</code>';
901 Renderer.prototype.br = function() {
902 return this.options.xhtml ? '<br/>' : '<br>';
905 Renderer.prototype.del = function(text) {
906 return '<del>' + text + '</del>';
909 Renderer.prototype.link = function(href, title, text) {
910 if (this.options.sanitize) {
912 var prot = decodeURIComponent(unescape(href))
913 .replace(/[^\w:]/g, '')
918 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
922 var out = '<a href="' + href + '"';
924 out += ' title="' + title + '"';
926 out += '>' + text + '</a>';
930 Renderer.prototype.image = function(href, title, text) {
931 var out = '<img src="' + href + '" alt="' + text + '"';
933 out += ' title="' + title + '"';
935 out += this.options.xhtml ? '/>' : '>';
939 Renderer.prototype.text = function(text) {
944 * Parsing & Compiling
947 function Parser(options) {
950 this.options = options || marked.defaults;
951 this.options.renderer = this.options.renderer || new Renderer;
952 this.renderer = this.options.renderer;
953 this.renderer.options = this.options;
957 * Static Parse Method
960 Parser.parse = function(src, options, renderer) {
961 var parser = new Parser(options, renderer);
962 return parser.parse(src);
969 Parser.prototype.parse = function(src) {
970 this.inline = new InlineLexer(src.links, this.options, this.renderer);
971 this.tokens = src.reverse();
974 while (this.next()) {
985 Parser.prototype.next = function() {
986 return this.token = this.tokens.pop();
993 Parser.prototype.peek = function() {
994 return this.tokens[this.tokens.length - 1] || 0;
1001 Parser.prototype.parseText = function() {
1002 var body = this.token.text;
1004 while (this.peek().type === 'text') {
1005 body += '\n' + this.next().text;
1008 return this.inline.output(body);
1012 * Parse Current Token
1015 Parser.prototype.tok = function() {
1016 switch (this.token.type) {
1021 return this.renderer.hr();
1024 return this.renderer.heading(
1025 this.inline.output(this.token.text),
1030 return this.renderer.code(this.token.text,
1032 this.token.escaped);
1045 for (i = 0; i < this.token.header.length; i++) {
1046 flags = { header: true, align: this.token.align[i] };
1047 cell += this.renderer.tablecell(
1048 this.inline.output(this.token.header[i]),
1049 { header: true, align: this.token.align[i] }
1052 header += this.renderer.tablerow(cell);
1054 for (i = 0; i < this.token.cells.length; i++) {
1055 row = this.token.cells[i];
1058 for (j = 0; j < row.length; j++) {
1059 cell += this.renderer.tablecell(
1060 this.inline.output(row[j]),
1061 { header: false, align: this.token.align[j] }
1065 body += this.renderer.tablerow(cell);
1067 return this.renderer.table(header, body);
1069 case 'blockquote_start': {
1072 while (this.next().type !== 'blockquote_end') {
1076 return this.renderer.blockquote(body);
1078 case 'list_start': {
1080 , ordered = this.token.ordered;
1082 while (this.next().type !== 'list_end') {
1086 return this.renderer.list(body, ordered);
1088 case 'list_item_start': {
1091 while (this.next().type !== 'list_item_end') {
1092 body += this.token.type === 'text'
1097 return this.renderer.listitem(body);
1099 case 'loose_item_start': {
1102 while (this.next().type !== 'list_item_end') {
1106 return this.renderer.listitem(body);
1109 var html = !this.token.pre && !this.options.pedantic
1110 ? this.inline.output(this.token.text)
1112 return this.renderer.html(html);
1115 return this.renderer.paragraph(this.inline.output(this.token.text));
1118 return this.renderer.paragraph(this.parseText());
1127 function escape(html, encode) {
1129 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
1130 .replace(/</g, '<')
1131 .replace(/>/g, '>')
1132 .replace(/"/g, '"')
1133 .replace(/'/g, ''');
1136 function unescape(html) {
1137 // explicitly match decimal, hex, and named HTML entities
1138 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
1139 n = n.toLowerCase();
1140 if (n === 'colon') return ':';
1141 if (n.charAt(0) === '#') {
1142 return n.charAt(1) === 'x'
1143 ? String.fromCharCode(parseInt(n.substring(2), 16))
1144 : String.fromCharCode(+n.substring(1));
1150 function replace(regex, opt) {
1151 regex = regex.source;
1153 return function self(name, val) {
1154 if (!name) return new RegExp(regex, opt);
1155 val = val.source || val;
1156 val = val.replace(/(^|[^\[])\^/g, '$1');
1157 regex = regex.replace(name, val);
1165 function merge(obj) {
1170 for (; i < arguments.length; i++) {
1171 target = arguments[i];
1172 for (key in target) {
1173 if (Object.prototype.hasOwnProperty.call(target, key)) {
1174 obj[key] = target[key];
1187 function marked(src, opt, callback) {
1188 if (callback || typeof opt === 'function') {
1194 opt = merge({}, marked.defaults, opt || {});
1196 var highlight = opt.highlight
1202 tokens = Lexer.lex(src, opt)
1207 pending = tokens.length;
1209 var done = function(err) {
1211 opt.highlight = highlight;
1212 return callback(err);
1218 out = Parser.parse(tokens, opt);
1223 opt.highlight = highlight;
1227 : callback(null, out);
1230 if (!highlight || highlight.length < 3) {
1234 delete opt.highlight;
1236 if (!pending) return done();
1238 for (; i < tokens.length; i++) {
1240 if (token.type !== 'code') {
1241 return --pending || done();
1243 return highlight(token.text, token.lang, function(err, code) {
1244 if (err) return done(err);
1245 if (code == null || code === token.text) {
1246 return --pending || done();
1249 token.escaped = true;
1250 --pending || done();
1258 if (opt) opt = merge({}, marked.defaults, opt);
1259 return Parser.parse(Lexer.lex(src, opt), opt);
1261 e.message += '\nPlease report this to https://github.com/chjj/marked.';
1262 if ((opt || marked.defaults).silent) {
1263 return '<p>An error occured:</p><pre>'
1264 + escape(e.message + '', true)
1276 marked.setOptions = function(opt) {
1277 merge(marked.defaults, opt);
1292 langPrefix: 'lang-',
1295 renderer: new Renderer,
1303 marked.Parser = Parser;
1304 marked.parser = Parser.parse;
1306 marked.Renderer = Renderer;
1308 marked.Lexer = Lexer;
1309 marked.lexer = Lexer.lex;
1311 marked.InlineLexer = InlineLexer;
1312 marked.inlineLexer = InlineLexer.output;
1314 marked.parse = marked;
1316 Roo.Markdown.marked = marked;