# Create simple shortcode to prevent markdown from rendering HTML

**URL:** <https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782>\
**Category:** support\
**Created:** [February 24, 2015, 10:36pm UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782 "2015-02-24T22:36:16Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 24, 2015, 10:36pm UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/1 "2015-02-24T22:36:16Z")

</div>

## Hi, Is there a shortcode I could put in a markdown file that very simply tells Hugo not to render any of the HTML inside it? Like:

## +++ front matter +++ \<shortcode\> a bunch of html that should be completely untouched by the markdown rendering engine \</shortcode\> this markdown content would be rendered normally

### Why?

Even though Markdown does a pretty good job not messing up HTML, it always seems to a little, and that gets in the way of a fast workflow.

This shortcode might be one half of a simple solution to the questions about (a) creating static content that can use partials and (b) creating nested, multi-level sites… I think if this works the matter will simply be a technique and no changes to Hugo would be necessary. I’ll write it up if I can make it work.

Thank you!

---

<div class="post-metadata">

**Author:** ![michael\_henderson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_henderson/32/10490_2.png) [@michael\_henderson](https://discourse.gohugo.io/u/michael_henderson)\
**Post date:** [February 25, 2015, 2:56am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/2 "2015-02-25T02:56:54Z")

</div>

Will {\< … \>} work for you?

---

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 25, 2015, 3:54am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/3 "2015-02-25T03:54:01Z")

</div>

Sorry…can you be more specific? Is that what goes in the shortcode file?

---

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 25, 2015, 4:05am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/4 "2015-02-25T04:05:48Z")

</div>

Whether or not a shortcode is used, it looks like when you put HTML in a markdown file it surrounds it with \<p\>…\</p\>. So this is another problem to overcome if the goal is to put content in content files and not store it in layouts (which seems like a worthy goal to me).

---

<div class="post-metadata">

**Author:** ![michael\_henderson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_henderson/32/10490_2.png) [@michael\_henderson](https://discourse.gohugo.io/u/michael_henderson)\
**Post date:** [February 25, 2015, 5:23am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/5 "2015-02-25T05:23:07Z")

</div>

I mistyped the shortcode, but it doesn’t matter. It gets wrapped as you say.

```auto
$ cat content/post/first.md
+++
date = "2015-02-24T23:14:31-06:00"
title = "first"
+++
{{< besafe >}}<h5>Hello <strong>World!</strong></h5>{{< /besafe >}}

$ cat layouts/shortcodes/besafe.html 
{{ .Inner }}

$ hugo server --watch

```

Produces

```auto
<!DOCTYPE html>
<html>
<title>first</title>
<body>
<p><h5>Hello <strong>World!</strong></h5>
</p>

<p><a href="/">Home</a></p>
</body>
</html>

```

Instead of the desired

```auto
<!DOCTYPE html>
<html>
<title>first</title>
<body>
<h5>Hello <strong>World!</strong></h5>

<p><a href="/">Home</a></p>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![michael\_henderson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_henderson/32/10490_2.png) [@michael\_henderson](https://discourse.gohugo.io/u/michael_henderson)\
**Post date:** [February 25, 2015, 5:28am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/6 "2015-02-25T05:28:34Z")

</div>

After looking through Blackfriday, which is the Markdown engine Hugo is using, I’m not sure that I’m answering the right question.

Inline HTML seems to be handled naturally in the Markdown file:

```auto
$ cat content/post/first.md
+++
date = "2015-02-24T23:14:31-06:00"
title = "first"
+++

<h5>Hello <strong>World!</strong></h5>

$ hugo

$ cat public/post/first/index.html
<!DOCTYPE html>
<html>
<title>first</title>
<body>

<h5>Hello <strong>World!</strong></h5>

<p><a href="/">Home</a></p>
</body>
</html>

```

You’ve found cases where that’s not working as you’d expect? What’s the input and output look like?

---

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 25, 2015, 6:11am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/7 "2015-02-25T06:11:32Z")

</div>

Yes - I found when I put in raw HTML, I occasionally get issues like the extra P tags and all of the comments in my HTML code come through lookling like \<!-- comment --\>. Which is strange because right here in the box I’m typing in right now, if I type \<!-- comment --\> it’s invisible, the way it should be. The markdown rendering engine on this site is different from Black Friday I suppose?

In terms of markdown adding the extra P tags, I see there’s a lot of discussion about it, not sure if it’s a bug or feature.

---

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 25, 2015, 6:14am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/8 "2015-02-25T06:14:25Z")

</div>

Also - big find - if I just change my markdown file to have an HTML file extension, Hugo doesn’t touch the HTML!! And it still passes the HTML to a template for inclusion and still honors the front matter which is where I can tell it what template to use. This is very cool and might be the solution.

I’ll just rename the content files that need to have a lot of HTML in them to filename.html.

**Do you know if this is intended behavior (i.e., won’t be changed? )** Really hope so.

---

<div class="post-metadata">

**Author:** ![michael\_henderson](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/michael_henderson/32/10490_2.png) [@michael\_henderson](https://discourse.gohugo.io/u/michael_henderson)\
**Post date:** [February 25, 2015, 6:21am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/9 "2015-02-25T06:21:50Z")

</div>

Mixins have been brought up a few times. I can’t find a recent thread, so I can’t confirm or deny.

---

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 25, 2015, 6:28am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/10 "2015-02-25T06:28:27Z")

</div>

Yeah the commenting behavior is very strange in Black Friday , definitely beyond my ability to see the logic, unless it’s buggy. I created a comment at the top of some HTML code in a Mardown file and it was rendered invisible, then put the same at the bottom and suddenly now both comments show up in the rendered HTML as \<!-- comment --\>.

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [February 25, 2015, 6:54am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/11 "2015-02-25T06:54:02Z")

</div>

## It is the intended behavior. We should document it better, but HTML is a supported markup language. Best,Steve

Steve Francia  
[http://stevefrancia.com](http://stevefrancia.com)[http://spf13.com](http://spf13.com)[http://twitter.com/spf13](http://twitter.com/spf13)

---

<div class="post-metadata">

**Author:** ![ChrisSLT](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@ChrisSLT](https://discourse.gohugo.io/u/ChrisSLT)\
**Post date:** [February 25, 2015, 7:08am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/12 "2015-02-25T07:08:56Z")

</div>

That is great news, thank you. Being able to have content files be HTML, and have Hugo not touch the HTML, would seem to solve all of the questions related to multi-level sites, static content with partials, homepage template behavior in other places, etc. I can write this up if you think it needs to be made clear? Or, it could be that I’m just late to the party 🙂

---

<div class="post-metadata">

**Author:** ![spf13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/spf13/32/37_2.png) [@spf13](https://discourse.gohugo.io/u/spf13)\
**Post date:** [February 25, 2015, 9:39am UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/13 "2015-02-25T09:39:10Z")

</div>

The whole community would benefit from your contribution

Steve Francia[spf13.com](http://spf13.com)@spf13

---

<div class="post-metadata">

**Author:** ![doompadee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/doompadee/32/15894_2.png) [@doompadee](https://discourse.gohugo.io/u/doompadee)\
**Post date:** [January 18, 2022, 3:32pm UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/14 "2022-01-18T15:32:13Z")

</div>

Do you use the Goldmark markdown handler? Have you tried the `unsafe = true` configuration option?

See [Configure Markup | Hugo](https://gohugo.io/getting-started/configuration-markup#configure-markup)

---

<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 18, 2022, 3:34pm UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/15 "2022-01-18T15:34:19Z")

</div>

You’re bumping a topic that is 7 years old?

---

<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 18, 2022, 3:34pm UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/16 "2022-01-18T15:34:24Z")

</div>



---

<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 18, 2022, 3:34pm UTC](https://discourse.gohugo.io/t/create-simple-shortcode-to-prevent-markdown-from-rendering-html/782/17 "2022-01-18T15:34:30Z")

</div>


