provide noescape function for templates

This commit is contained in:
f0x 2021-07-08 15:14:05 +02:00
commit 89c369f21e
3 changed files with 22 additions and 1 deletions

View file

@ -20,6 +20,7 @@ package web
import (
"fmt"
"html/template"
"net/http"
"os"
"path/filepath"
@ -84,6 +85,10 @@ func (m *Module) NotFoundHandler(c *gin.Context) {
})
}
func noescape(str string) template.HTML {
return template.HTML(str)
}
// Route satisfies the RESTAPIModule interface
func (m *Module) Route(s router.Router) error {
@ -101,5 +106,13 @@ func (m *Module) Route(s router.Router) error {
// 404 handler
s.AttachNoRouteHandler(m.NotFoundHandler)
s.SetTemplateFuncMap(template.FuncMap{
"noescape": noescape,
})
if err != nil {
return fmt.Errorf("error setting router FuncMap: %s", err)
}
return nil
}