-
Notifications
You must be signed in to change notification settings - Fork 2
/
stripdown.min.js
2 lines (2 loc) · 3.85 KB
/
stripdown.min.js
1
2
// stripdown.js v1.0.0 | github.com/chbk/stripdown.js
!function(){function e(a){a=l(String(a));for(var c,i,g,o="";a;)if(c=s.newline.exec(a))a=a.substring(c[0].length);else if(c=s.pre.exec(a))a=a.substring(c[0].length),c=c[0].replace(/^ {0,4}/gm,"").replace(/ *(\n *)*$/,""),i=r(c),o+="<pre>"+i+"</pre>";else if(c=s.blockquote.exec(a))a=a.substring(c[0].length),c=c[0].replace(/^ *>/gm,""),i=e(c),o+="<blockquote>"+i+"</blockquote>";else if(c=s.numlist.exec(a))a=a.substring(c[0].length),g=/^ *(\d+)\. /.exec(c[0])[1],o+="<ol"+(g>1?' start="'+g+'"':"")+">",o+=n(c[0],"numitem"),o+="</ol>";else if(c=s.abclist.exec(a))a=a.substring(c[0].length),g=/^ *([a-z])\. /.exec(c[0])[1].toLowerCase().charCodeAt(0)-96,o+='<ol type="a"'+(g>1?' start="'+g+'"':"")+">",o+=n(c[0],"abcitem"),o+="</ol>";else if(c=s.dashlist.exec(a))a=a.substring(c[0].length),o+="<ul>",o+=n(c[0],"dashitem"),o+="</ul>";else if(c=s.paragraph.exec(a))a=a.substring(c[0].length),c=c[0].replace(/^ */,"").replace(/ *(\n *)*$/,""),i=t(c),o+="<p>"+i+"</p>";else if(c=s.raw.exec(a))a=a.substring(c[0].length),c=c[0].replace(/^ */,"").replace(/ *(\n *)*$/,""),i=t(c),o+=i;else if(a)throw new Error("Infinite block loop on byte: "+a.charCodeAt(0));return o}function n(n,t){var r,l,a="";n=n.match(s[t]);for(var c=0;c<n.length;c++)r=n[c],r=r.replace(/^ {0,4}/gm,"").replace(/^ *(-|\d+\.|[a-z]\.) /,""),l=e(r),a+="<li>"+l+"</li>";return a}function t(e){for(var n,l,a,c,i="";e;)if(n=s.escape.exec(e))e=e.substring(n[0].length),i+=r(n[1]);else if(n=s.link.exec(e))e=e.substring(n[0].length),a=n[2]||"http://",a+=n[3].replace(/&/g,"&").replace(/"/g,"""),c=r(n[1].replace(/ {2,}/g," ")),i+='<a href="'+a+'">'+c+"</a>";else if(n=s.autolink.exec(e))e=e.substring(n[0].length),a=n[1].replace(/&/g,"&").replace(/"/g,"""),c=r(n[2]),i+='<a href="'+a+'">'+c+"</a>";else if(n=s.strong.exec(e))e=e.substring(n[0].length),l=t(n[1].replace(/[\n ]+$/,"")),i+="<strong>"+l+"</strong>";else if(n=s.em.exec(e))e=e.substring(n[0].length),l=t(n[1].replace(/[\n ]+$/,"")),i+="<em>"+l+"</em>";else if(n=s.code.exec(e))e=e.substring(n[0].length),l=r(n[1].replace(/\\([\\`])/g,"$1")),i+="<code>"+l+"</code>";else if(n=s.br.exec(e))e=e.substring(n[0].length),i+="<br/>";else if(n=s.text.exec(e))e=e.substring(n[0].length),l=r(n[0].replace(/ {2,}/g," ")),i+=l;else if(e)throw new Error("Infinite inline loop on byte: "+e.charCodeAt(0));return i}function r(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}function l(e){return e.replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u3000/g," ").replace(/\r/g,"\n").replace(/\f/g,"\n")}var s={newline:/^( *\n)+/,pre:/^(?: {4,}\S[^\n]*(?:\n(?! *\n)[^\n]*)*(?: *\n)*)+/,blockquote:/^(?: *> *\S[^\n]*(?:\n(?! *\n)[^\n]*)*(?: *\n)*)+/,numlist:/^(?: *\d+\. [^\n]*(?:\n(?:(?: *\n)* )?(?! *\n)[^\n]*)*(?: *\n)*)+/,abclist:/^(?: *[a-z]\. [^\n]*(?:\n(?:(?: *\n)* )?(?! *\n)[^\n]*)*(?: *\n)*)+/,dashlist:/^(?: *- [^\n]*(?:\n(?:(?: *\n)* )?(?! *\n)[^\n]*)*(?: *\n)*)+/,numitem:/^( ?)( ?)( ?)\d+\. [^\n]*(?:\n(?!\1?\2?\3?\d+\. )[^\n]*)*/gm,abcitem:/^( ?)( ?)( ?)[a-z]\. [^\n]*(?:\n(?!\1?\2?\3?[a-z]\. )[^\n]*)*/gm,dashitem:/^( ?)( ?)( ?)- [^\n]*(?:\n(?!\1?\2?\3?- )[^\n]*)*/gm,paragraph:/^ *\S[^\n]*(?:\n(?! *(?:\n|> *\S|- |\d+\. |[a-z]\. )| {4})[^\n]*)*/,raw:/^[^\n]*/,escape:/^\\([\\\[\-.`_>])/,autolink:/^(https?:\/\/([^\s<]+[^<.,:;"')\]\s]))/,link:/^\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\((\b|https?:\/{2})((?:[a-z0-9.\-]{2,})(?:\/\S*)?)\)/i,strong:/^__ *(?=\S)((?:[^\\_]|\\[\\_]|\\(?![\\_])|_ *(?=\S)(?:[^\\_]|\\[\\_]|\\(?![\\_]))+_)+)__/,em:/^_ *(?=\S)((?:[^\\_]|\\[\\_]|\\(?![\\_])|__ *(?=\S)(?:[^\\_]|\\[\\_]|\\(?![\\_]))+__)+)_/,code:/^`(?!`)((?:\\\\)*|[\s\S]*?(?:[^\\](?:\\\\)*|[^`\\]))`/,br:/^ *\n */,text:/^[\s\S]+?(?=\\[\\\[\-.`_>]|[\[`_]|https?:\/\/| *(?:\n|$))/};"object"==typeof module&&module.exports?module.exports=e:this.stripdown=e}();