mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Rename hstring.RenderedHTML => hstring.HTML
And add a comment about why it exists.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user