@@ -88,15 +88,14 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*yaml.Node, error) {
88
88
return nil , err
89
89
}
90
90
} else {
91
- log .Debug ("before hack, this is the data len: %" , len (children [0 ].Data ))
92
91
// comment hack for maps of scalars
93
92
// if the value is a scalar, the head comment of the scalar needs to go on the key?
94
93
// add tests for <z/> as well as multiple <ds> of inputXmlWithComments > yaml
95
94
if len (children [0 ].Children ) == 0 && children [0 ].HeadComment != "" {
96
95
if len (children [0 ].Data ) > 0 {
97
96
98
- log .Debug ("scalar comment hack" )
99
- labelNode .HeadComment = labelNode .HeadComment + " \n " + strings .TrimSpace (children [0 ].HeadComment )
97
+ log .Debug ("scalar comment hack, currentlabel [%v]" , labelNode . HeadComment )
98
+ labelNode .HeadComment = joinComments ([] string { labelNode .HeadComment , strings .TrimSpace (children [0 ].HeadComment )}, " \n " )
100
99
children [0 ].HeadComment = ""
101
100
} else {
102
101
// child is null, put the headComment as a linecomment for reasons
@@ -311,10 +310,10 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
311
310
312
311
} else if elem .state == "chardata" {
313
312
log .Debug ("got a line comment for (%v) %v: [%v]" , elem .state , elem .label , commentStr )
314
- elem .n .LineComment = joinFilter ([]string {elem .n .LineComment , commentStr })
313
+ elem .n .LineComment = joinComments ([]string {elem .n .LineComment , commentStr }, " " )
315
314
} else {
316
315
log .Debug ("got a head comment for (%v) %v: [%v]" , elem .state , elem .label , commentStr )
317
- elem .n .HeadComment = joinFilter ([]string {elem .n .HeadComment , commentStr })
316
+ elem .n .HeadComment = joinComments ([]string {elem .n .HeadComment , commentStr }, " " )
318
317
}
319
318
320
319
case xml.ProcInst :
@@ -339,21 +338,21 @@ func applyFootComment(elem *element, commentStr string) {
339
338
lastChildIndex := len (elem .n .Children ) - 1
340
339
childKv := elem .n .Children [lastChildIndex ]
341
340
log .Debug ("got a foot comment for %v: [%v]" , childKv .K , commentStr )
342
- childKv .FootComment = joinFilter ([]string {elem .n .FootComment , commentStr })
341
+ childKv .FootComment = joinComments ([]string {elem .n .FootComment , commentStr }, " " )
343
342
} else {
344
343
log .Debug ("got a foot comment for %v: [%v]" , elem .label , commentStr )
345
- elem .n .FootComment = joinFilter ([]string {elem .n .FootComment , commentStr })
344
+ elem .n .FootComment = joinComments ([]string {elem .n .FootComment , commentStr }, " " )
346
345
}
347
346
}
348
347
349
- func joinFilter (rawStrings []string ) string {
348
+ func joinComments (rawStrings []string , joinStr string ) string {
350
349
stringsToJoin := make ([]string , 0 )
351
350
for _ , str := range rawStrings {
352
351
if str != "" {
353
352
stringsToJoin = append (stringsToJoin , str )
354
353
}
355
354
}
356
- return strings .Join (stringsToJoin , " " )
355
+ return strings .Join (stringsToJoin , joinStr )
357
356
}
358
357
359
358
// trimNonGraphic returns a slice of the string s, with all leading and trailing
0 commit comments