Markdown in shortcode gets rendered literally?

Hi everyone,

I’m trying to write a shortcode to automate rendering links to the Hammerspoon documentation. My first instinct was to use Markdown, so I defined the shortcode like this:

[`{{ .Get 0 }}`](http://www.hammerspoon.org/docs/{{ .Get 0 }}.html)

However, when I invoke the shortcode with {{% hsapi "hs.hotkey" %}}, the Markdown gets rendered literally, i.e. I get

[`hs.hotkey`](http://www.hammerspoon.org/docs/hs.hotkey.html)

in the output.

I have for now defined the shortcode using HTML, i.e. like this in layouts/shortcodes/hsapi.html:

<a href="http://www.hammerspoon.org/docs/{{ .Get 0 }}.html"><code>{{ .Get 0 }}</code></a>

And then it works fine, but I’m wondering why the first one does not.

What am I missing? Thanks for any pointers!

ps. I’ve rebooted my website using Hugo. It’s mostly empty for now, but if you want to take a look: http://zzamboni.org/ :slight_smile:

—Diego

I believe that shortcodes with internal markdown require an opening and closing statement. I don’t actually think it’s what you want in this use case, so your second use–that is, the HTML block with get–is a better fit. Isn’t it the desired output you want?

1 Like

@rdwatters Thanks! I realize now I had misinterpreted what {{% ... %}} means - I had misread it as “the text produced by the shortcode will be interpreted as Markdown” instead of “The text provided to the shortcode will be interpreted as Markdown”.

I guess what I wanted to do could be achieved with markdownify, but I don’t think it’s worth it - my HTML-based shortcode is working well enough.

1 Like