Skip to content

Commit 63f7ce2

Browse files
committed
[xml mode] Fix zero-indentation for CDATA blocks
1 parent 5ca3d9b commit 63f7ce2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

mode/xml/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ <h1>CodeMirror 2: XML mode</h1>
2424
</textarea></form>
2525
<script>
2626
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
27-
mode: {name: "xml", htmlMode: true},
27+
mode: {name: "xml", alignCDATA: true},
2828
lineNumbers: true
2929
});
3030
</script>

mode/xml/xml.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
2121
if (ch == "<") {
2222
if (stream.eat("!")) {
2323
if (stream.eat("[")) {
24-
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
24+
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>", "!cdata"));
2525
else return null;
2626
}
2727
else if (stream.match("--")) return chain(inBlock("comment", "-->"));
@@ -90,7 +90,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
9090
};
9191
}
9292

93-
function inBlock(style, terminator) {
93+
function inBlock(style, terminator, tp) {
9494
return function(stream, state) {
9595
while (!stream.eol()) {
9696
if (stream.match(terminator)) {
@@ -99,6 +99,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
9999
}
100100
stream.next();
101101
}
102+
type = tp;
102103
return style;
103104
};
104105
}
@@ -158,7 +159,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
158159
if (err) setStyle = "error";
159160
return cont(endclosetag(err));
160161
}
161-
else if (type == "string") {
162+
else if (type == "!cdata") {
162163
if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata");
163164
if (curState.tokenize == inText) popContext();
164165
return cont();

0 commit comments

Comments
 (0)