Render hook's .Text wrapped in quotes

I have a render hook for links to add target="_blank" to external links, and it looks like this:

<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank"{{ end }}>{{ .Text }}</a>

However, when I render the following markdown, putting an image in the contents of the link, the output is the img html as text within the a tag, as you can see from this devtools screenshot:
image

It’s important to note that when I take away the render hook (and the link is rendered how hugo intends it) the image shows up perfectly fine. I have already tried enabling unsafe in the config file in case that helped, but it did not change anything. Is there something I am doing wrong here or is this a bug?

Thanks!

markdown

[![alt](/images/b.jpg)](https://gohugo.io "This is an external link").
 ---------------------  -----------------  ------------------------
      link text         link destination         link title

You need to pass the link text through the safeHTML function as shown in the documentation:
https://gohugo.io/templates/render-hooks/#link-with-title-markdown-example

This article might be helpful too:
https://www.digital.ink/blog/website-links-new-tab/

2 Likes

Ah, I missed that! Thank you!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.