func (t *Template) lookupAndEscapeTemplate(name string) (tmpl *Template, err error) {
	t.nameSpace.mu.Lock()
	defer t.nameSpace.mu.Unlock()
	t.nameSpace.escaped = true
	tmpl = t.set[name]
	if tmpl == nil {
		return nil, fmt.Errorf("html/template: %q is undefined", name)
	}
	if tmpl.escapeErr != nil && tmpl.escapeErr != errEscapeOK {
		return nil, tmpl.escapeErr
	}
	if tmpl.text.Tree == nil || tmpl.text.Root == nil {
		return nil, fmt.Errorf("html/template: %q is an incomplete template", name)
	}
	if t.text.Lookup(name) == nil {
		panic("html/template internal error: template escaping out of sync")
	}
	if tmpl.escapeErr == nil {
		err = escapeTemplate(tmpl, tmpl.text.Root, name)
	}
	return tmpl, err
}
lookupAndEscapeTemplate guarantees that the template with the given name
is escaped, or returns an error if it cannot be. It returns the named
template.
package template
import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"path/filepath"
	"sync"
	"text/template"
	"text/template/parse"
	"log"
	"github.com/google/safehtml"
	"github.com/google/safehtml/uncheckedconversions"
)
type Template struct {
	escapeErr error
	text *template.Template
	Tree       *parse.Tree
	*nameSpace  
}
var errEscapeOK = fmt.Errorf("template escaped correctly")
type nameSpace struct {
	mu      sync.Mutex
	set     map[string]*Template
	escaped bool
	cspCompatible bool
	esc           escaper
}
func (t *Template) Templates() []*Template {
	ns := t.nameSpace
	ns.mu.Lock()
	defer ns.mu.Unlock()
	m := make([]*Template, 0, len(ns.set))
	for _, v := range ns.set {
		m = append(m, v)
	}
	return m
}
func (t *Template) Option(opt ...string) *Template {
	t.text.Option(opt...)
	return t
}
func (t *Template) checkCanParse() error {
	if t == nil {
		return nil
	}
	t.nameSpace.mu.Lock()
	defer t.nameSpace.mu.Unlock()
	if t.nameSpace.escaped {
		return fmt.Errorf("html/template: cannot Parse after Execute")
	}
	return nil
}
func (t *Template) escape() error {
	t.nameSpace.mu.Lock()
	defer t.nameSpace.mu.Unlock()
	t.nameSpace.escaped = true
	if t.escapeErr == nil {
		if t.Tree == nil {
			return fmt.Errorf("template: %q is an incomplete or empty template", t.Name())
		}
		if err := escapeTemplate(t, t.text.Root, t.Name()); err != nil {
			return err
		}
	} else if t.escapeErr != errEscapeOK {
		return t.escapeErr
	}
	return nil
}
func (t *Template) Execute(wr io.Writer, data interface{}) error {
	if err := t.escape(); err != nil {
		return err
	}
	return t.text.Execute(wr, data)
}
func (t *Template) ExecuteToHTML(data interface{}) (safehtml.HTML, error) {
	var buf bytes.Buffer
	if err := t.Execute(&buf, data); err != nil {
		return safehtml.HTML{}, err
	}
	return uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(buf.String()), nil
}
func MustParseAndExecuteToHTML(text stringConstant) safehtml.HTML {
	t, err := New("").Parse(text)
	if err != nil {
		log.Fatal(err)
	}
	html, err := t.ExecuteToHTML(nil)
	if err != nil {
		log.Fatal(err)
	}
	return html
}
func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
	tmpl, err := t.lookupAndEscapeTemplate(name)
	if err != nil {
		return err
	}
	return tmpl.text.Execute(wr, data)
}
func (t *Template) ExecuteTemplateToHTML(name string, data interface{}) (safehtml.HTML, error) {
	var buf bytes.Buffer
	if err := t.ExecuteTemplate(&buf, name, data); err != nil {
		return safehtml.HTML{}, err
	}
	return uncheckedconversions.HTMLFromStringKnownToSatisfyTypeContract(buf.String()), nil
}