(function(){var Parser,slice=[].slice;Parser=function(){var array_keys,array_values,htmlspecialchars,pL,preg_quote,str_replace,trim,ucfirst;ucfirst=function(str){return str.charAt(0).toUpperCase()+str.substring(1)};preg_quote=function(str){return str.replace(/[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")};pL="A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";str_replace=function(search,replace,str){var i,j,l,len,len1,val;if(search instanceof Array){if(replace instanceof Array){for(i=j=0,len=search.length;j "+this.markLine(start,end)+htmlspecialchars(lines.join("\n"))+""+htmlspecialchars(matches[3])+"
")}}(this));text=text.replace(/(^|[^\\])(\$+)(.+?)\2/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return matches[1]+_this.makeHolder(matches[2]+htmlspecialchars(matches[3])+matches[2])}}(this));text=text.replace(/\\(.)/g,function(_this){return function(){var escaped,matches;matches=1<=arguments.length?slice.call(arguments,0):[];escaped=htmlspecialchars(matches[1]);escaped=escaped.replace(/\$/g,"$");return _this.makeHolder(escaped)}}(this));text=text.replace(/<(https?:\/\/.+)>/gi,function(_this){return function(){var link,matches,url;matches=1<=arguments.length?slice.call(arguments,0):[];url=_this.cleanUrl(matches[1]);link=_this.call("parseLink",matches[1]);return _this.makeHolder(''+link+"")}}(this));text=text.replace(/<(\/?)([a-z0-9-]+)(\s+[^>]*)?>/gi,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];if(_this.html||("|"+_this.commonWhiteList+"|"+whiteList+"|").indexOf("|"+matches[2].toLowerCase()+"|")>=0){return _this.makeHolder(matches[0])}else{return htmlspecialchars(matches[0])}}}(this));if(this.html){text=text.replace(//g,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return _this.makeHolder(matches[0])}}(this))}text=str_replace(["<",">"],["<",">"],text);text=text.replace(/\[\^((?:[^\]]|\\\]|\\\[)+?)\]/g,function(_this){return function(){var id,matches;matches=1<=arguments.length?slice.call(arguments,0):[];id=_this.footnotes.indexOf(matches[1]);if(id<0){id=_this.footnotes.length+1;_this.footnotes.push(_this.parseInline(matches[1],"",false))}return _this.makeHolder(''+id+"")}}(this));text=text.replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,function(_this){return function(){var escaped,matches,url;matches=1<=arguments.length?slice.call(arguments,0):[];escaped=htmlspecialchars(_this.escapeBracket(matches[1]));url=_this.escapeBracket(matches[2]);url=_this.cleanUrl(url);return _this.makeHolder('')}}(this));text=text.replace(/!\[((?:[^\]]|\\\]|\\\[)*?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,function(_this){return function(){var escaped,matches,result;matches=1<=arguments.length?slice.call(arguments,0):[];escaped=htmlspecialchars(_this.escapeBracket(matches[1]));result=_this.definitions[matches[2]]!=null?'
':escaped;return _this.makeHolder(result)}}(this));text=text.replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\(((?:[^\)]|\\\)|\\\()+?)\)/g,function(_this){return function(){var escaped,matches,url;matches=1<=arguments.length?slice.call(arguments,0):[];escaped=_this.parseInline(_this.escapeBracket(matches[1]),"",false,false);url=_this.escapeBracket(matches[2]);url=_this.cleanUrl(url);return _this.makeHolder(''+escaped+"")}}(this));text=text.replace(/\[((?:[^\]]|\\\]|\\\[)+?)\]\[((?:[^\]]|\\\]|\\\[)+?)\]/g,function(_this){return function(){var escaped,matches,result;matches=1<=arguments.length?slice.call(arguments,0):[];escaped=_this.parseInline(_this.escapeBracket(matches[1]),"",false,false);result=_this.definitions[matches[2]]!=null?''+escaped+"":escaped;return _this.makeHolder(result)}}(this));text=this.parseInlineCallback(text);text=text.replace(/<([_a-z0-9-\.\+]+@[^@]+\.[a-z]{2,})>/gi,'$1');if(enableAutoLink){regex=new RegExp('(^|[^"])((https?):['+pL+'_0-9-\\./%#!@\\?\\+=~\\|\\,&\\(\\)]+)($|[^"])',"ig");text=text.replace(regex,function(_this){return function(){var link,matches;matches=1<=arguments.length?slice.call(arguments,0):[];link=_this.call("parseLink",matches[2]);return matches[1]+''+link+""+matches[4]}}(this))}text=this.call("afterParseInlineBeforeRelease",text);text=this.releaseHolder(text,clearHolders);text=this.call("afterParseInline",text);return text};Parser.prototype.parseInlineCallback=function(text){text=text.replace(/(\*{3})((?:.|\r)+?)\1/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return""+_this.parseInlineCallback(matches[2])+""}}(this));text=text.replace(/(\*{2})((?:.|\r)+?)\1/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return""+_this.parseInlineCallback(matches[2])+""}}(this));text=text.replace(/(\*)((?:.|\r)+?)\1/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return""+_this.parseInlineCallback(matches[2])+""}}(this));text=text.replace(/(\s+|^)(_{3})((?:.|\r)+?)\2(\s+|$)/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return matches[1]+""+_this.parseInlineCallback(matches[3])+""+matches[4]}}(this));text=text.replace(/(\s+|^)(_{2})((?:.|\r)+?)\2(\s+|$)/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return matches[1]+""+_this.parseInlineCallback(matches[3])+""+matches[4]}}(this));text=text.replace(/(\s+|^)(_)((?:.|\r)+?)\2(\s+|$)/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return matches[1]+""+_this.parseInlineCallback(matches[3])+""+matches[4]}}(this));text=text.replace(/(~{2})((?:.|\r)+?)\1/gm,function(_this){return function(){var matches;matches=1<=arguments.length?slice.call(arguments,0):[];return"
"+_this.parseInlineCallback(matches[2])+""}}(this));return text};Parser.prototype.parseBlock=function(text,lines){var block,j,key,l,len,len1,line,name,parser,pass,ref,ref1,state;ref=text.split("\n");for(j=0,len=ref.length;j
"}};Parser.prototype.parsePre=function(lines,value,start){var str;lines=lines.map(function(line){return htmlspecialchars(line.substring(4))});str=this.markLines(lines,start).join("\n");if(str.match(/^\s*$/)){return""}else{return""+str+"
"}};Parser.prototype.parseAhtml=function(lines,value,start){return trim(this.markLines(lines,start).join("\n"))};Parser.prototype.parseShtml=function(lines,value,start){return trim(this.markLines(lines.slice(1,-1),start+1).join("\n"))};Parser.prototype.parseMath=function(lines,value,start,end){return""+str+"
"+this.parse(str,true,start)+"
"}};Parser.prototype.parseList=function(lines,value,start){var found,html,j,key,l,lastType,leftLines,leftStart,len,len1,line,matches,minSpace,row,rows,secondFound,secondMinSpace,space,text,type;html="";minSpace=99999;secondMinSpace=99999;found=false;secondFound=false;rows=[];for(key=j=0,len=lines.length;j";body=head?null:true;output=false;for(key=j=0,len=lines.length;j
"};Parser.prototype.parseHr=function(lines,value,start){if(this.line){return'";for(key in columns){column=columns[key];num=column[0],text=column[1];tag=head?"th":"td";html+="<"+tag;if(num>1){html+=' colspan="'+num+'"'}if(aligns[key]!=null&&aligns[key]!=="none"){html+=' align="'+aligns[key]+'"'}html+=">"+this.parseInline(text)+(""+tag+">")}html+=" ";if(head){html+=""}else if(body){body=false}}if(body!==null){html+=""}return html+="
'}else{return"
"}};Parser.prototype.parseNormal=function(lines,inline,start){var key,str;if(inline==null){inline=false}key=0;lines=lines.map(function(_this){return function(line){line=_this.parseInline(line);if(!line.match(/^\s*$/)){line=_this.markLine(start+key)+line}key+=1;return line}}(this));str=trim(lines.join("\n"));str=str.replace(/(\n\s*){2,}/g,"
");str=str.replace(/\n/g,"
");if(str.match(/^\s*$/)){return""}else{if(inline){return str}else{return"
"+str+"
"}}};Parser.prototype.parseFootnote=function(lines,value){var index,note,space;space=value[0],note=value[1];index=this.footnotes.indexOf(note);if(index>=0){lines=lines.slice(0);lines[0]=lines[0].replace(/^\[\^((?:[^\]]|\]|\[)+?)\]:/,"");this.footnotes[index]=lines}return""};Parser.prototype.parseDefinition=function(){return""};Parser.prototype.parseHtml=function(lines,type,start){lines=lines.map(function(_this){return function(line){return _this.parseInline(line,_this.specialWhiteList[type]!=null?_this.specialWhiteList[type]:"")}}(this));return this.markLines(lines,start).join("\n")};Parser.prototype.cleanUrl=function(url){var matches;if(!!(matches=url.match(/^\s*((http|https|ftp|mailto):[x80-xff_a-z0-9-\.\/%#!@\?\+=~\|\,&\(\)]+)/i))){matches[1]}if(!!(matches=url.match(/^\s*([x80-xff_a-z0-9-\.\/%#!@\?\+=~\|\,&]+)/i))){return matches[1]}else{return"#"}};Parser.prototype.escapeBracket=function(str){return str_replace(["\\[","\\]","\\(","\\)"],["[","]","(",")"],str)};Parser.prototype.startBlock=function(type,start,value){if(value==null){value=null}this.pos+=1;this.current=type;this.blocks.push([type,start,start,value]);return this};Parser.prototype.endBlock=function(){this.current="normal";return this};Parser.prototype.isBlock=function(type,value){if(value==null){value=null}return this.current===type&&(null===value?true:this.blocks[this.pos][3]===value)};Parser.prototype.getBlock=function(){if(this.blocks[this.pos]!=null){return this.blocks[this.pos]}else{return null}};Parser.prototype.setBlock=function(to,value){if(to==null){to=null}if(value==null){value=null}if(to!==null){this.blocks[this.pos][2]=to}if(value!==null){this.blocks[this.pos][3]=value}return this};Parser.prototype.backBlock=function(step,type,value){var item,last;if(value==null){value=null}if(this.pos<0){return this.startBlock(type,0,value)}last=this.blocks[this.pos][2];this.blocks[this.pos][2]=last-step;item=[type,last-step+1,last,value];if(this.blocks[this.pos][1]<=this.blocks[this.pos][2]){this.pos+=1;this.blocks.push(item)}else{this.blocks[this.pos]=item}this.current=type;return this};Parser.prototype.combineBlock=function(){var current,prev;if(this.pos<1){return this}prev=this.blocks[this.pos-1].slice(0);current=this.blocks[this.pos].slice(0);prev[2]=current[2];this.blocks[this.pos-1]=prev;this.current=prev[0];this.blocks=this.blocks.slice(0,-1);this.pos-=1;return this};return Parser}();if(typeof module!=="undefined"&&module!==null){module.exports=Parser}else if(typeof window!=="undefined"&&window!==null){window.HyperDown=Parser}}).call(this);