core/homeassistant/components/frontend/www_static/micromarkdown-js.html

11 lines
6.4 KiB
HTML
Raw Normal View History

<script type='text/javascript'>
2016-10-16 23:56:02 +00:00
/* * * * * * * * * * * *
* micromarkdown .js *
* Version 0.3.0 *
* License: MIT *
* Simon Waldherr *
* * * * * * * * * * * */
var micromarkdown={useajax:!1,regexobject:{headline:/^(\#{1,6})([^\#\n]+)$/m,code:/\s\`\`\`\n?([^`]+)\`\`\`/g,hr:/^(?:([\*\-_] ?)+)\1\1$/gm,lists:/^((\s*((\*|\-)|\d(\.|\))) [^\n]+)\n)+/gm,bolditalic:/(?:([\*_~]{1,3}))([^\*_~\n]+[^\*_~\s])\1/g,links:/!?\[([^\]<>]+)\]\(([^ \)<>]+)( "[^\(\)\"]+")?\)/g,reflinks:/\[([^\]]+)\]\[([^\]]+)\]/g,smlinks:/\@([a-z0-9]{3,})\@(t|gh|fb|gp|adn)/gi,mail:/<(([a-z0-9_\-\.])+\@([a-z0-9_\-\.])+\.([a-z]{2,7}))>/gim,tables:/\n(([^|\n]+ *\| *)+([^|\n]+\n))((:?\-+:?\|)+(:?\-+:?)*\n)((([^|\n]+ *\| *)+([^|\n]+)\n)+)/g,include:/[\[<]include (\S+) from (https?:\/\/[a-z0-9\.\-]+\.[a-z]{2,9}[a-z0-9\.\-\?\&\/]+)[\]>]/gi,url:/<([a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[\-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)?)>/g},parse:function(a,b){"use strict";var c,d,e,f,g,h,i,j,k,l,m,n=0,o=[],p=0,q=0,r=0;for(a="\n"+a+"\n",b!==!0&&(micromarkdown.regexobject.lists=/^((\s*(\*|\d\.) [^\n]+)\n)+/gm);null!==(m=micromarkdown.regexobject.code.exec(a));)a=a.replace(m[0],"<code>\n"+micromarkdown.htmlEncode(m[1]).replace(/\n/gm,"<br/>").replace(/\ /gm,"&nbsp;")+"</code>\n");for(;null!==(m=micromarkdown.regexobject.headline.exec(a));)k=m[1].length,a=a.replace(m[0],"<h"+k+">"+m[2]+"</h"+k+">\n");for(;null!==(m=micromarkdown.regexobject.lists.exec(a));){for(p=0,l="*"===m[0].trim().substr(0,1)||"-"===m[0].trim().substr(0,1)?"<ul>":"<ol>",h=m[0].split("\n"),i=[],d=0,g=!1,q=0;q<h.length;q++)if(null!==(c=/^((\s*)((\*|\-)|\d(\.|\))) ([^\n]+))/.exec(h[q]))){for(void 0===c[2]||0===c[2].length?n=0:(g===!1&&(g=c[2].replace(/\t/," ").length),n=Math.round(c[2].replace(/\t/," ").length/g));d>n;)l+=i.pop(),d--,p--;for(;n>d;)"*"===c[0].trim().substr(0,1)||"-"===c[0].trim().substr(0,1)?(l+="<ul>",i.push("</ul>")):(l+="<ol>",i.push("</ol>")),d++,p++;l+="<li>"+c[6]+"</li>\n"}for(;p>0;)l+="</ul>",p--;l+="*"===m[0].trim().substr(0,1)||"-"===m[0].trim().substr(0,1)?"</ul>":"</ol>",a=a.replace(m[0],l+"\n")}for(;null!==(m=micromarkdown.regexobject.tables.exec(a));){for(l="<table><tr>",h=m[1].split("|"),f=m[4].split("|"),q=0;q<h.length;q++)f.length<=q?f.push(0):f[q]=":"===f[q].trimRight().slice(-1)&&b!==!0?":"===f[q][0]?3:2:b!==!0?":"===f[q][0]?1:0:0;for(e=["<th>",'<th align="left">','<th align="right">','<th align="center">'],q=0;q<h.length;q++)l+=e[f[q]]+h[q].trim()+"</th>";for(l+="</tr>",e=["<td>",'<td align="left">','<td align="right">','<td align="center">'],i=m[7].split("\n"),q=0;q<i.length;q++)if(j=i[q].split("|"),0!==j[0].length){for(;f.length<j.length;)f.push(0);for(l+="<tr>",r=0;r<j.length;r++)l+=e[f[r]]+j[r].trim()+"</td>";l+="</tr>\n"}l+="</table>",a=a.replace(m[0],l)}for(q=0;3>q;q++)for(;null!==(m=micromarkdown.regexobject.bolditalic.exec(a));)if(l=[],"~~"===m[1])a=a.replace(m[0],"<del>"+m[2]+"</del>");else{switch(m[1].length){case 1:l=["<i>","</i>"];break;case 2:l=["<b>","</b>"];break;case 3:l=["<i><b>","</b></i>"]}a=a.replace(m[0],l[0]+m[2]+l[1])}for(;null!==(m=micromarkdown.regexobject.links.exec(a));)a="!"===m[0].substr(0,1)?a.replace(m[0],'<img src="'+m[2]+'" alt="'+m[1]+'" title="'+m[1]+'" />\n'):a.replace(m[0],"<a "+micromarkdown.mmdCSSclass(m[2],b)+'href="'+m[2]+'">'+m[1]+"</a>\n");for(;null!==(m=micromarkdown.regexobject.mail.exec(a));)a=a.replace(m[0],'<a href="mailto:'+m[1]+'">'+m[1]+"</a>");for(;null!==(m=micromarkdown.regexobject.url.exec(a));)l=m[1],-1===l.indexOf("://")&&(l="http://"+l),a=a.replace(m[0],"<a "+micromarkdown.mmdCSSclass(l,b)+'href="'+l+'">'+l.replace(/(https:\/\/|http:\/\/|mailto:|ftp:\/\/)/gim,"")+"</a>");for(;null!==(m=micromarkdown.regexobject.reflinks.exec(a));)i=new RegExp("\\["+m[2]+"\\]: ?([^ \n]+)","gi"),null!==(h=i.exec(a))&&(a=a.replace(m[0],"<a "+micromarkdown.mmdCSSclass(h[1],b)+'href="'+h[1]+'">'+m[1]+"</a>"),o.push(h[0]));for(q=0;q<o.length;q++)a=a.replace(o[q],"");for(;null!==(m=micromarkdown.regexobject.smlinks.exec(a));){switch(m[2]){case"t":l="https://twitter.com/"+m[1];break;case"gh":l="https://github.com/"+m[1];break;case"fb":l="https://www.facebook.com/"+m[1];break;case"gp":l="https://plus.google.com/+"+m[1];break;case"adn":l="https://alpha.app.net/"+m[1]}a=a.replace(m[0],"<a "+m
2016-10-19 00:59:14 +00:00
</script>