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