diff --git a/changelog_unreleased/html/19046.md b/changelog_unreleased/html/19046.md new file mode 100644 index 000000000..cfddbf83a --- /dev/null +++ b/changelog_unreleased/html/19046.md @@ -0,0 +1,26 @@ +#### Fix closing tag of pre-like elements being split across lines (#19046 by @kovsu) + + +```html + +
+
+  Content
+
+
+ + +
+
+  Content
+
+
+ + +
+
+  Content
+
+
+``` diff --git a/src/language-html/print/element.js b/src/language-html/print/element.js index b8826d647..8489ab7eb 100644 --- a/src/language-html/print/element.js +++ b/src/language-html/print/element.js @@ -12,6 +12,7 @@ import { import getNodeContent from "../get-node-content.js"; import { forceBreakContent, + isPreLikeNode, isScriptLikeTag, isVueCustomBlock, shouldPreserveContent, @@ -19,6 +20,7 @@ import { import { printChildren } from "./children.js"; import { needsToBorrowLastChildClosingTagEndMarker, + needsToBorrowParentClosingTagStartMarker, needsToBorrowPrevClosingTagEndMarker, printClosingTag, printClosingTagSuffix, @@ -124,6 +126,12 @@ function printElement(path, options, print) { } return ""; } + if ( + isPreLikeNode(node) && + needsToBorrowParentClosingTagStartMarker(node.lastChild) + ) { + return ""; + } if (shouldHugContent) { return ifBreak(softline, "", { groupId: attrGroupId }); } diff --git a/tests/format/angular/angular/__snapshots__/format.test.js.snap b/tests/format/angular/angular/__snapshots__/format.test.js.snap index eefc2db08..60eab7b43 100644 --- a/tests/format/angular/angular/__snapshots__/format.test.js.snap +++ b/tests/format/angular/angular/__snapshots__/format.test.js.snap @@ -2104,45 +2104,37 @@ parsers: ["angular"] +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 ================================================================================ `; @@ -2196,45 +2188,37 @@ parsers: ["angular"] +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 ================================================================================ `; @@ -2286,127 +2270,107 @@ printWidth: 1 + }} + }} + }} + }} + }} + }}123 + }}123 + }}123 + }}123 + }}123 + }} + }} + }} + }} + }} + }}123 + }}123 + }}123 + }}123 + }}123 ================================================================================ `; @@ -2460,45 +2424,37 @@ trailingComma: "es5" +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 ================================================================================ `; @@ -2552,45 +2508,37 @@ trailingComma: "none" +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 +{{ generatedDiscountCodes }} + {{ generatedDiscountCodes }} +{{ generatedDiscountCodes }}123 + {{ generatedDiscountCodes }}123 ================================================================================ `; diff --git a/tests/format/html/basics/__snapshots__/format.test.js.snap b/tests/format/html/basics/__snapshots__/format.test.js.snap index fe99c7005..9b2854dc9 100644 --- a/tests/format/html/basics/__snapshots__/format.test.js.snap +++ b/tests/format/html/basics/__snapshots__/format.test.js.snap @@ -718,12 +718,10 @@ e-wrap
block
  pre pr
-e
+e +e-wrap looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline @@ -758,12 +756,10 @@ e-wrap block
  pre pr
-e
+e +e-wrap looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline @@ -798,12 +794,10 @@ e-wrap block
  pre pr
-e
+e +e-wrap looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline @@ -838,12 +832,10 @@ e-wrap block
  pre pr
-e
+e +e-wrap looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline @@ -878,12 +870,10 @@ e-wrap block
  pre pr
-e
+e +e-wrap looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline diff --git a/tests/format/html/tags/__snapshots__/format.test.js.snap b/tests/format/html/tags/__snapshots__/format.test.js.snap index c3fe12f87..01568fb95 100644 --- a/tests/format/html/tags/__snapshots__/format.test.js.snap +++ b/tests/format/html/tags/__snapshots__/format.test.js.snap @@ -1307,6 +1307,13 @@ ___________________________

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1420,6 +1427,13 @@ ___________________________
 

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ ================================================================================ `; @@ -1531,6 +1545,13 @@ ___________________________

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1644,6 +1665,13 @@ ___________________________
 

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ ================================================================================ `; @@ -1754,6 +1782,13 @@ ___________________________

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -1857,6 +1892,13 @@ ___________________________
 

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ ================================================================================ `; @@ -1968,6 +2010,13 @@ ___________________________

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -2007,8 +2056,7 @@ ___________________________
 
 
-     Foo     Bar     
+ Foo Bar
      Foo     Bar
 
@@ -2016,8 +2064,7 @@ ___________________________ Foo Bar
-     Foo     Bar
+ Foo Bar

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ ================================================================================ `; @@ -2215,6 +2269,13 @@ ___________________________

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ =====================================output=====================================
 --------------------------------------------------------------------------------
@@ -2328,6 +2389,13 @@ ___________________________
 

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ +
+
+  Content
+
+
+ ================================================================================ `; @@ -5119,8 +5187,7 @@ printWidth: 1
+lorem ipsum
================================================================================ diff --git a/tests/format/html/tags/pre.html b/tests/format/html/tags/pre.html index 0c026accd..17ec09c29 100644 --- a/tests/format/html/tags/pre.html +++ b/tests/format/html/tags/pre.html @@ -99,3 +99,10 @@ ___________________________

long long long text long long long text long long long text long long long text

long long long text long long long text long long long text long long long text
+ + +
+
+  Content
+
+
diff --git a/tests/format/vue/vue/__snapshots__/format.test.js.snap b/tests/format/vue/vue/__snapshots__/format.test.js.snap index 9d4bbeb78..b398c9691 100644 --- a/tests/format/vue/vue/__snapshots__/format.test.js.snap +++ b/tests/format/vue/vue/__snapshots__/format.test.js.snap @@ -2996,8 +2996,7 @@ semi: false wqeqwwqwqweqweqwewwq || wqeqwwqwqweqweqwewwq }}123 -
+ ================================================================================ @@ -3101,8 +3100,7 @@ trailingComma: "es5" wqeqwwqwqweqweqwewwq || wqeqwwqwqweqweqwewwq }}123 - + ================================================================================ @@ -3206,8 +3204,7 @@ trailingComma: "none" wqeqwwqwqweqweqwewwq || wqeqwwqwqweqweqwewwq }}123 - + ================================================================================