aboutsummaryrefslogtreecommitdiff
path: root/js/codemirror/mode/xml/xml.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/codemirror/mode/xml/xml.js')
-rw-r--r--js/codemirror/mode/xml/xml.js231
1 files changed, 0 insertions, 231 deletions
diff --git a/js/codemirror/mode/xml/xml.js b/js/codemirror/mode/xml/xml.js
deleted file mode 100644
index b992964b..00000000
--- a/js/codemirror/mode/xml/xml.js
+++ /dev/null
@@ -1,231 +0,0 @@
1CodeMirror.defineMode("xml", function(config, parserConfig) {
2 var indentUnit = config.indentUnit;
3 var Kludges = parserConfig.htmlMode ? {
4 autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
5 "meta": true, "col": true, "frame": true, "base": true, "area": true},
6 doNotIndent: {"pre": true, "!cdata": true},
7 allowUnquoted: true
8 } : {autoSelfClosers: {}, doNotIndent: {"!cdata": true}, allowUnquoted: false};
9 var alignCDATA = parserConfig.alignCDATA;
10
11 // Return variables for tokenizers
12 var tagName, type;
13
14 function inText(stream, state) {
15 function chain(parser) {
16 state.tokenize = parser;
17 return parser(stream, state);
18 }
19
20 var ch = stream.next();
21 if (ch == "<") {
22 if (stream.eat("!")) {
23 if (stream.eat("[")) {
24 if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
25 else return null;
26 }
27 else if (stream.match("--")) return chain(inBlock("comment", "-->"));
28 else if (stream.match("DOCTYPE", true, true)) {
29 stream.eatWhile(/[\w\._\-]/);
30 return chain(inBlock("meta", ">"));
31 }
32 else return null;
33 }
34 else if (stream.eat("?")) {
35 stream.eatWhile(/[\w\._\-]/);
36 state.tokenize = inBlock("meta", "?>");
37 return "meta";
38 }
39 else {
40 type = stream.eat("/") ? "closeTag" : "openTag";
41 stream.eatSpace();
42 tagName = "";
43 var c;
44 while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
45 state.tokenize = inTag;
46 return "tag";
47 }
48 }
49 else if (ch == "&") {
50 stream.eatWhile(/[^;]/);
51 stream.eat(";");
52 return "atom";
53 }
54 else {
55 stream.eatWhile(/[^&<]/);
56 return null;
57 }
58 }
59
60 function inTag(stream, state) {
61 var ch = stream.next();
62 if (ch == ">" || (ch == "/" && stream.eat(">"))) {
63 state.tokenize = inText;
64 type = ch == ">" ? "endTag" : "selfcloseTag";
65 return "tag";
66 }
67 else if (ch == "=") {
68 type = "equals";
69 return null;
70 }
71 else if (/[\'\"]/.test(ch)) {
72 state.tokenize = inAttribute(ch);
73 return state.tokenize(stream, state);
74 }
75 else {
76 stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
77 return "word";
78 }
79 }
80
81 function inAttribute(quote) {
82 return function(stream, state) {
83 while (!stream.eol()) {
84 if (stream.next() == quote) {
85 state.tokenize = inTag;
86 break;
87 }
88 }
89 return "string";
90 };
91 }
92
93 function inBlock(style, terminator) {
94 return function(stream, state) {
95 while (!stream.eol()) {
96 if (stream.match(terminator)) {
97 state.tokenize = inText;
98 break;
99 }
100 stream.next();
101 }
102 return style;
103 };
104 }
105
106 var curState, setStyle;
107 function pass() {
108 for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
109 }
110 function cont() {
111 pass.apply(null, arguments);
112 return true;
113 }
114
115 function pushContext(tagName, startOfLine) {
116 var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
117 curState.context = {
118 prev: curState.context,
119 tagName: tagName,
120 indent: curState.indented,
121 startOfLine: startOfLine,
122 noIndent: noIndent
123 };
124 }
125 function popContext() {
126 if (curState.context) curState.context = curState.context.prev;
127 }
128
129 function element(type) {
130 if (type == "openTag") {curState.tagName = tagName; return cont(attributes, endtag(curState.startOfLine));}
131 else if (type == "closeTag") {
132 var err = false;
133 if (curState.context) {
134 err = curState.context.tagName != tagName;
135 popContext();
136 } else {
137 err = true;
138 }
139 if (err) setStyle = "error";
140 return cont(endclosetag(err));
141 }
142 else if (type == "string") {
143 if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
144 if (curState.tokenize == inText) popContext();
145 return cont();
146 }
147 else return cont();
148 }
149 function endtag(startOfLine) {
150 return function(type) {
151 if (type == "selfcloseTag" ||
152 (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
153 return cont();
154 if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
155 return cont();
156 };
157 }
158 function endclosetag(err) {
159 return function(type) {
160 if (err) setStyle = "error";
161 if (type == "endTag") return cont();
162 return pass();
163 }
164 }
165
166 function attributes(type) {
167 if (type == "word") {setStyle = "attribute"; return cont(attributes);}
168 if (type == "equals") return cont(attvalue, attributes);
169 return pass();
170 }
171 function attvalue(type) {
172 if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
173 if (type == "string") return cont(attvaluemaybe);
174 return pass();
175 }
176 function attvaluemaybe(type) {
177 if (type == "string") return cont(attvaluemaybe);
178 else return pass();
179 }
180
181 return {
182 startState: function() {
183 return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
184 },
185
186 token: function(stream, state) {
187 if (stream.sol()) {
188 state.startOfLine = true;
189 state.indented = stream.indentation();
190 }
191 if (stream.eatSpace()) return null;
192
193 setStyle = type = tagName = null;
194 var style = state.tokenize(stream, state);
195 if ((style || type) && style != "comment") {
196 curState = state;
197 while (true) {
198 var comb = state.cc.pop() || element;
199 if (comb(type || style)) break;
200 }
201 }
202 state.startOfLine = false;
203 return setStyle || style;
204 },
205
206 indent: function(state, textAfter) {
207 var context = state.context;
208 if (context && context.noIndent) return 0;
209 if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
210 if (context && /^<\//.test(textAfter))
211 context = context.prev;
212 while (context && !context.startOfLine)
213 context = context.prev;
214 if (context) return context.indent + indentUnit;
215 else return 0;
216 },
217
218 compareStates: function(a, b) {
219 if (a.indented != b.indented || a.tagName != b.tagName) return false;
220 for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
221 if (!ca || !cb) return ca == cb;
222 if (ca.tagName != cb.tagName) return false;
223 }
224 },
225
226 electricChars: "/"
227 };
228});
229
230CodeMirror.defineMIME("application/xml", "xml");
231CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});