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(),
37 text = text.replace(/\\\n/g,' ');
38 return Roo.Markdown.marked(text);
43 // Wraps all "globals" so that the only thing
44 // exposed is makeHtml().
54 code: /^( {4}[^\n]+\n*)+/,
56 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
57 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
59 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
60 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
61 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
62 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
63 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
65 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
69 block.bullet = /(?:[*+-]|\d+\.)/;
70 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
71 block.item = replace(block.item, 'gm')
72 (/bull/g, block.bullet)
75 block.list = replace(block.list)
76 (/bull/g, block.bullet)
77 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
78 ('def', '\\n+(?=' + block.def.source + ')')
81 block.blockquote = replace(block.blockquote)
86 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
87 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
88 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
90 block.html = replace(block.html)
91 ('comment', /<!--[\s\S]*?-->/)
92 ('closed', /<(tag)[\s\S]+?<\/\1>/)
93 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
97 block.paragraph = replace(block.paragraph)
99 ('heading', block.heading)
100 ('lheading', block.lheading)
101 ('blockquote', block.blockquote)
102 ('tag', '<' + block._tag)
107 * Normal Block Grammar
110 block.normal = merge({}, block);
116 block.gfm = merge({}, block.normal, {
117 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
119 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
122 block.gfm.paragraph = replace(block.paragraph)
124 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
125 + block.list.source.replace('\\1', '\\3') + '|')
129 * GFM + Tables Block Grammar
132 block.tables = merge({}, block.gfm, {
133 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
134 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
141 function Lexer(options) {
143 this.tokens.links = {};
144 this.options = options || marked.defaults;
145 this.rules = block.normal;
147 if (this.options.gfm) {
148 if (this.options.tables) {
149 this.rules = block.tables;
151 this.rules = block.gfm;
166 Lexer.lex = function(src, options) {
167 var lexer = new Lexer(options);
168 return lexer.lex(src);
175 Lexer.prototype.lex = function(src) {
177 .replace(/\r\n|\r/g, '\n')
179 .replace(/\u00a0/g, ' ')
180 .replace(/\u2424/g, '\n');
182 return this.token(src, true);
189 Lexer.prototype.token = function(src, top, bq) {
190 var src = src.replace(/^ +$/gm, '')
203 if (cap = this.rules.newline.exec(src)) {
204 src = src.substring(cap[0].length);
205 if (cap[0].length > 1) {
213 if (cap = this.rules.code.exec(src)) {
214 src = src.substring(cap[0].length);
215 cap = cap[0].replace(/^ {4}/gm, '');
218 text: !this.options.pedantic
219 ? cap.replace(/\n+$/, '')
226 if (cap = this.rules.fences.exec(src)) {
227 src = src.substring(cap[0].length);
237 if (cap = this.rules.heading.exec(src)) {
238 src = src.substring(cap[0].length);
241 depth: cap[1].length,
247 // table no leading pipe (gfm)
248 if (top && (cap = this.rules.nptable.exec(src))) {
249 src = src.substring(cap[0].length);
253 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
254 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
255 cells: cap[3].replace(/\n$/, '').split('\n')
258 for (i = 0; i < item.align.length; i++) {
259 if (/^ *-+: *$/.test(item.align[i])) {
260 item.align[i] = 'right';
261 } else if (/^ *:-+: *$/.test(item.align[i])) {
262 item.align[i] = 'center';
263 } else if (/^ *:-+ *$/.test(item.align[i])) {
264 item.align[i] = 'left';
266 item.align[i] = null;
270 for (i = 0; i < item.cells.length; i++) {
271 item.cells[i] = item.cells[i].split(/ *\| */);
274 this.tokens.push(item);
280 if (cap = this.rules.lheading.exec(src)) {
281 src = src.substring(cap[0].length);
284 depth: cap[2] === '=' ? 1 : 2,
291 if (cap = this.rules.hr.exec(src)) {
292 src = src.substring(cap[0].length);
300 if (cap = this.rules.blockquote.exec(src)) {
301 src = src.substring(cap[0].length);
304 type: 'blockquote_start'
307 cap = cap[0].replace(/^ *> ?/gm, '');
309 // Pass `top` to keep the current
310 // "toplevel" state. This is exactly
311 // how markdown.pl works.
312 this.token(cap, top, true);
315 type: 'blockquote_end'
322 if (cap = this.rules.list.exec(src)) {
323 src = src.substring(cap[0].length);
328 ordered: bull.length > 1
331 // Get each top-level item.
332 cap = cap[0].match(this.rules.item);
341 // Remove the list item's bullet
342 // so it is seen as the next token.
344 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
346 // Outdent whatever the
347 // list item contains. Hacky.
348 if (~item.indexOf('\n ')) {
349 space -= item.length;
350 item = !this.options.pedantic
351 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
352 : item.replace(/^ {1,4}/gm, '');
355 // Determine whether the next list item belongs here.
356 // Backpedal if it does not belong in this list.
357 if (this.options.smartLists && i !== l - 1) {
358 b = block.bullet.exec(cap[i + 1])[0];
359 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
360 src = cap.slice(i + 1).join('\n') + src;
365 // Determine whether item is loose or not.
366 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
367 // for discount behavior.
368 loose = next || /\n\n(?!\s*$)/.test(item);
370 next = item.charAt(item.length - 1) === '\n';
371 if (!loose) { loose = next; }
381 this.token(item, false, bq);
384 type: 'list_item_end'
396 if (cap = this.rules.html.exec(src)) {
397 src = src.substring(cap[0].length);
399 type: this.options.sanitize
402 pre: !this.options.sanitizer
403 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
410 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
411 src = src.substring(cap[0].length);
412 this.tokens.links[cap[1].toLowerCase()] = {
420 if (top && (cap = this.rules.table.exec(src))) {
421 src = src.substring(cap[0].length);
425 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
426 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
427 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
430 for (i = 0; i < item.align.length; i++) {
431 if (/^ *-+: *$/.test(item.align[i])) {
432 item.align[i] = 'right';
433 } else if (/^ *:-+: *$/.test(item.align[i])) {
434 item.align[i] = 'center';
435 } else if (/^ *:-+ *$/.test(item.align[i])) {
436 item.align[i] = 'left';
438 item.align[i] = null;
442 for (i = 0; i < item.cells.length; i++) {
443 item.cells[i] = item.cells[i]
444 .replace(/^ *\| *| *\| *$/g, '')
448 this.tokens.push(item);
453 // top-level paragraph
454 if (top && (cap = this.rules.paragraph.exec(src))) {
455 src = src.substring(cap[0].length);
458 text: cap[1].charAt(cap[1].length - 1) === '\n'
459 ? cap[1].slice(0, -1)
466 if (cap = this.rules.text.exec(src)) {
467 // Top-level should never reach here.
468 src = src.substring(cap[0].length);
478 Error('Infinite loop on byte: ' + src.charCodeAt(0));
486 * Inline-Level Grammar
490 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
491 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
493 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
494 link: /^!?\[(inside)\]\(href\)/,
495 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
496 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
497 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
498 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
499 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
500 br: /^ {2,}\n(?!\s*$)/,
502 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
505 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
506 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
508 inline.link = replace(inline.link)
509 ('inside', inline._inside)
510 ('href', inline._href)
513 inline.reflink = replace(inline.reflink)
514 ('inside', inline._inside)
518 * Normal Inline Grammar
521 inline.normal = merge({}, inline);
524 * Pedantic Inline Grammar
527 inline.pedantic = merge({}, inline.normal, {
528 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
529 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
536 inline.gfm = merge({}, inline.normal, {
537 escape: replace(inline.escape)('])', '~|])')(),
538 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
539 del: /^~~(?=\S)([\s\S]*?\S)~~/,
540 text: replace(inline.text)
547 * GFM + Line Breaks Inline Grammar
550 inline.breaks = merge({}, inline.gfm, {
551 br: replace(inline.br)('{2,}', '*')(),
552 text: replace(inline.gfm.text)('{2,}', '*')()
556 * Inline Lexer & Compiler
559 function InlineLexer(links, options) {
560 this.options = options || marked.defaults;
562 this.rules = inline.normal;
563 this.renderer = this.options.renderer || new Renderer;
564 this.renderer.options = this.options;
568 Error('Tokens array requires a `links` property.');
571 if (this.options.gfm) {
572 if (this.options.breaks) {
573 this.rules = inline.breaks;
575 this.rules = inline.gfm;
577 } else if (this.options.pedantic) {
578 this.rules = inline.pedantic;
583 * Expose Inline Rules
586 InlineLexer.rules = inline;
589 * Static Lexing/Compiling Method
592 InlineLexer.output = function(src, links, options) {
593 var inline = new InlineLexer(links, options);
594 return inline.output(src);
601 InlineLexer.prototype.output = function(src) {
610 if (cap = this.rules.escape.exec(src)) {
611 src = src.substring(cap[0].length);
617 if (cap = this.rules.autolink.exec(src)) {
618 src = src.substring(cap[0].length);
619 if (cap[2] === '@') {
620 text = cap[1].charAt(6) === ':'
621 ? this.mangle(cap[1].substring(7))
622 : this.mangle(cap[1]);
623 href = this.mangle('mailto:') + text;
625 text = escape(cap[1]);
628 out += this.renderer.link(href, null, text);
633 if (!this.inLink && (cap = this.rules.url.exec(src))) {
634 src = src.substring(cap[0].length);
635 text = escape(cap[1]);
637 out += this.renderer.link(href, null, text);
642 if (cap = this.rules.tag.exec(src)) {
643 if (!this.inLink && /^<a /i.test(cap[0])) {
645 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
648 src = src.substring(cap[0].length);
649 out += this.options.sanitize
650 ? this.options.sanitizer
651 ? this.options.sanitizer(cap[0])
658 if (cap = this.rules.link.exec(src)) {
659 src = src.substring(cap[0].length);
661 out += this.outputLink(cap, {
670 if ((cap = this.rules.reflink.exec(src))
671 || (cap = this.rules.nolink.exec(src))) {
672 src = src.substring(cap[0].length);
673 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
674 link = this.links[link.toLowerCase()];
675 if (!link || !link.href) {
676 out += cap[0].charAt(0);
677 src = cap[0].substring(1) + src;
681 out += this.outputLink(cap, link);
687 if (cap = this.rules.strong.exec(src)) {
688 src = src.substring(cap[0].length);
689 out += this.renderer.strong(this.output(cap[2] || cap[1]));
694 if (cap = this.rules.em.exec(src)) {
695 src = src.substring(cap[0].length);
696 out += this.renderer.em(this.output(cap[2] || cap[1]));
701 if (cap = this.rules.code.exec(src)) {
702 src = src.substring(cap[0].length);
703 out += this.renderer.codespan(escape(cap[2], true));
708 if (cap = this.rules.br.exec(src)) {
709 src = src.substring(cap[0].length);
710 out += this.renderer.br();
715 if (cap = this.rules.del.exec(src)) {
716 src = src.substring(cap[0].length);
717 out += this.renderer.del(this.output(cap[1]));
722 if (cap = this.rules.text.exec(src)) {
723 src = src.substring(cap[0].length);
724 out += this.renderer.text(escape(this.smartypants(cap[0])));
730 Error('Infinite loop on byte: ' + src.charCodeAt(0));
741 InlineLexer.prototype.outputLink = function(cap, link) {
742 var href = escape(link.href)
743 , title = link.title ? escape(link.title) : null;
745 return cap[0].charAt(0) !== '!'
746 ? this.renderer.link(href, title, this.output(cap[1]))
747 : this.renderer.image(href, title, escape(cap[1]));
751 * Smartypants Transformations
754 InlineLexer.prototype.smartypants = function(text) {
755 if (!this.options.smartypants) { return text; }
758 .replace(/---/g, '\u2014')
760 .replace(/--/g, '\u2013')
762 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
763 // closing singles & apostrophes
764 .replace(/'/g, '\u2019')
766 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
768 .replace(/"/g, '\u201d')
770 .replace(/\.{3}/g, '\u2026');
777 InlineLexer.prototype.mangle = function(text) {
778 if (!this.options.mangle) { return text; }
785 ch = text.charCodeAt(i);
786 if (Math.random() > 0.5) {
787 ch = 'x' + ch.toString(16);
789 out += '&#' + ch + ';';
799 function Renderer(options) {
800 this.options = options || {};
803 Renderer.prototype.code = function(code, lang, escaped) {
804 if (this.options.highlight) {
805 var out = this.options.highlight(code, lang);
806 if (out != null && out !== code) {
811 // hack!!! - it's already escapeD?
817 + (escaped ? code : escape(code, true))
821 return '<pre><code class="'
822 + this.options.langPrefix
825 + (escaped ? code : escape(code, true))
826 + '\n</code></pre>\n';
829 Renderer.prototype.blockquote = function(quote) {
830 return '<blockquote>\n' + quote + '</blockquote>\n';
833 Renderer.prototype.html = function(html) {
837 Renderer.prototype.heading = function(text, level, raw) {
841 + this.options.headerPrefix
842 + raw.toLowerCase().replace(/[^\w]+/g, '-')
850 Renderer.prototype.hr = function() {
851 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
854 Renderer.prototype.list = function(body, ordered) {
855 var type = ordered ? 'ol' : 'ul';
856 return '<' + type + '>\n' + body + '</' + type + '>\n';
859 Renderer.prototype.listitem = function(text) {
860 return '<li>' + text + '</li>\n';
863 Renderer.prototype.paragraph = function(text) {
864 return '<p>' + text + '</p>\n';
867 Renderer.prototype.table = function(header, body) {
868 return '<table class="table table-striped">\n'
878 Renderer.prototype.tablerow = function(content) {
879 return '<tr>\n' + content + '</tr>\n';
882 Renderer.prototype.tablecell = function(content, flags) {
883 var type = flags.header ? 'th' : 'td';
884 var tag = flags.align
885 ? '<' + type + ' style="text-align:' + flags.align + '">'
887 return tag + content + '</' + type + '>\n';
890 // span level renderer
891 Renderer.prototype.strong = function(text) {
892 return '<strong>' + text + '</strong>';
895 Renderer.prototype.em = function(text) {
896 return '<em>' + text + '</em>';
899 Renderer.prototype.codespan = function(text) {
900 return '<code>' + text + '</code>';
903 Renderer.prototype.br = function() {
904 return this.options.xhtml ? '<br/>' : '<br>';
907 Renderer.prototype.del = function(text) {
908 return '<del>' + text + '</del>';
911 Renderer.prototype.link = function(href, title, text) {
912 if (this.options.sanitize) {
914 var prot = decodeURIComponent(unescape(href))
915 .replace(/[^\w:]/g, '')
920 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
924 var out = '<a href="' + href + '"';
926 out += ' title="' + title + '"';
928 out += '>' + text + '</a>';
932 Renderer.prototype.image = function(href, title, text) {
933 var out = '<img src="' + href + '" alt="' + text + '"';
935 out += ' title="' + title + '"';
937 out += this.options.xhtml ? '/>' : '>';
941 Renderer.prototype.text = function(text) {
946 * Parsing & Compiling
949 function Parser(options) {
952 this.options = options || marked.defaults;
953 this.options.renderer = this.options.renderer || new Renderer;
954 this.renderer = this.options.renderer;
955 this.renderer.options = this.options;
959 * Static Parse Method
962 Parser.parse = function(src, options, renderer) {
963 var parser = new Parser(options, renderer);
964 return parser.parse(src);
971 Parser.prototype.parse = function(src) {
972 this.inline = new InlineLexer(src.links, this.options, this.renderer);
973 this.tokens = src.reverse();
976 while (this.next()) {
987 Parser.prototype.next = function() {
988 return this.token = this.tokens.pop();
995 Parser.prototype.peek = function() {
996 return this.tokens[this.tokens.length - 1] || 0;
1003 Parser.prototype.parseText = function() {
1004 var body = this.token.text;
1006 while (this.peek().type === 'text') {
1007 body += '\n' + this.next().text;
1010 return this.inline.output(body);
1014 * Parse Current Token
1017 Parser.prototype.tok = function() {
1018 switch (this.token.type) {
1023 return this.renderer.hr();
1026 return this.renderer.heading(
1027 this.inline.output(this.token.text),
1032 return this.renderer.code(this.token.text,
1034 this.token.escaped);
1047 for (i = 0; i < this.token.header.length; i++) {
1048 flags = { header: true, align: this.token.align[i] };
1049 cell += this.renderer.tablecell(
1050 this.inline.output(this.token.header[i]),
1051 { header: true, align: this.token.align[i] }
1054 header += this.renderer.tablerow(cell);
1056 for (i = 0; i < this.token.cells.length; i++) {
1057 row = this.token.cells[i];
1060 for (j = 0; j < row.length; j++) {
1061 cell += this.renderer.tablecell(
1062 this.inline.output(row[j]),
1063 { header: false, align: this.token.align[j] }
1067 body += this.renderer.tablerow(cell);
1069 return this.renderer.table(header, body);
1071 case 'blockquote_start': {
1074 while (this.next().type !== 'blockquote_end') {
1078 return this.renderer.blockquote(body);
1080 case 'list_start': {
1082 , ordered = this.token.ordered;
1084 while (this.next().type !== 'list_end') {
1088 return this.renderer.list(body, ordered);
1090 case 'list_item_start': {
1093 while (this.next().type !== 'list_item_end') {
1094 body += this.token.type === 'text'
1099 return this.renderer.listitem(body);
1101 case 'loose_item_start': {
1104 while (this.next().type !== 'list_item_end') {
1108 return this.renderer.listitem(body);
1111 var html = !this.token.pre && !this.options.pedantic
1112 ? this.inline.output(this.token.text)
1114 return this.renderer.html(html);
1117 return this.renderer.paragraph(this.inline.output(this.token.text));
1120 return this.renderer.paragraph(this.parseText());
1129 function escape(html, encode) {
1131 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
1132 .replace(/</g, '<')
1133 .replace(/>/g, '>')
1134 .replace(/"/g, '"')
1135 .replace(/'/g, ''');
1138 function unescape(html) {
1139 // explicitly match decimal, hex, and named HTML entities
1140 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
1141 n = n.toLowerCase();
1142 if (n === 'colon') { return ':'; }
1143 if (n.charAt(0) === '#') {
1144 return n.charAt(1) === 'x'
1145 ? String.fromCharCode(parseInt(n.substring(2), 16))
1146 : String.fromCharCode(+n.substring(1));
1152 function replace(regex, opt) {
1153 regex = regex.source;
1155 return function self(name, val) {
1156 if (!name) { return new RegExp(regex, opt); }
1157 val = val.source || val;
1158 val = val.replace(/(^|[^\[])\^/g, '$1');
1159 regex = regex.replace(name, val);
1167 function merge(obj) {
1172 for (; i < arguments.length; i++) {
1173 target = arguments[i];
1174 for (key in target) {
1175 if (Object.prototype.hasOwnProperty.call(target, key)) {
1176 obj[key] = target[key];
1189 function marked(src, opt, callback) {
1190 if (callback || typeof opt === 'function') {
1196 opt = merge({}, marked.defaults, opt || {});
1198 var highlight = opt.highlight
1204 tokens = Lexer.lex(src, opt)
1209 pending = tokens.length;
1211 var done = function(err) {
1213 opt.highlight = highlight;
1214 return callback(err);
1220 out = Parser.parse(tokens, opt);
1225 opt.highlight = highlight;
1229 : callback(null, out);
1232 if (!highlight || highlight.length < 3) {
1236 delete opt.highlight;
1238 if (!pending) { return done(); }
1240 for (; i < tokens.length; i++) {
1242 if (token.type !== 'code') {
1243 return --pending || done();
1245 return highlight(token.text, token.lang, function(err, code) {
1246 if (err) { return done(err); }
1247 if (code == null || code === token.text) {
1248 return --pending || done();
1251 token.escaped = true;
1252 --pending || done();
1260 if (opt) { opt = merge({}, marked.defaults, opt); }
1261 return Parser.parse(Lexer.lex(src, opt), opt);
1263 e.message += '\nPlease report this to https://github.com/chjj/marked.';
1264 if ((opt || marked.defaults).silent) {
1265 return '<p>An error occured:</p><pre>'
1266 + escape(e.message + '', true)
1278 marked.setOptions = function(opt) {
1279 merge(marked.defaults, opt);
1294 langPrefix: 'lang-',
1297 renderer: new Renderer,
1305 marked.Parser = Parser;
1306 marked.parser = Parser.parse;
1308 marked.Renderer = Renderer;
1310 marked.Lexer = Lexer;
1311 marked.lexer = Lexer.lex;
1313 marked.InlineLexer = InlineLexer;
1314 marked.inlineLexer = InlineLexer.output;
1316 marked.parse = marked;
1318 Roo.Markdown.marked = marked;