From 61208b944bf23e6c857f732e021b1910f0d1462b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 3 Aug 2026 22:05:58 +1000 Subject: [PATCH] Fragment no longer opens on a blank line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fragment is parsed against a context element, and PrettyMarkupFormatter breaks the line before every node that sits inside an element. That context element is never itself written, so the first node took the break with nothing in front of it and the markup opened on the second line. A document has no such context, and a fragment leading with text is not broken before either, so the ones affected were those leading with an element or a comment. The break is now dropped from the front of the formatted output. The seven fragment snapshots recorded the blank line rather than failing on it. The registered html comparer diffs the two DOMs, where a blank line before the first node is whitespace between nodes and no difference at all, so nothing here could see it — only a consumer comparing the snapshot as text. The new test compares as text for that reason, and is the only one in the fixture that fails when the trim is taken back out. --- src/Directory.Build.props | 2 +- ...entDoesNotOpenWithABlankLine.verified.html | 1 + ...agmentIsNotWrappedInDocument.verified.html | 3 +- ...ts.PreservesPreformattedText.verified.html | 3 +- ...s.PreservesTextareaAndScript.verified.html | 3 +- ...tHtmlTests.TableCellFragment.verified.html | 3 +- ....TableFragmentBehindAComment.verified.html | 3 +- ...ntHtmlTests.TableRowFragment.verified.html | 3 +- ...mlTests.TableSectionFragment.verified.html | 3 +- src/Tests/PrettyPrintHtmlTests.cs | 30 +++++++++++++++++++ src/Verify.AngleSharp/HtmlPrettyPrint.cs | 18 +++++++++++ 11 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/Tests/PrettyPrintHtmlTests.FragmentDoesNotOpenWithABlankLine.verified.html diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 2c31178..986736d 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;NU1608;NU1109 - 5.1.1 + 5.1.2 1.0.0 preview AngleSharp, Verify diff --git a/src/Tests/PrettyPrintHtmlTests.FragmentDoesNotOpenWithABlankLine.verified.html b/src/Tests/PrettyPrintHtmlTests.FragmentDoesNotOpenWithABlankLine.verified.html new file mode 100644 index 0000000..4f11014 --- /dev/null +++ b/src/Tests/PrettyPrintHtmlTests.FragmentDoesNotOpenWithABlankLine.verified.html @@ -0,0 +1 @@ +

My first paragraph.

\ No newline at end of file diff --git a/src/Tests/PrettyPrintHtmlTests.FragmentIsNotWrappedInDocument.verified.html b/src/Tests/PrettyPrintHtmlTests.FragmentIsNotWrappedInDocument.verified.html index 46fac00..4f11014 100644 --- a/src/Tests/PrettyPrintHtmlTests.FragmentIsNotWrappedInDocument.verified.html +++ b/src/Tests/PrettyPrintHtmlTests.FragmentIsNotWrappedInDocument.verified.html @@ -1,2 +1 @@ - -

My first paragraph.

\ No newline at end of file +

My first paragraph.

\ No newline at end of file diff --git a/src/Tests/PrettyPrintHtmlTests.PreservesPreformattedText.verified.html b/src/Tests/PrettyPrintHtmlTests.PreservesPreformattedText.verified.html index 65709a6..f9a64f7 100644 --- a/src/Tests/PrettyPrintHtmlTests.PreservesPreformattedText.verified.html +++ b/src/Tests/PrettyPrintHtmlTests.PreservesPreformattedText.verified.html @@ -1,5 +1,4 @@ - -
+
SELECT [e].[Name]
 FROM [Employees] AS [e]
 WHERE [e].[Active] = 1
diff --git a/src/Tests/PrettyPrintHtmlTests.PreservesTextareaAndScript.verified.html b/src/Tests/PrettyPrintHtmlTests.PreservesTextareaAndScript.verified.html index 9e897ae..9ec22f0 100644 --- a/src/Tests/PrettyPrintHtmlTests.PreservesTextareaAndScript.verified.html +++ b/src/Tests/PrettyPrintHtmlTests.PreservesTextareaAndScript.verified.html @@ -1,5 +1,4 @@ - -
+