Files
typecho/admin/js/hyperdown.js
T
joyqi 38f959890d replace compass with node-sass.
create new build tools.
2020-05-14 14:30:19 +08:00

1 line
22 KiB
JavaScript

(function(){var t,k,n,d,B,c,b,x,g,y=[].slice;function e(){this.commonWhiteList="kbd|b|i|strong|em|sup|sub|br|code|del|a|hr|small",this.blockHtmlTags="p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|svg|script|noscript",this.specialWhiteList={table:"table|tbody|thead|tfoot|tr|td|th"},this.hooks={},this.html=!1,this.line=!1,this.blockParsers=[["code",10],["shtml",20],["pre",30],["ahtml",40],["shr",50],["list",60],["math",70],["html",80],["footnote",90],["definition",100],["quote",110],["table",120],["sh",130],["mh",140],["dhr",150],["default",9999]],this.parsers={}}g=function(t){return t.charAt(0).toUpperCase()+t.substring(1)},c=function(t){return t.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},B="A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",b=function(t,e,r){var n,s,l,i,o,a;if(t instanceof Array)if(e instanceof Array)for(n=s=0,i=t.length;s<i;n=++s)a=t[n],r=b(a,e[n],r);else for(l=0,o=t.length;l<o;l++)a=t[l],r=b(a,e,r);else t=c(t),r=r.replace(new RegExp(t,"g"),e.replace(/\$/g,"$$$$"));return r},d=function(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},x=function(t,e){var r,n,s,l,i;if(null==e&&(e=null),null==e)return t.replace(/^\s*/,"").replace(/\s*$/,"");for(i="",n=s=0,l=e.length-1;0<=l?s<=l:l<=s;n=0<=l?++s:--s)r=e[n],i+=r=c(r);return i="["+i+"]*",t.replace(new RegExp("^"+i),"").replace(new RegExp(i+"$"),"")},k=function(t){var e,r,n,s=[];if(t instanceof Array)for(r=e=0,n=t.length;e<n;r=++e)t[r],s.push(r);else for(r in t)s.push(r);return s},n=function(t){var e,r,n,s,l=[];if(t instanceof Array)for(r=0,n=t.length;r<n;r++)s=t[r],l.push(s);else for(e in t)s=t[e],l.push(s);return l},e.prototype.makeHtml=function(t){var e,r,n,s,l,i;for(this.footnotes=[],this.definitions={},this.holders={},this.uniqid=Math.ceil(1e7*Math.random())+Math.ceil(1e7*Math.random()),this.id=0,this.blockParsers.sort(function(t,e){return t[1]<e[1]?-1:1}),r=0,n=(i=this.blockParsers).length;r<n;r++)s=(l=i[r])[0],void 0!==l[2]?this.parsers[s]=l[2]:this.parsers[s]=this["parseBlock"+g(s)].bind(this);return t=this.initText(t),e=this.parse(t),e=this.makeFootnotes(e),e=this.optimizeLines(e),this.call("makeHtml",e)},e.prototype.enableHtml=function(t){this.html=null==t||t},e.prototype.enableLine=function(t){this.line=null==t||t},e.prototype.hook=function(t,e){return null==this.hooks[t]&&(this.hooks[t]=[]),this.hooks[t].push(e)},e.prototype.makeHolder=function(t){var e="|\r"+this.uniqid+this.id+"\r|";return this.id+=1,this.holders[e]=t,e},e.prototype.initText=function(t){return t.replace(/\t/g," ").replace(/\r/g,"").replace(/(\u000A|\u000D|\u2028|\u2029)/g,"\n")},e.prototype.makeFootnotes=function(t){var e,r;if(0<this.footnotes.length){for(t+='<div class="footnotes"><hr><ol>',e=1;r=this.footnotes.shift();)"string"==typeof r?r+=' <a href="#fnref-'+e+'" class="footnote-backref">&#8617;</a>':(r[r.length-1]+=' <a href="#fnref-'+e+'" class="footnote-backref">&#8617;</a>',r=1<r.length?this.parse(r.join("\n")):this.parseInline(r[0])),t+='<li id="fn-'+e+'">'+r+"</li>",e+=1;t+="</ol></div>"}return t},e.prototype.parse=function(t,e,r){var n,s,l,i,o,a,c,h,p,u,f,k,m;for(null==e&&(e=!1),null==r&&(r=0),h=[],s=this.parseBlock(t,h),o="",e&&1===s.length&&"normal"===s[0][0]&&(s[0][3]=!0),a=0,c=s.length;a<c;a++)k=(n=s[a])[0],f=n[1],l=n[2],m=n[3],i=h.slice(f,l+1),p="parse"+g(k),i=this.call("before"+g(p),i,m),u=this[p](i,m,f+r,l+r),o+=u=this.call("after"+g(p),u,m);return o},e.prototype.call=function(){var t,e,r,n=arguments[0],s=2<=arguments.length?y.call(arguments,1):[],l=s[0];if(null==this.hooks[n])return l;for(t=0,e=(r=this.hooks[n]).length;t<e;t++)l=r[t].apply(this,s),s[0]=l;return l},e.prototype.releaseHolder=function(t,e){var r;for(null==e&&(e=!0),r=0;0<=t.indexOf("\r")&&r<10;)t=b(k(this.holders),n(this.holders),t),r+=1;return e&&(this.holders={}),t},e.prototype.markLine=function(t,e){return null==e&&(e=-1),this.line?'<span class="line" data-start="'+t+'" data-end="'+(e=e<0?t:e)+'" data-id="'+this.uniqid+'"></span>':""},e.prototype.markLines=function(t,e){var r,n=-1;return this.line?t.map((r=this,function(t){return n+=1,r.markLine(e+n)+t})):t},e.prototype.optimizeLines=function(t){var r=0,e=new RegExp('class="line" data\\-start="([0-9]+)" data\\-end="([0-9]+)" (data\\-id="'+this.uniqid+'")',"g");return this.line?t.replace(e,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=r!==parseInt(t[1])?'class="line" data-start="'+r+'" data-start-original="'+t[1]+'" data-end="'+t[2]+'" '+t[3]:t[0];return r=1+parseInt(t[2]),e}):t},e.prototype.parseInline=function(t,e,r,n){var s,l,i,o,a,c,h,p,u,f,k,m,g;return null==e&&(e=""),null==r&&(r=!0),null==n&&(n=!0),t=(t=(t=(t=(t=(t=this.call("beforeParseInline",t)).replace(/(^|[^\\])(`+)(.+?)\2/gm,(l=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return t[1]+l.makeHolder("<code>"+d(t[3])+"</code>")}))).replace(/(^|[^\\])(\$+)(.+?)\2/gm,(i=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return t[1]+i.makeHolder(t[2]+d(t[3])+t[2])}))).replace(/\\(.)/g,(o=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=d(t[1]);return e=e.replace(/\$/g,"&dollar;"),o.makeHolder(e)}))).replace(/<(https?:\/\/.+)>/gi,(a=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=a.cleanUrl(t[1]),r=a.call("parseLink",t[1]);return a.makeHolder('<a href="'+e+'">'+r+"</a>")}))).replace(/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/gi,(c=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return c.html||0<=("|"+c.commonWhiteList+"|"+e+"|").indexOf("|"+t[2].toLowerCase()+"|")?c.makeHolder(t[0]):d(t[0])})),this.html&&(t=t.replace(/<!\-\-(.*?)\-\->/g,(h=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return h.makeHolder(t[0])}))),t=(t=(t=(t=(t=(t=b(["<",">"],["&lt;","&gt;"],t)).replace(/\[\^((?:[^\]]|\\\]|\\\[)+?)\]/g,(p=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=p.footnotes.indexOf(t[1]);return e<0&&(e=p.footnotes.length+1,p.footnotes.push(p.parseInline(t[1],"",!1))),p.makeHolder('<sup id="fnref-'+e+'"><a href="#fn-'+e+'" class="footnote-ref">'+e+"</a></sup>")}))).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(u=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=d(u.escapeBracket(t[1])),r=u.escapeBracket(t[2]);return r=u.cleanUrl(r),u.makeHolder('<img src="'+r+'" alt="'+e+'" title="'+e+'">')}))).replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(f=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=d(f.escapeBracket(t[1])),r=null!=f.definitions[t[2]]?'<img src="'+f.definitions[t[2]]+'" alt="'+e+'" title="'+e+'">':e;return f.makeHolder(r)}))).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,(k=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=k.parseInline(k.escapeBracket(t[1]),"",!1,!1),r=k.escapeBracket(t[2]);return r=k.cleanUrl(r),k.makeHolder('<a href="'+r+'">'+e+"</a>")}))).replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,(m=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=m.parseInline(m.escapeBracket(t[1]),"",!1,!1),r=null!=m.definitions[t[2]]?'<a href="'+m.definitions[t[2]]+'">'+e+"</a>":e;return m.makeHolder(r)})),t=(t=this.parseInlineCallback(t)).replace(/<([_a-z0-9-\.\+]+@[^@]+\.[a-z]{2,})>/gi,'<a href="mailto:$1">$1</a>'),n&&(s=new RegExp('(^|[^"])((https?):['+B+'_0-9-\\./%#!@\\?\\+=~\\|\\,&\\(\\)]+)($|[^"])',"ig"),t=t.replace(s,(g=this,function(){var t=1<=arguments.length?y.call(arguments,0):[],e=g.call("parseLink",t[2]);return t[1]+'<a href="'+t[2]+'">'+e+"</a>"+t[4]}))),t=this.call("afterParseInlineBeforeRelease",t),t=this.releaseHolder(t,r),t=this.call("afterParseInline",t)},e.prototype.parseInlineCallback=function(t){var e,r,n,s,l,i,o;return t=(t=(t=(t=(t=(t=(t=t.replace(/(\*{3})((?:.|\r)+?)\1/gm,(e=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return"<strong><em>"+e.parseInlineCallback(t[2])+"</em></strong>"}))).replace(/(\*{2})((?:.|\r)+?)\1/gm,(r=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return"<strong>"+r.parseInlineCallback(t[2])+"</strong>"}))).replace(/(\*)((?:.|\r)+?)\1/gm,(n=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return"<em>"+n.parseInlineCallback(t[2])+"</em>"}))).replace(/(\s+|^)(_{3})((?:.|\r)+?)\2(\s+|$)/gm,(s=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return t[1]+"<strong><em>"+s.parseInlineCallback(t[3])+"</em></strong>"+t[4]}))).replace(/(\s+|^)(_{2})((?:.|\r)+?)\2(\s+|$)/gm,(l=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return t[1]+"<strong>"+l.parseInlineCallback(t[3])+"</strong>"+t[4]}))).replace(/(\s+|^)(_)((?:.|\r)+?)\2(\s+|$)/gm,(i=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return t[1]+"<em>"+i.parseInlineCallback(t[3])+"</em>"+t[4]}))).replace(/(~{2})((?:.|\r)+?)\1/gm,(o=this,function(){var t=1<=arguments.length?y.call(arguments,0):[];return"<del>"+o.parseInlineCallback(t[2])+"</del>"}))},e.prototype.parseBlock=function(t,e){for(var r,n,s,l,i,o,a,c,h,p=t.split("\n"),u=0,f=p.length;u<f;u++)i=p[u],e.push(i);for(this.blocks=[],this.current="normal",this.pos=-1,h={special:k(this.specialWhiteList).join("|"),empty:0,html:!1},n=s=0,l=e.length;s<l;n=++s)if(i=e[n],null!=(r=this.getBlock())&&(r=r.slice(0)),"normal"===this.current||this.parsers[this.current](r,n,i,h,e))for(o in c=this.parsers)if(a=c[o],o!==this.current&&!a(r,n,i,h,e))break;return this.optimizeBlocks(this.blocks,e)},e.prototype.parseBlockList=function(t,e,r,n){var s,l;if(s=r.match(/^(\s*)((?:[0-9]+\.)|\-|\+|\*)\s+/i))return l=s[1].length,n.empty=0,this.isBlock("list")?this.setBlock(e,l):this.startBlock("list",e,l),!1;if(this.isBlock("list")&&!r.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/)){if(n.empty<=1&&(s=r.match(/^(\s+)/))&&s[1].length>t[3])return n.empty=0,this.setBlock(e),!1;if(r.match(/^\s*$/)&&0===n.empty)return n.empty+=1,this.setBlock(e),!1}return!0},e.prototype.parseBlockCode=function(t,e,r){var n,s,l;return(s=r.match(/^(\s*)(~{3,}|`{3,})([^`~]*)$/i))?(this.isBlock("code")?(n=t[3][2])?this.combineBlock().setBlock(e):this.setBlock(e).endBlock():(n=!1,this.isBlock("list")&&(n=0<(l=t[3])&&s[1].length>=l||s[1].length>l),this.startBlock("code",e,[s[1],s[3],n])),!1):!this.isBlock("code")||(this.setBlock(e),!1)},e.prototype.parseBlockShtml=function(t,e,r,n){if(this.html){if(r.match(/^(\s*)!!!(\s*)$/))return this.isBlock("shtml")?this.setBlock(e).endBlock():this.startBlock("shtml",e),!1;if(this.isBlock("shtml"))return this.setBlock(e),!1}return!0},e.prototype.parseBlockAhtml=function(t,e,r,n){var s,l,i,o,a;if(this.html)if(l=new RegExp("^\\s*<("+this.blockHtmlTags+")(\\s+[^>]*)?>","i"),a=r.match(l)){if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(void 0===a[2]||"/"!==a[2]){for(this.startBlock("ahtml",e),s=new RegExp("\\s*<("+this.blockHtmlTags+")(\\s+[^>]*)?>","ig");o=s.exec(r);)i=o[1];return 0<=r.indexOf("</"+i+">")?this.endBlock():n.html=i,!1}}else{if(n.html&&0<=r.indexOf("</"+n.html+">"))return this.setBlock(e).endBlock(),n.html=!1;if(this.isBlock("ahtml"))return this.setBlock(e),!1;if(a=r.match(/^\s*<!\-\-(.*?)\-\->\s*$/))return this.startBlock("ahtml",e).endBlock(),!1}return!0},e.prototype.parseBlockMath=function(t,e,r){return r.match(/^(\s*)\$\$(\s*)$/)?(this.isBlock("math")?this.setBlock(e).endBlock():this.startBlock("math",e),!1):!this.isBlock("math")||(this.setBlock(e),!1)},e.prototype.parseBlockPre=function(t,e,r,n){return r.match(/^ {4}/)?(this.isBlock("pre")?this.setBlock(e):this.startBlock("pre",e),!1):!this.isBlock("pre")||!r.match(/^\s*$/)||(this.setBlock(e),!1)},e.prototype.parseBlockHtml=function(t,e,r,n){var s,l;return(s=r.match(new RegExp("^\\s*<("+n.special+")(\\s+[^>]*)?>","i")))?(l=s[1].toLowerCase(),this.isBlock("html",l)||this.isBlock("pre")||this.startBlock("html",e,l),!1):(s=r.match(new RegExp("</("+n.special+")>\\s*$","i")))?(l=s[1].toLowerCase(),this.isBlock("html",l)&&this.setBlock(e).endBlock(),!1):!this.isBlock("html")||(this.setBlock(e),!1)},e.prototype.parseBlockFootnote=function(t,e,r){var n,s;return!(n=r.match(/^\[\^((?:[^\]]|\\\]|\\\[)+?)\]:/))||(s=n[0].length-1,this.startBlock("footnote",e,[s,n[1]]),!1)},e.prototype.parseBlockDefinition=function(t,e,r){var n;return!(n=r.match(/^\s*\[((?:[^\]]|\\\]|\\\[)+?)\]:\s*(.+)$/))||(this.definitions[n[1]]=this.cleanUrl(n[2]),this.startBlock("definition",e).endBlock(),!1)},e.prototype.parseBlockQuote=function(t,e,r){var n;return!(n=r.match(/^(\s*)>/))||(this.isBlock("list")&&0<n[1].length||this.isBlock("quote")?this.setBlock(e):this.startBlock("quote",e),!1)},e.prototype.parseBlockTable=function(t,e,r,n,s){var l,i,o,a,c,h,p;if(h=r.match(/^((?:(?:(?:\||\+)(?:[ :]*\-+[ :]*)(?:\||\+))|(?:(?:[ :]*\-+[ :]*)(?:\||\+)(?:[ :]*\-+[ :]*))|(?:(?:[ :]*\-+[ :]*)(?:\||\+))|(?:(?:\||\+)(?:[ :]*\-+[ :]*)))+)$/)){if(this.isBlock("table"))t[3][0].push(t[3][2]),t[3][2]+=1,this.setBlock(e,t[3]);else{for(o=0,null==t||"normal"!==t[0]||s[t[2]].match(/^\s*$/)?this.startBlock("table",e):(o=1,this.backBlock(1,"table")),"|"===h[1][0]&&(h[1]=h[1].substring(1),"|"===h[1][h[1].length-1]&&(h[1]=h[1].substring(0,h[1].length-1))),i=[],a=0,c=(p=h[1].split(/\+|\|/)).length;a<c;a++)l="none",(h=p[a].match(/^\s*(:?)\-+(:?)\s*$/))&&(h[1]&&h[2]?l="center":h[1]?l="left":h[2]&&(l="right")),i.push(l);this.setBlock(e,[[o],i,o+1])}return!1}return!0},e.prototype.parseBlockSh=function(t,e,r){var n,s;return!(n=r.match(/^(#+)(.*)$/))||(s=Math.min(n[1].length,6),this.startBlock("sh",e,s).endBlock(),!1)},e.prototype.parseBlockMh=function(t,e,r,n,s){var l;return!((l=r.match(/^\s*((=|-){2,})\s*$/))&&null!=t&&"normal"===t[0]&&!s[t[2]].match(/^\s*$/)&&(this.isBlock("normal")?this.backBlock(1,"mh","="===l[1][0]?1:2).setBlock(e).endBlock():this.startBlock("normal",e),1))},e.prototype.parseBlockShr=function(t,e,r){return!r.match(/^(\* *){3,}\s*$/)||(this.startBlock("hr",e).endBlock(),!1)},e.prototype.parseBlockDhr=function(t,e,r){return!r.match(/^(- *){3,}\s*$/)||(this.startBlock("hr",e).endBlock(),!1)},e.prototype.parseBlockDefault=function(t,e,r,n){return this.isBlock("footnote")?r.match(/^(\s*)/)[1].length>=t[3][0]?this.setBlock(e):this.startBlock("normal",e):this.isBlock("table")?0<=r.indexOf("|")?(t[3][2]+=1,this.setBlock(e,t[3])):this.startBlock("normal",e):this.isBlock("quote")?r.match(/^(\s*)$/)?this.startBlock("normal",e):this.setBlock(e):null==t||"normal"!==t[0]?this.startBlock("normal",e):this.setBlock(e),!0},e.prototype.optimizeBlocks=function(t,e){var r,n,s,l,i,o,a,c,h,p=t.slice(0),u=e.slice(0);for(p=this.call("beforeOptimizeBlocks",p,u),s=0;null!=p[s];)l=!1,r=p[s],o=null!=p[s-1]?p[s-1]:null,i=null!=p[s+1]?p[s+1]:null,c=r[0],n=r[1],a=r[2],"pre"===c&&u.slice(r[1],r[2]+1).reduce(function(t,e){return e.match(/^\s*$/)&&t},!0)&&(r[0]=c="normal"),"normal"===c&&(h=["list","quote"],n===a&&u[n].match(/^\s*$/)&&null!=o&&null!=i&&o[0]===i[0]&&0<=h.indexOf(o[0])&&(p[s-1]=[o[0],o[1],i[2],null],p.splice(s,2),l=!0)),l||(s+=1);return this.call("afterOptimizeBlocks",p,u)},e.prototype.parseCode=function(t,e,r){var n,s,l,i,o=e[0],a=e[1];return a=x(a),n=o.length,a.match(/^[_a-z0-9-\+\#\:\.]+$/i)?1<(e=a.split(":")).length&&(a=e[0],l=e[1],a=x(a),l=x(l)):a=null,s=!0,t=t.slice(1,-1).map(function(t){return t=t.replace(new RegExp("/^[ ]{"+n+"}/"),""),s&&!t.match(/^\s*$/)&&(s=!1),d(t)}),i=this.markLines(t,r+1).join("\n"),s?"":"<pre><code"+(a?' class="'+a+'"':"")+(l?' rel="'+l+'"':"")+">"+i+"</code></pre>"},e.prototype.parsePre=function(t,e,r){var n;return t=t.map(function(t){return d(t.substring(4))}),(n=this.markLines(t,r).join("\n")).match(/^\s*$/)?"":"<pre><code>"+n+"</code></pre>"},e.prototype.parseAhtml=function(t,e,r){return x(this.markLines(t,r).join("\n"))},e.prototype.parseShtml=function(t,e,r){return x(this.markLines(t.slice(1,-1),r+1).join("\n"))},e.prototype.parseMath=function(t,e,r,n){return"<p>"+this.markLine(r,n)+d(t.join("\n"))+"</p>"},e.prototype.parseSh=function(t,e,r,n){var s=this.markLine(r,n)+this.parseInline(x(t[0],"# "));return s.match(/^\s*$/)?"":"<h"+e+">"+s+"</h"+e+">"},e.prototype.parseMh=function(t,e,r,n){return this.parseSh(t,e,r,n)},e.prototype.parseQuote=function(t,e,r){var n;return(n=(t=t.map(function(t){return t.replace(/^\s*> ?/,"")})).join("\n")).match(/^\s*$/)?"":"<blockquote>"+this.parse(n,!0,r)+"</blockquote>"},e.prototype.parseList=function(t,e,r){for(var n,s,l,i,o,a,c,h,p,u,f,k,m="",g=99999,d=99999,B=!1,b=!1,y=[],v=n=0,$=t.length;n<$;v=++n)(h=(c=t[v]).match(/^(\s*)((?:[0-9]+\.?)|\-|\+|\*)(\s+)(.*)$/i))?(u=h[1].length,k=0<="+-*".indexOf(h[2])?"ul":"ol",g=Math.min(u,g),B=!0,0<u&&(d=Math.min(u,d),b=!0),y.push([u,k,c,h[4]])):(y.push(c),(h=c.match(/^(\s*)/))&&0<(u=h[1].length)&&(d=Math.min(u,d),b=!0));for(g=B?g:0,d=b?d:g,l="",i=[],v=s=o=0,a=y.length;s<a;v=++s)(p=y[v])instanceof Array?(u=p[0],k=p[1],c=p[2],f=p[3],u!==g?i.push(c.replace(new RegExp("^\\s{"+d+"}"),"")):(0<i.length&&(m+="<li>"+this.parse(i.join("\n"),!0,r+o)+"</li>"),l!==k&&(l&&(m+="</"+l+">"),m+="<"+k+">"),o=v,i=[f],l=k)):i.push(p.replace(new RegExp("^\\s{"+d+"}"),""));return 0<i.length&&(m+="<li>"+this.parse(i.join("\n"),!0,r+o)+"</li></"+l+">"),m},e.prototype.parseTable=function(t,e,r){for(var n,s,l,i,o,a,c,h,p,u,f,k,m=e[0],g=e[1],d=0<m.length&&0<m.reduce(function(t,e){return e+t}),B="<table>",b=!d||null,y=!1,v=l=0,$=t.length;l<$;v=++l)if(c=t[v],0<=m.indexOf(v))d&&y&&(b=!(d=!1));else{for(y=!0,"|"===(c=x(c))[0]&&"|"===(c=c.substring(1))[c.length-1]&&(c=c.substring(0,c.length-1)),s={},o=-1,i=0,a=(u=c.split("|").map(function(t){return t.match(/^\s*$/)?" ":x(t)})).length;i<a;i++)0<(p=u[i]).length?s[o+=1]=[null!=s[o]?s[o][0]+1:1,p]:null!=s[o]?s[o][0]+=1:s[0]=[1,p];for(v in d?B+="<thead>":b&&(B+="<tbody>"),B+="<tr",this.line&&(B+=' class="line" data-start="'+(r+v)+'" data-end="'+(r+v)+'" data-id="'+this.uniqid+'"'),B+=">",s)h=(n=s[v])[0],k=n[1],B+="<"+(f=d?"th":"td"),1<h&&(B+=' colspan="'+h+'"'),null!=g[v]&&"none"!==g[v]&&(B+=' align="'+g[v]+'"'),B+=">"+this.parseInline(k)+"</"+f+">";B+="</tr>",d?B+="</thead>":b=b&&!1}return null!==b&&(B+="</tbody>"),B+"</table>"},e.prototype.parseHr=function(t,e,r){return this.line?'<hr class="line" data-start="'+r+'" data-end="'+r+'">':"<hr>"},e.prototype.parseNormal=function(t,e,r){var n,s,l;return null==e&&(e=!1),n=0,t=t.map((l=this,function(t){return(t=l.parseInline(t)).match(/^\s*$/)||(t=l.markLine(r+n)+t),n+=1,t})),(s=(s=(s=x(t.join("\n"))).replace(/(\n\s*){2,}/g,"</p><p>")).replace(/\n/g,"<br>")).match(/^\s*$/)?"":e?s:"<p>"+s+"</p>"},e.prototype.parseFootnote=function(t,e){e[0];var r=e[1],n=this.footnotes.indexOf(r);return 0<=n&&((t=t.slice(0))[0]=t[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,""),this.footnotes[n]=t),""},e.prototype.parseDefinition=function(){return""},e.prototype.parseHtml=function(t,e,r){var n;return t=t.map((n=this,function(t){return n.parseInline(t,null!=n.specialWhiteList[e]?n.specialWhiteList[e]:"")})),this.markLines(t,r).join("\n")},e.prototype.cleanUrl=function(t){var e,r=new RegExp("^\\s*((http|https|ftp|mailto):["+B+"_a-z0-9-:\\.\\*/%#!@\\?\\+=~\\|\\,&\\(\\)]+)","i"),n=new RegExp("^\\s*(["+B+"_a-z0-9-:\\.\\*/%#!@\\?\\+=~\\|\\,&]+)","i");return(e=t.match(r))||(e=t.match(n))?e[1]:"#"},e.prototype.escapeBracket=function(t){return b(["\\[","\\]","\\(","\\)"],["[","]","(",")"],t)},e.prototype.startBlock=function(t,e,r){return null==r&&(r=null),this.pos+=1,this.current=t,this.blocks.push([t,e,e,r]),this},e.prototype.endBlock=function(){return this.current="normal",this},e.prototype.isBlock=function(t,e){return null==e&&(e=null),this.current===t&&(null===e||this.blocks[this.pos][3]===e)},e.prototype.getBlock=function(){return null!=this.blocks[this.pos]?this.blocks[this.pos]:null},e.prototype.setBlock=function(t,e){return null==t&&(t=null),null==e&&(e=null),null!==t&&(this.blocks[this.pos][2]=t),null!==e&&(this.blocks[this.pos][3]=e),this},e.prototype.backBlock=function(t,e,r){var n,s;return null==r&&(r=null),this.pos<0?this.startBlock(e,0,r):(s=this.blocks[this.pos][2],this.blocks[this.pos][2]=s-t,n=[e,s-t+1,s,r],this.blocks[this.pos][1]<=this.blocks[this.pos][2]?(this.pos+=1,this.blocks.push(n)):this.blocks[this.pos]=n,this.current=e,this)},e.prototype.combineBlock=function(){var t,e;return this.pos<1||(e=this.blocks[this.pos-1].slice(0),t=this.blocks[this.pos].slice(0),e[2]=t[2],this.blocks[this.pos-1]=e,this.current=e[0],this.blocks=this.blocks.slice(0,-1),--this.pos),this},t=e,"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.HyperDown=t)}).call(this);