hugo

With Hugo, can we use HTML code in a md file?


With Hugo, I am writing some HTML as Goldmark markdown doesn't support CSS classes or IDs.

My code is in post1.md:

<h2 data-toggle="collapse" data-target="#collapse-definition" aria-expanded="false" aria-controls="collapse-definition">Définition</h2>

The above is not compiled to HTML. Even the simplest div markup is omitted.


Solution

  • From version 0.6, Hugo uses Goldmark for markdown.

    For security reasons, Goldmark wipes HTML code.

    However, if you use HTML frequently in your site, you can add to your config.toml

    [markup.goldmark.renderer]
      unsafe = true # Allow HTML in md files
    

    For a less frequent usage of HTML, you can add safeHTML parameter to your HTML string (Hugo doc for safeHTML).