tpl/debug: Add VisualizeSpaces

This commit is contained in:
Bjørn Erik Pedersen 2023-04-20 11:27:55 +02:00
parent 46a3cf6186
commit f1062519ae
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -16,6 +16,8 @@ package debug
import ( import (
"github.com/sanity-io/litter" "github.com/sanity-io/litter"
"github.com/spf13/cast"
"github.com/yuin/goldmark/util"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"
) )
@ -41,3 +43,9 @@ type Namespace struct {
func (ns *Namespace) Dump(val any) string { func (ns *Namespace) Dump(val any) string {
return litter.Sdump(val) return litter.Sdump(val)
} }
// VisualizeSpaces returns a string with spaces replaced by a visible string.
func (ns *Namespace) VisualizeSpaces(val any) string {
s := cast.ToString(val)
return string(util.VisualizeSpaces([]byte(s)))
}