-
Notifications
You must be signed in to change notification settings - Fork 77
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
Use "literal" multi-line string literals? #152
Comments
Three answers:
I think it's probably about time to flesh out |
@snoyberg: What about making the default behavior the "literal" style (i.e. prefix with |
Plenty of people have complained when the YAML library has been too aggressive in the past with forcing literal style. Plain style is almost always preferable for normal (short) string values. |
Right, but I'm referring to multi-line string literals, not short (presumably single-line) literals |
I see the confusion here: the "literal" block style you're referring to isn't preceded by a Preceding a string with an exclamation point can be part of YAML's tagging system, which is what I thought you were referring to. Using literal style for multiline strings seems reasonable to me. And if your takeaway from this is "YAML is too complicated," I can only agree with you. |
Yeah, I was less concerned about the tagging system and only added the exclamation mark because the examples I was cribbing from did so, too. I was more interested in the pipe to switch to literal style And yes, YAML is super-complicated :) |
Use literal style for multiline strings (fixes #152)
The context for this is that I was using this library to render a YAML configuration file with an inline code block (I know ...), and any indented code caused it to fall back to using non-multi-line string literals. The minimal reproducing example is any string containing relative indentation:
My understanding is that "plain" multi-line string literals in YAML don't support relative indentation since they strip leading newlines, so if you restrict yourself to plain multi-line string literals then the fallback is necessary. This is also the reason for the extra newlines in the rendered string since a blank line is required to generate a newline.
However, YAML does support an alternative "literal" multi-line string literal if you prefix the string with a
|
. This form preserves leading whitespace and also preserves newlines exactly, like this:Would it be possible to use that "literal" form for rendering multi-line string literals instead of the "plain" form?
(Note: I'm basing this off of https://yaml-multiline.info/ and some examples I've seen in the wild)
The text was updated successfully, but these errors were encountered: