# Nested Shortcodes converting to \<pre\>\<code\> blocks

**URL:** <https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033>\
**Category:** support\
**Created:** [September 5, 2020, 5:04pm UTC](https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033 "2020-09-05T17:04:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fragmentedfolly](https://avatars.discourse-cdn.com/v4/letter/f/d26b3c/32.png) [@fragmentedfolly](https://discourse.gohugo.io/u/fragmentedfolly)\
**Post date:** [September 5, 2020, 5:04pm UTC](https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033/1 "2020-09-05T17:04:46Z")

</div>

I’m trying to keep my markdown clean by shifting html production to short codes. So for example, some pseudocode:

```auto
{{< div >}}
{{< somehtmlcontent >}}
{{< /div >}}

```

Inside `{{< somehtmlcontent >}}` will be

```auto
<b>Helo my dear</b>
<a href="mailto:whatever@gohugo.io">whatever@gohugo.io</a>
{{ partial "somemorehtml.html" }}

```

So what happens is that `Hello my dear` renders fine, but the rest of `{{< somehtmlcontent >}}` is dumped side `<pre><code></code></pre>` and no longer functions as HTML.

I’ve tried fiddling with using `{{% div %}}` and piping to `safeHTML` and `markdownify`, and I tried looking into the Goldmark configuration, but nothing I did stopped Hugo from inserting `<pre><code>` tags in there.

I’ve read the following comment (Edit, sorry that was the wrong link):

> [@HTML in nested shortcode gets escaped](https://discourse.gohugo.io/t/html-in-nested-shortcode-gets-escaped/23813/4):
>
> @maiki You mean like: note-open.html: \<div class="note"\> \<div class="info-header"\> Note\</div\> \<div class="info-body"\> note-close.html \</div\> \</div\> And then using it like: {{\< note-open \>}} …regular markdown here… {{\< note-close \>}} ? That works, and thanks for the idea, but that seems like a really unfortunate hack. Even dynamically rewriting the DOM via Javascript seems more appealing. Adding raw HTML each time is out of the question – I’m writing documentation (almost 200 pages…

It is suggested that structures like the `{{< div >}}` tag should be broken up into two short codes, one to open and one to close. Is that all we got?

Thanks.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 5, 2020, 8:39pm UTC](https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033/2 "2020-09-05T20:39:53Z")

</div>

What is the output of `hugo version`?

---

<div class="post-metadata">

**Author:** ![fragmentedfolly](https://avatars.discourse-cdn.com/v4/letter/f/d26b3c/32.png) [@fragmentedfolly](https://discourse.gohugo.io/u/fragmentedfolly)\
**Post date:** [September 6, 2020, 11:24am UTC](https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033/3 "2020-09-06T11:24:50Z")

</div>

```auto
Hugo Static Site Generator v0.74.3 linux/amd64 BuildDate: 2020-07-23T20:37:11Z

```

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 6, 2020, 3:45pm UTC](https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033/4 "2020-09-06T15:45:26Z")

</div>

My best guess is that you have 4 chars (or multiple of that) of indentation where you insert your shortcode – which makes the markdown engine think it’s a code block.

---

<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:** [November 13, 2023, 4:48pm UTC](https://discourse.gohugo.io/t/nested-shortcodes-converting-to-pre-code-blocks/28033/5 "2023-11-13T16:48:47Z")

</div>

A post was split to a new topic: [Shortcodes and indentation](https://discourse.gohugo.io/t/shortcodes-and-indentation/47088)
