pydantic-yaml icon indicating copy to clipboard operation
pydantic-yaml copied to clipboard

Is there a mechanism or pattern for Block Style Literal Strings

Open Bengreen opened this issue 2 years ago • 4 comments
trafficstars

I have a string content that is muliline and currently I can use pydantic-yaml with ruamel to dump it as yaml. It uses the quoted string format.

Is there an option to use the block style ?

Or can suggest some options to consider.

https://yaml-multiline.info

Bengreen avatar Dec 15 '22 18:12 Bengreen

Hi, improving the flexibility of dumping YAML is something that's been on my wanted list for a while. It might wait until Pydantic 2.0 releases and I'll need to totally rewrite this... I'll probably base it around ruamel's or even (shudders) do the YAML part myself.

NowanIlfideme avatar Dec 15 '22 23:12 NowanIlfideme

Hi @Bengreen, in terms of user experience - would you prefer to do this configuration within the model class itself (using Pydantic-like config class) or within the "dumping engine" as a global configuration? How did you use it in the case above?

NowanIlfideme avatar Apr 28 '23 09:04 NowanIlfideme

Currently, limited support for this is now available within to_yaml_str and to_yaml_file using dumping keywords (since 1.1.0), or with a custom YAML dumper instance. For example, you could try configuring text longer than some length to use a block style. You'll have to go through the internals of ruamel.yaml though.

NowanIlfideme avatar Jul 19 '23 19:07 NowanIlfideme