# replaceRE markdown with html, then render safely

**URL:** <https://discourse.gohugo.io/t/replacere-markdown-with-html-then-render-safely/47916>\
**Category:** support\
**Created:** [January 22, 2024, 11:13pm UTC](https://discourse.gohugo.io/t/replacere-markdown-with-html-then-render-safely/47916 "2024-01-22T23:13:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/henrys/32/21083_2.png) [@henrys](https://discourse.gohugo.io/u/henrys)\
**Post date:** [January 22, 2024, 11:13pm UTC](https://discourse.gohugo.io/t/replacere-markdown-with-html-then-render-safely/47916/1 "2024-01-22T23:13:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 22, 2024, 11:21pm UTC](https://discourse.gohugo.io/t/replacere-markdown-with-html-then-render-safely/47916/2 "2024-01-22T23:21:31Z")

</div>

> [@henrys](#):
>
> I have markdown content, onto which I apply `replaceRE` with HTML

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

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

```

… you need to do this in your site configuration:

```plaintext
[markup.goldmark.renderer]
unsafe = true

```

It’s not unsafe if _you_ control the content.

---

<div class="post-metadata">

**Author:** ![henrys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/henrys/32/21083_2.png) [@henrys](https://discourse.gohugo.io/u/henrys)\
**Post date:** [January 23, 2024, 8:04am UTC](https://discourse.gohugo.io/t/replacere-markdown-with-html-then-render-safely/47916/3 "2024-01-23T08:04:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [January 25, 2024, 8:05am UTC](https://discourse.gohugo.io/t/replacere-markdown-with-html-then-render-safely/47916/4 "2024-01-25T08:05:08Z")

</div>

Closed on January 25, 2024, 8:05am UTC

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