Highlight Hugo-Html templates

A language grammar to highlight Hugo’s templating language with Highlight.js.

preview

Requirements

The module has been implemented using Highlight.js version 11.11.1. It will most likely not work with an older version.

Download

Packages can be downloaded from: Releases1.

Usage

Include the highlight.js library in your webpage or Node app, then load this module.

Static website or simple usage

Load the module after loading highlight.js.

<script type="text/javascript" src="/path/to/highlight.min.js"></script>
<script type="text/javascript" src="/path/to/hugo-html.min.js"></script>
<script type="text/javascript">
   hljs.highlightAll();
</script>

Using a CDN

As of now we do not publish anything to a CDN.

With Node or another build system

There’s no official node packages. You will have to build from source

The Node description is just copy&paste from a readme example!!!

If you’re using Node / Webpack / Rollup / Browserify, etc, simply require the language module, then register it with highlight.js.

var hljs = require("highlight.js");
var hljsHugo = require("hugo-html");
hljs.registerLanguage("hugo-html", hljsHugo);
hljs.highlightAll();

Example code

Enclose your code in <pre><code> tags and at best set the language with class="hugo-html". If you want to rely on auto detection, read the section about that below.

<pre><code class="hugo-html">
<title>{{.Title}}</title>
</code></pre>

A word on auto detection

Handlebars and Go templates (used by Hugo) have similar template tags. Without additional relevance settings Hugo grammars will loose most of the time. Relevance settings are used to beat Handlebars auto-detection – doing best to make it possible to have both grammars loaded at the same time. Importing both hugo-text and hugo-html may result in undetermined auto-detection. To be on the safe side specify the language you want for every code block.

Build your own

The module works with the standard Highlight.js extra build system. Download the grammar source from our Releases page and copy it to the highlight.js/extra directory. Check out the Highlight.js documentation for more details.

License

This package is released under the MIT License. See LICENSE file for details.

The Site logo, icons, pictures, … and it’s derivate are (c) 2026 Irkode and not MIT licensed. To state it simple every image that does not contribute in understanding the Documentation or Code.

Author


  1. Draft- and pre-releases have to be manually browsed and downloaded. ↩︎