From 3d98b5ea2231a1ab2f5a466d59fac740ef0e8aa8 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Tue, 7 Nov 2023 22:48:42 +0100 Subject: [PATCH] don't present block scalars in flow collections * ensure no block scalars (literal, folded) are output inside of flow collections * ref #140 --- yaml/presenter.nim | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/yaml/presenter.nim b/yaml/presenter.nim index 2a43240..761ccab 100644 --- a/yaml/presenter.nim +++ b/yaml/presenter.nim @@ -143,14 +143,15 @@ proc inspect( indentation : int, words, lines: var seq[tuple[start, finish: int]], lineLength : Option[int], + inFlow : bool, ): ScalarStyle {.raises: [].} = var inLine = false inWord = false multipleSpaces = true curWord, curLine: tuple[start, finish: int] - canUseFolded = true - canUseLiteral = true + canUseFolded = not inFlow + canUseLiteral = not inFlow canUsePlain = scalar.len > 0 and scalar[0] notin {'@', '`', '|', '>', '&', '*', '!', ' ', '\t'} for i, c in scalar: @@ -606,7 +607,11 @@ proc doPresent( var words, lines = newSeq[tuple[start, finish: int]]() case item.scalarContent.inspect( ctx.indentation + ctx.options.indentationStep, words, lines, - ctx.options.maxLineLength) + ctx.options.maxLineLength, ctx.levels.len > 0 and ctx.state in [ + dFlowImplicitMapKey, dFlowMapValue, + dFlowExplicitMapKey, dFlowSequenceItem, + dFlowMapStart, dFlowSequenceStart + ]) of sLiteral: ctx.writeLiteral(item.scalarContent, lines) of sFolded: ctx.writeFolded(item.scalarContent, words) of sPlain: ctx.safeWrite(item.scalarContent)