Skip to content

Commit c7b545b

Browse files
authored
fix: dump computed yaml strings with pipe style (#51)
1 parent df2d160 commit c7b545b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

himl/config_generator.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ def dict_constructor(loader, node):
144144
Dumper.add_representer(OrderedDict, dict_representer)
145145
Loader.add_constructor(_mapping_tag, dict_constructor)
146146

147-
Dumper.add_representer(str, SafeRepresenter.represent_str)
147+
def str_representer_pipestyle(dumper, data):
148+
style = '|' if '\n' in data else None
149+
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style=style)
150+
Dumper.add_representer(str, str_representer_pipestyle)
148151

149152
if not PY3:
150-
Dumper.add_representer(unicode, SafeRepresenter.represent_unicode)
153+
def unicode_representer_pipestyle(dumper, data):
154+
style = u'|' if u'\n' in data else None
155+
return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style=style)
156+
Dumper.add_representer(unicode, unicode_representer_pipestyle)
157+
151158
return Dumper
152159

153160
@staticmethod

0 commit comments

Comments
 (0)