Skip to content

Fragment no longer opens on a blank line - #597

Merged
SimonCropp merged 1 commit into
mainfrom
fragment-blank-line
Aug 3, 2026
Merged

Fragment no longer opens on a blank line#597
SimonCropp merged 1 commit into
mainfrom
fragment-blank-line

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

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.

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.
@SimonCropp SimonCropp added this to the 5.1.2 milestone Aug 3, 2026
@SimonCropp
SimonCropp merged commit 8594324 into main Aug 3, 2026
4 of 6 checks passed
@SimonCropp
SimonCropp deleted the fragment-blank-line branch August 3, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant