-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Preserve newlines within comments #116
Comments
That should work if the newline is itself commented, but not systematically otherwise. Conceptually, Changing this API would be rather difficult to do without breaking things, and I suspect it would also make it quite a bit more complicated to use. At the CST level, the library does parse any combination of comments and blank lines without issue, but that's much harder to use. One possibility would be to change what happens when the parser encounters a comment-blankline-comment sequence within a document. At the moment, the blank line is dropped, but it could be replaced by a const src = `
# foo
# bar
# baz
xx
`
const doc = YAML.parseDocument(src)
String(doc) Currently, this produces: # foo
# bar
# baz
xx The proposal would be to produce instead: # foo
# bar
#
# baz
xx To be honest, I'm not really sure which is better or less worse. Thoughts? |
Aside: Could we do something a little unclean by replacing the line with some place holder (say perhaps Of those two options the later option is less worse I think. It's not great since it still projects the notion that # bar
#
# baz are somehow two semantically related comments. However the spacing still preserves some sense of grouping. For example the case that got me interested in this is: # foo
# bar
## Header for some section
# explanation for section
# comment for particular node
xx Which under the current scheme becomes # foo
# bar
## Header for some section
# explanation for section
# comment for particular node The grouped chunk becomes illegible in longer cases. The alternative is slightly better: # foo
# bar
#
## Header for some section
#
# explanation for section
#
# comment for particular node
xx This is a niche case but I can't see a situation under which omitting the newline is ever better. |
Just realised the formatting was wrong in my previous comment. |
Commenting just to note that I've not forgotten about this, but probably won't get around to fixing this (and releasing a new version) for another week or so. PRs are of course welcome for the suggested alternative. |
Would it be possible to maintain newlines within comments? This would allow the structure of a lot of documentation to be adhered to more closely.
The text was updated successfully, but these errors were encountered: