From f1062519ae7d5dd41b681e43e992dbc66fcd0855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 20 Apr 2023 11:27:55 +0200 Subject: [PATCH] tpl/debug: Add VisualizeSpaces --- tpl/debug/debug.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tpl/debug/debug.go b/tpl/debug/debug.go index 11c925c75..d07a2804e 100644 --- a/tpl/debug/debug.go +++ b/tpl/debug/debug.go @@ -16,6 +16,8 @@ package debug import ( "github.com/sanity-io/litter" + "github.com/spf13/cast" + "github.com/yuin/goldmark/util" "github.com/gohugoio/hugo/deps" ) @@ -41,3 +43,9 @@ type Namespace struct { func (ns *Namespace) Dump(val any) string { 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))) +}