diff --git a/.run/Watch Playground.run.xml b/.run/Watch Playground.run.xml
index 37fd29f2d..44c5349e7 100644
--- a/.run/Watch Playground.run.xml
+++ b/.run/Watch Playground.run.xml
@@ -1,8 +1,19 @@
-
-
+
+
-
+
@@ -10,4 +21,4 @@
-
\ No newline at end of file
+
diff --git a/Src/CSharpier.Core/Xml/XNodePrinters/Element.cs b/Src/CSharpier.Core/Xml/XNodePrinters/Element.cs
index 2dd2124b9..36c1a7ac9 100644
--- a/Src/CSharpier.Core/Xml/XNodePrinters/Element.cs
+++ b/Src/CSharpier.Core/Xml/XNodePrinters/Element.cs
@@ -70,6 +70,14 @@ Doc PrintLineAfterChildren()
return Doc.IfBreak(Doc.SoftLine, "", attrGroupId);
}
+ if (
+ rawNode.Nodes.LastOrDefault() is { } node
+ && Tag.PrintParentClosingTagStartWithContent(node, context)
+ )
+ {
+ return Doc.Null;
+ }
+
if (
rawNode.Attributes.Length == 0
&& rawNode.Nodes is [{ NodeType: XmlNodeType.Text }]
diff --git a/Src/CSharpier.Core/Xml/XNodePrinters/Tag.cs b/Src/CSharpier.Core/Xml/XNodePrinters/Tag.cs
index 3532b57b1..028990039 100644
--- a/Src/CSharpier.Core/Xml/XNodePrinters/Tag.cs
+++ b/Src/CSharpier.Core/Xml/XNodePrinters/Tag.cs
@@ -45,7 +45,13 @@ public static Doc PrintClosingTag(RawNode rawNode, PrintingContext context)
{
return Doc.Concat(
rawNode.IsEmpty ? Doc.Null : PrintClosingTagStart(rawNode, context),
- PrintClosingTagEnd(rawNode, context)
+ rawNode.Nodes.LastOrDefault() is { } node
+ && PrintParentClosingTagStartWithContent(node, context)
+ ? Doc.Null
+ : Doc.Concat(
+ PrintClosingTagEndMarker(rawNode),
+ PrintClosingTagSuffix(rawNode, context)
+ )
);
}
@@ -63,14 +69,6 @@ public static Doc PrintClosingTagStartMarker(RawNode rawNode, PrintingContext co
return $"{rawNode.Name}";
}
- public static Doc PrintClosingTagEnd(RawNode rawNode, PrintingContext context)
- {
- return Doc.Concat(
- PrintClosingTagEndMarker(rawNode),
- PrintClosingTagSuffix(rawNode, context)
- );
- }
-
public static Doc PrintClosingTagEndMarker(RawNode rawNode)
{
return rawNode.IsEmpty ? "/>" : ">";
@@ -79,7 +77,10 @@ public static Doc PrintClosingTagEndMarker(RawNode rawNode)
public static Doc PrintClosingTagSuffix(RawNode rawNode, PrintingContext context)
{
return PrintParentClosingTagStartWithContent(rawNode, context)
- ? PrintClosingTagStartMarker(rawNode.Parent!, context)
+ ? Doc.Concat(
+ PrintClosingTagStartMarker(rawNode.Parent!, context),
+ PrintClosingTagEndMarker(rawNode.Parent!)
+ )
: NeedsToBorrowNextOpeningTagStartMarker(rawNode)
? PrintOpeningTagStartMarker(rawNode.NextNode!, context)
: Doc.Null;
@@ -92,38 +93,23 @@ private static Doc PrintOpeningTagStartMarker(RawNode rawNode, PrintingContext c
private static bool NeedsToBorrowNextOpeningTagStartMarker(RawNode rawNode)
{
- /*
- * 123
- */
+ /* 123
*/
return rawNode.NextNode is not null
&& !rawNode.NextNode.IsTextLike()
&& rawNode.IsTextLike()
- && rawNode.NodeType is XmlNodeType.Text and not XmlNodeType.CDATA
- // && node.isTrailingSpaceSensitive
- // prettier does something with removing end of line nodes and setting this value, I don't know
- // that we have that functionality
- // && !node.hasTrailingSpaces
- ;
+ && rawNode.NodeType is XmlNodeType.Text and not XmlNodeType.CDATA;
}
- private static bool PrintParentClosingTagStartWithContent(
+ public static bool PrintParentClosingTagStartWithContent(
RawNode rawNode,
PrintingContext context
)
{
- /*
- *
- * 123
- *
- * 123
- */
+ /*
+ 123
+ ^^^^*/
// TODO #1790 we really want this last condition only if the indentation of the last line of the text value matches
// the indentation of the start element. Bleh.
/*
@@ -161,15 +147,12 @@ public static bool NeedsToBorrowParentOpeningTagEndMarker(
PrintingContext context
)
{
- /*
- * 123
- * ^
- *
- *
123
+ ^
+ v4.5.2
+ >v4.5.2
diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements.test
index 339f9a9ff..222cd96ec 100644
--- a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements.test
+++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements.test
@@ -6,7 +6,9 @@
TextValue
TextValue
TextValue
+ >TextValue
+ TextValue
<b>SomeText</b>
diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_Blah.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_Blah.test
new file mode 100644
index 000000000..c12230dc3
--- /dev/null
+++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_Blah.test
@@ -0,0 +1,7 @@
+
+ true
+ true
+
diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_HtmlValues.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_HtmlValues.test
index 06a7c906b..0f4100d2b 100644
--- a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_HtmlValues.test
+++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/Elements_HtmlValues.test
@@ -2,7 +2,5 @@
Some texturl.com more text.
Some long text to make things break url.com more text.
+ >url.com more text.
diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/StrictWhitespace.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/StrictWhitespace.test
index 67cc6ad47..a2f4b2258 100644
--- a/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/StrictWhitespace.test
+++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/xml_strict/StrictWhitespace.test
@@ -12,16 +12,13 @@
>A containing a value that reflects the sort order of
as compared to . The following table defines the conditions
under which the returned value is a negative number, zero, or a positive
- number.
+ number.
Some text that ends with a space.
Some loooooooooooooooooooooooooooooooooong text with this and a space after this.
+ >Some loooooooooooooooooooooooooooooooooong text with this and a space after this.
The current instance is read-only and a set operation was attempted.
+ >The current instance is read-only and a set operation was attempted.
public void MethodName() {
}