Skip to content

Commit

Permalink
don't present block scalars in flow collections
Browse files Browse the repository at this point in the history
 * ensure no block scalars (literal, folded) are output inside of flow
   collections
 * ref #140
  • Loading branch information
flyx committed Nov 7, 2023
1 parent 00387d9 commit 3d98b5e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions yaml/presenter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3d98b5e

Please sign in to comment.