HsYAML icon indicating copy to clipboard operation
HsYAML copied to clipboard

Empty lines fail to round trip

Open TristanCacqueray opened this issue 5 years ago • 3 comments
trafficstars

It seems like empty lines do not have a corresponding Event:

a: 1

# comment
b: 2

Results in (after passing through yaml-test yaml2yaml):

a: 1
# comment
b : 2

Would it be possible to add a new event or comment attribute to preserve empty lines?

TristanCacqueray avatar Aug 01 '20 12:08 TristanCacqueray

Yes, line spaces and extra indentation is not preserved in a round trip. See https://hackage.haskell.org/package/HsYAML-0.2.1.0/docs/Data-YAML-Event.html#g:4 for more details.

vijayphoenix avatar Aug 01 '20 15:08 vijayphoenix

My use-case is to edit/format YAML document while preserving the file structure, and loosing empty lines is not very practical. It doesn't seems like a very intrusive change to add EmptyLine event and I would be interested in contributing such a feature if that would be acceptable (and fit the scope of HsYAML).

I also noticed parseEvents returns a list of Event, Pos Record, but writeEvents only accept a list of Event. Is there a particular reason a writeEventsWithPos function isn't provided? And if such function is technically feasible, then that seems like a better solution to my use-case.

TristanCacqueray avatar Aug 01 '20 15:08 TristanCacqueray

It would be nice to have such a feature. Any suggestions @hvr on how to proceed with this feature?

vijayphoenix avatar Aug 01 '20 15:08 vijayphoenix