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);
97 var noop = function () {}
103 var merge = function (obj) {
108 for (; i < arguments.length; i++) {
109 target = arguments[i];
110 for (key in target) {
111 if (Object.prototype.hasOwnProperty.call(target, key)) {
112 obj[key] = target[key];
122 * Block-Level Grammar
130 code: /^( {4}[^\n]+\n*)+/,
132 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
133 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
135 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
136 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
137 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
138 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
139 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
141 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
145 block.bullet = /(?:[*+-]|\d+\.)/;
146 block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
147 block.item = replace(block.item, 'gm')
148 (/bull/g, block.bullet)
151 block.list = replace(block.list)
152 (/bull/g, block.bullet)
153 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
154 ('def', '\\n+(?=' + block.def.source + ')')
157 block.blockquote = replace(block.blockquote)
161 block._tag = '(?!(?:'
162 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
163 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
164 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
166 block.html = replace(block.html)
167 ('comment', /<!--[\s\S]*?-->/)
168 ('closed', /<(tag)[\s\S]+?<\/\1>/)
169 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
173 block.paragraph = replace(block.paragraph)
175 ('heading', block.heading)
176 ('lheading', block.lheading)
177 ('blockquote', block.blockquote)
178 ('tag', '<' + block._tag)
183 * Normal Block Grammar
186 block.normal = merge({}, block);
192 block.gfm = merge({}, block.normal, {
193 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
195 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
198 block.gfm.paragraph = replace(block.paragraph)
200 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
201 + block.list.source.replace('\\1', '\\3') + '|')
205 * GFM + Tables Block Grammar
208 block.tables = merge({}, block.gfm, {
209 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
210 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
217 var Lexer = function (options) {
219 this.tokens.links = {};
220 this.options = options || marked.defaults;
221 this.rules = block.normal;
223 if (this.options.gfm) {
224 if (this.options.tables) {
225 this.rules = block.tables;
227 this.rules = block.gfm;
242 Lexer.lex = function(src, options) {
243 var lexer = new Lexer(options);
244 return lexer.lex(src);
251 Lexer.prototype.lex = function(src) {
253 .replace(/\r\n|\r/g, '\n')
255 .replace(/\u00a0/g, ' ')
256 .replace(/\u2424/g, '\n');
258 return this.token(src, true);
265 Lexer.prototype.token = function(src, top, bq) {
266 var src = src.replace(/^ +$/gm, '')
279 if (cap = this.rules.newline.exec(src)) {
280 src = src.substring(cap[0].length);
281 if (cap[0].length > 1) {
289 if (cap = this.rules.code.exec(src)) {
290 src = src.substring(cap[0].length);
291 cap = cap[0].replace(/^ {4}/gm, '');
294 text: !this.options.pedantic
295 ? cap.replace(/\n+$/, '')
302 if (cap = this.rules.fences.exec(src)) {
303 src = src.substring(cap[0].length);
313 if (cap = this.rules.heading.exec(src)) {
314 src = src.substring(cap[0].length);
317 depth: cap[1].length,
323 // table no leading pipe (gfm)
324 if (top && (cap = this.rules.nptable.exec(src))) {
325 src = src.substring(cap[0].length);
329 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
330 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
331 cells: cap[3].replace(/\n$/, '').split('\n')
334 for (i = 0; i < item.align.length; i++) {
335 if (/^ *-+: *$/.test(item.align[i])) {
336 item.align[i] = 'right';
337 } else if (/^ *:-+: *$/.test(item.align[i])) {
338 item.align[i] = 'center';
339 } else if (/^ *:-+ *$/.test(item.align[i])) {
340 item.align[i] = 'left';
342 item.align[i] = null;
346 for (i = 0; i < item.cells.length; i++) {
347 item.cells[i] = item.cells[i].split(/ *\| */);
350 this.tokens.push(item);
356 if (cap = this.rules.lheading.exec(src)) {
357 src = src.substring(cap[0].length);
360 depth: cap[2] === '=' ? 1 : 2,
367 if (cap = this.rules.hr.exec(src)) {
368 src = src.substring(cap[0].length);
376 if (cap = this.rules.blockquote.exec(src)) {
377 src = src.substring(cap[0].length);
380 type: 'blockquote_start'
383 cap = cap[0].replace(/^ *> ?/gm, '');
385 // Pass `top` to keep the current
386 // "toplevel" state. This is exactly
387 // how markdown.pl works.
388 this.token(cap, top, true);
391 type: 'blockquote_end'
398 if (cap = this.rules.list.exec(src)) {
399 src = src.substring(cap[0].length);
404 ordered: bull.length > 1
407 // Get each top-level item.
408 cap = cap[0].match(this.rules.item);
417 // Remove the list item's bullet
418 // so it is seen as the next token.
420 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
422 // Outdent whatever the
423 // list item contains. Hacky.
424 if (~item.indexOf('\n ')) {
425 space -= item.length;
426 item = !this.options.pedantic
427 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
428 : item.replace(/^ {1,4}/gm, '');
431 // Determine whether the next list item belongs here.
432 // Backpedal if it does not belong in this list.
433 if (this.options.smartLists && i !== l - 1) {
434 b = block.bullet.exec(cap[i + 1])[0];
435 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
436 src = cap.slice(i + 1).join('\n') + src;
441 // Determine whether item is loose or not.
442 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
443 // for discount behavior.
444 loose = next || /\n\n(?!\s*$)/.test(item);
446 next = item.charAt(item.length - 1) === '\n';
447 if (!loose) { loose = next; }
457 this.token(item, false, bq);
460 type: 'list_item_end'
472 if (cap = this.rules.html.exec(src)) {
473 src = src.substring(cap[0].length);
475 type: this.options.sanitize
478 pre: !this.options.sanitizer
479 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
486 if ((!bq && top) && (cap = this.rules.def.exec(src))) {
487 src = src.substring(cap[0].length);
488 this.tokens.links[cap[1].toLowerCase()] = {
496 if (top && (cap = this.rules.table.exec(src))) {
497 src = src.substring(cap[0].length);
501 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
502 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
503 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
506 for (i = 0; i < item.align.length; i++) {
507 if (/^ *-+: *$/.test(item.align[i])) {
508 item.align[i] = 'right';
509 } else if (/^ *:-+: *$/.test(item.align[i])) {
510 item.align[i] = 'center';
511 } else if (/^ *:-+ *$/.test(item.align[i])) {
512 item.align[i] = 'left';
514 item.align[i] = null;
518 for (i = 0; i < item.cells.length; i++) {
519 item.cells[i] = item.cells[i]
520 .replace(/^ *\| *| *\| *$/g, '')
524 this.tokens.push(item);
529 // top-level paragraph
530 if (top && (cap = this.rules.paragraph.exec(src))) {
531 src = src.substring(cap[0].length);
534 text: cap[1].charAt(cap[1].length - 1) === '\n'
535 ? cap[1].slice(0, -1)
542 if (cap = this.rules.text.exec(src)) {
543 // Top-level should never reach here.
544 src = src.substring(cap[0].length);
554 Error('Infinite loop on byte: ' + src.charCodeAt(0));
562 * Inline-Level Grammar
566 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
567 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
569 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
570 link: /^!?\[(inside)\]\(href\)/,
571 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
572 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
573 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
574 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
575 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
576 br: /^ {2,}\n(?!\s*$)/,
578 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
581 inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
582 inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
584 inline.link = replace(inline.link)
585 ('inside', inline._inside)
586 ('href', inline._href)
589 inline.reflink = replace(inline.reflink)
590 ('inside', inline._inside)
594 * Normal Inline Grammar
597 inline.normal = merge({}, inline);
600 * Pedantic Inline Grammar
603 inline.pedantic = merge({}, inline.normal, {
604 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
605 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
612 inline.gfm = merge({}, inline.normal, {
613 escape: replace(inline.escape)('])', '~|])')(),
614 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
615 del: /^~~(?=\S)([\s\S]*?\S)~~/,
616 text: replace(inline.text)
623 * GFM + Line Breaks Inline Grammar
626 inline.breaks = merge({}, inline.gfm, {
627 br: replace(inline.br)('{2,}', '*')(),
628 text: replace(inline.gfm.text)('{2,}', '*')()
632 * Inline Lexer & Compiler
635 var InlineLexer = function (links, options) {
636 this.options = options || marked.defaults;
638 this.rules = inline.normal;
639 this.renderer = this.options.renderer || new Renderer;
640 this.renderer.options = this.options;
644 Error('Tokens array requires a `links` property.');
647 if (this.options.gfm) {
648 if (this.options.breaks) {
649 this.rules = inline.breaks;
651 this.rules = inline.gfm;
653 } else if (this.options.pedantic) {
654 this.rules = inline.pedantic;
659 * Expose Inline Rules
662 InlineLexer.rules = inline;
665 * Static Lexing/Compiling Method
668 InlineLexer.output = function(src, links, options) {
669 var inline = new InlineLexer(links, options);
670 return inline.output(src);
677 InlineLexer.prototype.output = function(src) {
686 if (cap = this.rules.escape.exec(src)) {
687 src = src.substring(cap[0].length);
693 if (cap = this.rules.autolink.exec(src)) {
694 src = src.substring(cap[0].length);
695 if (cap[2] === '@') {
696 text = cap[1].charAt(6) === ':'
697 ? this.mangle(cap[1].substring(7))
698 : this.mangle(cap[1]);
699 href = this.mangle('mailto:') + text;
701 text = escape(cap[1]);
704 out += this.renderer.link(href, null, text);
709 if (!this.inLink && (cap = this.rules.url.exec(src))) {
710 src = src.substring(cap[0].length);
711 text = escape(cap[1]);
713 out += this.renderer.link(href, null, text);
718 if (cap = this.rules.tag.exec(src)) {
719 if (!this.inLink && /^<a /i.test(cap[0])) {
721 } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
724 src = src.substring(cap[0].length);
725 out += this.options.sanitize
726 ? this.options.sanitizer
727 ? this.options.sanitizer(cap[0])
734 if (cap = this.rules.link.exec(src)) {
735 src = src.substring(cap[0].length);
737 out += this.outputLink(cap, {
746 if ((cap = this.rules.reflink.exec(src))
747 || (cap = this.rules.nolink.exec(src))) {
748 src = src.substring(cap[0].length);
749 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
750 link = this.links[link.toLowerCase()];
751 if (!link || !link.href) {
752 out += cap[0].charAt(0);
753 src = cap[0].substring(1) + src;
757 out += this.outputLink(cap, link);
763 if (cap = this.rules.strong.exec(src)) {
764 src = src.substring(cap[0].length);
765 out += this.renderer.strong(this.output(cap[2] || cap[1]));
770 if (cap = this.rules.em.exec(src)) {
771 src = src.substring(cap[0].length);
772 out += this.renderer.em(this.output(cap[2] || cap[1]));
777 if (cap = this.rules.code.exec(src)) {
778 src = src.substring(cap[0].length);
779 out += this.renderer.codespan(escape(cap[2], true));
784 if (cap = this.rules.br.exec(src)) {
785 src = src.substring(cap[0].length);
786 out += this.renderer.br();
791 if (cap = this.rules.del.exec(src)) {
792 src = src.substring(cap[0].length);
793 out += this.renderer.del(this.output(cap[1]));
798 if (cap = this.rules.text.exec(src)) {
799 src = src.substring(cap[0].length);
800 out += this.renderer.text(escape(this.smartypants(cap[0])));
806 Error('Infinite loop on byte: ' + src.charCodeAt(0));
817 InlineLexer.prototype.outputLink = function(cap, link) {
818 var href = escape(link.href)
819 , title = link.title ? escape(link.title) : null;
821 return cap[0].charAt(0) !== '!'
822 ? this.renderer.link(href, title, this.output(cap[1]))
823 : this.renderer.image(href, title, escape(cap[1]));
827 * Smartypants Transformations
830 InlineLexer.prototype.smartypants = function(text) {
831 if (!this.options.smartypants) { return text; }
834 .replace(/---/g, '\u2014')
836 .replace(/--/g, '\u2013')
838 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
839 // closing singles & apostrophes
840 .replace(/'/g, '\u2019')
842 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
844 .replace(/"/g, '\u201d')
846 .replace(/\.{3}/g, '\u2026');
853 InlineLexer.prototype.mangle = function(text) {
854 if (!this.options.mangle) { return text; }
861 ch = text.charCodeAt(i);
862 if (Math.random() > 0.5) {
863 ch = 'x' + ch.toString(16);
865 out += '&#' + ch + ';';
879 var Renderer = function (options) {
880 this.options = options || {};
883 Renderer.prototype.code = function(code, lang, escaped) {
884 if (this.options.highlight) {
885 var out = this.options.highlight(code, lang);
886 if (out != null && out !== code) {
891 // hack!!! - it's already escapeD?
897 + (escaped ? code : escape(code, true))
901 return '<pre><code class="'
902 + this.options.langPrefix
905 + (escaped ? code : escape(code, true))
906 + '\n</code></pre>\n';
909 Renderer.prototype.blockquote = function(quote) {
910 return '<blockquote>\n' + quote + '</blockquote>\n';
913 Renderer.prototype.html = function(html) {
917 Renderer.prototype.heading = function(text, level, raw) {
921 + this.options.headerPrefix
922 + raw.toLowerCase().replace(/[^\w]+/g, '-')
930 Renderer.prototype.hr = function() {
931 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
934 Renderer.prototype.list = function(body, ordered) {
935 var type = ordered ? 'ol' : 'ul';
936 return '<' + type + '>\n' + body + '</' + type + '>\n';
939 Renderer.prototype.listitem = function(text) {
940 return '<li>' + text + '</li>\n';
943 Renderer.prototype.paragraph = function(text) {
944 return '<p>' + text + '</p>\n';
947 Renderer.prototype.table = function(header, body) {
948 return '<table class="table table-striped">\n'
958 Renderer.prototype.tablerow = function(content) {
959 return '<tr>\n' + content + '</tr>\n';
962 Renderer.prototype.tablecell = function(content, flags) {
963 var type = flags.header ? 'th' : 'td';
964 var tag = flags.align
965 ? '<' + type + ' style="text-align:' + flags.align + '">'
967 return tag + content + '</' + type + '>\n';
970 // span level renderer
971 Renderer.prototype.strong = function(text) {
972 return '<strong>' + text + '</strong>';
975 Renderer.prototype.em = function(text) {
976 return '<em>' + text + '</em>';
979 Renderer.prototype.codespan = function(text) {
980 return '<code>' + text + '</code>';
983 Renderer.prototype.br = function() {
984 return this.options.xhtml ? '<br/>' : '<br>';
987 Renderer.prototype.del = function(text) {
988 return '<del>' + text + '</del>';
991 Renderer.prototype.link = function(href, title, text) {
992 if (this.options.sanitize) {
994 var prot = decodeURIComponent(unescape(href))
995 .replace(/[^\w:]/g, '')
1000 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
1004 var out = '<a href="' + href + '"';
1006 out += ' title="' + title + '"';
1008 out += '>' + text + '</a>';
1012 Renderer.prototype.image = function(href, title, text) {
1013 var out = '<img src="' + href + '" alt="' + text + '"';
1015 out += ' title="' + title + '"';
1017 out += this.options.xhtml ? '/>' : '>';
1021 Renderer.prototype.text = function(text) {
1026 * Parsing & Compiling
1032 var Parser= function (options) {
1035 this.options = options || marked.defaults;
1036 this.options.renderer = this.options.renderer || new Renderer;
1037 this.renderer = this.options.renderer;
1038 this.renderer.options = this.options;
1042 * Static Parse Method
1045 Parser.parse = function(src, options, renderer) {
1046 var parser = new Parser(options, renderer);
1047 return parser.parse(src);
1054 Parser.prototype.parse = function(src) {
1055 this.inline = new InlineLexer(src.links, this.options, this.renderer);
1056 this.tokens = src.reverse();
1059 while (this.next()) {
1070 Parser.prototype.next = function() {
1071 return this.token = this.tokens.pop();
1075 * Preview Next Token
1078 Parser.prototype.peek = function() {
1079 return this.tokens[this.tokens.length - 1] || 0;
1086 Parser.prototype.parseText = function() {
1087 var body = this.token.text;
1089 while (this.peek().type === 'text') {
1090 body += '\n' + this.next().text;
1093 return this.inline.output(body);
1097 * Parse Current Token
1100 Parser.prototype.tok = function() {
1101 switch (this.token.type) {
1106 return this.renderer.hr();
1109 return this.renderer.heading(
1110 this.inline.output(this.token.text),
1115 return this.renderer.code(this.token.text,
1117 this.token.escaped);
1130 for (i = 0; i < this.token.header.length; i++) {
1131 flags = { header: true, align: this.token.align[i] };
1132 cell += this.renderer.tablecell(
1133 this.inline.output(this.token.header[i]),
1134 { header: true, align: this.token.align[i] }
1137 header += this.renderer.tablerow(cell);
1139 for (i = 0; i < this.token.cells.length; i++) {
1140 row = this.token.cells[i];
1143 for (j = 0; j < row.length; j++) {
1144 cell += this.renderer.tablecell(
1145 this.inline.output(row[j]),
1146 { header: false, align: this.token.align[j] }
1150 body += this.renderer.tablerow(cell);
1152 return this.renderer.table(header, body);
1154 case 'blockquote_start': {
1157 while (this.next().type !== 'blockquote_end') {
1161 return this.renderer.blockquote(body);
1163 case 'list_start': {
1165 , ordered = this.token.ordered;
1167 while (this.next().type !== 'list_end') {
1171 return this.renderer.list(body, ordered);
1173 case 'list_item_start': {
1176 while (this.next().type !== 'list_item_end') {
1177 body += this.token.type === 'text'
1182 return this.renderer.listitem(body);
1184 case 'loose_item_start': {
1187 while (this.next().type !== 'list_item_end') {
1191 return this.renderer.listitem(body);
1194 var html = !this.token.pre && !this.options.pedantic
1195 ? this.inline.output(this.token.text)
1197 return this.renderer.html(html);
1200 return this.renderer.paragraph(this.inline.output(this.token.text));
1203 return this.renderer.paragraph(this.parseText());
1215 var marked = function (src, opt, callback) {
1216 if (callback || typeof opt === 'function') {
1222 opt = merge({}, marked.defaults, opt || {});
1224 var highlight = opt.highlight
1230 tokens = Lexer.lex(src, opt)
1235 pending = tokens.length;
1239 var done = function(err) {
1241 opt.highlight = highlight;
1242 return callback(err);
1248 out = Parser.parse(tokens, opt);
1253 opt.highlight = highlight;
1257 : callback(null, out);
1260 if (!highlight || highlight.length < 3) {
1264 delete opt.highlight;
1266 if (!pending) { return done(); }
1268 for (; i < tokens.length; i++) {
1270 if (token.type !== 'code') {
1271 return --pending || done();
1273 return highlight(token.text, token.lang, function(err, code) {
1274 if (err) { return done(err); }
1275 if (code == null || code === token.text) {
1276 return --pending || done();
1279 token.escaped = true;
1280 --pending || done();
1288 if (opt) { opt = merge({}, marked.defaults, opt); }
1289 return Parser.parse(Lexer.lex(src, opt), opt);
1291 e.message += '\nPlease report this to https://github.com/chjj/marked.';
1292 if ((opt || marked.defaults).silent) {
1293 return '<p>An error occured:</p><pre>'
1294 + escape(e.message + '', true)
1306 marked.setOptions = function(opt) {
1307 merge(marked.defaults, opt);
1322 langPrefix: 'lang-',
1325 renderer: new Renderer,
1333 marked.Parser = Parser;
1334 marked.parser = Parser.parse;
1336 marked.Renderer = Renderer;
1338 marked.Lexer = Lexer;
1339 marked.lexer = Lexer.lex;
1341 marked.InlineLexer = InlineLexer;
1342 marked.inlineLexer = InlineLexer.output;
1344 marked.parse = marked;
1346 Roo.Markdown.marked = marked;