def _format_yaml_dump(data):
"""
Format yaml-dump to make file more readable
(yaml structure must be dumped to a stream before using this function)
| Currently does the following:
| - Add an empty line before a new item
:param data: string to format
:return: formatted string
"""
data = data.replace('\n\n', '\n')
ldata = data.split('\n')
rdata = []
for index, line in enumerate(ldata):
if line[-1:] == ':':
# no empty line before list attributes
if ldata[index+1].strip()[0] != '-':
rdata.append('')
rdata.append(line)
else:
rdata.append(line)
fdata = '\n'.join(rdata)
return fdata
评论列表
文章目录