summaryrefslogtreecommitdiff
path: root/emitter.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-08-05 12:27:52 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-08-05 12:27:52 +0200
commit06ea5a9886a6abb88b7a81481c6600477088f2c6 (patch)
treec8f72ab953eab349348714b2f5b65ce5356622d6 /emitter.py
parent9b15f5f59e52ce2257a579900d8315cd7d46e4c9 (diff)
downloadruamel.yaml-06ea5a9886a6abb88b7a81481c6600477088f2c6.tar.gz
leading empty lines and comments on root level literal scalars not preserved0.15.49
added test, fixed both now you can have --- !some_tag | # with a comment this is a multi- line literal scalar
Diffstat (limited to 'emitter.py')
-rw-r--r--emitter.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/emitter.py b/emitter.py
index 626a69e..a75fa52 100644
--- a/emitter.py
+++ b/emitter.py
@@ -811,7 +811,7 @@ class Emitter(object):
elif self.style == '>':
self.write_folded(self.analysis.scalar)
elif self.style == '|':
- self.write_literal(self.analysis.scalar)
+ self.write_literal(self.analysis.scalar, self.event.comment)
else:
self.write_plain(self.analysis.scalar, split)
self.analysis = None
@@ -1337,7 +1337,7 @@ class Emitter(object):
# type: (Any) -> Any
hints = ""
if text:
- if text[0] in u' \n\x85\u2028\u2029':
+ if not self.root_context and text[0] in u' \n\x85\u2028\u2029':
hints += text_type(self.best_sequence_indent)
if text[-1] not in u'\n\x85\u2028\u2029':
hints += u'-'
@@ -1404,10 +1404,16 @@ class Emitter(object):
spaces = ch == u' '
end += 1
- def write_literal(self, text):
+ def write_literal(self, text, comment=None):
# type: (Any) -> None
hints = self.determine_block_hints(text)
self.write_indicator(u'|' + hints, True)
+ try:
+ comment = comment[1][0]
+ if comment:
+ self.stream.write(comment)
+ except (TypeError, IndexError):
+ pass
if hints[-1:] == u'+':
self.open_ended = True
self.write_line_break()