Shortcodes and numbers for reference-style link definitions

I know there’s been several recent questions on shortcodes, but I haven’t been able to find the answer to my question, so here’s another one.

In my article, I have a lot of outbound links. I have written them in markdown using numbers as reference-style link definitions:

[products][1]

At the end of the article, I reference the link:

[1]: https://google.com/

I’d like to write a shortcode that gives the following output:

<a class="link" href="https://google.com/" rel="nofollow" target="_blank">products</a>

Normally, I would just create a shortcode like this:

<a class="link" href="{{.Get "href"}}" rel="nofollow" target="_blank">{{.Get "text"}}</a>

And apply it:

{{< myshortcode href="https://google.com/" text="products" >}}

But I’m not sure how to go about this when using reference-style link definitions.

Check out the footnotes part of the Blackfriday markdown options:

footnotes

default: enabled
Purpose: When enabled, Pandoc-style footnotes will be supported. The footnote marker in the text that will become a superscript text; the footnote definition will be placed in a list of footnotes at the end of the document.
Example:

This is a footnote.[^1]

[^1]: the footnote text.

I suspect there aren’t many shortcode discussions because of this kinda ubiquitous markdown convention. Will that work for you?

I ask, since I’m note sure if this solves your issue, or if you were asking from a another angle. :slight_smile:

Thanks for the reply, but not exactly what I’m after.

The use case for using numbers as reference-style link definitions in markdown is because I have a 100+ links in my article and having all the links at the bottom makes it easier to read and edit.

I now need to add rel="nofollow" to most of the links, but that requires a shortcode. Adding {{< myshortcode href="https://google.com/" text="products" >}} to each link makes it more difficult to review, less clean. Does that make sense?

So I’m just looking to see if there’s a different approach.

Blackfriday has options you can set: nofollowLinks, hrefTargetBlank etc.: Content formats | Hugo

1 Like