Path: blob/master/web-gui/buildyourownbotnet/assets/js/marked.js
1292 views
/**1* marked - a markdown parser2* Copyright (c) 2011-2013, Christopher Jeffrey. (MIT Licensed)3* https://github.com/chjj/marked4*/56;(function() {78/**9* Block-Level Grammar10*/1112var block = {13newline: /^\n+/,14code: /^( {4}[^\n]+\n*)+/,15fences: noop,16hr: /^( *[-*_]){3,} *(?:\n+|$)/,17heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,18nptable: noop,19lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,20blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,21list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,22html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,23def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,24table: noop,25paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,26text: /^[^\n]+/27};2829block.bullet = /(?:[*+-]|\d+\.)/;30block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;31block.item = replace(block.item, 'gm')32(/bull/g, block.bullet)33();3435block.list = replace(block.list)36(/bull/g, block.bullet)37('hr', /\n+(?=(?: *[-*_]){3,} *(?:\n+|$))/)38();3940block._tag = '(?!(?:'41+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'42+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'43+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';4445block.html = replace(block.html)46('comment', /<!--[\s\S]*?-->/)47('closed', /<(tag)[\s\S]+?<\/\1>/)48('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)49(/tag/g, block._tag)50();5152block.paragraph = replace(block.paragraph)53('hr', block.hr)54('heading', block.heading)55('lheading', block.lheading)56('blockquote', block.blockquote)57('tag', '<' + block._tag)58('def', block.def)59();6061/**62* Normal Block Grammar63*/6465block.normal = merge({}, block);6667/**68* GFM Block Grammar69*/7071block.gfm = merge({}, block.normal, {72fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,73paragraph: /^/74});7576block.gfm.paragraph = replace(block.paragraph)77('(?!', '(?!'78+ block.gfm.fences.source.replace('\\1', '\\2') + '|'79+ block.list.source.replace('\\1', '\\3') + '|')80();8182/**83* GFM + Tables Block Grammar84*/8586block.tables = merge({}, block.gfm, {87nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,88table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/89});9091/**92* Block Lexer93*/9495function Lexer(options) {96this.tokens = [];97this.tokens.links = {};98this.options = options || marked.defaults;99this.rules = block.normal;100101if (this.options.gfm) {102if (this.options.tables) {103this.rules = block.tables;104} else {105this.rules = block.gfm;106}107}108}109110/**111* Expose Block Rules112*/113114Lexer.rules = block;115116/**117* Static Lex Method118*/119120Lexer.lex = function(src, options) {121var lexer = new Lexer(options);122return lexer.lex(src);123};124125/**126* Preprocessing127*/128129Lexer.prototype.lex = function(src) {130src = src131.replace(/\r\n|\r/g, '\n')132.replace(/\t/g, ' ')133.replace(/\u00a0/g, ' ')134.replace(/\u2424/g, '\n');135136return this.token(src, true);137};138139/**140* Lexing141*/142143Lexer.prototype.token = function(src, top) {144var src = src.replace(/^ +$/gm, '')145, next146, loose147, cap148, bull149, b150, item151, space152, i153, l;154155while (src) {156// newline157if (cap = this.rules.newline.exec(src)) {158src = src.substring(cap[0].length);159if (cap[0].length > 1) {160this.tokens.push({161type: 'space'162});163}164}165166// code167if (cap = this.rules.code.exec(src)) {168src = src.substring(cap[0].length);169cap = cap[0].replace(/^ {4}/gm, '');170this.tokens.push({171type: 'code',172text: !this.options.pedantic173? cap.replace(/\n+$/, '')174: cap175});176continue;177}178179// fences (gfm)180if (cap = this.rules.fences.exec(src)) {181src = src.substring(cap[0].length);182this.tokens.push({183type: 'code',184lang: cap[2],185text: cap[3]186});187continue;188}189190// heading191if (cap = this.rules.heading.exec(src)) {192src = src.substring(cap[0].length);193this.tokens.push({194type: 'heading',195depth: cap[1].length,196text: cap[2]197});198continue;199}200201// table no leading pipe (gfm)202if (top && (cap = this.rules.nptable.exec(src))) {203src = src.substring(cap[0].length);204205item = {206type: 'table',207header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),208align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),209cells: cap[3].replace(/\n$/, '').split('\n')210};211212for (i = 0; i < item.align.length; i++) {213if (/^ *-+: *$/.test(item.align[i])) {214item.align[i] = 'right';215} else if (/^ *:-+: *$/.test(item.align[i])) {216item.align[i] = 'center';217} else if (/^ *:-+ *$/.test(item.align[i])) {218item.align[i] = 'left';219} else {220item.align[i] = null;221}222}223224for (i = 0; i < item.cells.length; i++) {225item.cells[i] = item.cells[i].split(/ *\| */);226}227228this.tokens.push(item);229230continue;231}232233// lheading234if (cap = this.rules.lheading.exec(src)) {235src = src.substring(cap[0].length);236this.tokens.push({237type: 'heading',238depth: cap[2] === '=' ? 1 : 2,239text: cap[1]240});241continue;242}243244// hr245if (cap = this.rules.hr.exec(src)) {246src = src.substring(cap[0].length);247this.tokens.push({248type: 'hr'249});250continue;251}252253// blockquote254if (cap = this.rules.blockquote.exec(src)) {255src = src.substring(cap[0].length);256257this.tokens.push({258type: 'blockquote_start'259});260261cap = cap[0].replace(/^ *> ?/gm, '');262263// Pass `top` to keep the current264// "toplevel" state. This is exactly265// how markdown.pl works.266this.token(cap, top);267268this.tokens.push({269type: 'blockquote_end'270});271272continue;273}274275// list276if (cap = this.rules.list.exec(src)) {277src = src.substring(cap[0].length);278bull = cap[2];279280this.tokens.push({281type: 'list_start',282ordered: bull.length > 1283});284285// Get each top-level item.286cap = cap[0].match(this.rules.item);287288next = false;289l = cap.length;290i = 0;291292for (; i < l; i++) {293item = cap[i];294295// Remove the list item's bullet296// so it is seen as the next token.297space = item.length;298item = item.replace(/^ *([*+-]|\d+\.) +/, '');299300// Outdent whatever the301// list item contains. Hacky.302if (~item.indexOf('\n ')) {303space -= item.length;304item = !this.options.pedantic305? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')306: item.replace(/^ {1,4}/gm, '');307}308309// Determine whether the next list item belongs here.310// Backpedal if it does not belong in this list.311if (this.options.smartLists && i !== l - 1) {312b = block.bullet.exec(cap[i + 1])[0];313if (bull !== b && !(bull.length > 1 && b.length > 1)) {314src = cap.slice(i + 1).join('\n') + src;315i = l - 1;316}317}318319// Determine whether item is loose or not.320// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/321// for discount behavior.322loose = next || /\n\n(?!\s*$)/.test(item);323if (i !== l - 1) {324next = item.charAt(item.length - 1) === '\n';325if (!loose) loose = next;326}327328this.tokens.push({329type: loose330? 'loose_item_start'331: 'list_item_start'332});333334// Recurse.335this.token(item, false);336337this.tokens.push({338type: 'list_item_end'339});340}341342this.tokens.push({343type: 'list_end'344});345346continue;347}348349// html350if (cap = this.rules.html.exec(src)) {351src = src.substring(cap[0].length);352this.tokens.push({353type: this.options.sanitize354? 'paragraph'355: 'html',356pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',357text: cap[0]358});359continue;360}361362// def363if (top && (cap = this.rules.def.exec(src))) {364src = src.substring(cap[0].length);365this.tokens.links[cap[1].toLowerCase()] = {366href: cap[2],367title: cap[3]368};369continue;370}371372// table (gfm)373if (top && (cap = this.rules.table.exec(src))) {374src = src.substring(cap[0].length);375376item = {377type: 'table',378header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),379align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),380cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')381};382383for (i = 0; i < item.align.length; i++) {384if (/^ *-+: *$/.test(item.align[i])) {385item.align[i] = 'right';386} else if (/^ *:-+: *$/.test(item.align[i])) {387item.align[i] = 'center';388} else if (/^ *:-+ *$/.test(item.align[i])) {389item.align[i] = 'left';390} else {391item.align[i] = null;392}393}394395for (i = 0; i < item.cells.length; i++) {396item.cells[i] = item.cells[i]397.replace(/^ *\| *| *\| *$/g, '')398.split(/ *\| */);399}400401this.tokens.push(item);402403continue;404}405406// top-level paragraph407if (top && (cap = this.rules.paragraph.exec(src))) {408src = src.substring(cap[0].length);409this.tokens.push({410type: 'paragraph',411text: cap[1].charAt(cap[1].length - 1) === '\n'412? cap[1].slice(0, -1)413: cap[1]414});415continue;416}417418// text419if (cap = this.rules.text.exec(src)) {420// Top-level should never reach here.421src = src.substring(cap[0].length);422this.tokens.push({423type: 'text',424text: cap[0]425});426continue;427}428429if (src) {430throw new431Error('Infinite loop on byte: ' + src.charCodeAt(0));432}433}434435return this.tokens;436};437438/**439* Inline-Level Grammar440*/441442var inline = {443escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,444autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,445url: noop,446tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,447link: /^!?\[(inside)\]\(href\)/,448reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,449nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,450strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,451em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,452code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,453br: /^ {2,}\n(?!\s*$)/,454del: noop,455text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/456};457458inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;459inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;460461inline.link = replace(inline.link)462('inside', inline._inside)463('href', inline._href)464();465466inline.reflink = replace(inline.reflink)467('inside', inline._inside)468();469470/**471* Normal Inline Grammar472*/473474inline.normal = merge({}, inline);475476/**477* Pedantic Inline Grammar478*/479480inline.pedantic = merge({}, inline.normal, {481strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,482em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/483});484485/**486* GFM Inline Grammar487*/488489inline.gfm = merge({}, inline.normal, {490escape: replace(inline.escape)('])', '~|])')(),491url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,492del: /^~~(?=\S)([\s\S]*?\S)~~/,493text: replace(inline.text)494(']|', '~]|')495('|', '|https?://|')496()497});498499/**500* GFM + Line Breaks Inline Grammar501*/502503inline.breaks = merge({}, inline.gfm, {504br: replace(inline.br)('{2,}', '*')(),505text: replace(inline.gfm.text)('{2,}', '*')()506});507508/**509* Inline Lexer & Compiler510*/511512function InlineLexer(links, options) {513this.options = options || marked.defaults;514this.links = links;515this.rules = inline.normal;516this.renderer = this.options.renderer || new Renderer;517this.renderer.options = this.options;518519if (!this.links) {520throw new521Error('Tokens array requires a `links` property.');522}523524if (this.options.gfm) {525if (this.options.breaks) {526this.rules = inline.breaks;527} else {528this.rules = inline.gfm;529}530} else if (this.options.pedantic) {531this.rules = inline.pedantic;532}533}534535/**536* Expose Inline Rules537*/538539InlineLexer.rules = inline;540541/**542* Static Lexing/Compiling Method543*/544545InlineLexer.output = function(src, links, options) {546var inline = new InlineLexer(links, options);547return inline.output(src);548};549550/**551* Lexing/Compiling552*/553554InlineLexer.prototype.output = function(src) {555var out = ''556, link557, text558, href559, cap;560561while (src) {562// escape563if (cap = this.rules.escape.exec(src)) {564src = src.substring(cap[0].length);565out += cap[1];566continue;567}568569// autolink570if (cap = this.rules.autolink.exec(src)) {571src = src.substring(cap[0].length);572if (cap[2] === '@') {573text = cap[1].charAt(6) === ':'574? this.mangle(cap[1].substring(7))575: this.mangle(cap[1]);576href = this.mangle('mailto:') + text;577} else {578text = escape(cap[1]);579href = text;580}581out += this.renderer.link(href, null, text);582continue;583}584585// url (gfm)586if (cap = this.rules.url.exec(src)) {587src = src.substring(cap[0].length);588text = escape(cap[1]);589href = text;590out += this.renderer.link(href, null, text);591continue;592}593594// tag595if (cap = this.rules.tag.exec(src)) {596src = src.substring(cap[0].length);597out += this.options.sanitize598? escape(cap[0])599: cap[0];600continue;601}602603// link604if (cap = this.rules.link.exec(src)) {605src = src.substring(cap[0].length);606out += this.outputLink(cap, {607href: cap[2],608title: cap[3]609});610continue;611}612613// reflink, nolink614if ((cap = this.rules.reflink.exec(src))615|| (cap = this.rules.nolink.exec(src))) {616src = src.substring(cap[0].length);617link = (cap[2] || cap[1]).replace(/\s+/g, ' ');618link = this.links[link.toLowerCase()];619if (!link || !link.href) {620out += cap[0].charAt(0);621src = cap[0].substring(1) + src;622continue;623}624out += this.outputLink(cap, link);625continue;626}627628// strong629if (cap = this.rules.strong.exec(src)) {630src = src.substring(cap[0].length);631out += this.renderer.strong(this.output(cap[2] || cap[1]));632continue;633}634635// em636if (cap = this.rules.em.exec(src)) {637src = src.substring(cap[0].length);638out += this.renderer.em(this.output(cap[2] || cap[1]));639continue;640}641642// code643if (cap = this.rules.code.exec(src)) {644src = src.substring(cap[0].length);645out += this.renderer.codespan(escape(cap[2], true));646continue;647}648649// br650if (cap = this.rules.br.exec(src)) {651src = src.substring(cap[0].length);652out += this.renderer.br();653continue;654}655656// del (gfm)657if (cap = this.rules.del.exec(src)) {658src = src.substring(cap[0].length);659out += this.renderer.del(this.output(cap[1]));660continue;661}662663// text664if (cap = this.rules.text.exec(src)) {665src = src.substring(cap[0].length);666out += escape(this.smartypants(cap[0]));667continue;668}669670if (src) {671throw new672Error('Infinite loop on byte: ' + src.charCodeAt(0));673}674}675676return out;677};678679/**680* Compile Link681*/682683InlineLexer.prototype.outputLink = function(cap, link) {684var href = escape(link.href)685, title = link.title ? escape(link.title) : null;686687return cap[0].charAt(0) !== '!'688? this.renderer.link(href, title, this.output(cap[1]))689: this.renderer.image(href, title, escape(cap[1]));690};691692/**693* Smartypants Transformations694*/695696InlineLexer.prototype.smartypants = function(text) {697if (!this.options.smartypants) return text;698return text699// em-dashes700.replace(/--/g, '\u2014')701// opening singles702.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')703// closing singles & apostrophes704.replace(/'/g, '\u2019')705// opening doubles706.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')707// closing doubles708.replace(/"/g, '\u201d')709// ellipses710.replace(/\.{3}/g, '\u2026');711};712713/**714* Mangle Links715*/716717InlineLexer.prototype.mangle = function(text) {718var out = ''719, l = text.length720, i = 0721, ch;722723for (; i < l; i++) {724ch = text.charCodeAt(i);725if (Math.random() > 0.5) {726ch = 'x' + ch.toString(16);727}728out += '&#' + ch + ';';729}730731return out;732};733734/**735* Renderer736*/737738function Renderer(options) {739this.options = options || {};740}741742Renderer.prototype.code = function(code, lang, escaped) {743if (this.options.highlight) {744var out = this.options.highlight(code, lang);745if (out != null && out !== code) {746escaped = true;747code = out;748}749}750751if (!lang) {752return '<pre><code>'753+ (escaped ? code : escape(code, true))754+ '\n</code></pre>';755}756757return '<pre><code class="'758+ this.options.langPrefix759+ escape(lang, true)760+ '">'761+ (escaped ? code : escape(code, true))762+ '\n</code></pre>\n';763};764765Renderer.prototype.blockquote = function(quote) {766return '<blockquote>\n' + quote + '</blockquote>\n';767};768769Renderer.prototype.html = function(html) {770return html;771};772773Renderer.prototype.heading = function(text, level, raw) {774return '<h'775+ level776+ ' id="'777+ this.options.headerPrefix778+ raw.toLowerCase().replace(/[^\w]+/g, '-')779+ '">'780+ text781+ '</h'782+ level783+ '>\n';784};785786Renderer.prototype.hr = function() {787return '<hr>\n';788};789790Renderer.prototype.list = function(body, ordered) {791var type = ordered ? 'ol' : 'ul';792return '<' + type + '>\n' + body + '</' + type + '>\n';793};794795Renderer.prototype.listitem = function(text) {796return '<li>' + text + '</li>\n';797};798799Renderer.prototype.paragraph = function(text) {800return '<p>' + text + '</p>\n';801};802803Renderer.prototype.table = function(header, body) {804return '<table>\n'805+ '<thead>\n'806+ header807+ '</thead>\n'808+ '<tbody>\n'809+ body810+ '</tbody>\n'811+ '</table>\n';812};813814Renderer.prototype.tablerow = function(content) {815return '<tr>\n' + content + '</tr>\n';816};817818Renderer.prototype.tablecell = function(content, flags) {819var type = flags.header ? 'th' : 'td';820var tag = flags.align821? '<' + type + ' style="text-align:' + flags.align + '">'822: '<' + type + '>';823return tag + content + '</' + type + '>\n';824};825826// span level renderer827Renderer.prototype.strong = function(text) {828return '<strong>' + text + '</strong>';829};830831Renderer.prototype.em = function(text) {832return '<em>' + text + '</em>';833};834835Renderer.prototype.codespan = function(text) {836return '<code>' + text + '</code>';837};838839Renderer.prototype.br = function() {840return '<br>';841};842843Renderer.prototype.del = function(text) {844return '<del>' + text + '</del>';845};846847Renderer.prototype.link = function(href, title, text) {848if (this.options.sanitize) {849try {850var prot = decodeURIComponent(unescape(href))851.replace(/[^\w:]/g, '')852.toLowerCase();853} catch (e) {854return '';855}856if (prot.indexOf('javascript:') === 0) {857return '';858}859}860var out = '<a href="' + href + '"';861if (title) {862out += ' title="' + title + '"';863}864out += '>' + text + '</a>';865return out;866};867868Renderer.prototype.image = function(href, title, text) {869var out = '<img src="' + href + '" alt="' + text + '"';870if (title) {871out += ' title="' + title + '"';872}873out += '>';874return out;875};876877/**878* Parsing & Compiling879*/880881function Parser(options) {882this.tokens = [];883this.token = null;884this.options = options || marked.defaults;885this.options.renderer = this.options.renderer || new Renderer;886this.renderer = this.options.renderer;887this.renderer.options = this.options;888}889890/**891* Static Parse Method892*/893894Parser.parse = function(src, options, renderer) {895var parser = new Parser(options, renderer);896return parser.parse(src);897};898899/**900* Parse Loop901*/902903Parser.prototype.parse = function(src) {904this.inline = new InlineLexer(src.links, this.options, this.renderer);905this.tokens = src.reverse();906907var out = '';908while (this.next()) {909out += this.tok();910}911912return out;913};914915/**916* Next Token917*/918919Parser.prototype.next = function() {920return this.token = this.tokens.pop();921};922923/**924* Preview Next Token925*/926927Parser.prototype.peek = function() {928return this.tokens[this.tokens.length - 1] || 0;929};930931/**932* Parse Text Tokens933*/934935Parser.prototype.parseText = function() {936var body = this.token.text;937938while (this.peek().type === 'text') {939body += '\n' + this.next().text;940}941942return this.inline.output(body);943};944945/**946* Parse Current Token947*/948949Parser.prototype.tok = function() {950switch (this.token.type) {951case 'space': {952return '';953}954case 'hr': {955return this.renderer.hr();956}957case 'heading': {958return this.renderer.heading(959this.inline.output(this.token.text),960this.token.depth,961this.token.text);962}963case 'code': {964return this.renderer.code(this.token.text,965this.token.lang,966this.token.escaped);967}968case 'table': {969var header = ''970, body = ''971, i972, row973, cell974, flags975, j;976977// header978cell = '';979for (i = 0; i < this.token.header.length; i++) {980flags = { header: true, align: this.token.align[i] };981cell += this.renderer.tablecell(982this.inline.output(this.token.header[i]),983{ header: true, align: this.token.align[i] }984);985}986header += this.renderer.tablerow(cell);987988for (i = 0; i < this.token.cells.length; i++) {989row = this.token.cells[i];990991cell = '';992for (j = 0; j < row.length; j++) {993cell += this.renderer.tablecell(994this.inline.output(row[j]),995{ header: false, align: this.token.align[j] }996);997}998999body += this.renderer.tablerow(cell);1000}1001return this.renderer.table(header, body);1002}1003case 'blockquote_start': {1004var body = '';10051006while (this.next().type !== 'blockquote_end') {1007body += this.tok();1008}10091010return this.renderer.blockquote(body);1011}1012case 'list_start': {1013var body = ''1014, ordered = this.token.ordered;10151016while (this.next().type !== 'list_end') {1017body += this.tok();1018}10191020return this.renderer.list(body, ordered);1021}1022case 'list_item_start': {1023var body = '';10241025while (this.next().type !== 'list_item_end') {1026body += this.token.type === 'text'1027? this.parseText()1028: this.tok();1029}10301031return this.renderer.listitem(body);1032}1033case 'loose_item_start': {1034var body = '';10351036while (this.next().type !== 'list_item_end') {1037body += this.tok();1038}10391040return this.renderer.listitem(body);1041}1042case 'html': {1043var html = !this.token.pre && !this.options.pedantic1044? this.inline.output(this.token.text)1045: this.token.text;1046return this.renderer.html(html);1047}1048case 'paragraph': {1049return this.renderer.paragraph(this.inline.output(this.token.text));1050}1051case 'text': {1052return this.renderer.paragraph(this.parseText());1053}1054}1055};10561057/**1058* Helpers1059*/10601061function escape(html, encode) {1062return html1063.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')1064.replace(/</g, '<')1065.replace(/>/g, '>')1066.replace(/"/g, '"')1067.replace(/'/g, ''');1068}10691070function unescape(html) {1071return html.replace(/&([#\w]+);/g, function(_, n) {1072n = n.toLowerCase();1073if (n === 'colon') return ':';1074if (n.charAt(0) === '#') {1075return n.charAt(1) === 'x'1076? String.fromCharCode(parseInt(n.substring(2), 16))1077: String.fromCharCode(+n.substring(1));1078}1079return '';1080});1081}10821083function replace(regex, opt) {1084regex = regex.source;1085opt = opt || '';1086return function self(name, val) {1087if (!name) return new RegExp(regex, opt);1088val = val.source || val;1089val = val.replace(/(^|[^\[])\^/g, '$1');1090regex = regex.replace(name, val);1091return self;1092};1093}10941095function noop() {}1096noop.exec = noop;10971098function merge(obj) {1099var i = 11100, target1101, key;11021103for (; i < arguments.length; i++) {1104target = arguments[i];1105for (key in target) {1106if (Object.prototype.hasOwnProperty.call(target, key)) {1107obj[key] = target[key];1108}1109}1110}11111112return obj;1113}111411151116/**1117* Marked1118*/11191120function marked(src, opt, callback) {1121if (callback || typeof opt === 'function') {1122if (!callback) {1123callback = opt;1124opt = null;1125}11261127opt = merge({}, marked.defaults, opt || {});11281129var highlight = opt.highlight1130, tokens1131, pending1132, i = 0;11331134try {1135tokens = Lexer.lex(src, opt)1136} catch (e) {1137return callback(e);1138}11391140pending = tokens.length;11411142var done = function() {1143var out, err;11441145try {1146out = Parser.parse(tokens, opt);1147} catch (e) {1148err = e;1149}11501151opt.highlight = highlight;11521153return err1154? callback(err)1155: callback(null, out);1156};11571158if (!highlight || highlight.length < 3) {1159return done();1160}11611162delete opt.highlight;11631164if (!pending) return done();11651166for (; i < tokens.length; i++) {1167(function(token) {1168if (token.type !== 'code') {1169return --pending || done();1170}1171return highlight(token.text, token.lang, function(err, code) {1172if (code == null || code === token.text) {1173return --pending || done();1174}1175token.text = code;1176token.escaped = true;1177--pending || done();1178});1179})(tokens[i]);1180}11811182return;1183}1184try {1185if (opt) opt = merge({}, marked.defaults, opt);1186return Parser.parse(Lexer.lex(src, opt), opt);1187} catch (e) {1188e.message += '\nPlease report this to https://github.com/chjj/marked.';1189if ((opt || marked.defaults).silent) {1190return '<p>An error occured:</p><pre>'1191+ escape(e.message + '', true)1192+ '</pre>';1193}1194throw e;1195}1196}11971198/**1199* Options1200*/12011202marked.options =1203marked.setOptions = function(opt) {1204merge(marked.defaults, opt);1205return marked;1206};12071208marked.defaults = {1209gfm: true,1210tables: true,1211breaks: false,1212pedantic: false,1213sanitize: false,1214smartLists: false,1215silent: false,1216highlight: null,1217langPrefix: 'lang-',1218smartypants: false,1219headerPrefix: '',1220renderer: new Renderer1221};12221223/**1224* Expose1225*/12261227marked.Parser = Parser;1228marked.parser = Parser.parse;12291230marked.Renderer = Renderer;12311232marked.Lexer = Lexer;1233marked.lexer = Lexer.lex;12341235marked.InlineLexer = InlineLexer;1236marked.inlineLexer = InlineLexer.output;12371238marked.parse = marked;12391240if (typeof exports === 'object') {1241module.exports = marked;1242} else if (typeof define === 'function' && define.amd) {1243define(function() { return marked; });1244} else {1245this.marked = marked;1246}12471248}).call(function() {1249return this || (typeof window !== 'undefined' ? window : global);1250}());125112521253