diff --git a/pkg/yqlib/decoder_properties.go b/pkg/yqlib/decoder_properties.go index e6aa3288..1c7eee14 100644 --- a/pkg/yqlib/decoder_properties.go +++ b/pkg/yqlib/decoder_properties.go @@ -51,8 +51,8 @@ func (dec *propertiesDecoder) applyProperty(properties *properties.Properties, c value, _ := properties.Get(key) path := parsePropKey(key) - log.Debug("comments: %v", properties.GetComments(key)) - log.Debug("comment: %v", properties.GetComment(key)) + IMPROVEMENT - target the key node with the comment, set as a header comment instead. + rhsNode := &yaml.Node{ Value: value, Tag: "!!str", diff --git a/pkg/yqlib/encoder_properties.go b/pkg/yqlib/encoder_properties.go index 6b922fd9..dc7c630a 100644 --- a/pkg/yqlib/encoder_properties.go +++ b/pkg/yqlib/encoder_properties.go @@ -75,7 +75,9 @@ func (pe *propertiesEncoder) Encode(writer io.Writer, node *yaml.Node) error { } func (pe *propertiesEncoder) doEncode(p *properties.Properties, node *yaml.Node, path string) error { - p.SetComment(path, strings.ReplaceAll(headAndLineComment(node), "\n", "\n# ")) + + commentsWithSpaces := strings.ReplaceAll(headAndLineComment(node), "\n", "\n ") + p.SetComments(path, strings.Split(commentsWithSpaces, "\n")) switch node.Kind { case yaml.ScalarNode: var nodeValue string