Skip to content

Commit 9e394f9

Browse files
committed
html: preserve newline before closing bracket
1 parent 4f52c49 commit 9e394f9

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

js/src/html/beautifier.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
378378
printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
379379
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
380380
printer.print_newline(false);
381+
} else if (this._is_wrap_attributes_preserve && raw_token.newlines) {
382+
printer.print_preserved_newlines(raw_token);
381383
}
382384
}
383385
printer.print_token(raw_token);

test/data/html/tests.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,49 @@ exports.test_data = {
12061206
'^^^indent_attr$$$(typeaheadOnSelect)="onSuggestionSelected($event)" />'
12071207
]
12081208
}]
1209+
}, {
1210+
name: "Issue #1707 -- Preserve newline before closing bracket",
1211+
description: "",
1212+
template: "^^^ $$$",
1213+
matrix: [{
1214+
options: [
1215+
{ name: "wrap_attributes", value: "'preserve-aligned'" }
1216+
],
1217+
indent_attr: ' '
1218+
}, {
1219+
options: [
1220+
{ name: "wrap_attributes", value: "'preserve'" }
1221+
],
1222+
indent_attr: ' '
1223+
}],
1224+
tests: [{
1225+
input: [
1226+
'<tag',
1227+
' attr1="val1"',
1228+
' attr2="val2"',
1229+
'>content</tag>'
1230+
],
1231+
output: [
1232+
'<tag',
1233+
'^^^indent_attr$$$attr1="val1"',
1234+
'^^^indent_attr$$$attr2="val2"',
1235+
'>content</tag>'
1236+
]
1237+
}, {
1238+
input: [
1239+
'<img',
1240+
' src="image.png"',
1241+
'/>'
1242+
],
1243+
output: [
1244+
'<img',
1245+
'^^^indent_attr$$$src="image.png"',
1246+
'/>'
1247+
]
1248+
}, {
1249+
fragment: true,
1250+
unchanged: '<tag attr="value">content</tag>'
1251+
}]
12091252
}, {
12101253
name: "Test wrap_attributes_min_attrs with force/force-xx options",
12111254
description: "",

0 commit comments

Comments
 (0)