How I Extended Markdown for Hugo

Interesting. I’m working on something similar (but a lot more limited) to make images turn into <figure> elements with the alt text in a <figcaption>.

In the single.html template, .Content is run through replaceRE (and safeHTML):

{{ .Content | replaceRE "<p><img src=\"([^\"]+)\" alt=\"([^\"]+)\" /></p>" "<figure><img src=\"$1\" alt=\"$2\"><figcaption>$2</figcaption></figure>" | safeHTML }}

Seems to work nicely and keeps the Markdown file clean (which I want because I also want to run them through Pandoc to make PDFs).

8 Likes