Skip to content

Instantly share code, notes, and snippets.

@makyo
Last active February 3, 2022 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makyo/ae3e93eab0b3341812218c8702e376c9 to your computer and use it in GitHub Desktop.
Save makyo/ae3e93eab0b3341812218c8702e376c9 to your computer and use it in GitHub Desktop.
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