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

11 lines
6.4 KiB
HTML

<script type='text/javascript'>
/* * * * * * * * * * * *
* 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 "+micromarkdown.mmdCSSclass(l,b)+'href="'+l+'">'+m[1]+"</a>")}for(;null!==(m=micromarkdown.regexobject.hr.exec(a));)a=a.replace(m[0],"\n<hr/>\n");if(micromarkdown.useajax!==!1&&b!==!0)for(;null!==(m=micromarkdown.regexobject.include.exec(a));)if(h=m[2].replace(/[\.\:\/]+/gm,""),i="",document.getElementById(h)?i=document.getElementById(h).innerHTML.trim():micromarkdown.ajax(m[2]),"csv"===m[1]&&""!==i){for(j={";":[]," ":[],",":[],"|":[]},j[0]=[";"," ",",","|"],i=i.split("\n"),r=0;r<j[0].length;r++)for(q=0;q<i.length;q++)q>0&&j[j[0][r]]!==!1&&(j[j[0][r]][q]!==j[j[0][r]][q-1]||1===j[j[0][r]][q])&&(j[j[0][r]]=!1);if(j[";"]!==!1||j[" "]!==!1||j[","]!==!1||j["|"]!==!1){for(j[";"]!==!1?j=";":j[" "]?j=" ":j[","]?j=",":j["|"]&&(j="|"),l="<table>",q=0;q<i.length;q++){for(h=i[q].split(j),l+="<tr>",r=0;r<h.length;r++)l+="<td>"+micromarkdown.htmlEncode(h[r])+"</td>";l+="</tr>"}l+="</table>",a=a.replace(m[0],l)}else a=a.replace(m[0],"<code>"+i.join("\n")+"</code>")}else a=a.replace(m[0],"");return a=a.replace(/ {2,}[\n]{1,}/gim,"<br/><br/>")},ajax:function(a){"use strict";var b;if(document.getElementById(a.replace(/[\.\:\/]+/gm,"")))return!1;if(window.ActiveXObject)try{b=new ActiveXObject("Microsoft.XMLHTTP")}catch(c){return b=null,c}else b=new XMLHttpRequest;b.onreadystatechange=function(){if(4===b.readyState){var c=document.createElement("code");c.innerHTML=b.responseText,c.id=a.replace(/[\.\:\/]+/gm,""),c.style.display="none",document.getElementsByTagName("body")[0].appendChild(c),micromarkdown.useajax()}},b.open("GET",a,!0),b.setRequestHeader("Content-type","application/x-www-form-urlencoded"),b.send()},countingChars:function(a,b){"use strict";return a=a.split(b),"object"==typeof a?a.length-1:0},htmlEncode:function(a){"use strict";var b=document.createElement("div");return b.appendChild(document.createTextNode(a)),a=b.innerHTML,b=void 0,a},mmdCSSclass:function(a,b){"use strict";var c;return-1!==a.indexOf("/")&&b!==!0?(c=a.split("/"),c=0===c[1].length?c[2].split("."):c[0].split("."),'class="mmd_'+c[c.length-2].replace(/[^\w\d]/g,"")+c[c.length-1]+'" '):""}};!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.returnExports=b()}(this,function(){"use strict";return micromarkdown});
</script>