go-yaml icon indicating copy to clipboard operation
go-yaml copied to clipboard

EncodeToNodeContext doesn't encode comments

Open alexjx opened this issue 3 years ago • 0 comments

Hi,

This is a great library!

While I'm playing with it, I found that EncodeToNodeContext doesn't respect CommentMap option. However from following code, it seems the comments also encoded into node before written out.

// EncodeContext writes the YAML encoding of v to the stream with context.Context.
func (e *Encoder) EncodeContext(ctx context.Context, v interface{}) error {
	node, err := e.EncodeToNodeContext(ctx, v)
	if err != nil {
		return errors.Wrapf(err, "failed to encode to node")
	}
	if err := e.setCommentByCommentMap(node); err != nil {
		return errors.Wrapf(err, "failed to set comment by comment map")
	}
	var p printer.Printer
	e.writer.Write(p.PrintNode(node))
	return nil
}

Is there any special consideration that not putting the comments code into EncodeToNodeContext ?

Thanks. Jia

alexjx avatar Feb 21 '22 13:02 alexjx