July 22, 2020

Add raw html support for hugo md files

Hugo does not allow to write raw html in markdown files but there is a easy way to enable this with hugo shortcodes. The suggested solution can be found here

Create raw html shortcode

Create file theme/[your-theme-name]/layouts/shortcodes/

And then you can use the short code in your markdown file e.g:

{{< rawhtml >}}
<div>
   <style type="text/css" scoped>
       button { color: green; } 
   </style>
   <script type="text/javascript">
      var clicks = 0;
      function onClick() {
          clicks += 1;
          document.getElementById("clicks").innerHTML = clicks;
      };
   </script>
   <button type="button" onClick="onClick()">Click me</button>
   <p>Clicks: <a id="clicks">0</a></p>
</div>
{{< /rawhtml >}}

Will render as

Clicks: 0

comments powered by Disqus

© Anis Alekic 2020