text: !(function(a){"object"==typeof exports&&"object"==typeof module?a(require("../../lib/codemirror"),require("../fold/xml-fold")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../fold/xml-fold"],a):a(CodeMirror)})((function(a){function b(b){if(b.getOption("disableInput"))return a.Pass;for(var c=b.listSelections(),d=[],i=b.getOption("autoCloseTags"),j=0;j<c.length;j++){if(!c[j].empty())return a.Pass;var k=c[j].head,l=b.getTokenAt(k),m=a.innerMode(b.getMode(),l.state),n=m.state;if("xml"!=m.mode.name||!n.tagName)return a.Pass;var o="html"==m.mode.configuration,p="object"==typeof i&&i.dontCloseTags||o&&g,q="object"==typeof i&&i.indentTags||o&&h,r=n.tagName;l.end>k.ch&&(r=r.slice(0,r.length-l.end+k.ch));var s=r.toLowerCase();if(!r||"string"==l.type&&(l.end!=k.ch||!/[\"\']/.test(l.string.charAt(l.string.length-1))||1==l.string.length)||"tag"==l.type&&"closeTag"==n.type||l.string.indexOf("/")==l.string.length-1||p&&e(p,s)>-1||f(b,r,k,n,!0))return a.Pass;var t=q&&e(q,s)>-1;d[j]={indent:t,text:">"+(t?"\n\n":"")+"</"+r+">",newPos:t?a.Pos(k.line+1,0):a.Pos(k.line,k.ch+1)}}for(var u="object"==typeof i&&i.dontIndentOnAutoClose,j=c.length-1;j>=0;j--){var v=d[j];b.replaceRange(v.text,c[j].head,c[j].anchor,"+insert");var w=b.listSelections().slice(0);w[j]={head:v.newPos,anchor:v.newPos},b.setSelections(w),!u&&v.indent&&(b.indentLine(v.newPos.line,null,!0),b.indentLine(v.newPos.line+1,null,!0))}}function c(b,c){for(var d=b.listSelections(),e=[],g=c?"/":"</",h=b.getOption("autoCloseTags"),i="object"==typeof h&&h.dontIndentOnSlash,j=0;j<d.length;j++){if(!d[j].empty())return a.Pass;var k=d[j].head,l=b.getTokenAt(k),m=a.innerMode(b.getMode(),l.state),n=m.state;if(c&&("string"==l.type||"<"!=l.string.charAt(0)||l.start!=k.ch-1))return a.Pass;var o;if("xml"!=m.mode.name)if("htmlmixed"==b.getMode().name&&"javascript"==m.mode.name)o=g+"script";else{if("htmlmixed"!=b.getMode().name||"css"!=m.mode.name)return a.Pass;o=g+"style"}else{if(!n.context||!n.context.tagName||f(b,n.context.tagName,k,n))return a.Pass;o=g+n.context.tagName}">"!=b.getLine(k.line).charAt(l.end)&&(o+=">"),e[j]=o}if(b.replaceSelections(e),d=b.listSelections(),!i)for(var j=0;j<d.length;j++)(j==d.length-1||d[j].head.line<d[j+1].head.line)&&b.indentLine(d[j].head.line)}function d(b){return b.getOption("disableInput")?a.Pass:c(b,!0)}function e(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c<d;++c)if(a[c]==b)return c;return-1}function f(b,c,d,e,f){if(!a.scanForClosingTag)return!1;var g=Math.min(b.lastLine()+1,d.line+500),h=a.scanForClosingTag(b,d,null,g);if(!h||h.tag!=c)return!1;for(var i=e.context,j=f?1:0;i&&i.tagName==c;i=i.prev)++j;d=h.to;for(var k=1;k<j;k++){var l=a.scanForClosingTag(b,d,null,g);if(!l||l.tag!=c)return!1;d=l.to}return!0}a.defineOption("autoCloseTags",!1,(function(c,e,f){if(f!=a.Init&&f&&c.removeKeyMap("autoCloseTags"),e){var g={name:"autoCloseTags"};("object"!=typeof e||e.whenClosing)&&(g["'/'"]=function(a){return d(a)}),("object"!=typeof e||e.whenOpening)&&(g["'>'"]=function(a){return b(a)}),c.addKeyMap(g)}}));var g=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],h=["applet","blockquote","body","button","div","dl","fieldset","form","frameset","h1","h2","h3","h4","h5","h6","head","html","iframe","layer","legend","object","ol","p","select","table","ul"];a.commands.closeTag=function(a){return c(a)}}));