aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/xml
diff options
context:
space:
mode:
authorValerio Virgillito2012-07-17 11:29:09 -0700
committerValerio Virgillito2012-07-17 11:29:09 -0700
commit58e86247524cc2d545bd6884f1b5c9fdba3b9164 (patch)
tree53305d354fce502ee39378babf47ace6c91ce2fd /imports/codemirror/mode/xml
parent0f0cffd4df85e7adf5081fe66c768c70b2ead9b3 (diff)
parent4f737b24c19ddc02d20f9783b8b080fc6ef11142 (diff)
downloadninja-58e86247524cc2d545bd6884f1b5c9fdba3b9164.tar.gz
Merge branch 'refs/heads/master' into v0.7.1
Diffstat (limited to 'imports/codemirror/mode/xml')
-rw-r--r--imports/codemirror/mode/xml/xml.js69
1 files changed, 63 insertions, 6 deletions
diff --git a/imports/codemirror/mode/xml/xml.js b/imports/codemirror/mode/xml/xml.js
index d8f17efb..3fbe98f9 100644
--- a/imports/codemirror/mode/xml/xml.js
+++ b/imports/codemirror/mode/xml/xml.js
@@ -1,12 +1,44 @@
1CodeMirror.defineMode("xml", function(config, parserConfig) { 1CodeMirror.defineMode("xml", function(config, parserConfig) {
2 var indentUnit = config.indentUnit; 2 var indentUnit = config.indentUnit;
3 var Kludges = parserConfig.htmlMode ? { 3 var Kludges = parserConfig.htmlMode ? {
4 autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true, 4 autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
5 "meta": true, "col": true, "frame": true, "base": true, "area": true}, 5 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
6 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
7 'track': true, 'wbr': true},
8 implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
9 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
10 'th': true, 'tr': true},
11 contextGrabbers: {
12 'dd': {'dd': true, 'dt': true},
13 'dt': {'dd': true, 'dt': true},
14 'li': {'li': true},
15 'option': {'option': true, 'optgroup': true},
16 'optgroup': {'optgroup': true},
17 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
18 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
19 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
20 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
21 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
22 'rp': {'rp': true, 'rt': true},
23 'rt': {'rp': true, 'rt': true},
24 'tbody': {'tbody': true, 'tfoot': true},
25 'td': {'td': true, 'th': true},
26 'tfoot': {'tbody': true},
27 'th': {'td': true, 'th': true},
28 'thead': {'tbody': true, 'tfoot': true},
29 'tr': {'tr': true}
30 },
6 doNotIndent: {"pre": true}, 31 doNotIndent: {"pre": true},
7 allowUnquoted: true, 32 allowUnquoted: true,
8 allowMissing: false 33 allowMissing: false
9 } : {autoSelfClosers: {}, doNotIndent: {}, allowUnquoted: false, allowMissing: false}; 34 } : {
35 autoSelfClosers: {},
36 implicitlyClosed: {},
37 contextGrabbers: {},
38 doNotIndent: {},
39 allowUnquoted: false,
40 allowMissing: false
41 };
10 var alignCDATA = parserConfig.alignCDATA; 42 var alignCDATA = parserConfig.alignCDATA;
11 43
12 // Return variables for tokenizers 44 // Return variables for tokenizers
@@ -162,7 +194,12 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
162 } else if (type == "closeTag") { 194 } else if (type == "closeTag") {
163 var err = false; 195 var err = false;
164 if (curState.context) { 196 if (curState.context) {
165 err = curState.context.tagName != tagName; 197 if (curState.context.tagName != tagName) {
198 if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
199 popContext();
200 }
201 err = !curState.context || curState.context.tagName != tagName;
202 }
166 } else { 203 } else {
167 err = true; 204 err = true;
168 } 205 }
@@ -174,9 +211,15 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
174 function endtag(startOfLine) { 211 function endtag(startOfLine) {
175 return function(type) { 212 return function(type) {
176 if (type == "selfcloseTag" || 213 if (type == "selfcloseTag" ||
177 (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase()))) 214 (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase()))) {
215 maybePopContext(curState.tagName.toLowerCase());
216 return cont();
217 }
218 if (type == "endTag") {
219 maybePopContext(curState.tagName.toLowerCase());
220 pushContext(curState.tagName, startOfLine);
178 return cont(); 221 return cont();
179 if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();} 222 }
180 return cont(); 223 return cont();
181 }; 224 };
182 } 225 }
@@ -188,6 +231,20 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
188 return cont(arguments.callee); 231 return cont(arguments.callee);
189 } 232 }
190 } 233 }
234 function maybePopContext(nextTagName) {
235 var parentTagName;
236 while (true) {
237 if (!curState.context) {
238 return;
239 }
240 parentTagName = curState.context.tagName.toLowerCase();
241 if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
242 !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
243 return;
244 }
245 popContext();
246 }
247 }
191 248
192 function attributes(type) { 249 function attributes(type) {
193 if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);} 250 if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);}