Backtestshugorun-20261024-162305#15112

Issue #15112 Merged fix PR #15149 Run 24 Oct 2026 · run-20261024-162305 gohugoio/hugo

Add css.ChromaStyles

Better

Our patch was judged better than the merged fix.

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

Both patches extract the CSS generation into highlight.ChromaStylesCSS and share it between the gen command and the new template function. Patch B follows the issue's explicit guidance to build the Resource via create.Client.FromString; Patch A instead calls ResourceSpec.NewResource directly with its own hash-keyed cache, ignoring that instruction. The issue's own example passes modeSelector as the string "dark"; Patch A's WeakDecode into a bool rejects this, and the independent TestBtJudgeChromaStylesIssueExample fails on A while passing on B. Patch B handles modeSelector as bool or class name (with validation), normalizes targetPath, errors on unknown options, and adds unit tests for the shared function, an integration test covering the issue example, a testscript update for the CLI, and docs. Patch A's tests are reasonable but narrower. B is more correct against the issue as written and better tested.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

55m 11s

Wall-clock time in the container

Full test suite

No new failures

240 passed · 2 skipped · 257 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

631vs 437 merged

Changed lines, ours vs merged

We have a CLI command for this, with Chroma's recent addition of dark/light modes, it would be convenient to generate these on-the-fly. This would allow this to be configured in hugo.toml and also allow the user an easier way to find the correct settings.

E.g.

{{ $dark := css.ChromaStyles dict 
  "targetPath" "css/croma_dark.css"
   "style" "monokai"
   "modeSelector" "dark"
    "mode" "dark"
}}
<link rel="stylesheet" href="{{ $dark.RelPermalink }}">

This would be even more useful if we fix #15103.

The two patches

Our patch+522 −109
commands/gen.goindex 8d9224a08..f3747722c 100644@@ -21,12 +21,8 @@ import ( 	"os" 	"path" 	"path/filepath"-	"slices" 	"strings" -	"github.com/alecthomas/chroma/v2"-	"github.com/alecthomas/chroma/v2/formatters/html"-	"github.com/alecthomas/chroma/v2/styles" 	"github.com/bep/simplecobra" 	"github.com/goccy/go-yaml" 	"github.com/gohugoio/hugo/common/hugo"@@ -34,6 +30,7 @@ import ( 	"github.com/gohugoio/hugo/helpers" 	"github.com/gohugoio/hugo/hugofs" 	"github.com/gohugoio/hugo/hugolib"+	"github.com/gohugoio/hugo/markup/highlight" 	"github.com/gohugoio/hugo/parser" 	"github.com/spf13/cobra" 	"github.com/spf13/cobra/doc"@@ -65,85 +62,24 @@ func newGenCommand() *genCommand { See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview of the available styles.`,  			run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {-				style = strings.ToLower(style)-				if !slices.Contains(styles.Names(), style) {-					return fmt.Errorf("invalid style: %s", style)-				}-				var chromaStyle *chroma.Style-				if mode != "" {-					var chromaMode chroma.Mode-					switch mode {-					case "light":-						chromaMode = chroma.Light-					case "dark":-						chromaMode = chroma.Dark-					default:-						return fmt.Errorf("invalid mode: %s", mode)-					}--					chromaStyle = styles.GetForMode(style, chromaMode)-					if chromaStyle.Mode() != chromaMode {-						return fmt.Errorf("style %q does not have a %q mode", style, mode)-					}-				} else {-					chromaStyle = styles.Get(style)-				}-				builder := chromaStyle.Builder()-				if highlightStyle != "" {-					builder.Add(chroma.LineHighlight, highlightStyle)-				}-				if lineNumbersInlineStyle != "" {-					builder.Add(chroma.LineNumbers, lineNumbersInlineStyle)-				}-				if lineNumbersTableStyle != "" {-					builder.Add(chroma.LineNumbersTable, lineNumbersTableStyle)-				}-				style, err := builder.Build()-				if err != nil {-					return err-				}- 				if omitEmpty { 					// See https://github.com/alecthomas/chroma/commit/5b2a4c5a26c503c79bc86ba3c4ae5b330028bd3d 					hugo.Deprecate("--omitEmpty", "Flag is no longer needed, empty classes are now always omitted.", "v0.149.0") 				}-				options := []html.Option{-					html.WithCSSComments(!omitClassComments),-				}-				if !modeSelector {-					// Only needed for the shared-scope overlay; --modeSelector-					// gives each mode its own scope and makes this redundant.-					options = append(options, html.WithCustomCSS(chromaCSSOverrides(style)))-				}--				formatter := html.New(options...)--				var buf bytes.Buffer-				fmt.Fprintf(&buf, "/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))-				formatter.WriteCSS(&buf, style)-				css := buf.String()-				if modeSelector {-					// Scope every selector under a top level mode class, e.g. ".dark .chroma".-					// 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.-					// TODO(bep) upstream option for this.-					var prefix string-					switch style.Mode() {-					case chroma.Light:-						prefix = ".light "-					case chroma.Dark:-						prefix = ".dark "-					default:-						return fmt.Errorf("style %q does not have a %q mode", style.Name, mode)-					}-					replacer := strings.NewReplacer(-						".bg {", prefix+".bg {",-						".chroma ", prefix+".chroma ",-					)-					css = replacer.Replace(css)+				css, err := highlight.ChromaStylesCSS(highlight.ChromaStylesOptions{+					Style:                  style,+					Mode:                   mode,+					ModeSelector:           modeSelector,+					HighlightStyle:         highlightStyle,+					LineNumbersInlineStyle: lineNumbersInlineStyle,+					LineNumbersTableStyle:  lineNumbersTableStyle,+					OmitClassComments:      omitClassComments,+				})+				if err != nil {+					return err 				} +				fmt.Printf("/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " ")) 				fmt.Print(css) 				return nil 			},@@ -330,38 +266,6 @@ url: %s 	} } -// chromaCSSOverrides re-emits leaf token colors that Chroma's minifier drops-// because they equal the style's default foreground (the .chroma color). Without-// modeSelector scoping, a paired light/dark stylesheet shares the same .chroma-// scope, and the light sheet's explicit rule (e.g. .chroma .nx) would otherwise-// leak into dark mode, since an explicit declaration beats inheritance.-func chromaCSSOverrides(style *chroma.Style) map[chroma.TokenType]string {-	bg := style.Get(chroma.Background)-	m := make(map[chroma.TokenType]string)-	for tt := range chroma.StandardTypes {-		if tt == chroma.Background || !style.Has(tt) || !chromaLeafToken(tt) {-			continue-		}-		entry := style.Get(tt)-		if !entry.Sub(bg).IsZero() || !entry.Colour.IsSet() {-			continue-		}-		if css := html.StyleEntryToCSS(chroma.StyleEntry{Colour: entry.Colour}); css != "" {-			m[tt] = css-		}-	}-	return m-}--func chromaLeafToken(tt chroma.TokenType) bool {-	for other := range chroma.StandardTypes {-		if other != tt && (other.Category() == tt || other.SubCategory() == tt) {-			return false-		}-	}-	return true-}- type genCommand struct { 	rootCmd *rootCommand docs/content/en/functions/css/ChromaStyles.mdnew file mode 100644index 000000000..1ab1252ad@@ -0,0 +1,54 @@+---+title: css.ChromaStyles+description: Returns a CSS stylesheet resource for the Chroma syntax highlighter, generated from the given options.+categories: []+keywords: [highlight,syntax,chroma]+params:+  functions_and_methods:+    aliases: []+    returnType: resource.Resource+    signatures: [css.ChromaStyles OPTIONS]+---++The stylesheet is needed if `markup.highlight.noClasses` is disabled in your site configuration. This function produces the same output as the [`hugo gen chromastyles`][] command, but it runs while the site builds.++```go-html-template+{{ $opts := dict+  "targetPath" "css/chroma-dark.css"+  "style" "github"+  "mode" "dark"+  "modeSelector" true+}}+{{ with css.ChromaStyles $opts }}+  <link rel="stylesheet" href="{{ .RelPermalink }}">+{{ end }}+```++## Options++targetPath+: (`string`) The path of the published stylesheet, relative to the `publishDir`. Required.++style+: (`string`) The name of the Chroma style. Defaults to the `markup.highlight.style` setting in your site configuration. See the [syntax highlighting styles][] for a preview of the available styles.++mode+: (`string`) The style mode, either `light` or `dark`. Leave this empty to use the style's default mode. Returns an error if the style has no variant for the given mode.++modeSelector+: (`bool` or `string`) If `true`, scopes every selector under a top-level class named after the style's mode, for example `.dark .chroma`. You can then switch between a light and a dark stylesheet by toggling a class on a parent element. If you pass a class name instead of a boolean, that class is used, for example `"night"` produces `.night .chroma`.++highlightStyle+: (`string`) The foreground and background colors for highlighted lines, for example `#fff000 bg:#000fff`.++lineNumbersInlineStyle+: (`string`) The foreground and background colors for inline line numbers, for example `#fff000 bg:#000fff`.++lineNumbersTableStyle+: (`string`) The foreground and background colors for table line numbers, for example `#fff000 bg:#000fff`.++omitClassComments+: (`bool`) Whether to leave out the CSS comment that precedes each rule and names its token type. Default is `false`.++[`hugo gen chromastyles`]: /commands/hugo_gen_chromastyles/+[syntax highlighting styles]: /quick-reference/syntax-highlighting-styles/markup/highlight/chromastyles.gonew file mode 100644index 000000000..39033e340@@ -0,0 +1,193 @@+// Copyright 2026 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package highlight++import (+	"bytes"+	"fmt"+	"slices"+	"strings"++	"github.com/alecthomas/chroma/v2"+	"github.com/alecthomas/chroma/v2/formatters/html"+	"github.com/alecthomas/chroma/v2/styles"+)++// ChromaStylesOptions configures the generation of a Chroma CSS stylesheet.+// It is shared by the "hugo gen chromastyles" command and the css.ChromaStyles template function.+type ChromaStylesOptions struct {+	// The Chroma style name, e.g. "monokai".+	Style string++	// The style mode, "light", "dark" or empty for the style's default.+	Mode string++	// Scope every selector under a top level mode class, e.g. ".dark .chroma".+	ModeSelector bool++	// If set, use this class name instead of the style's mode ("light" or "dark")+	// as the top level class, e.g. "night" gives ".night .chroma". Implies ModeSelector.+	ModeSelectorClass string `mapstructure:"-"`++	// Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff".+	HighlightStyle string++	// Foreground and background colors for inline line numbers.+	LineNumbersInlineStyle string++	// Foreground and background colors for table line numbers.+	LineNumbersTableStyle string++	// Omit CSS class comment prefixes in the generated CSS.+	OmitClassComments bool+}++// ChromaStylesCSS generates a CSS stylesheet for the Chroma code highlighter.+func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) {+	styleName := strings.ToLower(opts.Style)+	if !slices.Contains(styles.Names(), styleName) {+		return "", fmt.Errorf("invalid style: %s", styleName)+	}+	var chromaStyle *chroma.Style+	if opts.Mode != "" {+		var chromaMode chroma.Mode+		switch opts.Mode {+		case "light":+			chromaMode = chroma.Light+		case "dark":+			chromaMode = chroma.Dark+		default:+			return "", fmt.Errorf("invalid mode: %s", opts.Mode)+		}++		chromaStyle = styles.GetForMode(styleName, chromaMode)+		if chromaStyle.Mode() != chromaMode {+			return "", fmt.Errorf("style %q does not have a %q mode", styleName, opts.Mode)+		}+	} else {+		chromaStyle = styles.Get(styleName)+	}+	builder := chromaStyle.Builder()+	if opts.HighlightStyle != "" {+		builder.Add(chroma.LineHighlight, opts.HighlightStyle)+	}+	if opts.LineNumbersInlineStyle != "" {+		builder.Add(chroma.LineNumbers, opts.LineNumbersInlineStyle)+	}+	if opts.LineNumbersTableStyle != "" {+		builder.Add(chroma.LineNumbersTable, opts.LineNumbersTableStyle)+	}+	style, err := builder.Build()+	if err != nil {+		return "", err+	}++	if opts.ModeSelectorClass != "" {+		if !isValidCSSClassName(opts.ModeSelectorClass) {+			return "", fmt.Errorf("invalid mode selector class name: %q", opts.ModeSelectorClass)+		}+		opts.ModeSelector = true+	}++	options := []html.Option{+		html.WithCSSComments(!opts.OmitClassComments),+	}+	if !opts.ModeSelector {+		// Only needed for the shared-scope overlay; ModeSelector+		// gives each mode its own scope and makes this redundant.+		options = append(options, html.WithCustomCSS(chromaCSSOverrides(style)))+	}++	formatter := html.New(options...)++	var buf bytes.Buffer+	if err := formatter.WriteCSS(&buf, style); err != nil {+		return "", err+	}+	css := buf.String()+	if opts.ModeSelector {+		// Scope every selector under a top level mode class, e.g. ".dark .chroma".+		// 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.+		// TODO(bep) upstream option for this.+		var prefix string+		switch {+		case opts.ModeSelectorClass != "":+			prefix = "." + opts.ModeSelectorClass + " "+		case style.Mode() == chroma.Light:+			prefix = ".light "+		case style.Mode() == chroma.Dark:+			prefix = ".dark "+		default:+			return "", fmt.Errorf("style %q does not have a %q mode", style.Name, opts.Mode)+		}+		replacer := strings.NewReplacer(+			".bg {", prefix+".bg {",+			".chroma ", prefix+".chroma ",+		)+		css = replacer.Replace(css)+	}++	return css, nil+}++// isValidCSSClassName reports whether s is a simple CSS class name,+// i.e. letters, digits, hyphens and underscores not starting with a digit.+func isValidCSSClassName(s string) bool {+	if s == "" {+		return false+	}+	for i, r := range s {+		switch {+		case r >= 'a' && r <= 'z', r >= 'A' && r <= 'Z', r == '_', r == '-':+		case r >= '0' && r <= '9' && i > 0:+		default:+			return false+		}+	}+	return true+}++// chromaCSSOverrides re-emits leaf token colors that Chroma's minifier drops+// because they equal the style's default foreground (the .chroma color). Without+// modeSelector scoping, a paired light/dark stylesheet shares the same .chroma+// scope, and the light sheet's explicit rule (e.g. .chroma .nx) would otherwise+// leak into dark mode, since an explicit declaration beats inheritance.+func chromaCSSOverrides(style *chroma.Style) map[chroma.TokenType]string {+	bg := style.Get(chroma.Background)+	m := make(map[chroma.TokenType]string)+	for tt := range chroma.StandardTypes {+		if tt == chroma.Background || !style.Has(tt) || !chromaLeafToken(tt) {+			continue+		}+		entry := style.Get(tt)+		if !entry.Sub(bg).IsZero() || !entry.Colour.IsSet() {+			continue+		}+		if css := html.StyleEntryToCSS(chroma.StyleEntry{Colour: entry.Colour}); css != "" {+			m[tt] = css+		}+	}+	return m+}++func chromaLeafToken(tt chroma.TokenType) bool {+	for other := range chroma.StandardTypes {+		if other != tt && (other.Category() == tt || other.SubCategory() == tt) {+			return false+		}+	}+	return true+}markup/highlight/chromastyles_test.gonew file mode 100644index 000000000..bdb664fec@@ -0,0 +1,72 @@+// Copyright 2026 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package highlight++import (+	"testing"++	qt "github.com/frankban/quicktest"+)++func TestChromaStylesCSS(t *testing.T) {+	c := qt.New(t)++	css, err := ChromaStylesCSS(ChromaStylesOptions{Style: "Monokai"})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Contains, "/* GenericSubheading */")+	c.Assert(css, qt.Not(qt.Contains), ".dark ")++	css, err = ChromaStylesCSS(ChromaStylesOptions{Style: "monokai", OmitClassComments: true})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Not(qt.Contains), "GenericSubheading")++	// Same-colour leaf tokens are kept without a mode selector.+	css, err = ChromaStylesCSS(ChromaStylesOptions{Style: "github-dark"})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Contains, ".chroma .nx { color:#e6edf3 }")++	css, err = ChromaStylesCSS(ChromaStylesOptions{Style: "github", Mode: "dark", ModeSelector: true})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Contains, ".dark .bg {")+	c.Assert(css, qt.Contains, ".dark .chroma ")++	css, err = ChromaStylesCSS(ChromaStylesOptions{Style: "github", ModeSelector: true})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Contains, ".light .chroma ")++	css, err = ChromaStylesCSS(ChromaStylesOptions{Style: "github", Mode: "dark", ModeSelectorClass: "night"})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Contains, ".night .chroma ")+	c.Assert(css, qt.Not(qt.Contains), ".dark ")++	css, err = ChromaStylesCSS(ChromaStylesOptions{+		Style:                  "monokai",+		HighlightStyle:         "#fff000 bg:#000fff",+		LineNumbersInlineStyle: "#111111",+		LineNumbersTableStyle:  "#222222",+	})+	c.Assert(err, qt.IsNil)+	c.Assert(css, qt.Contains, ".chroma .hl { color:#fff000;background-color:#000fff }")+	c.Assert(css, qt.Contains, ".chroma .ln { white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#111 }")+	c.Assert(css, qt.Contains, ".chroma .lnt { white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#222 }")++	_, err = ChromaStylesCSS(ChromaStylesOptions{Style: "nope"})+	c.Assert(err, qt.ErrorMatches, "invalid style: nope")+	_, err = ChromaStylesCSS(ChromaStylesOptions{Style: "github", Mode: "dusk"})+	c.Assert(err, qt.ErrorMatches, "invalid mode: dusk")+	_, err = ChromaStylesCSS(ChromaStylesOptions{Style: "friendly", Mode: "dark"})+	c.Assert(err, qt.ErrorMatches, `style "friendly" does not have a "dark" mode`)+	_, err = ChromaStylesCSS(ChromaStylesOptions{Style: "github", ModeSelectorClass: "1a"})+	c.Assert(err, qt.ErrorMatches, `invalid mode selector class name: "1a"`)+}testscripts/commands/gen_chromastyles.txtindex 52fec26f0..f3d4b68d5 100644@@ -23,3 +23,9 @@ stdout 'GenericSubheading' hugo gen chromastyles --omitClassComments --style monokai ! stdout 'GenericSubheading' ++# Line highlight and line number styles.+hugo gen chromastyles --style monokai --highlightStyle '#fff000 bg:#000fff' --lineNumbersInlineStyle '#111111' --lineNumbersTableStyle '#222222'+stdout '\.chroma \.hl \{ color:#fff000;background-color:#000fff \}'+stdout '\.chroma \.ln \{.*color:#111 \}'+stdout '\.chroma \.lnt \{.*color:#222 \}'tpl/css/chromastyles_integration_test.gonew file mode 100644index 000000000..d2eddc40a@@ -0,0 +1,100 @@+// Copyright 2026 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package css_test++import (+	"strings"+	"testing"++	qt "github.com/frankban/quicktest"+	"github.com/gohugoio/hugo/hugolib"+)++func TestChromaStyles(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["page", "section", "taxonomy", "term", "sitemap", "rss"]+[markup.highlight]+style = "github"+-- layouts/home.html --+{{ $default := css.ChromaStyles (dict "targetPath" "css/chroma_default.css") }}+Default: {{ $default.RelPermalink }}|{{ $default.MediaType }}|+{{ $dark := css.ChromaStyles (dict "targetPath" "css/chroma_dark.css" "style" "github" "mode" "dark" "modeSelector" true) }}+Dark: {{ $dark.RelPermalink }}|+{{ $light := css.ChromaStyles (dict "targetPath" "/css/chroma_light.css" "style" "github" "mode" "light" "modeSelector" true "omitClassComments" true) }}+Light: {{ $light.RelPermalink }}|+{{ $custom := css.ChromaStyles (dict "targetPath" "css/chroma_custom.css" "style" "monokai" "modeSelector" "night" "highlightStyle" "#fff000 bg:#000fff") }}+Custom: {{ $custom.RelPermalink }}|+{{ $issue := css.ChromaStyles (dict "targetPath" "css/croma_dark.css" "style" "github" "mode" "dark" "modeSelector" "dark") }}+Issue: {{ $issue.RelPermalink }}|+`++	b := hugolib.Test(t, files)++	b.AssertFileContent("public/index.html",+		"Default: /css/chroma_default.css|text/css|",+		"Dark: /css/chroma_dark.css|",+		"Light: /css/chroma_light.css|",+		"Custom: /css/chroma_custom.css|",+		"Issue: /css/croma_dark.css|",+	)++	// Style defaults to markup.highlight.style; no mode selector.+	b.AssertFileContent("public/css/chroma_default.css", "/* Background */ .bg { background-color:#f7f7f7; }")+	b.AssertFileContent("public/css/chroma_dark.css", "/* Background */ .dark .bg {", ".dark .chroma ")+	b.AssertFileContent("public/css/chroma_light.css", ".light .bg {", ".light .chroma ", "! Background")+	b.AssertFileContent("public/css/chroma_custom.css", ".night .chroma .hl { color:#fff000;background-color:#000fff }")+	b.AssertFileContent("public/css/croma_dark.css", ".dark .chroma ")++	dark := b.FileContent("public/css/chroma_dark.css")+	light := b.FileContent("public/css/chroma_light.css")+	b.Assert(dark, qt.Not(qt.Equals), light)+	b.Assert(strings.Contains(b.FileContent("public/css/chroma_default.css"), ".light "), qt.IsFalse)+}++func TestChromaStylesErrors(t *testing.T) {+	t.Parallel()++	for _, test := range []struct {+		name string+		opts string+		want string+	}{+		{"missing target path", `(dict "style" "monokai")`, "must provide a targetPath"},+		{"invalid style", `(dict "targetPath" "a.css" "style" "__invalid__")`, "invalid style: __invalid__"},+		{"invalid mode", `(dict "targetPath" "a.css" "style" "github" "mode" "dusk")`, "invalid mode: dusk"},+		{"missing mode", `(dict "targetPath" "a.css" "style" "friendly" "mode" "dark")`, `style "friendly" does not have a "dark" mode`},+		{"unknown option", `(dict "targetPath" "a.css" "styel" "monokai")`, "styel"},+		{"invalid class", `(dict "targetPath" "a.css" "modeSelector" ".foo bar")`, "invalid mode selector class name"},+		{"slash only target path", `(dict "targetPath" "/" "style" "monokai")`, "must provide a targetPath"},+		{"empty mode selector", `(dict "targetPath" "a.css" "modeSelector" "")`, "got an empty string"},+		{"internal mode selector class option", `(dict "targetPath" "a.css" "modeSelectorClass" "x")`, "modeSelectorClass"},+	} {+		t.Run(test.name, func(t *testing.T) {+			t.Parallel()+			files := `+-- hugo.toml --+disableKinds = ["page", "section", "taxonomy", "term", "sitemap", "rss"]+-- layouts/home.html --+{{ $r := css.ChromaStyles OPTS }}{{ $r.RelPermalink }}+`+			files = strings.ReplaceAll(files, "OPTS", test.opts)+			b, err := hugolib.TestE(t, files)+			b.Assert(err, qt.IsNotNil)+			b.Assert(err.Error(), qt.Contains, test.want)+		})+	}+}tpl/css/css.goindex 64fc45ea6..961e49a78 100644@@ -4,6 +4,8 @@ import ( 	"context" 	"errors" 	"fmt"+	"maps"+	"strconv" 	"sync"  	"github.com/gohugoio/hugo/common/hmaps"@@ -11,8 +13,11 @@ import ( 	"github.com/gohugoio/hugo/common/paths" 	"github.com/gohugoio/hugo/common/types/css" 	"github.com/gohugoio/hugo/deps"+	"github.com/gohugoio/hugo/markup/highlight"+	"github.com/gohugoio/hugo/markup/markup_config" 	"github.com/gohugoio/hugo/resources" 	"github.com/gohugoio/hugo/resources/resource"+	"github.com/gohugoio/hugo/resources/resource_factories/create" 	"github.com/gohugoio/hugo/resources/resource_transformers/babel" 	"github.com/gohugoio/hugo/resources/resource_transformers/cssjs" 	jstransform "github.com/gohugoio/hugo/resources/resource_transformers/js"@@ -21,6 +26,7 @@ import ( 	"github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss" 	"github.com/gohugoio/hugo/tpl/internal" 	"github.com/gohugoio/hugo/tpl/internal/resourcehelpers"+	"github.com/mitchellh/mapstructure" 	"github.com/spf13/cast" ) @@ -34,6 +40,7 @@ type Namespace struct { 	tailwindcssClient *cssjs.TailwindCSSClient 	babelClient       *babel.Client 	jsTransformClient *jstransform.Client+	createClient      *create.Client  	// The Dart Client requires a os/exec process, so  only 	// create it if we really need it.@@ -54,6 +61,77 @@ func (ns *Namespace) Unquoted(v any) css.UnquotedString { 	return css.UnquotedString(s) } +// chromaStylesOptions are the options for ChromaStyles.+type chromaStylesOptions struct {+	// The target path of the generated stylesheet. Required.+	TargetPath string++	highlight.ChromaStylesOptions `mapstructure:",squash"`+}++// ChromaStyles creates a CSS stylesheet Resource for the Chroma code highlighter+// using the given options, the same as the "hugo gen chromastyles" command.+// The style defaults to the markup.highlight.style configuration setting.+func (ns *Namespace) ChromaStyles(args ...any) (resource.Resource, error) {+	if len(args) != 1 {+		return nil, errors.New("must provide an options map")+	}+	m, err := hmaps.ToStringMapE(args[0])+	if err != nil {+		return nil, fmt.Errorf("failed to decode options: %w", err)+	}++	var opts chromaStylesOptions++	// modeSelector can be either a boolean or a custom top level class name.+	m = maps.Clone(m)+	if v, k, found := hmaps.LookupEqualFold(m, "modeSelector"); found {+		delete(m, k)+		switch vv := v.(type) {+		case bool:+			opts.ModeSelector = vv+		case string:+			if vv == "" {+				return nil, errors.New("modeSelector must be a boolean or a class name, got an empty string")+			}+			if b, err := strconv.ParseBool(vv); err == nil {+				opts.ModeSelector = b+			} else {+				opts.ModeSelectorClass = vv+			}+		default:+			return nil, fmt.Errorf("modeSelector must be a boolean or a class name, got %T", v)+		}+	}++	decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{+		Result:           &opts,+		WeaklyTypedInput: true,+		ErrorUnused:      true,+	})+	if err != nil {+		return nil, err+	}+	if err := decoder.Decode(m); err != nil {+		return nil, fmt.Errorf("failed to decode options: %w", err)+	}++	targetPath := paths.ToSlashTrimLeading(opts.TargetPath)+	if targetPath == "" {+		return nil, errors.New("must provide a targetPath")+	}+	if opts.Style == "" {+		opts.Style = ns.d.Conf.GetConfigSection("markup").(markup_config.Config).Highlight.Style+	}++	css, err := highlight.ChromaStylesCSS(opts.ChromaStylesOptions)+	if err != nil {+		return nil, err+	}++	return ns.createClient.FromString(targetPath, css)+}+ // PostCSS processes the given Resource with PostCSS. func (ns *Namespace) PostCSS(args ...any) (resource.Resource, error) { 	if len(args) > 2 {@@ -189,6 +267,7 @@ func init() { 			tailwindcssClient: cssjs.NewTailwindCSSClient(d.ResourceSpec), 			babelClient:       babel.New(d.ResourceSpec), 			jsTransformClient: jstransform.New(d.BaseFs.Assets, d.ResourceSpec, true),+			createClient:      create.New(d.ResourceSpec), 		}  		ns := &internal.TemplateFuncsNamespace{@@ -196,6 +275,11 @@ func init() { 			Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, 		} +		ns.AddMethodMapping(ctx.ChromaStyles,+			nil,+			[][2]string{},+		)+ 		ns.AddMethodMapping(ctx.PostCSS, 			[]string{"postCSS"}, 			[][2]string{}, 
Merged fix · PR #15149+328 −109
commands/gen.goindex 8d9224a08..f3747722c 100644@@ -21,12 +21,8 @@ import ( 	"os" 	"path" 	"path/filepath"-	"slices" 	"strings" -	"github.com/alecthomas/chroma/v2"-	"github.com/alecthomas/chroma/v2/formatters/html"-	"github.com/alecthomas/chroma/v2/styles" 	"github.com/bep/simplecobra" 	"github.com/goccy/go-yaml" 	"github.com/gohugoio/hugo/common/hugo"@@ -34,6 +30,7 @@ import ( 	"github.com/gohugoio/hugo/helpers" 	"github.com/gohugoio/hugo/hugofs" 	"github.com/gohugoio/hugo/hugolib"+	"github.com/gohugoio/hugo/markup/highlight" 	"github.com/gohugoio/hugo/parser" 	"github.com/spf13/cobra" 	"github.com/spf13/cobra/doc"@@ -65,85 +62,24 @@ func newGenCommand() *genCommand { See https://gohugo.io/quick-reference/syntax-highlighting-styles/ for a preview of the available styles.`,  			run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {-				style = strings.ToLower(style)-				if !slices.Contains(styles.Names(), style) {-					return fmt.Errorf("invalid style: %s", style)-				}-				var chromaStyle *chroma.Style-				if mode != "" {-					var chromaMode chroma.Mode-					switch mode {-					case "light":-						chromaMode = chroma.Light-					case "dark":-						chromaMode = chroma.Dark-					default:-						return fmt.Errorf("invalid mode: %s", mode)-					}--					chromaStyle = styles.GetForMode(style, chromaMode)-					if chromaStyle.Mode() != chromaMode {-						return fmt.Errorf("style %q does not have a %q mode", style, mode)-					}-				} else {-					chromaStyle = styles.Get(style)-				}-				builder := chromaStyle.Builder()-				if highlightStyle != "" {-					builder.Add(chroma.LineHighlight, highlightStyle)-				}-				if lineNumbersInlineStyle != "" {-					builder.Add(chroma.LineNumbers, lineNumbersInlineStyle)-				}-				if lineNumbersTableStyle != "" {-					builder.Add(chroma.LineNumbersTable, lineNumbersTableStyle)-				}-				style, err := builder.Build()-				if err != nil {-					return err-				}- 				if omitEmpty { 					// See https://github.com/alecthomas/chroma/commit/5b2a4c5a26c503c79bc86ba3c4ae5b330028bd3d 					hugo.Deprecate("--omitEmpty", "Flag is no longer needed, empty classes are now always omitted.", "v0.149.0") 				}-				options := []html.Option{-					html.WithCSSComments(!omitClassComments),-				}-				if !modeSelector {-					// Only needed for the shared-scope overlay; --modeSelector-					// gives each mode its own scope and makes this redundant.-					options = append(options, html.WithCustomCSS(chromaCSSOverrides(style)))-				}--				formatter := html.New(options...)--				var buf bytes.Buffer-				fmt.Fprintf(&buf, "/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))-				formatter.WriteCSS(&buf, style)-				css := buf.String()-				if modeSelector {-					// Scope every selector under a top level mode class, e.g. ".dark .chroma".-					// 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.-					// TODO(bep) upstream option for this.-					var prefix string-					switch style.Mode() {-					case chroma.Light:-						prefix = ".light "-					case chroma.Dark:-						prefix = ".dark "-					default:-						return fmt.Errorf("style %q does not have a %q mode", style.Name, mode)-					}-					replacer := strings.NewReplacer(-						".bg {", prefix+".bg {",-						".chroma ", prefix+".chroma ",-					)-					css = replacer.Replace(css)+				css, err := highlight.ChromaStylesCSS(highlight.ChromaStylesOptions{+					Style:                  style,+					Mode:                   mode,+					ModeSelector:           modeSelector,+					HighlightStyle:         highlightStyle,+					LineNumbersInlineStyle: lineNumbersInlineStyle,+					LineNumbersTableStyle:  lineNumbersTableStyle,+					OmitClassComments:      omitClassComments,+				})+				if err != nil {+					return err 				} +				fmt.Printf("/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " ")) 				fmt.Print(css) 				return nil 			},@@ -330,38 +266,6 @@ url: %s 	} } -// chromaCSSOverrides re-emits leaf token colors that Chroma's minifier drops-// because they equal the style's default foreground (the .chroma color). Without-// modeSelector scoping, a paired light/dark stylesheet shares the same .chroma-// scope, and the light sheet's explicit rule (e.g. .chroma .nx) would otherwise-// leak into dark mode, since an explicit declaration beats inheritance.-func chromaCSSOverrides(style *chroma.Style) map[chroma.TokenType]string {-	bg := style.Get(chroma.Background)-	m := make(map[chroma.TokenType]string)-	for tt := range chroma.StandardTypes {-		if tt == chroma.Background || !style.Has(tt) || !chromaLeafToken(tt) {-			continue-		}-		entry := style.Get(tt)-		if !entry.Sub(bg).IsZero() || !entry.Colour.IsSet() {-			continue-		}-		if css := html.StyleEntryToCSS(chroma.StyleEntry{Colour: entry.Colour}); css != "" {-			m[tt] = css-		}-	}-	return m-}--func chromaLeafToken(tt chroma.TokenType) bool {-	for other := range chroma.StandardTypes {-		if other != tt && (other.Category() == tt || other.SubCategory() == tt) {-			return false-		}-	}-	return true-}- type genCommand struct { 	rootCmd *rootCommand markup/highlight/chromastyles.gonew file mode 100644index 000000000..f76f37b29@@ -0,0 +1,161 @@+// Copyright 2026 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package highlight++import (+	"bytes"+	"fmt"+	"slices"+	"strings"++	"github.com/alecthomas/chroma/v2"+	"github.com/alecthomas/chroma/v2/formatters/html"+	"github.com/alecthomas/chroma/v2/styles"+)++// ChromaStylesOptions holds options for ChromaStylesCSS.+type ChromaStylesOptions struct {+	// Highlighter style, e.g. "monokai".+	Style string++	// Style mode, "light" or "dark".+	Mode string++	// Scope selectors under a top level mode class, e.g. ".dark .chroma".+	ModeSelector bool++	// Foreground and background colors for highlighted lines, e.g. "#fff000 bg:#000fff".+	HighlightStyle string++	// Foreground and background colors for inline line numbers.+	LineNumbersInlineStyle string++	// Foreground and background colors for table line numbers.+	LineNumbersTableStyle string++	// Omit CSS class comment prefixes in the generated CSS.+	OmitClassComments bool+}++// ChromaStylesCSS generates a CSS stylesheet for the Chroma code highlighter.+// This stylesheet is needed if markup.highlight.noClasses is disabled in config.+func ChromaStylesCSS(opts ChromaStylesOptions) (string, error) {+	name := strings.ToLower(opts.Style)+	if !slices.Contains(styles.Names(), name) {+		return "", fmt.Errorf("invalid style: %s", name)+	}+	var chromaStyle *chroma.Style+	if opts.Mode != "" {+		var mode chroma.Mode+		switch opts.Mode {+		case "light":+			mode = chroma.Light+		case "dark":+			mode = chroma.Dark+		default:+			return "", fmt.Errorf("invalid mode: %s", opts.Mode)+		}++		chromaStyle = styles.GetForMode(name, mode)+		if chromaStyle.Mode() != mode {+			return "", fmt.Errorf("style %q does not have a %q mode", name, opts.Mode)+		}+	} else {+		chromaStyle = styles.Get(name)+	}+	builder := chromaStyle.Builder()+	if opts.HighlightStyle != "" {+		builder.Add(chroma.LineHighlight, opts.HighlightStyle)+	}+	if opts.LineNumbersInlineStyle != "" {+		builder.Add(chroma.LineNumbers, opts.LineNumbersInlineStyle)+	}+	if opts.LineNumbersTableStyle != "" {+		builder.Add(chroma.LineNumbersTable, opts.LineNumbersTableStyle)+	}+	style, err := builder.Build()+	if err != nil {+		return "", err+	}++	options := []html.Option{+		html.WithCSSComments(!opts.OmitClassComments),+	}+	if !opts.ModeSelector {+		// Only needed for the shared-scope overlay; modeSelector+		// gives each mode its own scope and makes this redundant.+		options = append(options, html.WithCustomCSS(chromaCSSOverrides(style)))+	}++	var buf bytes.Buffer+	if err := html.New(options...).WriteCSS(&buf, style); err != nil {+		return "", err+	}+	css := buf.String()+	if opts.ModeSelector {+		// Scope every selector under a top level mode class, e.g. ".dark .chroma".+		// 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.+		// TODO(bep) upstream option for this.+		var prefix string+		switch style.Mode() {+		case chroma.Light:+			prefix = ".light "+		case chroma.Dark:+			prefix = ".dark "+		default:+			return "", fmt.Errorf("style %q does not have a light or dark mode", style.Name)+		}+		replacer := strings.NewReplacer(+			".bg {", prefix+".bg {",+			".chroma ", prefix+".chroma ",+		)+		css = replacer.Replace(css)+	}++	return css, nil+}++// chromaCSSOverrides re-emits leaf token colors that Chroma's minifier drops+// because they equal the style's default foreground (the .chroma color). Without+// modeSelector scoping, a paired light/dark stylesheet shares the same .chroma+// scope, and the light sheet's explicit rule (e.g. .chroma .nx) would otherwise+// leak into dark mode, since an explicit declaration beats inheritance.+func chromaCSSOverrides(style *chroma.Style) map[chroma.TokenType]string {+	bg := style.Get(chroma.Background)+	m := make(map[chroma.TokenType]string)+	for tt := range chroma.StandardTypes {+		if tt == chroma.Background || !style.Has(tt) || !chromaLeafToken(tt) {+			continue+		}+		entry := style.Get(tt)+		if !entry.Sub(bg).IsZero() || !entry.Colour.IsSet() {+			continue+		}+		if css := html.StyleEntryToCSS(chroma.StyleEntry{Colour: entry.Colour}); css != "" {+			m[tt] = css+		}+	}+	return m+}++func chromaLeafToken(tt chroma.TokenType) bool {+	for other := range chroma.StandardTypes {+		if other != tt && (other.Category() == tt || other.SubCategory() == tt) {+			return false+		}+	}+	return true+}tpl/css/chromastyles_integration_test.gonew file mode 100644index 000000000..f4e366c3f@@ -0,0 +1,97 @@+// Copyright 2026 The Hugo Authors. All rights reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++package css_test++import (+	"strings"+	"testing"++	qt "github.com/frankban/quicktest"+	"github.com/gohugoio/hugo/hugolib"+	"github.com/gohugoio/hugo/tpl/css"+)++// See issue 15112.+func TestChromaStyles(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "section", "page"]+[markup.highlight]+style = "monokai"+-- layouts/home.html --+{{ $light := css.ChromaStyles (dict "targetPath" "css/chroma-light.css" "style" "github" "mode" "light" "modeSelector" true) }}+{{ $dark := css.ChromaStyles (dict "targetPath" "css/chroma-dark.css" "style" "github" "mode" "dark" "modeSelector" true) }}+{{ $default := css.ChromaStyles (dict "targetPath" "css/chroma.css") }}+Light: {{ $light.RelPermalink }}|Dark: {{ $dark.RelPermalink }}|Default: {{ $default.RelPermalink }}|+`++	b := hugolib.Test(t, files)++	b.AssertFileContent("public/index.html", "Light: /css/chroma-light.css|Dark: /css/chroma-dark.css|Default: /css/chroma.css|")+	b.AssertFileContent("public/css/chroma-light.css", ".light .chroma ", ".light .bg {")+	b.AssertFileContent("public/css/chroma-dark.css", ".dark .chroma ", ".dark .bg {")+	// Style defaults to markup.highlight.style, monokai background.+	b.AssertFileContent("public/css/chroma.css", "/* Background */ .bg {", "background-color:#272822")+}++func TestChromaStylesErrors(t *testing.T) {+	t.Parallel()++	filesTemplate := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "section", "page"]+-- layouts/home.html --+{{ css.ChromaStyles OPTS }}+`++	for _, test := range []struct {+		opts  string+		match string+	}{+		{`(dict "style" "monokai")`, `.*targetPath cannot be empty.*`},+		{`(dict "targetPath" "css/chroma.css" "style" "doesnotexist")`, `.*invalid style: doesnotexist.*`},+		{`(dict "targetPath" "css/chroma.css" "mode" "blue")`, `.*invalid mode: blue.*`},+		{`(dict "targetPath" "css/chroma.css" "style" "friendly" "mode" "dark")`, `.*style "friendly" does not have a "dark" mode.*`},+	} {+		files := strings.ReplaceAll(filesTemplate, "OPTS", test.opts)+		b, err := hugolib.TestE(t, files)+		b.Assert(err, qt.ErrorMatches, test.match)+	}+}++func BenchmarkChromaStyles(b *testing.B) {+	files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "section", "page"]+-- layouts/all.html --+All.+`++	bb := hugolib.Test(b, files)++	bb.Assert(true, qt.IsTrue)+	s := bb.H.Sites[0]+	ns := s.TemplateStore.GetTemplateFuncsNamespace("css").(*css.Namespace)++	opts := map[string]any{"targetPath": "css/chroma.css", "style": "monokai", "mode": "light", "modeSelector": true}++	b.ResetTimer()++	for b.Loop() {+		_, err := ns.ChromaStyles(opts)+		bb.Assert(err, qt.IsNil)+	}+}tpl/css/css.goindex 64fc45ea6..71cc605be 100644@@ -6,11 +6,16 @@ import ( 	"fmt" 	"sync" +	"github.com/gohugoio/hugo/common/hashing" 	"github.com/gohugoio/hugo/common/hmaps"+	"github.com/gohugoio/hugo/common/hugio" 	"github.com/gohugoio/hugo/common/hugo" 	"github.com/gohugoio/hugo/common/paths" 	"github.com/gohugoio/hugo/common/types/css" 	"github.com/gohugoio/hugo/deps"+	"github.com/gohugoio/hugo/identity"+	"github.com/gohugoio/hugo/markup/highlight"+	"github.com/gohugoio/hugo/markup/markup_config" 	"github.com/gohugoio/hugo/resources" 	"github.com/gohugoio/hugo/resources/resource" 	"github.com/gohugoio/hugo/resources/resource_transformers/babel"@@ -21,6 +26,7 @@ import ( 	"github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss" 	"github.com/gohugoio/hugo/tpl/internal" 	"github.com/gohugoio/hugo/tpl/internal/resourcehelpers"+	"github.com/mitchellh/mapstructure" 	"github.com/spf13/cast" ) @@ -34,6 +40,8 @@ type Namespace struct { 	tailwindcssClient *cssjs.TailwindCSSClient 	babelClient       *babel.Client 	jsTransformClient *jstransform.Client+	chromaStylesCache *hmaps.Cache[uint64, resource.Resource]+	highlightConfig   highlight.Config  	// The Dart Client requires a os/exec process, so  only 	// create it if we really need it.@@ -42,6 +50,48 @@ type Namespace struct { 	scssClientDartSass     *dartsass.Client } +// ChromaStyles generates a CSS stylesheet for the Chroma code highlighter+// and returns it as a Resource. This stylesheet is needed if+// markup.highlight.noClasses is disabled in config.+// The style defaults to the markup.highlight.style config setting.+func (ns *Namespace) ChromaStyles(opts any) (resource.Resource, error) {+	key := hashing.HashUint64(opts)+	return ns.chromaStylesCache.GetOrCreate(key, func() (resource.Resource, error) {+		m, err := hmaps.ToStringMapE(opts)+		if err != nil {+			return nil, err+		}+		var o struct {+			TargetPath                    string+			highlight.ChromaStylesOptions `mapstructure:",squash"`+		}++		if err := mapstructure.WeakDecode(m, &o); err != nil {+			return nil, err+		}+		if o.TargetPath == "" {+			return nil, errors.New("targetPath cannot be empty")+		}+		if o.Style == "" {+			o.Style = ns.highlightConfig.Style+		}+		css, err := highlight.ChromaStylesCSS(o.ChromaStylesOptions)+		if err != nil {+			return nil, err+		}++		return ns.d.ResourceSpec.NewResource(+			resources.ResourceSourceDescriptor{+				LazyPublish:   true,+				GroupIdentity: identity.Anonymous,+				OpenReadSeekCloser: func() (hugio.ReadSeekCloser, error) {+					return hugio.NewReadSeekerNoOpCloserFromString(css), nil+				},+				TargetPath: o.TargetPath,+			})+	})+}+ // Quoted returns a string that needs to be quoted in CSS. func (ns *Namespace) Quoted(v any) css.QuotedString { 	s := cast.ToString(v)@@ -189,6 +239,8 @@ func init() { 			tailwindcssClient: cssjs.NewTailwindCSSClient(d.ResourceSpec), 			babelClient:       babel.New(d.ResourceSpec), 			jsTransformClient: jstransform.New(d.BaseFs.Assets, d.ResourceSpec, true),+			chromaStylesCache: hmaps.NewCacheWithOptions[uint64, resource.Resource](hmaps.CacheOptions{Size: 10}),+			highlightConfig:   d.Conf.GetConfigSection("markup").(markup_config.Config).Highlight, 		}  		ns := &internal.TemplateFuncsNamespace{@@ -196,6 +248,11 @@ func init() { 			Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil }, 		} +		ns.AddMethodMapping(ctx.ChromaStyles,+			nil,+			[][2]string{},+		)+ 		ns.AddMethodMapping(ctx.PostCSS, 			[]string{"postCSS"}, 			[][2]string{},