diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-09-01 10:03:10 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-09-01 10:04:20 +0200 |
commit | 469124823c8cb4477816686f56efdeebc79a9044 (patch) | |
tree | 37c473a1ac7e22989bf347d645e8fc5d70e5a0df /common | |
parent | 96afea4acc7ca8cdfce460127b8ae17e303c77c0 (diff) | |
download | hugo-469124823c8cb4477816686f56efdeebc79a9044.tar.gz hugo-469124823c8cb4477816686f56efdeebc79a9044.zip |
Rename hstring.RenderedHTML => hstring.HTML
And add a comment about why it exists.
Diffstat (limited to 'common')
-rw-r--r-- | common/types/hstring/stringtypes.go | 14 | ||||
-rw-r--r-- | common/types/hstring/stringtypes_test.go | 4 |
2 files changed, 10 insertions, 8 deletions
diff --git a/common/types/hstring/stringtypes.go b/common/types/hstring/stringtypes.go index 05977ddce..53ce2068f 100644 --- a/common/types/hstring/stringtypes.go +++ b/common/types/hstring/stringtypes.go @@ -19,16 +19,18 @@ import ( "github.com/gohugoio/hugo/common/types" ) -var _ types.PrintableValueProvider = RenderedHTML("") +var _ types.PrintableValueProvider = HTML("") -// RenderedHTML is a string that represents rendered HTML. -// When printed in templates it will be rendered as template.HTML and considered safe. -type RenderedHTML string +// HTML is a string that represents rendered HTML. +// When printed in templates it will be rendered as template.HTML and considered safe so no need to pipe it into `safeHTML`. +// This type was introduced as a wasy to prevent a common case of inifinite recursion in the template rendering +// when the `linkify` option is enabled with a common (wrong) construct like `{{ .Text | .Page.RenderString }}` in a hook template. +type HTML string -func (s RenderedHTML) String() string { +func (s HTML) String() string { return string(s) } -func (s RenderedHTML) PrintableValue() any { +func (s HTML) PrintableValue() any { return template.HTML(s) } diff --git a/common/types/hstring/stringtypes_test.go b/common/types/hstring/stringtypes_test.go index 75b7af13c..05e2c22b9 100644 --- a/common/types/hstring/stringtypes_test.go +++ b/common/types/hstring/stringtypes_test.go @@ -25,6 +25,6 @@ func TestRenderedString(t *testing.T) { c := qt.New(t) // Validate that it will behave like a string in Hugo settings. - c.Assert(cast.ToString(RenderedHTML("Hugo")), qt.Equals, "Hugo") - c.Assert(template.HTML(RenderedHTML("Hugo")), qt.Equals, template.HTML("Hugo")) + c.Assert(cast.ToString(HTML("Hugo")), qt.Equals, "Hugo") + c.Assert(template.HTML(HTML("Hugo")), qt.Equals, template.HTML("Hugo")) } |