From 568849965033de21f023c50610c4a440189d7347 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Sun, 20 Mar 2016 09:21:52 +0100 Subject: [PATCH] Fixed bugs with presenting block scalars * Folded block scalars were presented with "|" instead of ">" * It has not been properly detected that a scalar cannot be outputted as literal block scalar --- private/presenter.nim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/private/presenter.nim b/private/presenter.nim index 8a9cded..0fce03e 100644 --- a/private/presenter.nim +++ b/private/presenter.nim @@ -59,7 +59,7 @@ proc inspect(scalar: string, indentation: int, if not inLine: curLine.start = i inLine = false curLine.finish = i - 1 - if curLine.start - curLine.finish + 1 > 80 - indentation: + if curLine.finish - curLine.start + 1 > 80 - indentation: canUseLiteral = false lines.add(curLine) else: @@ -180,7 +180,9 @@ proc writeFolded(scalar: string, indentation, indentStep: int, s: Stream, words: seq[tuple[start, finish: int]], newline: string) {.raises: [YamlPresenterOutputError].} = try: - s.write("|-") + s.write(">") + if scalar[^1] != '\l': s.write('-') + if scalar[0] in [' ', '\t']: s.write($indentStep) var curPos = 80 for word in words: if word.start > 0 and scalar[word.start - 1] == '\l': @@ -579,7 +581,7 @@ proc present*(s: var YamlStream, target: Stream, tagLib: TagLibrary, indentation -= options.indentationStep safeWrite('}') of dBlockMapValue, dBlockInlineMap: discard - else: assert false + else: assert(false) indentation -= options.indentationStep of yamlEndDoc: if finished(s): break