baker
November 6, 2021, 1:18am
1
How to open a link in a new tab?
This does not work: (although it has the target="_blank in it)
Neither does: {:target="_blank"}
But what does work?
For the meantime I overcame the sketchy documentation for unsafe and made it work without markdown, with some guessing this HTML workaround worked:
[markup.goldmark.renderer]
unsafe = true
If the render hook isn’t working, you’re doing it wrong.
layouts/_default/_markup/render-link.html
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
{{- /* chomp */ -}}
markdown
[hugo](https://gohugo.io/)
rendered
<a href="https://gohugo.io/" target="_blank" rel="noopener">hugo</a>
Works great.
2 Likes
baker
November 6, 2021, 2:57am
3
I use your layouts/_default/_markup/render-link.html
Markdown
[hugo](https://gohugo.io/)
Rendered
<a href="https://gohugo.io/">hugo</a>
I still use Hugo ext. 0.89 though.
What is ‘this’?
Render hooks only apply to Markdown links in Markdown files. With Markdown render-link.html works great with version long before 0.89, so if it’s not working, you need show your repository (i.e. give us a link to a public repo) or a minimal reproducible test case in a public repository.
Otherwise you are wasting everyone’s time (yours and ours).
baker
November 6, 2021, 2:03pm
5
I created: layouts/_default/_markup/render-link.html
with this content (tried other too):
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a> {{- /* chomp */ -}}
markdown.md has
[hugo](https://gohugo.io/)
Which renders to:
<a href="https://gohugo.io/">hugo</a>
Cntr.C etc was done. So I wonder why it ain’t working?
It’s something I am working on and not public yet.
Then if you want help you need to create a minimal reproducible test case that is public.