Rough idea on how to preserve newlines #31
Closed
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.
This PR shows a possible approach to address empty line preservation.
At this stage, it's not at all meant for merge, but only for discussion. The idea is to subclass the XML writer and add special handling of subsequent newlines, the code is detecting the presence of text blocks with white space and multiple newlines, and tracking them. When mlutiple newlines are detected, they are not fully skipped, but a single newline is issued in output.
You can see how that works by checking existing test failures, in particular,
FormatUtilsTest.test2
would fail returning this output (which is not what the tests expects, but what I'd like to get given its input file):Behavior becomes a bit more similar to a Java code formatters, where new lines are not fully removed.
In order to go from here to something usable, I was thinking to do the following:
keepBlankLines
option for this behavior, maybe it could be named the same way. Documentation for the option says: "Should blank lines in the pom-file be perserved. A maximum of one line is preserved between each tag.".XMLWriter
,BlankLinesXMLWriter
, that works as the anonymous inner class I have in this draft PRXMLWriter
, or theBlankLinesXMLWriter