When parsing a multiline string with |+, LiteralNode.Value.Value contains the trailing blank lines, but LiteralNode.String() does not render them.
Is this intentional behavior?
I expected LiteralNode.String() to include these trailing blank lines, because these newlines are part of the AST node and change both the value and the representation in the source.
Go Playground reproduction:
https://go.dev/play/p/Y1m0qWMgymQ
This came up in yamldiff: semihbkgr/yamldiff#60
Example
Input:
Observed output:
== raw input ==
01: description: |+$
02: one$
03: two$
04: $
05: $
06: $
== AST node type ==
Literal
== node.String() ==
01: |+$
02: one$
03: two$
== LiteralNode.Value.Value ==
01: one$
02: two$
03: $
04: $
05: $
Go quoted value: "one\ntwo\n\n\n\n"
LiteralNode.Value.Value includes the trailing blank lines:
But node.String() renders only:
When parsing a multiline string with
|+,LiteralNode.Value.Valuecontains the trailing blank lines, butLiteralNode.String()does not render them.Is this intentional behavior?
I expected
LiteralNode.String()to include these trailing blank lines, because these newlines are part of the AST node and change both the value and the representation in the source.Go Playground reproduction:
https://go.dev/play/p/Y1m0qWMgymQ
This came up in
yamldiff: semihbkgr/yamldiff#60Example
Input:
Observed output:
LiteralNode.Value.Valueincludes the trailing blank lines:But
node.String()renders only: