Update: Chroma now supports solarized-dark
families. Currently, this version is not used in Hugo.
Hugo has switched to Chroma for syntax highlighting from Pygments. While it still supports Pygments, it appears Chroma is much faster. However, Chroma does not support the solarized dark theme that is used by Hugo-Octopress. So I had to generate the CSS and add it manually.
The process is decently simple because Chroma has a built-in tool for converting styles _tools/style.py
. You can see the files inside my clone:
These steps are for an Ubuntu 16 machine, but can be adapted for any OS.
GOPATH
and the rest.go get github.com/alecthomas/chroma
.sudo apt-get install python3-pygments
.sudo apt-get install python3-pystache
.solarized dark
: git clone https://github.com/john2x/solarized-pygment/
(do not need to install it).solarized=pygment/pygments_solarized
to more descriptive names. For example dark.py
might become solarized-dark.py
.dark.py
it's SolarizedDarkStyle
.pygments
installation path. On my machine it was:/usr/local/lib/python3.5/dist-packages/Pygments-2.2.0-py3.5.egg/pygments/styles
._tools/style.py
to generate go
files from styles:python3 style.py [style-name] pygments.styles.[py-file-name].[style-class-name] > style-name.go
style-name
is a string with new style's name. E.g. solarized-dark
.py-file-name
is the name of the py
file (w/o extension) that was copied to the Pygments directory. E.g. dark
.style-class-name
is the name of the python class inside the style. E.g. SolarizedDarkStyle
.python3 style.py solarized-dark pygments.styles.dark.SolarizedDarkStyle > solarized-dark.go
go
files to $GOPATH/Go/src/github.com/alecthomas/chroma/styles
.chroma.MustNewStyle
:var SolarizedDark = Register(chroma.MustNewStyle("solarized-dark", chroma.StyleEntries{
Now create the following Go application (or copy createCSS.go
). Modify the file and style names as needed and execute it:
|
|
Copy/paste the CSS files to your theme's CSS.
Inside your site's config file:
pygmentsUseClassic
: This will tell Hugo to use Chroma.pygmentsuseclasses = true
: Use CSS for highlighting.pygmentscodefences = true
: This adds code highlight to code fences.