diff --git a/changelog_unreleased/html/pr-5959 b/changelog_unreleased/html/pr-5959 new file mode 100644 index 000000000..a55167123 --- /dev/null +++ b/changelog_unreleased/html/pr-5959 @@ -0,0 +1,24 @@ +#### Comments in `pre` tags caused bad formatting of following closing tag ([#5959](https://github.com/prettier/prettier/pull/5959) by [@selvazhagan](https://github.com/selvazhagan)) + + +``` + +
+
+    
+  
+ + +
+
+    
+  
+ + +
+
+    
+  
+
+``` diff --git a/src/language-html/utils.js b/src/language-html/utils.js index 0b7827312..8a9cab05c 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -194,6 +194,7 @@ function isLeadingSpaceSensitiveNode(node) { if ( !node.prev && (node.parent.type === "root" || + (isPreLikeNode(node) && node.parent) || isScriptLikeTag(node.parent) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay)) ) { @@ -235,6 +236,7 @@ function isTrailingSpaceSensitiveNode(node) { if ( !node.next && (node.parent.type === "root" || + (isPreLikeNode(node) && node.parent) || isScriptLikeTag(node.parent) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay)) ) { diff --git a/tests/html_tags/__snapshots__/jsfmt.spec.js.snap b/tests/html_tags/__snapshots__/jsfmt.spec.js.snap index 41f028cc1..7b9b5127e 100644 --- a/tests/html_tags/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_tags/__snapshots__/jsfmt.spec.js.snap @@ -806,6 +806,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -896,6 +905,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -986,6 +1006,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1100,6 +1129,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -1189,6 +1229,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1271,6 +1320,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -1362,6 +1422,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1452,6 +1521,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; @@ -1543,6 +1623,15 @@ ___________________________
+
+

+  
+ +
+  
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1633,6 +1722,17 @@ ___________________________
 
 
+
+

+  
+
+ +
+
+  
+
+
+ ================================================================================ `; diff --git a/tests/html_tags/pre.html b/tests/html_tags/pre.html index 6307de469..05b61de54 100644 --- a/tests/html_tags/pre.html +++ b/tests/html_tags/pre.html @@ -78,3 +78,12 @@ ___________________________

 
 
+ +
+

+  
+ +
+  
+
+