Markdown Reference Links in Shortcodes

I have a shortcode named ‘q.html’ that looks like this:

 {{ .Inner }}

and the markdown content is:

{{%q%}}This is a [test][testlink].{{%/q%}}


It renders incorrectly as

<p><a href="">test</a></p>
This is a [test][testlink].

If I change the shortcode to:

{{ markdownify (delimit (slice .Inner "[testlink]:") "\n") }}

Then it renders correctly:

<p><a href="">test</a></p>
This is a <a href="">test</a>.

Which seems to indicate that when processing shortcodes reference-style links defined in the content markdown aren’t being passed to the Blackfriday processor.

Is there a way to make the defined reference links available to shortcodes rendered separately by Blackfriday?

The workaround I’m currently looking at is to define the links in the front matter and then use a shortcode to retrieve the link when needed.

Workaround shortcode (link.html):

{{ index .Page.Params.links (.Get 0) }}

Invoking the shortcode:


[test]({{<link testlink>}})
{{%q%}}This is a [test]({{<link testlink>}}).{{%/q%}}

Which renders correctly.

Is there a better workaround (assuming there’s no way to pass the reference links to Blackfriday)?


The shortcodes and the surrounding content share no common (Blackfriday) context, so no way to pass the ref to Blackfriday that I can think of. (and to stop a follow up question: I don’t see how we could easily do that with some code change, either).

Thanks for the quick reply. That was the answer I expected and I agree that it would be a non-trivial bit of work to somehow merge the contexts.

If anyone has other workarounds or approaches to avoid writing a URL multiple times in a way that works with shortcodes I’d appreciate it. My workaround works, but is kind of clunky. Maybe if there was an elegant way to reference the parameters defined in the front matter in the markdown…

This one seems like it’s pretty disastrous. I am using the expand shortcode from the learn theme - and all of the markdown reference links break.

Is there a way to change the shortcode so that it passes its contents through Blackfriday, and still has access to the reference links in the parent markdown file? I have files with about 50 links - my other solution will be to just not use shortcodes, which seems like it’s not the point.

With multiple links on one page I use the following syntax:


Read here [W3C][] or here [W3C][].

[W3C]: "Subresource Integrity"