Closed pansen closed 6 years ago
Hi,
Current behavior in this module is to use explicitly-specified string style unconditionally, i.e. for all strings, so not possible to do what you want via simple parameter. https://github.com/mk-fg/pretty-yaml/blob/370130d/pyaml/__init__.py#L113-L136
What I'd probably do is to subclass UnsafePrettyYAMLDumper and override represent_stringish method there to check for newlines and using style = '|'
for these and calling original method or using style = "'"
for everything else.
Don't remember if using UnsafePrettyYAMLDumper.add_representer(str_type, myfunc)
will do the same, maybe can be used instead of subclassing, though latter is probably same LoC-wise and won't alter global stuff.
Actually, if you want to change existing yaml doc without breaking formatting, comments in there or anything like that, maybe also check out ruamel.yaml module, which I've used for that recently and found to be very powerful for any kind of humane yaml stuff (esp. preserving comments is like a killer feature!).
EDIT: wanted to add it to README too, but apparently did so a while ago already, so you probably seen it there.
Awesome, thanks a lot @mk-fg. I will check your suggestions and respond my final solution. :)
Hi!
I have some OpenAPI schema definition, that I'm extracting via ApiSpec.
Apispec is doing all the heavy lifting, but I changed the yaml library to pretty-yaml to get rid of the Python type hints.
Question
Given the yaml above, how can I accomplish to receive multiline blocks as a block
and
have single line Strings quoted
Currently I'm using
which unfortunately puts the mutline Strings in simple quotes as well.
Thank you :)