ace.define("ace/ext/beautify",["require","exports","module","ace/token_iterator"],(function(e,t,r){"use strict";var a=e("../token_iterator").TokenIterator;function o(e,t){return e.type.lastIndexOf(t+".xml")>-1}t.singletonTags=["area","base","br","col","command","embed","hr","html","img","input","keygen","link","meta","param","source","track","wbr"],t.blockTags=["article","aside","blockquote","body","div","dl","fieldset","footer","form","head","header","html","nav","ol","p","script","section","style","table","tbody","tfoot","thead","ul"],t.beautify=function(e){for(var r,s,n,i=new a(e,0,0),c=i.getCurrentToken(),u=e.getTabString(),l=t.singletonTags,m=t.blockTags,p=!1,f=!1,h=!1,y="",d="",b="",g=0,$=0,k=0,x=0,w=0,v=0,T=0,R=0,O=0,q=!1,C=!1,I=!1,_=!1,j={0:0},B=[],F=function(){r&&r.value&&"string.regexp"!==r.type&&(r.value=r.value.replace(/^\s*/,""))},S=function(){y=y.replace(/ +$/,"")},K=function(){y=y.trimRight(),p=!1};null!==c;){if(R=i.getCurrentTokenRow(),i.$rowTokens,r=i.stepForward(),"undefined"!==typeof c){if(d=c.value,w=0,I="style"===b||"ace/mode/css"===e.$modeId,o(c,"tag-open")?(C=!0,r&&(_=-1!==m.indexOf(r.value)),"0;O--)y+="\n";p=!0,o(c,"comment")||c.type.match(/^(comment|string)$/)||(d=d.trimLeft())}if(d){if("keyword"===c.type&&d.match(/^(if|else|elseif|for|foreach|while|switch)$/)?(B[g]=d,F(),h=!0,d.match(/^(else|elseif)$/)&&y.match(/\}[\s]*$/)&&(K(),f=!0)):"paren.lparen"===c.type?(F(),"{"===d.substr(-1)&&(h=!0,q=!1,C||(O=1)),"{"===d.substr(0,1)&&(f=!0,"["!==y.substr(-1)&&"["===y.trimRight().substr(-1)?(K(),f=!1):")"===y.trimRight().substr(-1)?K():S())):"paren.rparen"===c.type?(w=1,"}"===d.substr(0,1)&&("case"===B[g-1]&&w++,"{"===y.trimRight().substr(-1)?K():(f=!0,I&&(O+=2))),"]"===d.substr(0,1)&&"}"!==y.substr(-1)&&"}"===y.trimRight().substr(-1)&&(f=!1,x++,K()),")"===d.substr(0,1)&&"("!==y.substr(-1)&&"("===y.trimRight().substr(-1)&&(f=!1,x++,K()),S()):"keyword.operator"!==c.type&&"keyword"!==c.type||!d.match(/^(=|==|===|!=|!==|&&|\|\||and|or|xor|\+=|.=|>|>=|<|<=|=>)$/)?"punctuation.operator"===c.type&&";"===d?(K(),F(),h=!0,I&&O++):"punctuation.operator"===c.type&&d.match(/^(:|,)$/)?(K(),F(),d.match(/^(,)$/)&&T>0&&0===v?O++:(h=!0,p=!1)):"support.php_tag"!==c.type||"?>"!==d||p?o(c,"attribute-name")&&y.substr(-1).match(/^\s$/)?f=!0:o(c,"attribute-equals")?(S(),F()):o(c,"tag-close")&&(S(),"/>"===d&&(f=!0)):(K(),f=!0):(K(),F(),f=!0,h=!0),p&&(!c.type.match(/^(comment)$/)||d.substr(0,1).match(/^[/#]$/))&&(!c.type.match(/^(string)$/)||d.substr(0,1).match(/^['"]$/))){if(x=k,g>$)for(x++,n=g;n>$;n--)j[n]=x;else g<$&&(x=j[g]);for($=g,k=x,w&&(x-=w),q&&!v&&(x++,q=!1),n=0;n"===d)&&(O=_&&r&&""===d&&-1===l.indexOf(b)&&g--,s=R}}c=r}y=y.trim(),e.doc.setValue(y)},t.commands=[{name:"beautify",description:"Format selection (Beautify)",exec:function(e){t.beautify(e.session)},bindKey:"Ctrl-Shift-B"}]})),ace.require(["ace/ext/beautify"],(function(e){"object"==typeof module&&"object"==typeof exports&&module&&(module.exports=e)}));