@@ -96,6 +96,7 @@ func (ky *Encoder) FromYAML(in io.Reader, out io.Writer) error {
96
96
if err := ky .renderDocument (& doc , 0 , ky .flags (), out ); err != nil {
97
97
return err
98
98
}
99
+ fmt .Fprintf (out , "\n " )
99
100
}
100
101
101
102
return nil
@@ -112,7 +113,8 @@ func (ky *Encoder) FromObject(obj any, out io.Writer) error {
112
113
return ky .FromYAML (bytes .NewReader (jb ), out )
113
114
}
114
115
115
- // Marshal renders a single Go object as KYAML, without the header.
116
+ // Marshal renders a single Go object as KYAML, without the header or trailing
117
+ // newline.
116
118
func (ky * Encoder ) Marshal (obj any ) ([]byte , error ) {
117
119
// Convert the object to JSON bytes to take advantage of all the JSON tag
118
120
// handling and things like that.
@@ -210,7 +212,7 @@ func (ky *Encoder) renderNode(node *yaml.Node, indent int, flags flagMask, out i
210
212
211
213
// renderDocument processes a YAML document node, rendering it to the output.
212
214
// This function assumes that the output "cursor" is positioned at the start of
213
- // the document and should always emit a final newline.
215
+ // the document. This does not emit a final newline.
214
216
func (ky * Encoder ) renderDocument (doc * yaml.Node , indent int , flags flagMask , out io.Writer ) error {
215
217
if len (doc .Content ) == 0 {
216
218
return fmt .Errorf ("kyaml internal error: line %d: document has no content node (%d)" , doc .Line , len (doc .Content ))
@@ -243,18 +245,17 @@ func (ky *Encoder) renderDocument(doc *yaml.Node, indent int, flags flagMask, ou
243
245
if len (child .LineComment ) > 0 {
244
246
ky .renderComments (" " + child .LineComment , 0 , out )
245
247
}
246
- fmt .Fprint (out , "\n " )
247
248
if len (child .FootComment ) > 0 {
248
- ky .renderComments (child .FootComment , indent , out )
249
249
fmt .Fprint (out , "\n " )
250
+ ky .renderComments (child .FootComment , indent , out )
250
251
}
251
252
if len (doc .LineComment ) > 0 {
252
- ky .renderComments (" " + doc .LineComment , 0 , out )
253
253
fmt .Fprint (out , "\n " )
254
+ ky .renderComments (" " + doc .LineComment , 0 , out )
254
255
}
255
256
if len (doc .FootComment ) > 0 {
256
- ky .renderComments (doc .FootComment , indent , out )
257
257
fmt .Fprint (out , "\n " )
258
+ ky .renderComments (doc .FootComment , indent , out )
258
259
}
259
260
}
260
261
return nil
0 commit comments