To use Chroma code highlighting with the Hugo Academic theme
The Academic theme uses Highlight.js for code highlighting, and it works well with the theme. Unfortunately, Highlight.js doesn’t support Emacs-lisp code highlighting. I spent some time to add Emacs-lisp to the lisp configuration using
hljs.registerLanguage
, but I could not understand how those work.
Hugo 0.28+ uses Chroma as the default code highlighter, and Chroma supports Emacs-lips syntax highlighting. So I have a couple of good reasons to try Chroma. I use Hugo v0.68.3 and Academic theme v4.8.0.
First, to disable Highlight.js, set highlight = false
in params.toml
. Then to enable Chroma, find [markup.highlight]
in config.toml
and put lines below:
|
|
There are some mismatch between background colors of code block and snippets. To fix it, run hugo gen chromastyles --style=<my_style>
to find the background color of my_style
. I choose “emacs”, whose background color is #f8f8f8
. The last step is to set background-color
of code
in assets/scss/custom.scss
. Visit the gallery of the highligh style in https://xyproto.github.io/splash/docs/all.html.
/* assets/scss/custom.scss */
code {
background-color: #f8f8f8;
}
The result is code blocks in this post. Displaying line numbers and line highlights are a plug of using Chroma.