Hello, I would like links with an https in their address to open in a separate tab, meaning they should have the target="_blank" attribute applied to them. However, I only want this to apply to links within articles.
I searched the forum and found that this can be achieved by modifying the _default/_markup template that renders the links, but since I’m using Emacs Org Mode, that solution doesn’t apply to me. However, I came across another post that suggested an alternative method, which seems to work:
The problem is that I’m using .Content in four different files, so I would need to add the same code to each one. That feels a bit redundant, but if that’s the only way to do it, I’ll go ahead with that.
CyrusYip Thank you. The layouts/_default/_markup/render-link.html metdod doesn’t work with Org format. As I mentioned in my first post, I’m not using Markdown.
irkode Thank you. I will try. I didn’t know that shortcodes can be used for inline HTML elements as well.
I created a shortcode named extlink taking inspiration from the figure shortcode:
{{- if .Get "url" -}}
<a href="{{ .Get "url" }}" target="_blank">
{{ with .Get "description" }}{{ . }}{{ end }}
</a>
{{- end -}}
then I call it like so:
Lorem ipsum {{< extlink url="https://domain.tld" description="Link text" >}} dolor sit.
I don’t use a closing {{< / extlink >}}. I think it’s fine in this case, though I’m not entirely sure. I would appreciate it if someone could point it out if I did anything wrong.
Since I haven’t received a response, I assume using the shortcode is acceptable. I was just asking because I wasn’t sure if shortcodes can work for inline elements without needing a closing shortcode tag.
Thank you. I appreciate it. It seems like I’m missing out on a lot of features by using the org format. I need to check out ox-hugo, it seems like a better method, with org files being exported to markdown. Honestly, I didn’t know about it until recently.