asXml(): emit formatting line breaks only where the document contains whitespace#1158
Merged
Conversation
… whitespace Adjacent elements without whitespace in between no longer gain a fabricated line break, which rendered as a visible space between inline elements after a parse round-trip. Whitespace-only text nodes now mark where the formatting break belongs instead of being silently dropped, so the output follows the whitespace actually present in the document.
|
Member
|
@shapiroronny thanks (as always), have done a bit more hacking on this topic. Please have a look and provide feedback. Maybe there is more room for improvements for the output. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



asXml()inserted a line break and indentation at every element boundary. When two elements were adjacent in the source with no whitespace between them, that break was not part of the document, and after a parse round-trip it renders as a visible space between inline elements — e.g.<span>a</span><span>b</span>came back as "a b".DomElement.printXml()no longer forces a break before the first child or before the following sibling. A whitespace-only text node now marks where a formatting break belongs (DomText.printXml()sets the flag instead of dropping the node), so the output follows the whitespace actually present in the document: adjacent elements stay adjacent, and breaks appear only where the source had whitespace.Documents whose elements are already separated by whitespace — the common case — serialize as before. Verified against every
asXml()-referencing test class (1736 test runs) andCodeStyleTest, all green.