vendor/assets/javascripts/codemirror/modes/xml.js in codemirror-rails-3.14 vs vendor/assets/javascripts/codemirror/modes/xml.js in codemirror-rails-3.15
- old
+ new
@@ -1,8 +1,9 @@
CodeMirror.defineMode("xml", function(config, parserConfig) {
var indentUnit = config.indentUnit;
var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1;
+ var multilineTagIndentPastTag = parserConfig.multilineTagIndentPastTag || true;
var Kludges = parserConfig.htmlMode ? {
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
@@ -109,27 +110,30 @@
return null;
} else if (ch == "<") {
return "error";
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
+ state.stringStartCol = stream.column();
return state.tokenize(stream, state);
} else {
stream.eatWhile(/[^\s\u00a0=<>\"\']/);
return "word";
}
}
function inAttribute(quote) {
- return function(stream, state) {
+ var closure = function(stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
};
+ closure.isInAttribute = true;
+ return closure;
}
function inBlock(style, terminator) {
return function(stream, state) {
while (!stream.eol()) {
@@ -297,14 +301,24 @@
return setStyle || style;
},
indent: function(state, textAfter, fullLine) {
var context = state.context;
+ // Indent multi-line strings (e.g. css).
+ if (state.tokenize.isInAttribute) {
+ return state.stringStartCol + 1;
+ }
if ((state.tokenize != inTag && state.tokenize != inText) ||
context && context.noIndent)
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
- if (state.tagName) return state.tagStart + indentUnit * multilineTagIndentFactor;
+ // Indent the starts of attribute names.
+ if (state.tagName) {
+ if (multilineTagIndentPastTag)
+ return state.tagStart + state.tagName.length + 2;
+ else
+ return state.tagStart + indentUnit * multilineTagIndentFactor;
+ }
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
if (context && /^<\//.test(textAfter))
context = context.prev;
while (context && !context.startOfLine)
context = context.prev;
@@ -314,10 +328,11 @@
electricChars: "/",
blockCommentStart: "<!--",
blockCommentEnd: "-->",
- configuration: parserConfig.htmlMode ? "html" : "xml"
+ configuration: parserConfig.htmlMode ? "html" : "xml",
+ helperType: parserConfig.htmlMode ? "html" : "xml"
};
});
CodeMirror.defineMIME("text/xml", "xml");
CodeMirror.defineMIME("application/xml", "xml");