replaceRE markdown with html, then render safely

I have markdown content, onto which I apply replaceRE with HTML replacement in my layout/*.html.

If I apply safeHTML, then the markdown is rendered literally.

If I apply markdownify, then <!-- raw HTML omitted -->.

Whelp!

What should I do to safely and simultaneously render my markdown and parse my HTML (short of enabling Goldmark unsafe rendering)?

Thanks,
Henry

Please provide an example, but if you’re mixing HTML with markdown and rendering the result…

{{ "**foo**" | replaceRE `foo` `<em>bar</em>` | .Page.RenderString }}

… you need to do this in your site configuration:

[markup.goldmark.renderer]
unsafe = true

It’s not unsafe if you control the content.

Thank you, this is really helpful!

I have ended up applying split to the string, then applying replaceRE and safeHTML to the different list elements, this way I can keep the Goldmark safe. I’m building a Hugo CMS for my users, as I couldn’t find one I was happy with, and it has to be baby proof.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.