Add the ability to disable whitespace mutations
This commit is contained in:
parent
da0b1ebb52
commit
f4307541c4
23
namespace.go
23
namespace.go
@ -9,15 +9,20 @@ type Namespace struct {
|
||||
vars map[string]any
|
||||
tags map[string]Tag
|
||||
|
||||
escapeHTML *bool
|
||||
// WhitespaceMutations enables postprocessing to remove whitespace where it isn't needed
|
||||
// to make the resulting document look better. Postprocessing is only done oncewhen the
|
||||
// template is parsed, so it will not affect performance. (default: true)
|
||||
WhitespaceMutations bool
|
||||
escapeHTML *bool
|
||||
}
|
||||
|
||||
// New returns a new template namespace
|
||||
func New() *Namespace {
|
||||
return &Namespace{
|
||||
tmpls: map[string]Template{},
|
||||
vars: map[string]any{},
|
||||
tags: map[string]Tag{},
|
||||
tmpls: map[string]Template{},
|
||||
vars: map[string]any{},
|
||||
tags: map[string]Tag{},
|
||||
WhitespaceMutations: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +54,7 @@ func (n *Namespace) WithTagMap(m map[string]Tag) *Namespace {
|
||||
return n
|
||||
}
|
||||
|
||||
// WithVarMap turns HTML escaping on or off for the namespace
|
||||
// WithEscapeHTML turns HTML escaping on or off for the namespace
|
||||
func (n *Namespace) WithEscapeHTML(b bool) *Namespace {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
@ -57,6 +62,14 @@ func (n *Namespace) WithEscapeHTML(b bool) *Namespace {
|
||||
return n
|
||||
}
|
||||
|
||||
// WithWhitespaceMutations turns whitespace mutations on or off for the namespace
|
||||
func (n *Namespace) WithWhitespaceMutations(b bool) *Namespace {
|
||||
n.mu.Lock()
|
||||
defer n.mu.Unlock()
|
||||
n.WhitespaceMutations = true
|
||||
return n
|
||||
}
|
||||
|
||||
// GetTemplate tries to get a template from the namespace's template map.
|
||||
// If it finds the template, it returns the template and true. If it
|
||||
// doesn't find it, it returns nil and false.
|
||||
|
Loading…
Reference in New Issue
Block a user