Backtestshugorun-20261005-133023#15167

Issue #15167 Merged fix PR # Run 5 Oct 2026 · run-20261005-133023 gohugoio/hugo

Add classDark and classLight to css.ChromaStyles and "gen chromastyles" (default dark/light)

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Both patches make the same core change. They add ClassDark and ClassLight to ChromaStylesOptions, fall back to "dark" and "light" when the values are empty, and add the matching --classDark and --classLight CLI flags. The template function presumably maps dict keys to struct fields through mapstructure, so both should work from templates. On correctness the patches are equivalent; the defaulting differs only in style (A uses cmp.Or, B uses explicit if-blocks).

The difference is in testing. Patch A extends the CLI testscript to exercise the new flags, including negative checks: the default class is absent when a custom one is set, and custom classes are ignored without --modeSelector. Its integration test also adds negative assertions, such as no leakage of the other mode's class and no prefix without modeSelector. Patch B adds only a positive integration test and never tests the gen chromastyles CLI path the issue explicitly mentions. A's tests are more thorough and cover both surfaces named in the issue. Craft is comparable, with A's cmp.Or slightly more concise. A wins on tests.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

1h 4m

Wall-clock time in the container

Full test suite

No new failures

3,692 passed · 99 skipped · 3,800 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

61vs 44 merged

Changed lines, ours vs merged

I argued with @jmooring that it would be very unlikely that e.g. the CSS dark class would collide with existing classes in a project. After thinking a little, I still don't think that is a likely issue, but:

  1. I suspect there are JS/CSS frameworks with other naming standards for these mode classes (e.g. theme-dark)
  2. I would be an annoyed Hugo user if I needed to customise this class and had to do ugly string replacements.
  3. The cost for us adding these 2 new options is small.

The two patches

Our patch+58 −3
commands/gen.goindex f3747722c..e97d88405 100644@@ -46,6 +46,8 @@ func newGenCommand() *genCommand { 		style                  string 		mode                   string 		modeSelector           bool+		classDark              string+		classLight             string 		highlightStyle         string 		lineNumbersInlineStyle string 		lineNumbersTableStyle  string@@ -70,6 +72,8 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview 					Style:                  style, 					Mode:                   mode, 					ModeSelector:           modeSelector,+					ClassDark:              classDark,+					ClassLight:             classLight, 					HighlightStyle:         highlightStyle, 					LineNumbersInlineStyle: lineNumbersInlineStyle, 					LineNumbersTableStyle:  lineNumbersTableStyle,@@ -91,6 +95,10 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview 				_ = cmd.RegisterFlagCompletionFunc("mode", cobra.FixedCompletions([]string{"light", "dark"}, cobra.ShellCompDirectiveNoFileComp)) 				cmd.PersistentFlags().BoolVar(&modeSelector, "modeSelector", false, `scope selectors under a top level mode class, e.g. ".dark .chroma"`) 				_ = cmd.RegisterFlagCompletionFunc("modeSelector", cobra.NoFileCompletions)+				cmd.PersistentFlags().StringVar(&classDark, "classDark", "dark", `CSS class name for the dark mode selector, used with --modeSelector`)+				_ = cmd.RegisterFlagCompletionFunc("classDark", cobra.NoFileCompletions)+				cmd.PersistentFlags().StringVar(&classLight, "classLight", "light", `CSS class name for the light mode selector, used with --modeSelector`)+				_ = cmd.RegisterFlagCompletionFunc("classLight", cobra.NoFileCompletions) 				cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", `foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff"`) 				_ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions) 				cmd.PersistentFlags().StringVar(&lineNumbersInlineStyle, "lineNumbersInlineStyle", "", `foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff"`)markup/highlight/chromastyles.goindex c595c780a..7231926e3 100644@@ -15,6 +15,7 @@ package highlight  import ( 	"bytes"+	"cmp" 	"fmt" 	"slices" 	"strings"@@ -35,6 +36,14 @@ type ChromaStylesOptions struct { 	// Scope selectors under a top level mode class, e.g. ".dark .chroma". 	ModeSelector bool +	// The CSS class name used for the dark mode selector when ModeSelector is set.+	// Defaults to "dark".+	ClassDark string++	// The CSS class name used for the light mode selector when ModeSelector is set.+	// Defaults to "light".+	ClassLight string+ 	// Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff". 	HighlightStyle string @@ -100,7 +109,8 @@ func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) { 	} 	css := buf.String() 	if opts.ModeSelector {-		// Scope every selector under a top level mode class, e.g. ".dark .chroma".+		// Scope every selector under a top level mode class, e.g. ".dark .chroma"+		// (the class names can be set with ClassDark and ClassLight). 		// This allows generating both light and dark stylesheets and toggling 		// them with a parent class on the page. 		// There's no upstream option for this (I think), so do string replacements for now.@@ -108,9 +118,9 @@ func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) { 		var prefix string 		switch style.Mode() { 		case chroma.Light:-			prefix = ".light "+			prefix = "." + cmp.Or(opts.ClassLight, "light") + " " 		case chroma.Dark:-			prefix = ".dark "+			prefix = "." + cmp.Or(opts.ClassDark, "dark") + " " 		default: 			return "", fmt.Errorf("style %q does not have a light or dark mode", style.Name) 		}testscripts/commands/gen_chromastyles_mode.txtindex 229f5f8cc..91b149944 100644@@ -22,3 +22,19 @@ stdout '\.light \.chroma' # --modeSelector without --mode on a default dark style. hugo gen chromastyles --style ashen --modeSelector stdout '\.dark \.chroma'++# Custom dark mode class.+hugo gen chromastyles --style github --mode dark --modeSelector --classDark theme-dark+stdout '\.theme-dark \.chroma'+stdout '\.theme-dark \.bg \{'+! stdout '\.dark \.chroma'++# Custom light mode class.+hugo gen chromastyles --style github --mode light --modeSelector --classLight theme-light+stdout '\.theme-light \.chroma'+stdout '\.theme-light \.bg \{'+! stdout '\.light \.chroma'++# Custom classes are ignored without --modeSelector.+hugo gen chromastyles --style github --mode dark --classDark theme-dark+! stdout '\.theme-dark 'tpl/css/chromastyles_integration_test.goindex 402ef2ca6..b7be5336e 100644@@ -47,6 +47,27 @@ 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" "classDark" "theme-dark") }}+{{ $dark := css.ChromaStyles (dict "targetPath" "css/chroma-dark.css" "style" "github" "mode" "dark" "modeSelector" true "classLight" "theme-light" "classDark" "theme-dark") }}+{{ $noSelector := css.ChromaStyles (dict "targetPath" "css/chroma-noselector.css" "style" "github" "mode" "dark" "classDark" "theme-dark") }}+Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|NoSelector: {{ $noSelector.RelPermalink }}|+`++	b := hugolib.Test(t, files)++	b.AssertFileContent("public/css/chroma-light.css", ".theme-light .chroma ", ".theme-light .bg {", "! .light .chroma", "! theme-dark")+	b.AssertFileContent("public/css/chroma-dark.css", ".theme-dark .chroma ", ".theme-dark .bg {", "! .dark .chroma", "! theme-light")+	b.AssertFileContent("public/css/chroma-noselector.css", "/* Background */ .bg {", "! theme-dark")+}+ // 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. 
Merged fix · PR #+42 −2
commands/gen.goindex f3747722c..42b22165d 100644@@ -46,6 +46,8 @@ func newGenCommand() *genCommand { 		style                  string 		mode                   string 		modeSelector           bool+		classDark              string+		classLight             string 		highlightStyle         string 		lineNumbersInlineStyle string 		lineNumbersTableStyle  string@@ -70,6 +72,8 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview 					Style:                  style, 					Mode:                   mode, 					ModeSelector:           modeSelector,+					ClassDark:              classDark,+					ClassLight:             classLight, 					HighlightStyle:         highlightStyle, 					LineNumbersInlineStyle: lineNumbersInlineStyle, 					LineNumbersTableStyle:  lineNumbersTableStyle,@@ -91,6 +95,10 @@ See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview 				_ = cmd.RegisterFlagCompletionFunc("mode", cobra.FixedCompletions([]string{"light", "dark"}, cobra.ShellCompDirectiveNoFileComp)) 				cmd.PersistentFlags().BoolVar(&modeSelector, "modeSelector", false, `scope selectors under a top level mode class, e.g. ".dark .chroma"`) 				_ = cmd.RegisterFlagCompletionFunc("modeSelector", cobra.NoFileCompletions)+				cmd.PersistentFlags().StringVar(&classDark, "classDark", "dark", `class name used by --modeSelector for dark styles`)+				_ = cmd.RegisterFlagCompletionFunc("classDark", cobra.NoFileCompletions)+				cmd.PersistentFlags().StringVar(&classLight, "classLight", "light", `class name used by --modeSelector for light styles`)+				_ = cmd.RegisterFlagCompletionFunc("classLight", cobra.NoFileCompletions) 				cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", `foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff"`) 				_ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions) 				cmd.PersistentFlags().StringVar(&lineNumbersInlineStyle, "lineNumbersInlineStyle", "", `foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff"`)markup/highlight/chromastyles.goindex c595c780a..f17170ad0 100644@@ -35,6 +35,12 @@ type ChromaStylesOptions struct { 	// Scope selectors under a top level mode class, e.g. ".dark .chroma". 	ModeSelector bool +	// Class name used by ModeSelector for dark styles, defaults to "dark".+	ClassDark string++	// Class name used by ModeSelector for light styles, defaults to "light".+	ClassLight string+ 	// Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff". 	HighlightStyle string @@ -105,12 +111,19 @@ func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) { 		// them with a parent class on the page. 		// There's no upstream option for this (I think), so do string replacements for now. 		// TODO(bep) upstream option for this.+		classDark, classLight := opts.ClassDark, opts.ClassLight+		if classDark == "" {+			classDark = "dark"+		}+		if classLight == "" {+			classLight = "light"+		} 		var prefix string 		switch style.Mode() { 		case chroma.Light:-			prefix = ".light "+			prefix = "." + classLight + " " 		case chroma.Dark:-			prefix = ".dark "+			prefix = "." + classDark + " " 		default: 			return "", fmt.Errorf("style %q does not have a light or dark mode", style.Name) 		}tpl/css/chromastyles_integration_test.goindex 402ef2ca6..682f11724 100644@@ -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.