aboutsummaryrefslogtreecommitdiffhomepage
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-08-31 17:25:15 +0200
committerBjørn Erik Pedersen <[email protected]>2024-08-31 21:05:58 +0200
commit6d97ee711e834ad4a0d2aca44fafb042008a8429 (patch)
tree2c3beb6cb9782e8d2a117de6ea977b85c31eb402 /common
parentf738669a4d09ca04619f4d0f89d90c9b414e9f2e (diff)
downloadhugo-6d97ee711e834ad4a0d2aca44fafb042008a8429.tar.gz
hugo-6d97ee711e834ad4a0d2aca44fafb042008a8429.zip
Make all renderhook Text methods return template.HTML
Diffstat (limited to 'common')
-rw-r--r--common/types/hstring/stringtypes.go18
-rw-r--r--common/types/hstring/stringtypes_test.go4
2 files changed, 18 insertions, 4 deletions
diff --git a/common/types/hstring/stringtypes.go b/common/types/hstring/stringtypes.go
index 5e8e3a23d..05977ddce 100644
--- a/common/types/hstring/stringtypes.go
+++ b/common/types/hstring/stringtypes.go
@@ -13,8 +13,22 @@
package hstring
-type RenderedString string
+import (
+ "html/template"
-func (s RenderedString) String() string {
+ "github.com/gohugoio/hugo/common/types"
+)
+
+var _ types.PrintableValueProvider = RenderedHTML("")
+
+// 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
+
+func (s RenderedHTML) String() string {
return string(s)
}
+
+func (s RenderedHTML) PrintableValue() any {
+ return template.HTML(s)
+}
diff --git a/common/types/hstring/stringtypes_test.go b/common/types/hstring/stringtypes_test.go
index 2f1f865c8..75b7af13c 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(RenderedString("Hugo")), qt.Equals, "Hugo")
- c.Assert(template.HTML(RenderedString("Hugo")), qt.Equals, template.HTML("Hugo"))
+ c.Assert(cast.ToString(RenderedHTML("Hugo")), qt.Equals, "Hugo")
+ c.Assert(template.HTML(RenderedHTML("Hugo")), qt.Equals, template.HTML("Hugo"))
}