Skip to content

Instantly share code, notes, and snippets.

@makyo
Last active Feb 3, 2022
Embed
What would you like to do?
Markdown footnotes in Hugo Shortcodes

I needed footnotes within a shortcode that utilized HTML. Theoretically, that is what {{% style shortcodes are for, but they don't work with a subset of markdown, notably footnotes. In order to get around that, it turns out that you need to use printf to print the HTML tags, as that takes place in the postprocessor. Thanks to Nelis Oostens for the tip, but as I'll be using this in multiple sites with different themes, I wanted it easy to just snag.

---
title: Fancy poem
type: list
---

{{% verse %}}
test[^footnote]
test
{{% /verse %}}

[^footnote]: test
{{/* `printf` required to prevent goldmark from refusing to markdownify .Inner */}}
{{ printf "<div class=\"verse\">" | htmlUnescape | safeHTML }}
{{ .Inner }}
{{ printf "</div>" | htmlUnescape | safeHTML }}
.verse {
white-space: pre-wrap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment