Skip to content

Commit e4c42b5

Browse files
committed
[formatting addon] Don't line-break around inline tags
1 parent a14e1e9 commit e4c42b5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

addon/format/formatting.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
}
2323
});
2424

25+
var inlineElements = /^(a|abbr|acronym|area|base|bdo|big|br|button|caption|cite|code|col|colgroup|dd|del|dfn|em|frame|hr|iframe|img|input|ins|kbd|label|legend|link|map|object|optgroup|option|param|q|samp|script|select|small|span|strong|sub|sup|textarea|tt|var)$/;
26+
2527
CodeMirror.extendMode("xml", {
2628
commentStart: "<!--",
2729
commentEnd: "-->",
28-
newlineAfterToken: function(type, content, textAfter) {
29-
return type == "tag" && />$/.test(content) || /^</.test(textAfter);
30+
newlineAfterToken: function(type, content, textAfter, state) {
31+
var inline = false;
32+
if (this.configuration == "html")
33+
inline = state.context ? inlineElements.test(state.context.tagName) : false;
34+
return !inline && ((type == "tag" && />$/.test(content) && state.context) ||
35+
/^</.test(textAfter));
3036
}
3137
});
3238

demo/formatting.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h1>CodeMirror: Formatting demo</h1>
2929
function test(c){ for (var i = 0; i < 10; i++){ process("a.b();c = null;", 300);}
3030
}
3131
</script>
32-
<table><tr><td>test 1</td></tr><tr><td>test 2</td></tr></table>
32+
<table><tr><td>test 1</td></tr><tr><td>test <strong>2</strong></td></tr></table>
3333
<script> function test() { return 1;} </script>
3434
<style> .test { font-size: medium; font-family: monospace; }
3535
</style></textarea></form>

0 commit comments

Comments
 (0)