From e302233956c4d6b83392b57c455fc596f1e7a00e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 17 Mar 2018 11:28:16 +0200 Subject: Fix: represent long string with the | style --- prettyml | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)) -- cgit v1.2.1