Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/dtd/dtd.js
1293 views
1
/*
2
DTD mode
3
Ported to CodeMirror by Peter Kroon <[email protected]>
4
Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues
5
GitHub: @peterkroon
6
*/
7
8
CodeMirror.defineMode("dtd", function(config) {
9
var indentUnit = config.indentUnit, type;
10
function ret(style, tp) {type = tp; return style;}
11
12
function tokenBase(stream, state) {
13
var ch = stream.next();
14
15
if (ch == "<" && stream.eat("!") ) {
16
if (stream.eatWhile(/[\-]/)) {
17
state.tokenize = tokenSGMLComment;
18
return tokenSGMLComment(stream, state);
19
} else if (stream.eatWhile(/[\w]/)) return ret("keyword", "doindent");
20
} else if (ch == "<" && stream.eat("?")) { //xml declaration
21
state.tokenize = inBlock("meta", "?>");
22
return ret("meta", ch);
23
} else if (ch == "#" && stream.eatWhile(/[\w]/)) return ret("atom", "tag");
24
else if (ch == "|") return ret("keyword", "seperator");
25
else if (ch.match(/[\(\)\[\]\-\.,\+\?>]/)) return ret(null, ch);//if(ch === ">") return ret(null, "endtag"); else
26
else if (ch.match(/[\[\]]/)) return ret("rule", ch);
27
else if (ch == "\"" || ch == "'") {
28
state.tokenize = tokenString(ch);
29
return state.tokenize(stream, state);
30
} else if (stream.eatWhile(/[a-zA-Z\?\+\d]/)) {
31
var sc = stream.current();
32
if( sc.substr(sc.length-1,sc.length).match(/\?|\+/) !== null )stream.backUp(1);
33
return ret("tag", "tag");
34
} else if (ch == "%" || ch == "*" ) return ret("number", "number");
35
else {
36
stream.eatWhile(/[\w\\\-_%.{,]/);
37
return ret(null, null);
38
}
39
}
40
41
function tokenSGMLComment(stream, state) {
42
var dashes = 0, ch;
43
while ((ch = stream.next()) != null) {
44
if (dashes >= 2 && ch == ">") {
45
state.tokenize = tokenBase;
46
break;
47
}
48
dashes = (ch == "-") ? dashes + 1 : 0;
49
}
50
return ret("comment", "comment");
51
}
52
53
function tokenString(quote) {
54
return function(stream, state) {
55
var escaped = false, ch;
56
while ((ch = stream.next()) != null) {
57
if (ch == quote && !escaped) {
58
state.tokenize = tokenBase;
59
break;
60
}
61
escaped = !escaped && ch == "\\";
62
}
63
return ret("string", "tag");
64
};
65
}
66
67
function inBlock(style, terminator) {
68
return function(stream, state) {
69
while (!stream.eol()) {
70
if (stream.match(terminator)) {
71
state.tokenize = tokenBase;
72
break;
73
}
74
stream.next();
75
}
76
return style;
77
};
78
}
79
80
return {
81
startState: function(base) {
82
return {tokenize: tokenBase,
83
baseIndent: base || 0,
84
stack: []};
85
},
86
87
token: function(stream, state) {
88
if (stream.eatSpace()) return null;
89
var style = state.tokenize(stream, state);
90
91
var context = state.stack[state.stack.length-1];
92
if (stream.current() == "[" || type === "doindent" || type == "[") state.stack.push("rule");
93
else if (type === "endtag") state.stack[state.stack.length-1] = "endtag";
94
else if (stream.current() == "]" || type == "]" || (type == ">" && context == "rule")) state.stack.pop();
95
else if (type == "[") state.stack.push("[");
96
return style;
97
},
98
99
indent: function(state, textAfter) {
100
var n = state.stack.length;
101
102
if( textAfter.match(/\]\s+|\]/) )n=n-1;
103
else if(textAfter.substr(textAfter.length-1, textAfter.length) === ">"){
104
if(textAfter.substr(0,1) === "<")n;
105
else if( type == "doindent" && textAfter.length > 1 )n;
106
else if( type == "doindent")n--;
107
else if( type == ">" && textAfter.length > 1)n;
108
else if( type == "tag" && textAfter !== ">")n;
109
else if( type == "tag" && state.stack[state.stack.length-1] == "rule")n--;
110
else if( type == "tag")n++;
111
else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule" && type === ">")n--;
112
else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule")n;
113
else if( textAfter.substr(0,1) !== "<" && textAfter.substr(0,1) === ">" )n=n-1;
114
else if( textAfter === ">")n;
115
else n=n-1;
116
//over rule them all
117
if(type == null || type == "]")n--;
118
}
119
120
return state.baseIndent + n * indentUnit;
121
},
122
123
electricChars: "]>"
124
};
125
});
126
127
CodeMirror.defineMIME("application/xml-dtd", "dtd");
128
129