You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Since YAML parsers are not required to maintain empty line information, no available YAML library is capable of parsing YAML and reproducing the exact same line break information.
To explain what I mean, the following YAML in:
a: 1b: 2
Coming back out would look like this:
a: 1b: 2
This is because the parser will toss away the empty lines, since they are not vital syntax information and are only for readability.
Describe the solution you'd like
A solution similar to the WithComments option would be really great to have this.
This works a decent amount of the time, but causes strange errors in weird edge cases, and YAML is essentially a language of weird edge cases. 🥲
Additional context
I have tried to implement this myself in my fork of yaml.v3 but it has proven to be infeasible. I also tried in this library but had no luck. That's why I decided to make an issue to see if anyone has ideas for whether this is feasible. If it is, I'm willing to do any implementation work.
The text was updated successfully, but these errors were encountered:
Thanks @goccy I didn't notice that! I followed the lineage of that PR to see how they were using the library, and when I do the same thing the line breaks are maintained as expected. Thank you!
Is your feature request related to a problem? Please describe.
Since YAML parsers are not required to maintain empty line information, no available YAML library is capable of parsing YAML and reproducing the exact same line break information.
To explain what I mean, the following YAML in:
Coming back out would look like this:
This is because the parser will toss away the empty lines, since they are not vital syntax information and are only for readability.
Describe the solution you'd like
A solution similar to the
WithComments
option would be really great to have this.Describe alternatives you've considered
In my tool yamlfmt I have a hack that works 75% of the time, which is to add a magic comment line to every empty line break before sending it into the parser, and replacing that magic line with linebreaks on the way out. https://github.com/google/yamlfmt/blob/1bfe5e4a8cf49bf0cdc3e77aa2ffbfb46a1bc812/internal/hotfix/retain_line_break.go#L29
This works a decent amount of the time, but causes strange errors in weird edge cases, and YAML is essentially a language of weird edge cases. 🥲
Additional context
I have tried to implement this myself in my fork of yaml.v3 but it has proven to be infeasible. I also tried in this library but had no luck. That's why I decided to make an issue to see if anyone has ideas for whether this is feasible. If it is, I'm willing to do any implementation work.
The text was updated successfully, but these errors were encountered: