cloudcmd/lib/client/editor/codemirror/pack/xml.pack.js
2012-07-27 08:16:16 -04:00

1 line
No EOL
6.5 KiB
JavaScript

CodeMirror.defineMode("xml",function(config,parserConfig){function inText(stream,state){function chain(parser){return state.tokenize=parser,parser(stream,state)}var ch=stream.next();if(ch=="<"){if(stream.eat("!"))return stream.eat("[")?stream.match("CDATA[")?chain(inBlock("atom","]]>")):null:stream.match("--")?chain(inBlock("comment","-->")):stream.match("DOCTYPE",!0,!0)?(stream.eatWhile(/[\w\._\-]/),chain(doctype(1))):null;if(stream.eat("?"))return stream.eatWhile(/[\w\._\-]/),state.tokenize=inBlock("meta","?>"),"meta";type=stream.eat("/")?"closeTag":"openTag",stream.eatSpace(),tagName="";var c;while(c=stream.eat(/[^\s\u00a0=<>\"\'\/?]/))tagName+=c;return state.tokenize=inTag,"tag"}if(ch=="&"){var ok;return stream.eat("#")?stream.eat("x")?ok=stream.eatWhile(/[a-fA-F\d]/)&&stream.eat(";"):ok=stream.eatWhile(/[\d]/)&&stream.eat(";"):ok=stream.eatWhile(/[\w\.\-:]/)&&stream.eat(";"),ok?"atom":"error"}return stream.eatWhile(/[^&<]/),null}function inTag(stream,state){var ch=stream.next();return ch==">"||ch=="/"&&stream.eat(">")?(state.tokenize=inText,type=ch==">"?"endTag":"selfcloseTag","tag"):ch=="="?(type="equals",null):/[\'\"]/.test(ch)?(state.tokenize=inAttribute(ch),state.tokenize(stream,state)):(stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/),"word")}function inAttribute(quote){return function(stream,state){while(!stream.eol())if(stream.next()==quote){state.tokenize=inTag;break}return"string"}}function inBlock(style,terminator){return function(stream,state){while(!stream.eol()){if(stream.match(terminator)){state.tokenize=inText;break}stream.next()}return style}}function doctype(depth){return function(stream,state){var ch;while((ch=stream.next())!=null){if(ch=="<")return state.tokenize=doctype(depth+1),state.tokenize(stream,state);if(ch==">"){if(depth==1){state.tokenize=inText;break}return state.tokenize=doctype(depth-1),state.tokenize(stream,state)}}return"meta"}}function pass(){for(var i=arguments.length-1;i>=0;i--)curState.cc.push(arguments[i])}function cont(){return pass.apply(null,arguments),!0}function pushContext(tagName,startOfLine){var noIndent=Kludges.doNotIndent.hasOwnProperty(tagName)||curState.context&&curState.context.noIndent;curState.context={prev:curState.context,tagName:tagName,indent:curState.indented,startOfLine:startOfLine,noIndent:noIndent}}function popContext(){curState.context&&(curState.context=curState.context.prev)}function element(type){if(type=="openTag")return curState.tagName=tagName,cont(attributes,endtag(curState.startOfLine));if(type=="closeTag"){var err=!1;return curState.context?curState.context.tagName!=tagName&&(Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())&&popContext(),err=!curState.context||curState.context.tagName!=tagName):err=!0,err&&(setStyle="error"),cont(endclosetag(err))}return cont()}function endtag(startOfLine){return function(type){return type=="selfcloseTag"||type=="endTag"&&Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())?(maybePopContext(curState.tagName.toLowerCase()),cont()):type=="endTag"?(maybePopContext(curState.tagName.toLowerCase()),pushContext(curState.tagName,startOfLine),cont()):cont()}}function endclosetag(err){return function(type){return err&&(setStyle="error"),type=="endTag"?(popContext(),cont()):(setStyle="error",cont(arguments.callee))}}function maybePopContext(nextTagName){var parentTagName;for(;;){if(!curState.context)return;parentTagName=curState.context.tagName.toLowerCase();if(!Kludges.contextGrabbers.hasOwnProperty(parentTagName)||!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName))return;popContext()}}function attributes(type){return type=="word"?(setStyle="attribute",cont(attribute,attributes)):type=="endTag"||type=="selfcloseTag"?pass():(setStyle="error",cont(attributes))}function attribute(type){return type=="equals"?cont(attvalue,attributes):(Kludges.allowMissing||(setStyle="error"),type=="endTag"||type=="selfcloseTag"?pass():cont())}function attvalue(type){return type=="string"?cont(attvaluemaybe):type=="word"&&Kludges.allowUnquoted?(setStyle="string",cont()):(setStyle="error",type=="endTag"||type=="selfCloseTag"?pass():cont())}function attvaluemaybe(type){return type=="string"?cont(attvaluemaybe):pass()}var indentUnit=config.indentUnit,Kludges=parserConfig.htmlMode?{autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!1}:{autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1},alignCDATA=parserConfig.alignCDATA,tagName,type,curState,setStyle;return{startState:function(){return{tokenize:inText,cc:[],indented:0,startOfLine:!0,tagName:null,context:null}},token:function(stream,state){stream.sol()&&(state.startOfLine=!0,state.indented=stream.indentation());if(stream.eatSpace())return null;setStyle=type=tagName=null;var style=state.tokenize(stream,state);state.type=type;if((style||type)&&style!="comment"){curState=state;for(;;){var comb=state.cc.pop()||element;if(comb(type||style))break}}return state.startOfLine=!1,setStyle||style},indent:function(state,textAfter,fullLine){var context=state.context;if(state.tokenize!=inTag&&state.tokenize!=inText||context&&context.noIndent)return fullLine?fullLine.match(/^(\s*)/)[0].length:0;if(alignCDATA&&/<!\[CDATA\[/.test(textAfter))return 0;context&&/^<\//.test(textAfter)&&(context=context.prev);while(context&&!context.startOfLine)context=context.prev;return context?context.indent+indentUnit:0},compareStates:function(a,b){if(a.indented!=b.indented||a.tokenize!=b.tokenize)return!1;for(var ca=a.context,cb=b.context;;ca=ca.prev,cb=cb.prev){if(!ca||!cb)return ca==cb;if(ca.tagName!=cb.tagName||ca.indent!=cb.indent)return!1}},electricChars:"/"}}),CodeMirror.defineMIME("text/xml","xml"),CodeMirror.defineMIME("application/xml","xml"),CodeMirror.mimeModes.hasOwnProperty("text/html")||CodeMirror.defineMIME("text/html",{name:"xml",htmlMode:!0})