Hello,
I would like to open external links, those with https
in the URL, in a new tab. I recently switched from using Org mode syntax to Markdown for content and I noticed that Markdown supports render hooks. According to the documentation, the following code adds a rel
attribute to external links:
{{- $u := urls.Parse .Destination -}}
<a href="{{ .Destination | safeURL }}"
{{- with .Title }} title="{{ . }}"{{ end -}}
{{- if $u.IsAbs }} rel="external"{{ end -}}
>
{{- with .Text }}{{ . }}{{ end -}}
</a>
{{- /* chomp trailing newline */ -}}
However, from what I’ve noticed, browsers don’t seem to recognize the rel
attribute on its own or take any action based on it. I think I should use JavaScript in this case. Right? Or would it be better just to add target="_blank"
? Personally, I try to avoid using JavaScript unless absolutely necessary, as some users may have it disabled.
Do you think something like this is allowed in a render hook, or does my modification not conform to the intended use?
{{- $u := urls.Parse .Destination -}}
<a href="{{ .Destination | safeURL }}"
{{- with .Title }} title="{{ . }}"{{ end -}}
{{- if $u.IsAbs }} rel="external" target="_blank"{{ end -}}
>
I would be grateful for any suggestions.