diff options
author | Jonathan Duran | 2012-07-17 11:42:09 -0700 |
---|---|---|
committer | Jonathan Duran | 2012-07-17 11:42:09 -0700 |
commit | b4b3e45d6684e77d361b4f8ca5be4889428320c5 (patch) | |
tree | 2156d9920ea1b7db49ed6460545fea7cda121bae /imports/codemirror/mode/xml | |
parent | 4a87ff575693509ac578d46af26fa137c0dc3f58 (diff) | |
parent | 4f737b24c19ddc02d20f9783b8b080fc6ef11142 (diff) | |
download | ninja-b4b3e45d6684e77d361b4f8ca5be4889428320c5.tar.gz |
Merge branch 'refs/heads/NINJA-master' into TimelineUber
Diffstat (limited to 'imports/codemirror/mode/xml')
-rw-r--r-- | imports/codemirror/mode/xml/xml.js | 69 |
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 @@ | |||
1 | CodeMirror.defineMode("xml", function(config, parserConfig) { | 1 | CodeMirror.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);} |