In the theme that I use on this site Poison, the syntax highlighting for codeblocks was not working by default.
Hugo gives us the ability to override theme files by the static/ folder in our site’s root directory (where config.toml lives).
More specifically, in the case of Poison, the file in question was under:
|
|
Generate the desired syntax highlighting stylesheet
To override it we need to generate a syntax.css file for our desired syntax highlighting style.
Hugo has a guide to do so available in their documentation, but in short use the following command in the site’s root directory:
|
|
This generates the monokai style, changing the --style= parameter will allow you to use other supported styles, check the list of availablable styles in their documentation.
Move the file into the correct subfolder
In our case, we need to put the file here: static/css/syntax.css
This will override the theme’s file inside /themes/THEMENAME/static/css/syntax.css
Setup the config.toml file for our site
Now we need to change the configuration (or ensure that it is setup) so that syntax highlighting will be supported.
As per the default from their documentation available here, this was added to my config.toml file to make sure everything works fine:
|
|