From 9e394f9762795c10644effa42d4e76cea8316294 Mon Sep 17 00:00:00 2001
From: "Joey@macstudio" <4296411@qq.com>
Date: Mon, 17 Aug 2026 17:54:02 +0800
Subject: [PATCH] html: preserve newline before closing bracket
---
js/src/html/beautifier.js | 2 ++
test/data/html/tests.js | 43 +++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js
index 5e535a5ba..ffc6944bf 100644
--- a/js/src/html/beautifier.js
+++ b/js/src/html/beautifier.js
@@ -378,6 +378,8 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
printer.print_newline(false);
+ } else if (this._is_wrap_attributes_preserve && raw_token.newlines) {
+ printer.print_preserved_newlines(raw_token);
}
}
printer.print_token(raw_token);
diff --git a/test/data/html/tests.js b/test/data/html/tests.js
index caae9bd5d..d6097297e 100644
--- a/test/data/html/tests.js
+++ b/test/data/html/tests.js
@@ -1206,6 +1206,49 @@ exports.test_data = {
'^^^indent_attr$$$(typeaheadOnSelect)="onSuggestionSelected($event)" />'
]
}]
+ }, {
+ name: "Issue #1707 -- Preserve newline before closing bracket",
+ description: "",
+ template: "^^^ $$$",
+ matrix: [{
+ options: [
+ { name: "wrap_attributes", value: "'preserve-aligned'" }
+ ],
+ indent_attr: ' '
+ }, {
+ options: [
+ { name: "wrap_attributes", value: "'preserve'" }
+ ],
+ indent_attr: ' '
+ }],
+ tests: [{
+ input: [
+ 'content'
+ ],
+ output: [
+ 'content'
+ ]
+ }, {
+ input: [
+ '
'
+ ],
+ output: [
+ '
'
+ ]
+ }, {
+ fragment: true,
+ unchanged: 'content'
+ }]
}, {
name: "Test wrap_attributes_min_attrs with force/force-xx options",
description: "",