@@ -58,6 +58,7 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*yaml.Node, error) {
58
58
yamlNode := & yaml.Node {Kind : yaml .MappingNode , Tag : "!!map" }
59
59
60
60
if len (n .Data ) > 0 {
61
+ log .Debug ("creating content node for map" )
61
62
label := dec .prefs .ContentName
62
63
labelNode := createScalarNode (label , label )
63
64
labelNode .HeadComment = dec .processComment (n .HeadComment )
@@ -87,13 +88,21 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*yaml.Node, error) {
87
88
return nil , err
88
89
}
89
90
} else {
91
+ log .Debug ("before hack, this is the data len: %" , len (children [0 ].Data ))
90
92
// comment hack for maps of scalars
91
93
// if the value is a scalar, the head comment of the scalar needs to go on the key?
92
94
// add tests for <z/> as well as multiple <ds> of inputXmlWithComments > yaml
93
95
if len (children [0 ].Children ) == 0 && children [0 ].HeadComment != "" {
94
- log .Debug ("scalar comment hack" )
95
- labelNode .HeadComment = labelNode .HeadComment + "\n " + strings .TrimSpace (children [0 ].HeadComment )
96
- children [0 ].HeadComment = ""
96
+ if len (children [0 ].Data ) > 0 {
97
+
98
+ log .Debug ("scalar comment hack" )
99
+ labelNode .HeadComment = labelNode .HeadComment + "\n " + strings .TrimSpace (children [0 ].HeadComment )
100
+ children [0 ].HeadComment = ""
101
+ } else {
102
+ // child is null, put the headComment as a linecomment for reasons
103
+ children [0 ].LineComment = children [0 ].HeadComment
104
+ children [0 ].HeadComment = ""
105
+ }
97
106
}
98
107
valueNode , err = dec .convertToYamlNode (children [0 ])
99
108
if err != nil {
0 commit comments