UNPKG

15.9 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.marked3=t()}(this,function(){"use strict";function e(e){for(var t,n,r=arguments,s=1;s<arguments.length;s++){t=r[s];for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}function t(){}function n(e,t){return e.replace(t?/&/g:/&(?!#?\w+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function r(e){return e.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g,function(e,t){return t=t.toLowerCase(),"colon"===t?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(Number(t.substring(1))):""})}function s(e,t){return e=e.source,t=t||"",function n(r,s){return r?(s=s.source||s,s=s.replace(/(^|[^\[])\^/g,"$1"),e=e.replace(r,s),n):new RegExp(e,t)}}function i(e){return e.replace(/<(?:.|\n)*?>/gm,"").replace(/[!\"#$%&'\(\)\*\+,\/:;<=>\?\@\[\\\]\^`\{\|\}~]/g,"").replace(/(\s|\.)/g,"-").replace(/-{2,}/g,"-").toLowerCase()}function o(t,n){try{return n&&(n=e({},a,n)),u.parse(g.lex(t,n),n)}catch(e){if(e.message+="\nPlease report this to https://github.com/egoist/marked3.",(n||a).silent)return"<p>An error occured:</p><pre>"+escape(String(e.message),!0)+"</pre>";throw e}}t.exec=t;var l=function(e){this.options=e||{},this._headings=[]};l.prototype.code=function(e,t,r){if(this.options.highlight){var s=this.options.highlight(e,t);null!==s&&s!==e&&(r=!0,e=s)}return t?'<pre><code class="'+this.options.langPrefix+n(t,!0)+'">'+(r?e:n(e,!0))+"\n</code></pre>\n":"<pre><code>"+(r?e:n(e,!0))+"\n</code></pre>"},l.prototype.blockquote=function(e){return"<blockquote>\n"+e+"</blockquote>\n"},l.prototype.html=function(e){return e},l.prototype.heading=function(e,t,n){var r=i(n),s=this._headings.filter(function(e){return e===n}).length;return s>0&&(r+="-"+s),this._headings.push(n),"<h"+t+' id="'+this.options.headerPrefix+r+'">'+e+"</h"+t+">\n"},l.prototype.hr=function(){return this.options.xhtml?"<hr/>\n":"<hr>\n"},l.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(n?' class="task-list"':"")+">\n"+e+"</"+r+">\n"},l.prototype.listitem=function(e,t){return void 0===t?"<li>"+e+"</li>\n":'<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox"'+(t?" checked":"")+"> "+e+"</li>\n"},l.prototype.paragraph=function(e){return"<p>"+e+"</p>\n"},l.prototype.table=function(e,t){return"<table>\n<thead>\n"+e+"</thead>\n<tbody>\n"+t+"</tbody>\n</table>\n"},l.prototype.tablerow=function(e){return"<tr>\n"+e+"</tr>\n"},l.prototype.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' style="text-align:'+t.align+'">':"<"+n+">")+e+"</"+n+">\n"},l.prototype.strong=function(e){return"<strong>"+e+"</strong>"},l.prototype.em=function(e){return"<em>"+e+"</em>"},l.prototype.codespan=function(e){return"<code>"+e+"</code>"},l.prototype.br=function(){return this.options.xhtml?"<br/>":"<br>"},l.prototype.del=function(e){return"<del>"+e+"</del>"},l.prototype.link=function(e,t,n){if(this.options.sanitize){var s;try{s=decodeURIComponent(r(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(0===s.indexOf("javascript:")||0===s.indexOf("vbscript:")||0===s.indexOf("data:"))return""}var i='<a href="'+e+'"';return t&&(i+=' title="'+t+'"'),i+=">"+n+"</a>"},l.prototype.image=function(e,t,n){var r='<img src="'+e+'" alt="'+n+'"';return t&&(r+=' title="'+t+'"'),r+=this.options.xhtml?"/>":">"},l.prototype.text=function(e){return e};var a={gfm:!0,tables:!0,taskLists:!0,breaks:!1,pedantic:!1,sanitize:!1,sanitizer:null,mangle:!0,smartLists:!1,silent:!1,highlight:null,langPrefix:"lang-",smartypants:!1,headerPrefix:"",renderer:new l,xhtml:!1},p={escape:/^\\([\\`*{}[\]()#+\-.!_>])/,autolink:/^<([^ >]+(@|:\/)[^ >]+)>/,url:t,tag:/^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,link:/^!?\[(inside)\]\(href\)/,reflink:/^!?\[(inside)\]\s*\[([^\]]*)\]/,nolink:/^!?\[((?:\[[^\]]*\]|[^[\]])*)\]/,strong:/^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,em:/^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,code:/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,br:/^ {2,}\n(?!\s*$)/,del:t,text:/^[\s\S]+?(?=[\\<![_*`]| {2,}\n|$)/};p._inside=/(?:\[[^\]]*\]|[^[\]]|\](?=[^[]*\]))*/,p._href=/\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/,p.link=s(p.link)("inside",p._inside)("href",p._href)(),p.reflink=s(p.reflink)("inside",p._inside)(),p.normal=e({},p),p.pedantic=e({},p.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/}),p.gfm=e({},p.normal,{escape:s(p.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:s(p.text)("]|","~]|")("|","|https?://|")()}),p.breaks=e({},p.gfm,{br:s(p.br)("{2,}","*")(),text:s(p.gfm.text)("{2,}","*")()});var h=function(e,t){if(void 0===t&&(t=a),this.options=t,this.links=e,this.renderer=this.options.renderer||new l,this.renderer.options=this.options,!this.links)throw new Error("Tokens array requires a `links` property.");this.options.gfm?this.options.breaks?this.rules=p.breaks:this.rules=p.gfm:this.options.pedantic?this.rules=p.pedantic:this.rules=p.normal};h.output=function(e,t,n){return new h(t,n).output(e)},h.prototype.output=function(e){for(var t,r,s,i,o=this,l="";e;)if(i=o.rules.escape.exec(e))e=e.substring(i[0].length),l+=i[1];else if(i=o.rules.autolink.exec(e))e=e.substring(i[0].length),"@"===i[2]?(r=":"===i[1].charAt(6)?o.mangle(i[1].substring(7)):o.mangle(i[1]),s=o.mangle("mailto:")+r):(r=n(i[1]),s=r),l+=o.renderer.link(s,null,r);else if(o.inLink||!(i=o.rules.url.exec(e))){if(i=o.rules.tag.exec(e))!o.inLink&&/^<a /i.test(i[0])?o.inLink=!0:o.inLink&&/^<\/a>/i.test(i[0])&&(o.inLink=!1),e=e.substring(i[0].length),l+=o.options.sanitize?o.options.sanitizer?o.options.sanitizer(i[0]):n(i[0]):i[0];else if(i=o.rules.link.exec(e))e=e.substring(i[0].length),o.inLink=!0,l+=o.outputLink(i,{href:i[2],title:i[3]}),o.inLink=!1;else if((i=o.rules.reflink.exec(e))||(i=o.rules.nolink.exec(e))){if(e=e.substring(i[0].length),t=(i[2]||i[1]).replace(/\s+/g," "),!(t=o.links[t.toLowerCase()])||!t.href){l+=i[0].charAt(0),e=i[0].substring(1)+e;continue}o.inLink=!0,l+=o.outputLink(i,t),o.inLink=!1}else if(i=o.rules.strong.exec(e))e=e.substring(i[0].length),l+=o.renderer.strong(o.output(i[2]||i[1]));else if(i=o.rules.em.exec(e))e=e.substring(i[0].length),l+=o.renderer.em(o.output(i[2]||i[1]));else if(i=o.rules.code.exec(e))e=e.substring(i[0].length),l+=o.renderer.codespan(n(i[2],!0));else if(i=o.rules.br.exec(e))e=e.substring(i[0].length),l+=o.renderer.br();else if(i=o.rules.del.exec(e))e=e.substring(i[0].length),l+=o.renderer.del(o.output(i[1]));else if(i=o.rules.text.exec(e))e=e.substring(i[0].length),l+=o.renderer.text(n(o.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else e=e.substring(i[0].length),r=n(i[1]),s=r,l+=o.renderer.link(s,null,r);return l},h.prototype.outputLink=function(e,t){var r=n(t.href),s=t.title?n(t.title):null;return"!"===e[0].charAt(0)?this.renderer.image(r,s,n(e[1])):this.renderer.link(r,s,this.output(e[1]))},h.prototype.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014\/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014\/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},h.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=0;r<e.length;r++)t=e.charCodeAt(r),Math.random()>.5&&(t="x"+t.toString(16)),n+="&#"+t+";";return n},h.rules=p;var u=function(e){void 0===e&&(e=a),this.tokens=[],this.token=null,this.options=e,this.options.renderer=this.options.renderer||new l,this.renderer=this.options.renderer,this.renderer.options=this.options};u.parse=function(e,t,n){return new u(t,n).parse(e)},u.prototype.parse=function(e){var t=this;this.inline=new h(e.links,this.options,this.renderer),this.tokens=e.reverse();for(var n="";this.next();)n+=t.tok();return this.renderer._headings=[],n},u.prototype.next=function(){return this.token=this.tokens.pop(),this.token},u.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},u.prototype.parseText=function(){for(var e=this,t=this.token.text;"text"===this.peek().type;)t+="\n"+e.next().text;return this.inline.output(t)},u.prototype.tok=function(){var e=this;switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text);case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var t,n,r,s,i="",o="";for(r="",t=0;t<this.token.header.length;t++)r+=e.renderer.tablecell(e.inline.output(e.token.header[t]),{header:!0,align:e.token.align[t]});for(i+=this.renderer.tablerow(r),t=0;t<this.token.cells.length;t++){for(n=e.token.cells[t],r="",s=0;s<n.length;s++)r+=e.renderer.tablecell(e.inline.output(n[s]),{header:!1,align:e.token.align[s]});o+=e.renderer.tablerow(r)}return this.renderer.table(i,o);case"blockquote_start":for(var l="";"blockquote_end"!==this.next().type;)l+=e.tok();return this.renderer.blockquote(l);case"list_start":for(var a="",p=!1,h=this.token.ordered;"list_end"!==this.next().type;)void 0!==e.token.checked&&(p=!0),a+=e.tok();return this.renderer.list(a,h,p);case"list_item_start":for(var u="",c=this.token.checked;"list_item_end"!==this.next().type;)u+="text"===e.token.type?e.parseText():e.tok();return this.renderer.listitem(u,c);case"loose_item_start":for(var g="",d=this.token.checked;"list_item_end"!==this.next().type;)g+=e.tok();return this.renderer.listitem(g,d);case"html":var f=this.token.pre||this.options.pedantic?this.token.text:this.inline.output(this.token.text);return this.renderer.html(f);case"paragraph":return this.renderer.paragraph(this.inline.output(this.token.text));case"text":return this.renderer.paragraph(this.parseText());default:throw new Error("Unknow type")}};var c={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:t,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:t,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:t,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};c.bullet=/(?:[*+-]|\d+\.)/,c.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,c.item=s(c.item,"gm")(/bull/g,c.bullet)(),c.list=s(c.list)(/bull/g,c.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+c.def.source+")")(),c.blockquote=s(c.blockquote)("def",c.def)(),c._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",c.html=s(c.html)("comment",/<!--[\s\S]*?-->/)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g,c._tag)(),c.paragraph=s(c.paragraph)("hr",c.hr)("heading",c.heading)("lheading",c.lheading)("blockquote",c.blockquote)("tag","<"+c._tag)("def",c.def)(),c.normal=e({},c),c.gfm=e({},c.normal,{fences:/^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,paragraph:/^/,heading:/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/,checkbox:/^\[([ x])\] +/}),c.gfm.paragraph=s(c.paragraph)("(?!","(?!"+c.gfm.fences.source.replace("\\1","\\2")+"|"+c.list.source.replace("\\1","\\3")+"|")(),c.tables=e({},c.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/});var g=function(e){void 0===e&&(e=a),this.tokens=[],this.tokens.links={},this.options=e,this.options.gfm?this.options.table?this.rules=c.table:this.rules=c.gfm:this.rules=c.normal};return g.lex=function(e,t){return new g(t).lex(e)},g.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n"),this.token(e,!0)},g.prototype.token=function(e,t,n){var r=this;e=e.replace(/^ +$/gm,"");for(var s,i,o,l,a,p,h,u,c,g;e;)if((o=r.rules.newline.exec(e))&&(e=e.substring(o[0].length),o[0].length>1&&r.tokens.push({type:"space"})),o=r.rules.code.exec(e))e=e.substring(o[0].length),o=o[0].replace(/^ {4}/gm,""),r.tokens.push({type:"code",text:r.options.pedantic?o:o.replace(/\n+$/,"")});else if(o=r.rules.fences.exec(e))e=e.substring(o[0].length),r.tokens.push({type:"code",lang:o[2],text:o[3]||""});else if(o=r.rules.heading.exec(e))e=e.substring(o[0].length),r.tokens.push({type:"heading",depth:o[1].length,text:o[2]});else if(t&&(o=r.rules.nptable.exec(e))){for(e=e.substring(o[0].length),p={type:"table",header:o[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:o[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:o[3].replace(/\n$/,"").split("\n")},u=0;u<p.align.length;u++)/^ *-+: *$/.test(p.align[u])?p.align[u]="right":/^ *:-+: *$/.test(p.align[u])?p.align[u]="center":/^ *:-+ *$/.test(p.align[u])?p.align[u]="left":p.align[u]=null;for(u=0;u<p.cells.length;u++)p.cells[u]=p.cells[u].split(/ *\| */);r.tokens.push(p)}else if(o=r.rules.lheading.exec(e))e=e.substring(o[0].length),r.tokens.push({type:"heading",depth:"="===o[2]?1:2,text:o[1]});else if(o=r.rules.hr.exec(e))e=e.substring(o[0].length),r.tokens.push({type:"hr"});else if(o=r.rules.blockquote.exec(e))e=e.substring(o[0].length),r.tokens.push({type:"blockquote_start"}),o=o[0].replace(/^ *> ?/gm,""),r.token(o,t,!0),r.tokens.push({type:"blockquote_end"});else if(o=r.rules.list.exec(e)){for(e=e.substring(o[0].length),l=o[2],r.tokens.push({type:"list_start",ordered:l.length>1}),o=o[0].match(r.rules.item),s=!1,c=o.length,u=0;u<c;u++)p=o[u],h=p.length,p=p.replace(/^ *([*+-]|\d+\.) +/,""),r.options.gfm&&r.options.taskLists&&(g=r.rules.checkbox.exec(p),g?(g="x"===g[1],p=p.replace(r.rules.checkbox,"")):g=void 0),-1!==p.indexOf("\n ")&&(h-=p.length,p=r.options.pedantic?p.replace(/^ {1,4}/gm,""):p.replace(new RegExp("^ {1,"+h+"}","gm"),"")),r.options.smartLists&&u!==c-1&&(a=r.rules.bullet.exec(o[u+1])[0],l===a||l.length>1&&a.length>1||(e=o.slice(u+1).join("\n")+e,u=c-1)),i=s||/\n\n(?!\s*$)/.test(p),u!==c-1&&(s="\n"===p.charAt(p.length-1),i||(i=s)),r.tokens.push({checked:g,type:i?"loose_item_start":"list_item_start"}),r.token(p,!1,n),r.tokens.push({type:"list_item_end"});r.tokens.push({type:"list_end"})}else if(o=r.rules.html.exec(e))e=e.substring(o[0].length),r.tokens.push({type:r.options.sanitize?"paragraph":"html",pre:!r.options.sanitizer&&("pre"===o[1]||"script"===o[1]||"style"===o[1]),text:o[0]});else if(!n&&t&&(o=r.rules.def.exec(e)))e=e.substring(o[0].length),r.tokens.links[o[1].toLowerCase()]={href:o[2],title:o[3]};else if(t&&(o=r.rules.table.exec(e))){for(e=e.substring(o[0].length),p={type:"table",header:o[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:o[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:o[3].replace(/(?: *\| *)?\n$/,"").split("\n")},u=0;u<p.align.length;u++)/^ *-+: *$/.test(p.align[u])?p.align[u]="right":/^ *:-+: *$/.test(p.align[u])?p.align[u]="center":/^ *:-+ *$/.test(p.align[u])?p.align[u]="left":p.align[u]=null;for(u=0;u<p.cells.length;u++)p.cells[u]=p.cells[u].replace(/^ *\| *| *\| *$/g,"").split(/ *\| */);r.tokens.push(p)}else if(t&&(o=r.rules.paragraph.exec(e)))e=e.substring(o[0].length),r.tokens.push({type:"paragraph",text:"\n"===o[1].charAt(o[1].length-1)?o[1].slice(0,-1):o[1]});else if(o=r.rules.text.exec(e))e=e.substring(o[0].length),r.tokens.push({type:"text",text:o[0]});else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0));return this.tokens},g.rules=c,o.Renderer=l,o.Parser=u,o.Lexer=g,o.InlineLexer=h,o});
2//# sourceMappingURL=marked3.min.js.map