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().
58 var escape = function (html, encode) {
60 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
61 .replace(/</g, '<')
62 .replace(/>/g, '>')
63 .replace(/"/g, '"')
64 .replace(/'/g, ''');
67 var unescape = function (html) {
68 // explicitly match decimal, hex, and named HTML entities
69 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
71 if (n === 'colon') { return ':'; }
72 if (n.charAt(0) === '#') {
73 return n.charAt(1) === 'x'
74 ? String.fromCharCode(parseInt(n.substring(2), 16))
75 : String.fromCharCode(+n.substring(1));
81 var replace = function (regex, opt) {
84 return function self(name, val) {
85 if (!name) { return new RegExp(regex, opt); }
86 val = val.source || val;
87 val = val.replace(/(^|[^\[])\^/g, '$1');
88 regex = regex.replace(name, val);
102 code: /^( {4}[^\n]+\n*)+/,
104 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
105 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
107 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
108 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
109 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
110 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
111 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
113 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
117 block.bullet = /(?:[*+-]|\d+\.)/;
118 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
119 block.item = replace(block.item, 'gm')
120 (/bull/g, block.bullet)
123 block.list = replace(block.list)
124 (/bull/g, block.bullet)
125 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
126 ('def', '\\n+(?=' + block.def.source + ')')
129 block.blockquote = replace(block.blockquote)
133 block._tag = '(?!(?:'
134 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
135 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
136 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
138 block.html = replace(block.html)
139 ('comment', /<!--[\s\S]*?-->/)
140 ('closed', /<(tag)[\s\S]+?<\/\1>/)
141 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
145 block.paragraph = replace(block.paragraph)
147 ('heading', block.heading)
148 ('lheading', block.lheading)
149 ('blockquote', block.blockquote)
150 ('tag', '<' + block._tag)
155 * Normal Block Grammar
158 block.normal = merge({}, block);
164 block.gfm = merge({}, block.normal, {
165 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
167 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
170 block.gfm.paragraph = replace(block.paragraph)
172 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
173 + block.list.source.replace('\\1', '\\3') + '|')
177 * GFM + Tables Block Grammar
180 block.tables = merge({}, block.gfm, {
181 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
182 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
189 var Lexer = function (options) {
191 this.tokens.links = {};
192 this.options = options || marked.defaults;
193 this.rules = block.normal;
195 if (this.options.gfm) {
196 if (this.options.tables) {
197 this.rules = block.tables;
199 this.rules = block.gfm;
214 Lexer.lex = function(src, options) {
215 var lexer = new Lexer(options);
216 return lexer.lex(src);
223 Lexer.prototype.lex = function(src) {
225 .replace(/\r\n|\r/g, '\n')
227 .replace(/\u00a0/g, ' ')
228 .replace(/\u2424/g, '\n');
230 return this.token(src, true);
237 Lexer.prototype.token = function(src, top, bq) {
238 var src = src.replace(/^ +$/gm, '')
251 if (cap = this.rules.newline.exec(src)) {
252 src = src.substring(cap[0].length);
253 if (cap[0].length > 1) {
261 if (cap = this.rules.code.exec(src)) {
262 src = src.substring(cap[0].length);
263 cap = cap[0].replace(/^ {4}/gm, '');
266 text: !this.options.pedantic
267 ? cap.replace(/\n+$/, '')
274 if (cap = this.rules.fences.exec(src)) {
275 src = src.substring(cap[0].length);
285 if (cap = this.rules.heading.exec(src)) {
286 src = src.substring(cap[0].length);
289 depth: cap[1].length,
295 // table no leading pipe (gfm)
296 if (top && (cap = this.rules.nptable.exec(src))) {
297 src = src.substring(cap[0].length);
301 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
302 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
303 cells: cap[3].replace(/\n$/, '').split('\n')
306 for (i = 0; i < item.align.length; i++) {
307 if (/^ *-+: *$/.test(item.align[i])) {
308 item.align[i] = 'right';
309 } else if (/^ *:-+: *$/.test(item.align[i])) {
310 item.align[i] = 'center';
311 } else if (/^ *:-+ *$/.test(item.align[i])) {
312 item.align[i] = 'left';
314 item.align[i] = null;
318 for (i = 0; i < item.cells.length; i++) {
319 item.cells[i] = item.cells[i].split(/ *\| */);
322 this.tokens.push(item);
328 if (cap = this.rules.lheading.exec(src)) {
329 src = src.substring(cap[0].length);
332 depth: cap[2] === '=' ? 1 : 2,
339 if (cap = this.rules.hr.exec(src)) {
340 src = src.substring(cap[0].length);
348 if (cap = this.rules.blockquote.exec(src)) {
349 src = src.substring(cap[0].length);
352 type: 'blockquote_start'
355 cap = cap[0].replace(/^ *> ?/gm, '');
357 // Pass `top` to keep the current
358 // "toplevel" state. This is exactly
359 // how markdown.pl works.
360 this.token(cap, top, true);
363 type: 'blockquote_end'
370 if (cap = this.rules.list.exec(src)) {
371 src = src.substring(cap[0].length);
376 ordered: bull.length > 1
379 // Get each top-level item.
380 cap = cap[0].match(this.rules.item);
389 // Remove the list item's bullet
390 // so it is seen as the next token.
392 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
394 // Outdent whatever the
395 // list item contains. Hacky.
396 if (~item.indexOf('\n ')) {
397 space -= item.length;
398 item = !this.options.pedantic
399 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
400 : item.replace(/^ {1,4}/gm, '');
403 // Determine whether the next list item belongs here.
404 // Backpedal if it does not belong in this list.
405 if (this.options.smartLists && i !== l - 1) {
406 b = block.bullet.exec(cap[i + 1])[0];
407 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
408 src = cap.slice(i + 1).join('\n') + src;
413 // Determine whether item is loose or not.
414 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
415 // for discount behavior.
416 loose = next || /\n\n(?!\s*$)/.test(item);
418 next = item.charAt(item.length - 1) === '\n';
419 if (!loose) { loose = next; }
429 this.token(item, false, bq);
432 type: 'list_item_end'
444 if (cap = this.rules.html.exec(src)) {
445 src = src.substring(cap[0].length);
447 type: this.options.sanitize
450 pre: !this.options.sanitizer
451 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
458 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
459 src = src.substring(cap[0].length);
460 this.tokens.links[cap[1].toLowerCase()] = {
468 if (top && (cap = this.rules.table.exec(src))) {
469 src = src.substring(cap[0].length);
473 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
474 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
475 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
478 for (i = 0; i < item.align.length; i++) {
479 if (/^ *-+: *$/.test(item.align[i])) {
480 item.align[i] = 'right';
481 } else if (/^ *:-+: *$/.test(item.align[i])) {
482 item.align[i] = 'center';
483 } else if (/^ *:-+ *$/.test(item.align[i])) {
484 item.align[i] = 'left';
486 item.align[i] = null;
490 for (i = 0; i < item.cells.length; i++) {
491 item.cells[i] = item.cells[i]
492 .replace(/^ *\| *| *\| *$/g, '')
496 this.tokens.push(item);
501 // top-level paragraph
502 if (top && (cap = this.rules.paragraph.exec(src))) {
503 src = src.substring(cap[0].length);
506 text: cap[1].charAt(cap[1].length - 1) === '\n'
507 ? cap[1].slice(0, -1)
514 if (cap = this.rules.text.exec(src)) {
515 // Top-level should never reach here.
516 src = src.substring(cap[0].length);
526 Error('Infinite loop on byte: ' + src.charCodeAt(0));
534 * Inline-Level Grammar
538 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
539 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
541 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
542 link: /^!?\[(inside)\]\(href\)/,
543 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
544 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
545 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
546 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
547 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
548 br: /^ {2,}\n(?!\s*$)/,
550 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
553 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
554 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
556 inline.link = replace(inline.link)
557 ('inside', inline._inside)
558 ('href', inline._href)
561 inline.reflink = replace(inline.reflink)
562 ('inside', inline._inside)
566 * Normal Inline Grammar
569 inline.normal = merge({}, inline);
572 * Pedantic Inline Grammar
575 inline.pedantic = merge({}, inline.normal, {
576 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
577 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
584 inline.gfm = merge({}, inline.normal, {
585 escape: replace(inline.escape)('])', '~|])')(),
586 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
587 del: /^~~(?=\S)([\s\S]*?\S)~~/,
588 text: replace(inline.text)
595 * GFM + Line Breaks Inline Grammar
598 inline.breaks = merge({}, inline.gfm, {
599 br: replace(inline.br)('{2,}', '*')(),
600 text: replace(inline.gfm.text)('{2,}', '*')()
604 * Inline Lexer & Compiler
607 var InlineLexer = function (links, options) {
608 this.options = options || marked.defaults;
610 this.rules = inline.normal;
611 this.renderer = this.options.renderer || new Renderer;
612 this.renderer.options = this.options;
616 Error('Tokens array requires a `links` property.');
619 if (this.options.gfm) {
620 if (this.options.breaks) {
621 this.rules = inline.breaks;
623 this.rules = inline.gfm;
625 } else if (this.options.pedantic) {
626 this.rules = inline.pedantic;
631 * Expose Inline Rules
634 InlineLexer.rules = inline;
637 * Static Lexing/Compiling Method
640 InlineLexer.output = function(src, links, options) {
641 var inline = new InlineLexer(links, options);
642 return inline.output(src);
649 InlineLexer.prototype.output = function(src) {
658 if (cap = this.rules.escape.exec(src)) {
659 src = src.substring(cap[0].length);
665 if (cap = this.rules.autolink.exec(src)) {
666 src = src.substring(cap[0].length);
667 if (cap[2] === '@') {
668 text = cap[1].charAt(6) === ':'
669 ? this.mangle(cap[1].substring(7))
670 : this.mangle(cap[1]);
671 href = this.mangle('mailto:') + text;
673 text = escape(cap[1]);
676 out += this.renderer.link(href, null, text);
681 if (!this.inLink && (cap = this.rules.url.exec(src))) {
682 src = src.substring(cap[0].length);
683 text = escape(cap[1]);
685 out += this.renderer.link(href, null, text);
690 if (cap = this.rules.tag.exec(src)) {
691 if (!this.inLink && /^<a /i.test(cap[0])) {
693 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
696 src = src.substring(cap[0].length);
697 out += this.options.sanitize
698 ? this.options.sanitizer
699 ? this.options.sanitizer(cap[0])
706 if (cap = this.rules.link.exec(src)) {
707 src = src.substring(cap[0].length);
709 out += this.outputLink(cap, {
718 if ((cap = this.rules.reflink.exec(src))
719 || (cap = this.rules.nolink.exec(src))) {
720 src = src.substring(cap[0].length);
721 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
722 link = this.links[link.toLowerCase()];
723 if (!link || !link.href) {
724 out += cap[0].charAt(0);
725 src = cap[0].substring(1) + src;
729 out += this.outputLink(cap, link);
735 if (cap = this.rules.strong.exec(src)) {
736 src = src.substring(cap[0].length);
737 out += this.renderer.strong(this.output(cap[2] || cap[1]));
742 if (cap = this.rules.em.exec(src)) {
743 src = src.substring(cap[0].length);
744 out += this.renderer.em(this.output(cap[2] || cap[1]));
749 if (cap = this.rules.code.exec(src)) {
750 src = src.substring(cap[0].length);
751 out += this.renderer.codespan(escape(cap[2], true));
756 if (cap = this.rules.br.exec(src)) {
757 src = src.substring(cap[0].length);
758 out += this.renderer.br();
763 if (cap = this.rules.del.exec(src)) {
764 src = src.substring(cap[0].length);
765 out += this.renderer.del(this.output(cap[1]));
770 if (cap = this.rules.text.exec(src)) {
771 src = src.substring(cap[0].length);
772 out += this.renderer.text(escape(this.smartypants(cap[0])));
778 Error('Infinite loop on byte: ' + src.charCodeAt(0));
789 InlineLexer.prototype.outputLink = function(cap, link) {
790 var href = escape(link.href)
791 , title = link.title ? escape(link.title) : null;
793 return cap[0].charAt(0) !== '!'
794 ? this.renderer.link(href, title, this.output(cap[1]))
795 : this.renderer.image(href, title, escape(cap[1]));
799 * Smartypants Transformations
802 InlineLexer.prototype.smartypants = function(text) {
803 if (!this.options.smartypants) { return text; }
806 .replace(/---/g, '\u2014')
808 .replace(/--/g, '\u2013')
810 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
811 // closing singles & apostrophes
812 .replace(/'/g, '\u2019')
814 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
816 .replace(/"/g, '\u201d')
818 .replace(/\.{3}/g, '\u2026');
825 InlineLexer.prototype.mangle = function(text) {
826 if (!this.options.mangle) { return text; }
833 ch = text.charCodeAt(i);
834 if (Math.random() > 0.5) {
835 ch = 'x' + ch.toString(16);
837 out += '&#' + ch + ';';
851 var Renderer = function (options) {
852 this.options = options || {};
855 Renderer.prototype.code = function(code, lang, escaped) {
856 if (this.options.highlight) {
857 var out = this.options.highlight(code, lang);
858 if (out != null && out !== code) {
863 // hack!!! - it's already escapeD?
869 + (escaped ? code : escape(code, true))
873 return '<pre><code class="'
874 + this.options.langPrefix
877 + (escaped ? code : escape(code, true))
878 + '\n</code></pre>\n';
881 Renderer.prototype.blockquote = function(quote) {
882 return '<blockquote>\n' + quote + '</blockquote>\n';
885 Renderer.prototype.html = function(html) {
889 Renderer.prototype.heading = function(text, level, raw) {
893 + this.options.headerPrefix
894 + raw.toLowerCase().replace(/[^\w]+/g, '-')
902 Renderer.prototype.hr = function() {
903 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
906 Renderer.prototype.list = function(body, ordered) {
907 var type = ordered ? 'ol' : 'ul';
908 return '<' + type + '>\n' + body + '</' + type + '>\n';
911 Renderer.prototype.listitem = function(text) {
912 return '<li>' + text + '</li>\n';
915 Renderer.prototype.paragraph = function(text) {
916 return '<p>' + text + '</p>\n';
919 Renderer.prototype.table = function(header, body) {
920 return '<table class="table table-striped">\n'
930 Renderer.prototype.tablerow = function(content) {
931 return '<tr>\n' + content + '</tr>\n';
934 Renderer.prototype.tablecell = function(content, flags) {
935 var type = flags.header ? 'th' : 'td';
936 var tag = flags.align
937 ? '<' + type + ' style="text-align:' + flags.align + '">'
939 return tag + content + '</' + type + '>\n';
942 // span level renderer
943 Renderer.prototype.strong = function(text) {
944 return '<strong>' + text + '</strong>';
947 Renderer.prototype.em = function(text) {
948 return '<em>' + text + '</em>';
951 Renderer.prototype.codespan = function(text) {
952 return '<code>' + text + '</code>';
955 Renderer.prototype.br = function() {
956 return this.options.xhtml ? '<br/>' : '<br>';
959 Renderer.prototype.del = function(text) {
960 return '<del>' + text + '</del>';
963 Renderer.prototype.link = function(href, title, text) {
964 if (this.options.sanitize) {
966 var prot = decodeURIComponent(unescape(href))
967 .replace(/[^\w:]/g, '')
972 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
976 var out = '<a href="' + href + '"';
978 out += ' title="' + title + '"';
980 out += '>' + text + '</a>';
984 Renderer.prototype.image = function(href, title, text) {
985 var out = '<img src="' + href + '" alt="' + text + '"';
987 out += ' title="' + title + '"';
989 out += this.options.xhtml ? '/>' : '>';
993 Renderer.prototype.text = function(text) {
998 * Parsing & Compiling
1004 var Parser= function (options) {
1007 this.options = options || marked.defaults;
1008 this.options.renderer = this.options.renderer || new Renderer;
1009 this.renderer = this.options.renderer;
1010 this.renderer.options = this.options;
1014 * Static Parse Method
1017 Parser.parse = function(src, options, renderer) {
1018 var parser = new Parser(options, renderer);
1019 return parser.parse(src);
1026 Parser.prototype.parse = function(src) {
1027 this.inline = new InlineLexer(src.links, this.options, this.renderer);
1028 this.tokens = src.reverse();
1031 while (this.next()) {
1042 Parser.prototype.next = function() {
1043 return this.token = this.tokens.pop();
1047 * Preview Next Token
1050 Parser.prototype.peek = function() {
1051 return this.tokens[this.tokens.length - 1] || 0;
1058 Parser.prototype.parseText = function() {
1059 var body = this.token.text;
1061 while (this.peek().type === 'text') {
1062 body += '\n' + this.next().text;
1065 return this.inline.output(body);
1069 * Parse Current Token
1072 Parser.prototype.tok = function() {
1073 switch (this.token.type) {
1078 return this.renderer.hr();
1081 return this.renderer.heading(
1082 this.inline.output(this.token.text),
1087 return this.renderer.code(this.token.text,
1089 this.token.escaped);
1102 for (i = 0; i < this.token.header.length; i++) {
1103 flags = { header: true, align: this.token.align[i] };
1104 cell += this.renderer.tablecell(
1105 this.inline.output(this.token.header[i]),
1106 { header: true, align: this.token.align[i] }
1109 header += this.renderer.tablerow(cell);
1111 for (i = 0; i < this.token.cells.length; i++) {
1112 row = this.token.cells[i];
1115 for (j = 0; j < row.length; j++) {
1116 cell += this.renderer.tablecell(
1117 this.inline.output(row[j]),
1118 { header: false, align: this.token.align[j] }
1122 body += this.renderer.tablerow(cell);
1124 return this.renderer.table(header, body);
1126 case 'blockquote_start': {
1129 while (this.next().type !== 'blockquote_end') {
1133 return this.renderer.blockquote(body);
1135 case 'list_start': {
1137 , ordered = this.token.ordered;
1139 while (this.next().type !== 'list_end') {
1143 return this.renderer.list(body, ordered);
1145 case 'list_item_start': {
1148 while (this.next().type !== 'list_item_end') {
1149 body += this.token.type === 'text'
1154 return this.renderer.listitem(body);
1156 case 'loose_item_start': {
1159 while (this.next().type !== 'list_item_end') {
1163 return this.renderer.listitem(body);
1166 var html = !this.token.pre && !this.options.pedantic
1167 ? this.inline.output(this.token.text)
1169 return this.renderer.html(html);
1172 return this.renderer.paragraph(this.inline.output(this.token.text));
1175 return this.renderer.paragraph(this.parseText());
1183 var noop = function () {}
1189 var merge = function (obj) {
1194 for (; i < arguments.length; i++) {
1195 target = arguments[i];
1196 for (key in target) {
1197 if (Object.prototype.hasOwnProperty.call(target, key)) {
1198 obj[key] = target[key];
1213 var marked = function (src, opt, callback) {
1214 if (callback || typeof opt === 'function') {
1220 opt = merge({}, marked.defaults, opt || {});
1222 var highlight = opt.highlight
1228 tokens = Lexer.lex(src, opt)
1233 pending = tokens.length;
1237 var done = function(err) {
1239 opt.highlight = highlight;
1240 return callback(err);
1246 out = Parser.parse(tokens, opt);
1251 opt.highlight = highlight;
1255 : callback(null, out);
1258 if (!highlight || highlight.length < 3) {
1262 delete opt.highlight;
1264 if (!pending) { return done(); }
1266 for (; i < tokens.length; i++) {
1268 if (token.type !== 'code') {
1269 return --pending || done();
1271 return highlight(token.text, token.lang, function(err, code) {
1272 if (err) { return done(err); }
1273 if (code == null || code === token.text) {
1274 return --pending || done();
1277 token.escaped = true;
1278 --pending || done();
1286 if (opt) { opt = merge({}, marked.defaults, opt); }
1287 return Parser.parse(Lexer.lex(src, opt), opt);
1289 e.message += '\nPlease report this to https://github.com/chjj/marked.';
1290 if ((opt || marked.defaults).silent) {
1291 return '<p>An error occured:</p><pre>'
1292 + escape(e.message + '', true)
1304 marked.setOptions = function(opt) {
1305 merge(marked.defaults, opt);
1320 langPrefix: 'lang-',
1323 renderer: new Renderer,
1331 marked.Parser = Parser;
1332 marked.parser = Parser.parse;
1334 marked.Renderer = Renderer;
1336 marked.Lexer = Lexer;
1337 marked.lexer = Lexer.lex;
1339 marked.InlineLexer = InlineLexer;
1340 marked.inlineLexer = InlineLexer.output;
1342 marked.parse = marked;
1344 Roo.Markdown.marked = marked;