Skip to content

Commit

Permalink
[formatting addon] Don't line-break around inline tags
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jan 21, 2013
1 parent a14e1e9 commit e4c42b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions addon/format/formatting.js
Expand Up @@ -22,11 +22,17 @@
}
});

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)$/;

CodeMirror.extendMode("xml", {
commentStart: "<!--",
commentEnd: "-->",
newlineAfterToken: function(type, content, textAfter) {
return type == "tag" && />$/.test(content) || /^</.test(textAfter);
newlineAfterToken: function(type, content, textAfter, state) {
var inline = false;
if (this.configuration == "html")
inline = state.context ? inlineElements.test(state.context.tagName) : false;
return !inline && ((type == "tag" && />$/.test(content) && state.context) ||
/^</.test(textAfter));
}
});

Expand Down
2 changes: 1 addition & 1 deletion demo/formatting.html
Expand Up @@ -29,7 +29,7 @@ <h1>CodeMirror: Formatting demo</h1>
function test(c){ for (var i = 0; i < 10; i++){ process("a.b();c = null;", 300);}
}
</script>
<table><tr><td>test 1</td></tr><tr><td>test 2</td></tr></table>
<table><tr><td>test 1</td></tr><tr><td>test <strong>2</strong></td></tr></table>
<script> function test() { return 1;} </script>
<style> .test { font-size: medium; font-family: monospace; }
</style></textarea></form>
Expand Down

0 comments on commit e4c42b5

Please sign in to comment.