0
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet-module.git synced 2024-07-01 06:15:04 +03:00
salet-module/test/lib/marked.min.js

1 line
16 KiB
JavaScript

(function(){var d={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:l,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:l,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:l,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};d.bullet=/(?:[*+-]|\d+\.)/;d.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;d.item=c(d.item,"gm")(/bull/g,d.bullet)();d.list=c(d.list)(/bull/g,d.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+d.def.source+")")();d.blockquote=c(d.blockquote)("def",d.def)();d._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";d.html=c(d.html)("comment",/<!--[\s\S]*?-->/)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)(/tag/g,d._tag)();d.paragraph=c(d.paragraph)("hr",d.hr)("heading",d.heading)("lheading",d.lheading)("blockquote",d.blockquote)("tag","<"+d._tag)("def",d.def)();d.normal=i({},d);d.gfm=i({},d.normal,{fences:/^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,paragraph:/^/,heading:/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/});d.gfm.paragraph=c(d.paragraph)("(?!","(?!"+d.gfm.fences.source.replace("\\1","\\2")+"|"+d.list.source.replace("\\1","\\3")+"|")();d.tables=i({},d.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/});function b(m){this.tokens=[];this.tokens.links={};this.options=m||a.defaults;this.rules=d.normal;if(this.options.gfm){if(this.options.tables){this.rules=d.tables}else{this.rules=d.gfm}}}b.rules=d;b.lex=function(o,m){var n=new b(m);return n.lex(o)};b.prototype.lex=function(m){m=m.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n");return this.token(m,true)};b.prototype.token=function(n,t,x){var n=n.replace(/^ +$/gm,""),r,p,v,s,u,w,m,q,o;while(n){if(v=this.rules.newline.exec(n)){n=n.substring(v[0].length);if(v[0].length>1){this.tokens.push({type:"space"})}}if(v=this.rules.code.exec(n)){n=n.substring(v[0].length);v=v[0].replace(/^ {4}/gm,"");this.tokens.push({type:"code",text:!this.options.pedantic?v.replace(/\n+$/,""):v});continue}if(v=this.rules.fences.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:"code",lang:v[2],text:v[3]||""});continue}if(v=this.rules.heading.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:"heading",depth:v[1].length,text:v[2]});continue}if(t&&(v=this.rules.nptable.exec(n))){n=n.substring(v[0].length);w={type:"table",header:v[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:v[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:v[3].replace(/\n$/,"").split("\n")};for(q=0;q<w.align.length;q++){if(/^ *-+: *$/.test(w.align[q])){w.align[q]="right"}else{if(/^ *:-+: *$/.test(w.align[q])){w.align[q]="center"}else{if(/^ *:-+ *$/.test(w.align[q])){w.align[q]="left"}else{w.align[q]=null}}}}for(q=0;q<w.cells.length;q++){w.cells[q]=w.cells[q].split(/ *\| */)}this.tokens.push(w);continue}if(v=this.rules.lheading.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:"heading",depth:v[2]==="="?1:2,text:v[1]});continue}if(v=this.rules.hr.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:"hr"});continue}if(v=this.rules.blockquote.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:"blockquote_start"});v=v[0].replace(/^ *> ?/gm,"");this.token(v,t,true);this.tokens.push({type:"blockquote_end"});continue}if(v=this.rules.list.exec(n)){n=n.substring(v[0].length);s=v[2];this.tokens.push({type:"list_start",ordered:s.length>1});v=v[0].match(this.rules.item);r=false;o=v.length;q=0;for(;q<o;q++){w=v[q];m=w.length;w=w.replace(/^ *([*+-]|\d+\.) +/,"");if(~w.indexOf("\n ")){m-=w.length;w=!this.options.pedantic?w.replace(new RegExp("^ {1,"+m+"}","gm"),""):w.replace(/^ {1,4}/gm,"")}if(this.options.smartLists&&q!==o-1){u=d.bullet.exec(v[q+1])[0];if(s!==u&&!(s.length>1&&u.length>1)){n=v.slice(q+1).join("\n")+n;q=o-1}}p=r||/\n\n(?!\s*$)/.test(w);if(q!==o-1){r=w.charAt(w.length-1)==="\n";if(!p){p=r}}this.tokens.push({type:p?"loose_item_start":"list_item_start"});this.token(w,false,x);this.tokens.push({type:"list_item_end"})}this.tokens.push({type:"list_end"});continue}if(v=this.rules.html.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:this.options.sanitize?"paragraph":"html",pre:!this.options.sanitizer&&(v[1]==="pre"||v[1]==="script"||v[1]==="style"),text:v[0]});continue}if((!x&&t)&&(v=this.rules.def.exec(n))){n=n.substring(v[0].length);this.tokens.links[v[1].toLowerCase()]={href:v[2],title:v[3]};continue}if(t&&(v=this.rules.table.exec(n))){n=n.substring(v[0].length);w={type:"table",header:v[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:v[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:v[3].replace(/(?: *\| *)?\n$/,"").split("\n")};for(q=0;q<w.align.length;q++){if(/^ *-+: *$/.test(w.align[q])){w.align[q]="right"}else{if(/^ *:-+: *$/.test(w.align[q])){w.align[q]="center"}else{if(/^ *:-+ *$/.test(w.align[q])){w.align[q]="left"}else{w.align[q]=null}}}}for(q=0;q<w.cells.length;q++){w.cells[q]=w.cells[q].replace(/^ *\| *| *\| *$/g,"").split(/ *\| */)}this.tokens.push(w);continue}if(t&&(v=this.rules.paragraph.exec(n))){n=n.substring(v[0].length);this.tokens.push({type:"paragraph",text:v[1].charAt(v[1].length-1)==="\n"?v[1].slice(0,-1):v[1]});continue}if(v=this.rules.text.exec(n)){n=n.substring(v[0].length);this.tokens.push({type:"text",text:v[0]});continue}if(n){throw new Error("Infinite loop on byte: "+n.charCodeAt(0))}}return this.tokens};var h={escape:/^\\([\\`*{}\[\]()#+\-.!_>])/,autolink:/^<([^ >]+(@|:\/)[^ >]+)>/,url:l,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:l,text:/^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/};h._inside=/(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;h._href=/\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;h.link=c(h.link)("inside",h._inside)("href",h._href)();h.reflink=c(h.reflink)("inside",h._inside)();h.normal=i({},h);h.pedantic=i({},h.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/});h.gfm=i({},h.normal,{escape:c(h.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:c(h.text)("]|","~]|")("|","|https?://|")()});h.breaks=i({},h.gfm,{br:c(h.br)("{2,}","*")(),text:c(h.gfm.text)("{2,}","*")()});function j(m,n){this.options=n||a.defaults;this.links=m;this.rules=h.normal;this.renderer=this.options.renderer||new f;this.renderer.options=this.options;if(!this.links){throw new Error("Tokens array requires a `links` property.")}if(this.options.gfm){if(this.options.breaks){this.rules=h.breaks}else{this.rules=h.gfm}}else{if(this.options.pedantic){this.rules=h.pedantic}}}j.rules=h;j.output=function(p,m,n){var o=new j(m,n);return o.output(p)};j.prototype.output=function(r){var n="",p,q,m,o;while(r){if(o=this.rules.escape.exec(r)){r=r.substring(o[0].length);n+=o[1];continue}if(o=this.rules.autolink.exec(r)){r=r.substring(o[0].length);if(o[2]==="@"){q=o[1].charAt(6)===":"?this.mangle(o[1].substring(7)):this.mangle(o[1]);m=this.mangle("mailto:")+q}else{q=k(o[1]);m=q}n+=this.renderer.link(m,null,q);continue}if(!this.inLink&&(o=this.rules.url.exec(r))){r=r.substring(o[0].length);q=k(o[1]);m=q;n+=this.renderer.link(m,null,q);continue}if(o=this.rules.tag.exec(r)){if(!this.inLink&&/^<a /i.test(o[0])){this.inLink=true}else{if(this.inLink&&/^<\/a>/i.test(o[0])){this.inLink=false}}r=r.substring(o[0].length);n+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(o[0]):k(o[0]):o[0];continue}if(o=this.rules.link.exec(r)){r=r.substring(o[0].length);this.inLink=true;n+=this.outputLink(o,{href:o[2],title:o[3]});this.inLink=false;continue}if((o=this.rules.reflink.exec(r))||(o=this.rules.nolink.exec(r))){r=r.substring(o[0].length);p=(o[2]||o[1]).replace(/\s+/g," ");p=this.links[p.toLowerCase()];if(!p||!p.href){n+=o[0].charAt(0);r=o[0].substring(1)+r;continue}this.inLink=true;n+=this.outputLink(o,p);this.inLink=false;continue}if(o=this.rules.strong.exec(r)){r=r.substring(o[0].length);n+=this.renderer.strong(this.output(o[2]||o[1]));continue}if(o=this.rules.em.exec(r)){r=r.substring(o[0].length);n+=this.renderer.em(this.output(o[2]||o[1]));continue}if(o=this.rules.code.exec(r)){r=r.substring(o[0].length);n+=this.renderer.codespan(k(o[2],true));continue}if(o=this.rules.br.exec(r)){r=r.substring(o[0].length);n+=this.renderer.br();continue}if(o=this.rules.del.exec(r)){r=r.substring(o[0].length);n+=this.renderer.del(this.output(o[1]));continue}if(o=this.rules.text.exec(r)){r=r.substring(o[0].length);n+=this.renderer.text(k(this.smartypants(o[0])));continue}if(r){throw new Error("Infinite loop on byte: "+r.charCodeAt(0))}}return n};j.prototype.outputLink=function(n,o){var m=k(o.href),p=o.title?k(o.title):null;return n[0].charAt(0)!=="!"?this.renderer.link(m,p,this.output(n[1])):this.renderer.image(m,p,k(n[1]))};j.prototype.smartypants=function(m){if(!this.options.smartypants){return m}return m.replace(/---/g,"\u2014").replace(/--/g,"\u2013").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1\u2018").replace(/'/g,"\u2019").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1\u201c").replace(/"/g,"\u201d").replace(/\.{3}/g,"\u2026")};j.prototype.mangle=function(q){if(!this.options.mangle){return q}var n="",m=q.length,o=0,p;for(;o<m;o++){p=q.charCodeAt(o);if(Math.random()>0.5){p="x"+p.toString(16)}n+="&#"+p+";"}return n};function f(m){this.options=m||{}}f.prototype.code=function(n,p,o){if(this.options.highlight){var m=this.options.highlight(n,p);if(m!=null&&m!==n){o=true;n=m}}if(!p){return"<pre><code>"+(o?n:k(n,true))+"\n</code></pre>"}return'<pre><code class="'+this.options.langPrefix+k(p,true)+'">'+(o?n:k(n,true))+"\n</code></pre>\n"};f.prototype.blockquote=function(m){return"<blockquote>\n"+m+"</blockquote>\n"};f.prototype.html=function(m){return m};f.prototype.heading=function(n,o,m){return"<h"+o+' id="'+this.options.headerPrefix+m.toLowerCase().replace(/[^\w]+/g,"-")+'">'+n+"</h"+o+">\n"};f.prototype.hr=function(){return this.options.xhtml?"<hr/>\n":"<hr>\n"};f.prototype.list=function(m,n){var o=n?"ol":"ul";return"<"+o+">\n"+m+"</"+o+">\n"};f.prototype.listitem=function(m){return"<li>"+m+"</li>\n"};f.prototype.paragraph=function(m){return"<p>"+m+"</p>\n"};f.prototype.table=function(n,m){return"<table>\n<thead>\n"+n+"</thead>\n<tbody>\n"+m+"</tbody>\n</table>\n"};f.prototype.tablerow=function(m){return"<tr>\n"+m+"</tr>\n"};f.prototype.tablecell=function(p,n){var o=n.header?"th":"td";var m=n.align?"<"+o+' style="text-align:'+n.align+'">':"<"+o+">";return m+p+"</"+o+">\n"};f.prototype.strong=function(m){return"<strong>"+m+"</strong>"};f.prototype.em=function(m){return"<em>"+m+"</em>"};f.prototype.codespan=function(m){return"<code>"+m+"</code>"};f.prototype.br=function(){return this.options.xhtml?"<br/>":"<br>"};f.prototype.del=function(m){return"<del>"+m+"</del>"};f.prototype.link=function(m,r,q){if(this.options.sanitize){try{var o=decodeURIComponent(g(m)).replace(/[^\w:]/g,"").toLowerCase()}catch(p){return""}if(o.indexOf("javascript:")===0||o.indexOf("vbscript:")===0){return""}}var n='<a href="'+m+'"';if(r){n+=' title="'+r+'"'}n+=">"+q+"</a>";return n};f.prototype.image=function(m,p,o){var n='<img src="'+m+'" alt="'+o+'"';if(p){n+=' title="'+p+'"'}n+=this.options.xhtml?"/>":">";return n};f.prototype.text=function(m){return m};function e(m){this.tokens=[];this.token=null;this.options=m||a.defaults;this.options.renderer=this.options.renderer||new f;this.renderer=this.options.renderer;this.renderer.options=this.options}e.parse=function(o,m,n){var p=new e(m,n);return p.parse(o)};e.prototype.parse=function(n){this.inline=new j(n.links,this.options,this.renderer);this.tokens=n.reverse();var m="";while(this.next()){m+=this.tok()}return m};e.prototype.next=function(){return this.token=this.tokens.pop()};e.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0};e.prototype.parseText=function(){var m=this.token.text;while(this.peek().type==="text"){m+="\n"+this.next().text}return this.inline.output(m)};e.prototype.tok=function(){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 q="",s="",o,u,t,m,n;t="";for(o=0;o<this.token.header.length;o++){m={header:true,align:this.token.align[o]};t+=this.renderer.tablecell(this.inline.output(this.token.header[o]),{header:true,align:this.token.align[o]})}q+=this.renderer.tablerow(t);for(o=0;o<this.token.cells.length;o++){u=this.token.cells[o];t="";for(n=0;n<u.length;n++){t+=this.renderer.tablecell(this.inline.output(u[n]),{header:false,align:this.token.align[n]})}s+=this.renderer.tablerow(t)}return this.renderer.table(q,s);case"blockquote_start":var s="";while(this.next().type!=="blockquote_end"){s+=this.tok()}return this.renderer.blockquote(s);case"list_start":var s="",r=this.token.ordered;while(this.next().type!=="list_end"){s+=this.tok()}return this.renderer.list(s,r);case"list_item_start":var s="";while(this.next().type!=="list_item_end"){s+=this.token.type==="text"?this.parseText():this.tok()}return this.renderer.listitem(s);case"loose_item_start":var s="";while(this.next().type!=="list_item_end"){s+=this.tok()}return this.renderer.listitem(s);case"html":var p=!this.token.pre&&!this.options.pedantic?this.inline.output(this.token.text):this.token.text;return this.renderer.html(p);case"paragraph":return this.renderer.paragraph(this.inline.output(this.token.text));case"text":return this.renderer.paragraph(this.parseText())}};function k(m,n){return m.replace(!n?/&(?!#?\w+;)/g:/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function g(m){return m.replace(/&([#\w]+);/g,function(o,p){p=p.toLowerCase();if(p==="colon"){return":"}if(p.charAt(0)==="#"){return p.charAt(1)==="x"?String.fromCharCode(parseInt(p.substring(2),16)):String.fromCharCode(+p.substring(1))}return""})}function c(o,n){o=o.source;n=n||"";return function m(p,q){if(!p){return new RegExp(o,n)}q=q.source||q;q=q.replace(/(^|[^\[])\^/g,"$1");o=o.replace(p,q);return m}}function l(){}l.exec=l;function i(p){var n=1,o,m;for(;n<arguments.length;n++){o=arguments[n];for(m in o){if(Object.prototype.hasOwnProperty.call(o,m)){p[m]=o[m]}}}return p}function a(m,o,u){if(u||typeof o==="function"){if(!u){u=o;o=null}o=i({},a.defaults,o||{});var p=o.highlight,t,n,r=0;try{t=b.lex(m,o)}catch(s){return u(s)}n=t.length;var q=function(w){if(w){o.highlight=p;return u(w)}var v;try{v=e.parse(t,o)}catch(x){w=x}o.highlight=p;return w?u(w):u(null,v)};if(!p||p.length<3){return q()}delete o.highlight;if(!n){return q()}for(;r<t.length;r++){(function(v){if(v.type!=="code"){return --n||q()}return p(v.text,v.lang,function(x,w){if(x){return q(x)}if(w==null||w===v.text){return --n||q()}v.text=w;v.escaped=true;--n||q()})})(t[r])}return}try{if(o){o=i({},a.defaults,o)}return e.parse(b.lex(m,o),o)}catch(s){s.message+="\nPlease report this to https://github.com/chjj/marked.";if((o||a.defaults).silent){return"<p>An error occured:</p><pre>"+k(s.message+"",true)+"</pre>"}throw s}}a.options=a.setOptions=function(m){i(a.defaults,m);return a};a.defaults={gfm:true,tables:true,breaks:false,pedantic:false,sanitize:false,sanitizer:null,mangle:true,smartLists:false,silent:false,highlight:null,langPrefix:"lang-",smartypants:false,headerPrefix:"",renderer:new f,xhtml:false};a.Parser=e;a.parser=e.parse;a.Renderer=f;a.Lexer=b;a.lexer=b.lex;a.InlineLexer=j;a.inlineLexer=j.output;a.parse=a;if(typeof module!=="undefined"&&typeof exports==="object"){module.exports=a}else{if(typeof define==="function"&&define.amd){define(function(){return a})}else{this.marked=a}}}).call(function(){return this||(typeof window!=="undefined"?window:global)}());