diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-13 17:46:39 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-13 17:46:39 +0100 |
commit | e75b7bd1ff6e3624fb7150fd2209e1a2b41b36a3 (patch) | |
tree | 0d9c0ce13ea77dd94f07aa6a90c3f01652edd98d | |
parent | f74c504f870e37eb0148dc1d0533440026c5dae5 (diff) | |
download | ruamel.yaml-e75b7bd1ff6e3624fb7150fd2209e1a2b41b36a3.tar.gz |
Preserve some of the blank lines in the input when round-tripping.
-rw-r--r-- | py/scanner.py | 9 | ||||
-rw-r--r-- | test/test_yaml.py | 14 |
2 files changed, 22 insertions, 1 deletions
diff --git a/py/scanner.py b/py/scanner.py index 721437c..1c011e0 100644 --- a/py/scanner.py +++ b/py/scanner.py @@ -1355,7 +1355,14 @@ class Scanner(object): if not spaces or self.peek() == u'#' \ or (not self.flow_level and self.column < indent): break - return ScalarToken(u''.join(chunks), True, start_mark, end_mark) + + token = ScalarToken(u''.join(chunks), True, start_mark, end_mark) + if spaces and spaces[0] == '\n': + # Create a comment token to preserve the trailing line breaks. + comment = CommentToken(''.join(spaces) + '\n', start_mark, end_mark) + token.add_post_comment(comment) + return token + def scan_plain_spaces(self, indent, start_mark): # See the specification for details. diff --git a/test/test_yaml.py b/test/test_yaml.py index 7376d92..3815b08 100644 --- a/test/test_yaml.py +++ b/test/test_yaml.py @@ -71,3 +71,17 @@ class TestYAML: ? b ? c """) + + def test_blank_line(self): + round_trip(""" + # foo + + a: foo + + # bar + b: + - bar + + + - baz + """) |