summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-14 11:13:06 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-14 11:13:06 +0100
commit678a543368772a6780e85e3558a54cb33b289660 (patch)
tree3882803a3c7ce55ba5e249661fa775b811808eb3
parente75b7bd1ff6e3624fb7150fd2209e1a2b41b36a3 (diff)
downloadruamel.yaml-678a543368772a6780e85e3558a54cb33b289660.tar.gz
Preserve blank lines after comments
-rw-r--r--py/scanner.py5
-rw-r--r--test/test_yaml.py8
2 files changed, 9 insertions, 4 deletions
diff --git a/py/scanner.py b/py/scanner.py
index 1c011e0..1286e4f 100644
--- a/py/scanner.py
+++ b/py/scanner.py
@@ -1621,6 +1621,11 @@ class RoundTripScanner(Scanner):
break
comment += ch
self.forward()
+ # gather any blank lines following the comment too
+ ch = self.scan_line_break()
+ while len(ch) > 0:
+ comment += ch
+ ch = self.scan_line_break()
end_mark = self.get_mark()
if not self.flow_level:
self.allow_simple_key = True
diff --git a/test/test_yaml.py b/test/test_yaml.py
index 3815b08..c5d69b4 100644
--- a/test/test_yaml.py
+++ b/test/test_yaml.py
@@ -72,13 +72,13 @@ class TestYAML:
? c
""")
- def test_blank_line(self):
+ def test_blank_lines(self):
round_trip("""
- # foo
+ # Comment with a space after it.
- a: foo
+ a: 1
- # bar
+ # Seq with spaces in between items.
b:
- bar