Skip to content

Commit aa82eb9

Browse files
authored
Merge pull request #2101 from lgarron/dont-break-layout
Avoid layout-breaking whitespace by treating all custom elements as inline elements.
2 parents b4fb269 + 1576f0a commit aa82eb9

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

js/src/html/beautifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to g
658658

659659
parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
660660
parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
661-
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_start_char === '{';
661+
parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || parser_token.tag_name.includes("-") || parser_token.tag_start_char === '{';
662662

663663
return parser_token;
664664
};

test/data/html/tests.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3642,6 +3642,46 @@ exports.test_data = {
36423642
'{{/row}}'
36433643
]
36443644
}]
3645+
}, {
3646+
name: "Does not add whitespace around custom elements ",
3647+
description: "Regression test for https://github.com/beautify-web/js-beautify/issues/1989",
3648+
tests: [{
3649+
input: [
3650+
'<span>',
3651+
' <span>',
3652+
' <span>The time for this result is 1:02</span',
3653+
' ><div>.</div',
3654+
' ><section>27</section>',
3655+
' </span>',
3656+
'</span>'
3657+
],
3658+
output: [
3659+
'<span>',
3660+
' <span>',
3661+
' <span>The time for this result is 1:02</span>',
3662+
' <div>.</div>',
3663+
' <section>27</section>',
3664+
' </span>',
3665+
'</span>'
3666+
]
3667+
}, {
3668+
input: [
3669+
'<span>',
3670+
' <span>',
3671+
' <span>The time for this result is 1:02</span',
3672+
' ><time-dot>.</time-dot',
3673+
' ><time-decimals>27</time-decimals>',
3674+
' </span>',
3675+
'</span>'
3676+
],
3677+
output: [
3678+
'<span>',
3679+
' <span>',
3680+
' <span>The time for this result is 1:02</span><time-dot>.</time-dot><time-decimals>27</time-decimals>',
3681+
' </span>',
3682+
'</span>'
3683+
]
3684+
}]
36453685
}, {
36463686
name: "New Test Suite"
36473687
}]

0 commit comments

Comments
 (0)