Skip to content

Commit

Permalink
tpl/transform: Make Plainify and ToMath return template.HTML
Browse files Browse the repository at this point in the history
None of these are useful as plain strings in the templates, which forces the users to do `transform.Plainify "foo" | safeHTML`.

If people have trust issues with the output of these functions, they need to just stop using them.

Closes gohugoio#8732
  • Loading branch information
bep committed Aug 11, 2024
1 parent 5d84f64 commit 71897a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/content/en/functions/transform/Plainify.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords: []
action:
aliases: [plainify]
related: []
returnType: string
returnType: template.HTML
signatures: [transform.Plainify INPUT]
aliases: [/functions/plainify]
---
Expand Down
6 changes: 3 additions & 3 deletions tpl/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,18 @@ func (ns *Namespace) Markdownify(ctx context.Context, s any) (template.HTML, err
}

// Plainify returns a copy of s with all HTML tags removed.
func (ns *Namespace) Plainify(s any) (string, error) {
func (ns *Namespace) Plainify(s any) (template.HTML, error) {
ss, err := cast.ToStringE(s)
if err != nil {
return "", err
}

return tpl.StripHTML(ss), nil
return template.HTML(tpl.StripHTML(ss)), nil
}

// ToMath converts a LaTeX string to math in the given format, default MathML.
// This uses KaTeX to render the math, see https://katex.org/.
func (ns *Namespace) ToMath(ctx context.Context, args ...any) (string, error) {
func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, error) {
if len(args) < 1 {
return "", errors.New("must provide at least one argument")
}
Expand Down

0 comments on commit 71897a7

Please sign in to comment.