Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty lines fail to round trip #48

Open
TristanCacqueray opened this issue Aug 1, 2020 · 3 comments
Open

Empty lines fail to round trip #48

TristanCacqueray opened this issue Aug 1, 2020 · 3 comments

Comments

@TristanCacqueray
Copy link
Contributor

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?

@vijayphoenix
Copy link
Collaborator

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.

@TristanCacqueray
Copy link
Contributor Author

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.

@vijayphoenix
Copy link
Collaborator

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

TristanCacqueray added a commit to TristanCacqueray/HsYAML that referenced this issue Aug 1, 2020
This change adds rudimentary support for preserving empty lines.

Fixes: haskell-hvr#48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants