Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/dtd/dtd.js
1293 views
/*1DTD mode2Ported to CodeMirror by Peter Kroon <[email protected]>3Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues4GitHub: @peterkroon5*/67CodeMirror.defineMode("dtd", function(config) {8var indentUnit = config.indentUnit, type;9function ret(style, tp) {type = tp; return style;}1011function tokenBase(stream, state) {12var ch = stream.next();1314if (ch == "<" && stream.eat("!") ) {15if (stream.eatWhile(/[\-]/)) {16state.tokenize = tokenSGMLComment;17return tokenSGMLComment(stream, state);18} else if (stream.eatWhile(/[\w]/)) return ret("keyword", "doindent");19} else if (ch == "<" && stream.eat("?")) { //xml declaration20state.tokenize = inBlock("meta", "?>");21return ret("meta", ch);22} else if (ch == "#" && stream.eatWhile(/[\w]/)) return ret("atom", "tag");23else if (ch == "|") return ret("keyword", "seperator");24else if (ch.match(/[\(\)\[\]\-\.,\+\?>]/)) return ret(null, ch);//if(ch === ">") return ret(null, "endtag"); else25else if (ch.match(/[\[\]]/)) return ret("rule", ch);26else if (ch == "\"" || ch == "'") {27state.tokenize = tokenString(ch);28return state.tokenize(stream, state);29} else if (stream.eatWhile(/[a-zA-Z\?\+\d]/)) {30var sc = stream.current();31if( sc.substr(sc.length-1,sc.length).match(/\?|\+/) !== null )stream.backUp(1);32return ret("tag", "tag");33} else if (ch == "%" || ch == "*" ) return ret("number", "number");34else {35stream.eatWhile(/[\w\\\-_%.{,]/);36return ret(null, null);37}38}3940function tokenSGMLComment(stream, state) {41var dashes = 0, ch;42while ((ch = stream.next()) != null) {43if (dashes >= 2 && ch == ">") {44state.tokenize = tokenBase;45break;46}47dashes = (ch == "-") ? dashes + 1 : 0;48}49return ret("comment", "comment");50}5152function tokenString(quote) {53return function(stream, state) {54var escaped = false, ch;55while ((ch = stream.next()) != null) {56if (ch == quote && !escaped) {57state.tokenize = tokenBase;58break;59}60escaped = !escaped && ch == "\\";61}62return ret("string", "tag");63};64}6566function inBlock(style, terminator) {67return function(stream, state) {68while (!stream.eol()) {69if (stream.match(terminator)) {70state.tokenize = tokenBase;71break;72}73stream.next();74}75return style;76};77}7879return {80startState: function(base) {81return {tokenize: tokenBase,82baseIndent: base || 0,83stack: []};84},8586token: function(stream, state) {87if (stream.eatSpace()) return null;88var style = state.tokenize(stream, state);8990var context = state.stack[state.stack.length-1];91if (stream.current() == "[" || type === "doindent" || type == "[") state.stack.push("rule");92else if (type === "endtag") state.stack[state.stack.length-1] = "endtag";93else if (stream.current() == "]" || type == "]" || (type == ">" && context == "rule")) state.stack.pop();94else if (type == "[") state.stack.push("[");95return style;96},9798indent: function(state, textAfter) {99var n = state.stack.length;100101if( textAfter.match(/\]\s+|\]/) )n=n-1;102else if(textAfter.substr(textAfter.length-1, textAfter.length) === ">"){103if(textAfter.substr(0,1) === "<")n;104else if( type == "doindent" && textAfter.length > 1 )n;105else if( type == "doindent")n--;106else if( type == ">" && textAfter.length > 1)n;107else if( type == "tag" && textAfter !== ">")n;108else if( type == "tag" && state.stack[state.stack.length-1] == "rule")n--;109else if( type == "tag")n++;110else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule" && type === ">")n--;111else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule")n;112else if( textAfter.substr(0,1) !== "<" && textAfter.substr(0,1) === ">" )n=n-1;113else if( textAfter === ">")n;114else n=n-1;115//over rule them all116if(type == null || type == "]")n--;117}118119return state.baseIndent + n * indentUnit;120},121122electricChars: "]>"123};124});125126CodeMirror.defineMIME("application/xml-dtd", "dtd");127128129