🎨 Use block scalars in YAML dumps (#4702)

This commit is contained in:
Shyam Sunder authored and GitHub committed 2023-01-23 15:27:54 +01:00
1 parent 45d2e0e119
commit 4334939ea2
2 files changed
+9

No files matched your search

+1
View File
@@ -175,6 +175,7 @@ date of first contribution):
* [Frederik Kemner](https://github.com/040medien)
* [Moiz Rasheed](https://github.com/msrasheed)
* [Scott Martin](https://github.com/smartin015)
* [Shyam Sunder](https://github.com/sgsunder)
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
[Daid Braam](https://github.com/daid). Parts of its communication layer and
+8
View File
@@ -44,6 +44,14 @@ def _save_to_file_base(data, file=None, path=None, pretty=False, **kwargs):
except ImportError:
from yaml import SafeDumper
# make multiline strings look better by using block scalars
def _block_scalar_str_presenter(dumper, data):
return dumper.represent_scalar(
"tag:yaml.org,2002:str", data, style="|" if "\n" in data else None
)
SafeDumper.add_representer(str, _block_scalar_str_presenter)
if pretty:
# make each element go on a new line and indent by 2
kwargs.update(default_flow_style=False, indent=2)