summaryrefslogtreecommitdiff
path: root/emitter.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2018-09-01 09:30:27 +0200
committerAnthon van der Neut <anthon@mnt.org>2018-09-01 09:30:27 +0200
commit94d2de64fbbe298365c42246e801e366aaaa9a60 (patch)
tree715523ff68b56615574d1bfec8fa70434aea851a /emitter.py
parent849c06e2272a9535bfabb068711a75484b622f1e (diff)
downloadruamel.yaml-94d2de64fbbe298365c42246e801e366aaaa9a60.tar.gz
rt of doc with root literal and embedded directive/document end
Diffstat (limited to 'emitter.py')
-rw-r--r--emitter.py45
1 files changed, 34 insertions, 11 deletions
diff --git a/emitter.py b/emitter.py
index f48899b..cb9916a 100644
--- a/emitter.py
+++ b/emitter.py
@@ -517,7 +517,7 @@ class Emitter(object):
and not self.canonical
and not self.brace_single_entry_mapping_in_flow_sequence
):
- # single map item with flow context no curly braces necessary
+ # single map item with flow context, no curly braces necessary
map_init = u''
self.write_indicator(u' ' * ind + map_init, True, whitespace=True)
self.flow_context.append(map_init)
@@ -1365,21 +1365,42 @@ class Emitter(object):
def determine_block_hints(self, text):
# type: (Any) -> Any
- hints = u""
+ indent = 0
+ indicator = ''
+ hints = u''
if text:
- if not self.root_context and text[0] in u' \n\x85\u2028\u2029':
- hints += text_type(self.best_sequence_indent)
+ if text[0] in u' \n\x85\u2028\u2029':
+ indent = self.best_sequence_indent
+ hints += text_type(indent)
+ elif self.root_context:
+ for end in ['\n---', '\n...']:
+ pos = 0
+ while True:
+ pos = text.find(end, pos)
+ if pos == -1:
+ break
+ try:
+ if text[pos + 4] in ' \r\n':
+ break
+ except IndexError:
+ pass
+ pos += 1
+ if pos > -1:
+ break
+ if pos > 0:
+ indent = self.best_sequence_indent
if text[-1] not in u'\n\x85\u2028\u2029':
- hints += u'-'
+ indicator = u'-'
elif len(text) == 1 or text[-2] in u'\n\x85\u2028\u2029':
- hints += u'+'
- return hints
+ indicator = u'+'
+ hints += indicator
+ return hints, indent, indicator
def write_folded(self, text):
# type: (Any) -> None
- hints = self.determine_block_hints(text)
+ hints, _indent, _indicator = self.determine_block_hints(text)
self.write_indicator(u'>' + hints, True)
- if hints[-1:] == u'+':
+ if _indicator == u'+':
self.open_ended = True
self.write_line_break()
leading_space = True
@@ -1440,7 +1461,7 @@ class Emitter(object):
def write_literal(self, text, comment=None):
# type: (Any, Any) -> None
- hints = self.determine_block_hints(text)
+ hints, _indent, _indicator = self.determine_block_hints(text)
self.write_indicator(u'|' + hints, True)
try:
comment = comment[1][0]
@@ -1448,7 +1469,7 @@ class Emitter(object):
self.stream.write(comment)
except (TypeError, IndexError):
pass
- if hints[-1:] == u'+':
+ if _indicator == u'+':
self.open_ended = True
self.write_line_break()
breaks = True
@@ -1466,6 +1487,8 @@ class Emitter(object):
self.write_line_break(br)
if ch is not None and (not self.root_context or self.requested_indent):
self.write_indent()
+ if ch is not None and _indent:
+ self.stream.write(u' ' * _indent)
start = end
else:
if ch is None or ch in u'\n\x85\u2028\u2029':