Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add skip escape config #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions etree.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ type WriteSettings struct {
// are also produced for " and '. Default: false.
CanonicalText bool

// EscapeSkipText skip escape for text data Default: false.
EscapeSkipText bool

// EscapeSkipText skip escape for attribute value Default: false.
EscapeSkipAttrVal bool

// CanonicalAttrVal forces the production of XML character references for
// attribute value characters &, < and ". If false, XML character
// references are also produced for > and '. Ignored when AttrSingleQuote
Expand Down Expand Up @@ -1464,7 +1470,9 @@ func (a *Attr) WriteTo(w Writer, s *WriteSettings) {
w.WriteString(`="`)
}
var m escapeMode
if s.CanonicalAttrVal && !s.AttrSingleQuote {
if s.EscapeSkipAttrVal {
m = escapeSkip
} else if s.CanonicalAttrVal && !s.AttrSingleQuote {
m = escapeCanonicalAttr
} else {
m = escapeNormal
Expand Down Expand Up @@ -1579,7 +1587,9 @@ func (c *CharData) WriteTo(w Writer, s *WriteSettings) {
w.WriteString(`]]>`)
} else {
var m escapeMode
if s.CanonicalText {
if s.EscapeSkipText {
m = escapeSkip
} else if s.CanonicalText {
m = escapeCanonicalText
} else {
m = escapeNormal
Expand Down
5 changes: 5 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,15 @@ const (
escapeNormal escapeMode = iota
escapeCanonicalText
escapeCanonicalAttr
escapeSkip
)

// escapeString writes an escaped version of a string to the writer.
func escapeString(w Writer, s string, m escapeMode) {
if m == escapeSkip {
w.WriteString(s)
return
}
var esc []byte
last := 0
for i := 0; i < len(s); {
Expand Down