css: Add classDark and classLight options to css.ChromaStyles and gen chromastyles

Closes #15167
This commit is contained in:
Bjørn Erik Pedersen
2026-08-05 11:34:04 +02:00
parent 64da6d7c62
commit 33d1f2c853
3 changed files with 42 additions and 2 deletions
+19
View File
@@ -47,6 +47,25 @@ Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|Default: {{ $def
b.AssertFileContent("public/css/chroma.css", "/* Background */ .bg {", "background-color:#272822")
}
// See issue 15167.
func TestChromaStylesCustomModeClasses(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ["taxonomy", "term", "rss", "sitemap", "section", "page"]
-- layouts/home.html --
{{ $light := css.ChromaStyles (dict "targetPath" "css/chroma-light.css" "style" "github" "mode" "light" "modeSelector" true "classLight" "theme-light") }}
{{ $dark := css.ChromaStyles (dict "targetPath" "css/chroma-dark.css" "style" "github" "mode" "dark" "modeSelector" true "classDark" "theme-dark") }}
Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/css/chroma-light.css", ".theme-light .chroma ", ".theme-light .bg {")
b.AssertFileContent("public/css/chroma-dark.css", ".theme-dark .chroma ", ".theme-dark .bg {")
}
// Chroma's minifier drops token rules whose color equals the style's default
// foreground (e.g. .nx in github-dark). In a paired light/dark setup the light
// sheet's explicit rule would then leak into dark mode, so these must be re-emitted.