shadowproject/shadow

View on GitHub
src/qt/res/assets/plugins/markdown/markdown.min.js

Summary

Maintainability
A
0 mins
Test Coverage
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(e,t){"use strict";var r,n,l,o,c,a,i,s,m,d,g,u=0,p=[],h=0,f=0,b=0;for(e="\n"+e+"\n",t!==!0&&(micromarkdown.regexobject.lists=/^((\s*(\*|\d\.) [^\n]+)\n)+/gm);null!==(g=micromarkdown.regexobject.code.exec(e));)e=e.replace(g[0],"<code>\n"+g[1].replace(/\n/gm,"<br/>")+"</code>\n");for(;null!==(g=micromarkdown.regexobject.headline.exec(e));)m=g[1].length,e=e.replace(g[0],"<h"+m+">"+g[2]+"</h"+m+">\n");for(;null!==(g=micromarkdown.regexobject.lists.exec(e));){for(h=0,d="*"===g[0].trim().substr(0,1)||"-"===g[0].trim().substr(0,1)?"<ul>":"<ol>",a=g[0].split("\n"),i=[],n=0,c=!1,f=0;f<a.length;f++)if(null!==(r=/^((\s*)((\*|\-)|\d(\.|\))) ([^\n]+))/.exec(a[f]))){for(void 0===r[2]||0===r[2].length?u=0:(c===!1&&(c=r[2].replace(/\t/,"    ").length),u=Math.round(r[2].replace(/\t/,"    ").length/c));n>u;)d+=i.pop(),n--,h--;for(;n<u;)"*"===r[0].trim().substr(0,1)||"-"===r[0].trim().substr(0,1)?(d+="<ul>",i.push("</ul>")):(d+="<ol>",i.push("</ol>")),n++,h++;d+="<li>"+r[6]+"</li>\n"}for(;h>0;)d+="</ul>",h--;d+="*"===g[0].trim().substr(0,1)||"-"===g[0].trim().substr(0,1)?"</ul>":"</ol>",e=e.replace(g[0],d+"\n")}for(;null!==(g=micromarkdown.regexobject.tables.exec(e));){for(d="<table><tr>",a=g[1].split("|"),o=g[4].split("|"),f=0;f<a.length;f++)o.length<=f?o.push(0):":"===o[f].trimRight().slice(-1)&&t!==!0?":"===o[f][0]?o[f]=3:o[f]=2:t!==!0&&":"===o[f][0]?o[f]=1:o[f]=0;for(l=["<th>",'<th align="left">','<th align="right">','<th align="center">'],f=0;f<a.length;f++)d+=l[o[f]]+a[f].trim()+"</th>";for(d+="</tr>",l=["<td>",'<td align="left">','<td align="right">','<td align="center">'],i=g[7].split("\n"),f=0;f<i.length;f++)if(s=i[f].split("|"),0!==s[0].length){for(;o.length<s.length;)o.push(0);for(d+="<tr>",b=0;b<s.length;b++)d+=l[o[b]]+s[b].trim()+"</td>";d+="</tr>\n"}d+="</table>",e=e.replace(g[0],d)}for(f=0;f<3;f++)for(;null!==(g=micromarkdown.regexobject.bolditalic.exec(e));)if(d=[],"~~"===g[1])e=e.replace(g[0],"<del>"+g[2]+"</del>");else if("__"===g[1])e=e.replace(g[0],"<u>"+g[2]+"</u>");else{switch(g[1].length){case 1:d=["<i>","</i>"];break;case 2:d=["<b>","</b>"];break;case 3:d=["<i><b>","</b></i>"]}e=e.replace(g[0],d[0]+g[2]+d[1])}for(;null!==(g=micromarkdown.regexobject.links.exec(e));)e="!"===g[0].substr(0,1)?e.replace(g[0],'<img src="qrc:///assets/img/sdc_leak_image.jpg" onclick="confirmConversationShowImage(this)" data-src="'+g[2]+'" alt="'+g[1]+'" title="'+g[1]+'" />\n'):e.replace(g[0],"<a "+micromarkdown.mmdCSSclass(g[2],t)+'onclick="return confirmConversationOpenLink()" target="_blank" href="'+g[2]+'">'+g[1]+"</a>\n");for(;null!==(g=micromarkdown.regexobject.mail.exec(e));)e=e.replace(g[0],'<a href="mailto:'+g[1]+'">'+g[1]+"</a>");for(;null!==(g=micromarkdown.regexobject.url.exec(e));)d=g[1],d.indexOf("://")===-1&&(d="http://"+d),e=e.replace(g[0],"<a "+micromarkdown.mmdCSSclass(d,t)+'href="'+d+'">'+d.replace(/(https:\/\/|http:\/\/|mailto:|ftp:\/\/)/gim,"")+"</a>");for(;null!==(g=micromarkdown.regexobject.reflinks.exec(e));)i=new RegExp("\\["+g[2]+"\\]: ?([^ \n]+)","gi"),null!==(a=i.exec(e))&&(e=e.replace(g[0],"<a "+micromarkdown.mmdCSSclass(a[1],t)+'href="'+a[1]+'">'+g[1]+"</a>"),p.push(a[0]));for(f=0;f<p.length;f++)e=e.replace(p[f],"");for(;null!==(g=micromarkdown.regexobject.smlinks.exec(e));){switch(g[2]){case"t":d="https://twitter.com/"+g[1];break;case"gh":d="https://github.com/"+g[1];break;case"fb":d="https://www.facebook.com/"+g[1];break;case"gp":d="https://plus.google.com/+"+g[1];break;case"adn":d="https://alpha.app.net/"+g[1]}e=e.replace(g[0],"<a "+micromarkdown.mmdCSSclass(d,t)+'href="'+d+'">'+g[1]+"</a>")}for(;null!==(g=micromarkdown.regexobject.hr.exec(e));)e=e.replace(g[0],"\n<hr/>\n");if(micromarkdown.useajax!==!1&&t!==!0)for(;null!==(g=micromarkdown.regexobject.include.exec(e));)if(a=g[2].replace(/[\.\:\/]+/gm,""),i="",document.getElementById(a)?i=document.getElementById(a).innerHTML.trim():micromarkdown.ajax(g[2]),"csv"===g[1]&&""!==i){for(s={";":[],"\t":[],",":[],"|":[]},s[0]=[";","\t",",","|"],i=i.split("\n"),b=0;b<s[0].length;b++)for(f=0;f<i.length;f++)f>0&&s[s[0][b]]!==!1&&(s[s[0][b]][f]===s[s[0][b]][f-1]&&1!==s[s[0][b]][f]||(s[s[0][b]]=!1));if(s[";"]!==!1||s["\t"]!==!1||s[","]!==!1||s["|"]!==!1){for(s[";"]!==!1?s=";":s["\t"]?s="\t":s[","]?s=",":s["|"]&&(s="|"),d="<table>",f=0;f<i.length;f++){for(a=i[f].split(s),d+="<tr>",b=0;b<a.length;b++)d+="<td>"+micromarkdown.htmlEncode(a[b])+"</td>";d+="</tr>"}d+="</table>",e=e.replace(g[0],d)}else e=e.replace(g[0],"<code>"+i.join("\n")+"</code>")}else e=e.replace(g[0],"");return e},ajax:function(e){"use strict";var t;if(document.getElementById(e.replace(/[\.\:\/]+/gm,"")))return!1;if(window.ActiveXObject)try{t=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){return t=null,e}else t=new XMLHttpRequest;t.onreadystatechange=function(){if(4===t.readyState){var r=document.createElement("code");r.innerHTML=t.responseText,r.id=e.replace(/[\.\:\/]+/gm,""),r.style.display="none",document.getElementsByTagName("body")[0].appendChild(r),micromarkdown.useajax()}},t.open("GET",e,!0),t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),t.send()},countingChars:function(e,t){"use strict";return e=e.split(t),"object"==typeof e?e.length-1:0},htmlEncode:function(e){"use strict";var t=document.createElement("div");return t.appendChild(document.createTextNode(e)),e=t.innerHTML,t=void 0,e},mmdCSSclass:function(e,t){"use strict";var r;return e.indexOf("/")!==-1&&t!==!0?(r=e.split("/"),r=0===r[1].length?r[2].split("."):r[0].split("."),'class="mmd_'+r[r.length-2].replace(/[^\w\d]/g,"")+r[r.length-1]+'" '):""}};!function(e,t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():e.returnExports=t()}(this,function(){"use strict";return micromarkdown});