And add a comment about why it exists.
"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)
}
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"))
}
contentToRenderv := args[sidx]
- if _, ok := contentToRenderv.(hstring.RenderedHTML); ok {
+ if _, ok := contentToRenderv.(hstring.HTML); 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")
Title() string
// The rendered (HTML) text.
- Text() hstring.RenderedHTML
+ Text() hstring.HTML
// The plain variant of Text.
PlainText() string
// The blockquote text.
// If type is "alert", this will be the alert text.
- Text() hstring.RenderedHTML
+ Text() hstring.HTML
/// Returns the blockquote type, one of "regular" and "alert".
// Type "alert" indicates that this is a GitHub type alert.
// Anchor is the HTML id assigned to the heading.
Anchor() string
// Text is the rendered (HTML) heading text, excluding the heading marker.
- Text() hstring.RenderedHTML
+ Text() hstring.HTML
// PlainText is the unrendered version of Text.
PlainText() string
type GetRendererFunc func(t RendererType, id any) any
type TableCell struct {
- Text hstring.RenderedHTML
+ Text hstring.HTML
Alignment string // left, center, or right
}
BaseContext: render.NewBaseContext(ctx, renderer, n, src, nil, ordinal),
typ: typ,
alertType: alertType,
- text: hstring.RenderedHTML(text),
+ text: hstring.HTML(text),
AttributesHolder: attributes.New(n.Attributes(), attributes.AttributesOwnerGeneral),
}
type blockquoteContext struct {
hooks.BaseContext
- text hstring.RenderedHTML
+ text hstring.HTML
alertType string
typ string
return c.alertType
}
-func (c *blockquoteContext) Text() hstring.RenderedHTML {
+func (c *blockquoteContext) Text() hstring.HTML {
return c.text
}
pageInner any
destination string
title string
- text hstring.RenderedHTML
+ text hstring.HTML
plainText string
*attributes.AttributesHolder
}
return ctx.pageInner
}
-func (ctx linkContext) Text() hstring.RenderedHTML {
+func (ctx linkContext) Text() hstring.HTML {
return ctx.text
}
pageInner any
level int
anchor string
- text hstring.RenderedHTML
+ text hstring.HTML
plainText string
*attributes.AttributesHolder
}
return ctx.anchor
}
-func (ctx headingContext) Text() hstring.RenderedHTML {
+func (ctx headingContext) Text() hstring.HTML {
return ctx.text
}
pageInner: pageInner,
destination: string(n.Destination),
title: string(n.Title),
- text: hstring.RenderedHTML(text),
+ text: hstring.HTML(text),
plainText: string(n.Text(source)),
AttributesHolder: attributes.New(attrs, attributes.AttributesOwnerGeneral),
},
pageInner: pageInner,
destination: string(n.Destination),
title: string(n.Title),
- text: hstring.RenderedHTML(text),
+ text: hstring.HTML(text),
plainText: string(n.Text(source)),
AttributesHolder: attributes.Empty,
},
page: page,
pageInner: pageInner,
destination: url,
- text: hstring.RenderedHTML(label),
+ text: hstring.HTML(label),
plainText: label,
AttributesHolder: attributes.Empty,
},
pageInner: pageInner,
level: n.Level,
anchor: string(anchor),
- text: hstring.RenderedHTML(text),
+ text: hstring.HTML(text),
plainText: string(n.Text(source)),
AttributesHolder: attributes.New(n.Attributes(), attributes.AttributesOwnerGeneral),
},
alignment = "left"
}
- cell := hooks.TableCell{Text: hstring.RenderedHTML(text), Alignment: alignment}
+ cell := hooks.TableCell{Text: hstring.HTML(text), Alignment: alignment}
if node.Parent().Kind() == gast.KindTableHeader {
table.THead[len(table.THead)-1] = append(table.THead[len(table.THead)-1], cell)