Skip to content

Commit

Permalink
Add newline for block end tag with multiline child
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-zeyu committed Jul 19, 2020
1 parent 491d69a commit 9d0d14b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
13 changes: 9 additions & 4 deletions js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,12 +734,17 @@ Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_tok
}
}

if (!parser_token.is_inline_element && last_token.type !== 'TK_CONTENT') {
if (parser_token.parent) {
parser_token.parent.multiline_content = true;
}
var do_set_parent_multiline;
if (parser_token.is_inline_element) {
do_set_parent_multiline = raw_token.newlines && parser_token.parent && !parser_token.parent.is_inline_element;
} else if (last_token.type !== 'TK_CONTENT') {
do_set_parent_multiline = parser_token.parent;
printer.print_newline(false);
}

if (do_set_parent_multiline) {
parser_token.parent.multiline_content = true;
}
}
};

Expand Down
15 changes: 15 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" x="0" y="0" viewBox="0 0 900 710" width="100%" height="100%">\n' +
' <circle id="mycircle" cx="182.901" cy="91.4841" style="fill:rosybrown;stroke:black;stroke-width:1px;" r="48" />\n' +
'</svg>');
test_fragment(
'<div class="col-xs-2">\n' +
'<input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" />\n' +
'<label for="coli" class="control-label">Collision</label></div>',
// -- output --
'<div class="col-xs-2">\n' +
' <input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" />\n' +
' <label for="coli" class="control-label">Collision</label>\n' +
'</div>');
test_fragment(
'<label class="col-xs-2">Collision\n' +
'<input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" /></label>',
// -- output --
'<label class="col-xs-2">Collision\n' +
' <input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" /></label>');


//============================================================
Expand Down
25 changes: 25 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ exports.test_data = {
' <circle id="mycircle" cx="182.901" cy="91.4841" style="fill:rosybrown;stroke:black;stroke-width:1px;" r="48" />',
'</svg>'
]
}, {
// Issue #1365 -- Inline tags with newlines should break block parent ending tags into another line
fragment: true,
input: [
'<div class="col-xs-2">',
'<input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" />',
'<label for="coli" class="control-label">Collision</label></div>'
],
output: [
'<div class="col-xs-2">',
' <input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" />',
' <label for="coli" class="control-label">Collision</label>',
'</div>'
]
}, {
// Issue #1365 -- Inline tags with newlines should not break inline parent ending tags into another line
fragment: true,
input: [
'<label class="col-xs-2">Collision',
'<input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" /></label>'
],
output: [
'<label class="col-xs-2">Collision',
' <input type="radio" class="control-label" ng-disabled="!col" ng-model="col" value="2" class="form-control" id="coli" name="coli" /></label>'
]
}]
}, {
name: "End With Newline",
Expand Down

0 comments on commit 9d0d14b

Please sign in to comment.