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:

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?



[![alt](/images/b.jpg)]( "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:

This article might be helpful too:


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.