Skip to content

Commit 8fb67ff

Browse files
authored
Preserve multiline strings (#12)
1 parent ea09503 commit 8fb67ff

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

bin/update-aws-spec.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
import click
1010

11+
12+
def str_presenter(dumper, data):
13+
"""
14+
Reading multiline yaml strings (with the `|` indicator) results in newlines added when dumping the YAML.
15+
This function helps to preserve the original multiline formatting.
16+
"""
17+
if '\n' in data:
18+
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
19+
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
20+
21+
22+
yaml.add_representer(str, str_presenter)
23+
24+
1125
@click.command()
1226
@click.option('--latest', is_flag=True, default=False, help='If enabled, sets the version of the spec to latest.')
1327
def update_aws_spec(latest: bool) -> None:

0 commit comments

Comments
 (0)