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 for Go/Hugo templates.

If you import both languages flavours – Hugo and Go there’s no way to be sure the right variant is taken. For templates having special Hugo stuff (like try, or hugo built_ins) it will work, but expect for templates without you might get the wrong flavor.

Handlebars is a winner

The above worked well in our test scenarios, but real live examples showed handlebars beats us most of the time.

Constructs like this one: {{- "hello" -}} may work. You can get that pass the Handlebars Playground if

with that you could even do

Although a JSON field “-” and a function named “-” even more. but some like it short and it’s legal.

We need a magic wand

The Highlight.js documentation about relevance is quite unspecific.

Highlight.js language grammar for Handlebars is too permissive. Some will shift it to the overall discussion where Syntax ends and Semantic starts.

The above simple “hello” scores 5 in handlebars, with three Scopes identified where two are nested within the first one.

<span class="hljs-template-variable"
   >{{ <span class="hljs-name">-</span> <span class="hljs-string">"hello"</span> -}}
</span>

with hugo-html that scores 2, with just three scopes in a row

<span class="hljs-template-tag">{{- </span>
<span class="hljs-string">"hello"</span>
<span class="hljs-template-tag"> -}}</span>

Nesting seems to raise relevance here.

What we currently do

If we would want to tackle this:

we might also analyze the possibility to detect hugo-html vs hugo-text