summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-17 11:28:16 +0200
committerLars Wirzenius <liw@liw.fi>2018-03-17 11:40:02 +0200
commite302233956c4d6b83392b57c455fc596f1e7a00e (patch)
tree630153e0d7239b99fa488539d399dc3a0453cf45
parente92515e92689e1a9b7950f936758b191bc61c33a (diff)
downloadextrautils-e302233956c4d6b83392b57c455fc596f1e7a00e.tar.gz
Fix: represent long string with the | style
-rwxr-xr-xprettyml10
1 files changed, 10 insertions, 0 deletions
diff --git a/prettyml b/prettyml
index 12f1a8e..e15b3b2 100755
--- a/prettyml
+++ b/prettyml
@@ -13,6 +13,16 @@ def inputs(args):
yield '-', sys.stdin
+def string_representer(dumper, data):
+ style = None
+ if '\n' in data:
+ style = '|'
+ return dumper.represent_scalar('tag:yaml.org,2002:str', data, style=style)
+
+
+yaml.add_representer(str, string_representer, Dumper=yaml.SafeDumper)
+
+
objs = []
for filename, f in inputs(sys.argv[1:]):
objs.append(yaml.load(f, Loader=yaml.CSafeLoader))