Skip to content

Commit

Permalink
added support for skipping comments in result xml
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehler authored and kkoehler committed Nov 18, 2022
1 parent 74894f2 commit 430f1eb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type outputConfiguration struct {
printSelf bool
preserveSpaces bool
emptyElementTagSupport bool
skipComments bool
}

type OutputOption func(*outputConfiguration)
Expand All @@ -73,6 +74,13 @@ func WithEmptyTagSupport() OutputOption {
}
}

// WithoutComments will skip comments in output
func WithoutComments() OutputOption {
return func(oc *outputConfiguration) {
oc.skipComments = true
}
}

// InnerText returns the text between the start and end tags of the object.
func (n *Node) InnerText() string {
var output func(*bytes.Buffer, *Node)
Expand Down Expand Up @@ -121,9 +129,11 @@ func outputXML(buf *bytes.Buffer, n *Node, preserveSpaces bool, config *outputCo
buf.WriteString("]]>")
return
case CommentNode:
buf.WriteString("<!--")
buf.WriteString(n.Data)
buf.WriteString("-->")
if !config.skipComments {
buf.WriteString("<!--")
buf.WriteString(n.Data)
buf.WriteString("-->")
}
return
case DeclarationNode:
buf.WriteString("<?" + n.Data)
Expand Down

0 comments on commit 430f1eb

Please sign in to comment.