Remove Markdown Syntax Images from .Content

As we all know Hugo 0.32+ renders images alongside content with the new .Resources related functions.

But… what if you want to use a Markdown editor to preview those images while you work. Or you simply want to keep these images in your markdown files for reference’s sake.

Markdown images with a relative path in the form of ![alt](1.jpg) will have a broken path when published. And this hasn’t changed with Hugo 032+

So how can we get rid of these broken markdown syntax images when the Hugo site is generated?

Like this:

{{ .Content | replaceRE "<img[^>]*>" "" | safeHTML }}

And that’s it. Now we can have our cake and eat it to.

Live preview in any Markdown Editor and clean markup in our generated Hugo sites.

4 Likes