Differences between Hugo builtin-chroma and standalone chroma?

I have working syntax highlighting in Hugo 0.29, but not as good as I get with chroma standalone, and I’m wondering why…

Portion of my config:

pygmentsCodeFences: true
pygmentsUseClasses: true

In my hugo generated HTML, the tags have class names that look like s7d2 (for NameBuiltin), whereas with chroma standalone I get class names that look like nb (for NameBuiltin).

  • Why does it generate different class names than chroma?
  • Is it possible to use the original class names that chroma uses?
  • Why does standalone chroma do better highlighting? For example:
echo '(setq test "test")' | chroma -l emacs-lisp --html

With chroma standalone I get:

<span class="nb">setq</span> <span class="nv">test</span> <span class="s">&

But with hugo I get:

<span class="s7d0">setq</span><span class="s1f40"> </span><span class="s7d0">test</span><span class="s1f40"> </span><span class="sc1c">"test"</span>

The problem being that hugo applies the same class to both the setq and test, so I cannot style them differently, whereas standalone chroma applies different classes: the setq gets bolded, and test does not.

I’m assuming s7d0 is a default catch-all class? hugo gen chromastyles doesn’t even output that one.

heh, it’s already fixed in Chroma upstream :slight_smile: Now Chroma supports the original Pygments class names. So the CSS files used for Pygments can be used for Chroma too, without any modification.

Why does standalone chroma do better highlighting?

That issue was present in the Chroma released with Hugo 0.29, which also was fixed later. It is this issue. Chroma was lacking parsing of Emacs Lisp keywords. Alec Thomas, Chroma developer, was kind enough to quickly add that support.

See if this helps you; it’s a bash script to build using master branch of Hugo with master branch of Chroma. If you use 64-bit Linux, you can use the binary I built using that script.

1 Like

Fantastic, thank you for the info and your work!

:wave: Hi! I ran into a similar issue when upgrading to 0.29, and got the old behavior back using

pygmentsUseClassic = true

in my TOML config. I want the output to stay the same wrt the class naming and the styles but quite obviously I’d prefer to use chroma for this if it is indeed that much faster. Rather than installing from source, can I expect that to be fixed in the next stable release, and can you point me to a release calendar on when to expect it to land in homebrew, for example?

Great work, I love using Hugo!