I have added representers for folded strings, literal strings as mentioned in Any yaml libraries in Python that support dumping of long strings as block literals or folded blocks?. I have also added representer to print a list in block style in the dumped yaml content.
But the issue is that when the string is empty, i.e., "" or the list is empty, they appear in non-block style in the dumped YAML content.
How do force the pyyaml dumper to output "" empty strings with ">" or "|" style and empty list with flow_style=False in a block style in the generated YAML content?
After a bit of research, I am able to dump empty strings as block literals (style in '|>') in a YAML file using Pyyaml. My work is partially based on Any yaml libraries in Python that support dumping of long strings as block literals or folded blocks?.
Output:
However, I am not able to find a way to dump an empty list in block style. For this, I tried to mess with yaml/emitter.py and realized that I needed a non-empty list to dump it in block style.
Anyways, this effort did not go in vain, rather it was quite exciting :) I hope that some one may find this useful or may have something to share.