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"))
}
diff --git a/hugolib/content_render_hooks_test.go b/hugolib/content_render_hooks_test.go
index abe305762..593d01da8 100644
--- a/hugolib/content_render_hooks_test.go
+++ b/hugolib/content_render_hooks_test.go
@@ -98,8 +98,8 @@ baseURL="https://example.org"
P1: {{ $p.Content }}
`,
- "_default/_markup/render-link.html", `html-link: {{ .Destination | safeURL }}|Text: {{ .Text | safeHTML }}|Plain: {{ .PlainText | safeHTML }}`,
- "_default/_markup/render-image.html", `html-image: {{ .Destination | safeURL }}|Text: {{ .Text | safeHTML }}|Plain: {{ .PlainText | safeHTML }}`,
+ "_default/_markup/render-link.html", `html-link: {{ .Destination | safeURL }}|Text: {{ .Text }}|Plain: {{ .PlainText | safeHTML }}`,
+ "_default/_markup/render-image.html", `html-image: {{ .Destination | safeURL }}|Text: {{ .Text }}|Plain: {{ .PlainText | safeHTML }}`,
)
b.WithContent("p1.md", `---
diff --git a/hugolib/page__content.go b/hugolib/page__content.go
index 30caebed0..31080b929 100644
--- a/hugolib/page__content.go
+++ b/hugolib/page__content.go
@@ -928,7 +928,7 @@ func (c *cachedContentScope) RenderString(ctx context.Context, args ...any) (tem
contentToRenderv := args[sidx]
- if _, ok := contentToRenderv.(hstring.RenderedString); ok {
+ if _, ok := contentToRenderv.(hstring.RenderedHTML); ok {
// This content is already rendered, this is potentially
// a infinite recursion.
return "", errors.New("text is already rendered, repeating it may cause infinite recursion")
diff --git a/markup/converter/hooks/hooks.go b/markup/converter/hooks/hooks.go
index 9487fd0a7..0232b619f 100644
--- a/markup/converter/hooks/hooks.go
+++ b/markup/converter/hooks/hooks.go
@@ -41,7 +41,7 @@ type LinkContext interface {
Title() string
// The rendered (HTML) text.
- Text() hstring.RenderedString
+ Text() hstring.RenderedHTML
// The plain variant of Text.
PlainText() string
@@ -100,7 +100,7 @@ type BlockquoteContext interface {
// The blockquote text.
// If type is "alert", this will be the alert text.
- Text() hstring.RenderedString
+ Text() hstring.RenderedHTML
/// Returns the blockquote type, one of "regular" and "alert".
// Type "alert" indicates that this is a GitHub type alert.
@@ -166,7 +166,7 @@ type HeadingContext interface {
// Anchor is the HTML id assigned to the heading.
Anchor() string
// Text is the rendered (HTML) heading text, excluding the heading marker.
- Text() hstring.RenderedString
+ Text() hstring.RenderedHTML
// PlainText is the unrendered version of Text.
PlainText() string
@@ -213,7 +213,7 @@ const (
type GetRendererFunc func(t RendererType, id any) any
type TableCell struct {
- Text hstring.RenderedString
+ Text hstring.RenderedHTML
Alignment string // left, center, or right
}
diff --git a/markup/goldmark/blockquotes/blockquotes.go b/markup/goldmark/blockquotes/blockquotes.go
index a261ec4fe..f68cccd06 100644
--- a/markup/goldmark/blockquotes/blockquotes.go
+++ b/markup/goldmark/blockquotes/blockquotes.go
@@ -95,7 +95,7 @@ func (r *htmlRenderer) renderBlockquote(w util.BufWriter, src []byte, node ast.N
BaseContext: render.NewBaseContext(ctx, renderer, n, src, nil, ordinal),
typ: typ,
alertType: alertType,
- text: hstring.RenderedString(text),
+ text: hstring.RenderedHTML(text),
AttributesHolder: attributes.New(n.Attributes(), attributes.AttributesOwnerGeneral),
}
@@ -134,7 +134,7 @@ func (r *htmlRenderer) renderBlockquoteDefault(
type blockquoteContext struct {
hooks.BaseContext
- text hstring.RenderedString
+ text hstring.RenderedHTML
alertType string
typ string
@@ -149,7 +149,7 @@ func (c *blockquoteContext) AlertType() string {
return c.alertType
}
-func (c *blockquoteContext) Text() hstring.RenderedString {
+func (c *blockquoteContext) Text() hstring.RenderedHTML {
return c.text
}
diff --git a/markup/goldmark/blockquotes/blockquotes_integration_test.go b/markup/goldmark/blockquotes/blockquotes_integration_test.go
index e4447e5e9..f12600b42 100644
--- a/markup/goldmark/blockquotes/blockquotes_integration_test.go
+++ b/markup/goldmark/blockquotes/blockquotes_integration_test.go
@@ -32,9 +32,9 @@ func TestBlockquoteHook(t *testing.T) {
block = true
title = true
-- layouts/_default/_markup/render-blockquote.html --
-Blockquote: |{{ .Text | safeHTML }}|{{ .Type }}|
+Blockquote: |{{ .Text }}|{{ .Type }}|
-- layouts/_default/_markup/render-blockquote-alert.html --
-{{ $text := .Text | safeHTML }}
+{{ $text := .Text }}
Blockquote Alert: |{{ $text }}|{{ .Type }}|
Blockquote Alert Attributes: |{{ $text }}|{{ .Attributes }}|
Blockquote Alert Page: |{{ $text }}|{{ .Page.Title }}|{{ .PageInner.Title }}|
diff --git a/markup/goldmark/goldmark_integration_test.go b/markup/goldmark/goldmark_integration_test.go
index 19338310c..c691435ee 100644
--- a/markup/goldmark/goldmark_integration_test.go
+++ b/markup/goldmark/goldmark_integration_test.go
@@ -76,7 +76,7 @@ title: "p1"
{{- range $k, $v := .Attributes -}}
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
{{- end -}}
->{{ .Text | safeHTML }}
+>{{ .Text }}
`
b := hugolib.Test(t, files)
@@ -146,11 +146,11 @@ title: "p1"
{{ .Content }}
-- layouts/_default/_markup/render-heading.html --