Theme-aware syntax highlighting
(sidenote: I keep having to specify, so it doesn’t seem like I’m referring to myself in third person.) (the static site generator) supports static syntax highlighting.
Instead of using a JavaScript based highlighter, you can perform highlighting at build time, rather than pulling in yet another dependency to slow down your site.
There’s great documentation for it here.
Unfortunately, it doesn’t support generating theme-aware CSS. If someone is viewing this blog in dark mode, they’ll see a light style, or vice-versa depending on the syntax highlighting theme.
Thankfully, there’s a nice way around this: media queries!
Here’s a short video to demonstrate what I’m talking about:
When in light mode, the syntax theme is solarized. When dark mode is toggled, the theme switches to solarized-dark.
To achieve this, we first need to generate both light and dark styles:
hugo gen chromastyles --style=solarized-dark > syntax-dark.css
hugo gen chromastyles --style=solarized > syntax-light.cssYou can find a list of available styles here.
Once that’s done, we can combine them into one file:
/* file: syntax.css */
/* Paste the default syntax CSS here, e.g. solarized-light */
@media screen and (prefers-color-scheme: dark) {
/* Paste the dark syntax CSS here, e.g. solarized-dark */
}All that’s left to do is import the above snippet into your
theme’s <head> template, like so:
{{ $syntax := resources.Get "css/syntax.css" | minify | fingerprint }}
<link rel="stylesheet" href="{{ $syntax.Permalink }}" integrity="{{ $syntax.Data.Integrity }}">The above snippet assumes syntax.css is stored in assets/css/.
On the web
Home alone, movie nights, Silksong returns - W04
Tue Jan 27 2026 by joelchrono's blogBuilding a TUI to index and search my coding agent sessions
Sat Jan 17 2026 by Stan's blogRecap 2025
Wed Dec 31 2025 by stefanzweifel.devA Fair, Cancelable Semaphore in Go
Sun Dec 21 2025 by Andrew Healey's BlogAn average new Dad's approach to training with kettlebells (and other tools) to develop General Physical Preparedness (GPP) at home
Mon Nov 24 2025 by Nicholas A. Danes, PhD
Generated by openring