Hugo shortcode for raw HTML

Sometimes a Markdown file needs one small block of HTML. Enabling raw HTML for the whole site works, but a shortcode makes that exception explicit in the content.

Create layouts/shortcodes/rawhtml.html:

<!-- raw html -->
{{.Inner}}

Then wrap the HTML in your Markdown file with the shortcode:

{{ < rawhtml > }}
  <p>Hello World!</p>
{{ < /rawhtml >}}

Keep the exception small

This shortcode outputs its inner content directly. Never use it for untrusted or user-generated HTML unless that content has been properly sanitized, because it can introduce cross-site scripting vulnerabilities.

Raw HTML also bypasses some of the useful constraints Markdown gives you. Keep the markup semantic, preserve accessibility, and prefer a purpose-built shortcode when the same component appears more than once. I would use this generic shortcode for occasional trusted markup, not as the default way to build content.