Skip to content

fix(cmd/chroma): --html-styles ignores the other --html-* flags - #1348

Open
VXNCXNX wants to merge 2 commits into
alecthomas:masterfrom
VXNCXNX:fix/html-styles-flags-v2
Open

fix(cmd/chroma): --html-styles ignores the other --html-* flags#1348
VXNCXNX wants to merge 2 commits into
alecthomas:masterfrom
VXNCXNX:fix/html-styles-flags-v2

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1347, which is needed for cmd/chroma to build at all.

--html-styles ignores every other --html-* flag.

$ chroma --html-styles --html-prefix=foo- --html-tab-width=4 | head -2
/* Background */ .bg { color: #e5e5e5; background-color: #000000; }
/* PreWrapper */ .chroma { color: #e5e5e5; background-color: #000000; -webkit-text-size-adjust: none; }

After:

/* Background */ .foo-bg { color: #e5e5e5; background-color: #000000;tab-size: 4; }
/* PreWrapper */ .foo-chroma { color: #e5e5e5; background-color: #000000;tab-size: 4; -webkit-text-size-adjust: none; }

Generating a stylesheet is exactly when --html-prefix matters most, since the prefix has to agree with whatever generated the HTML. Emitting unprefixed CSS produces a stylesheet that silently matches nothing.

Cause

if cli.Formatter == "html" {
	configureHTMLFormatter(ctx)
}

but --html-styles writes CSS from the html formatter regardless of which formatter is selected. So unless you also pass -f html, which is pointless when you only want the stylesheet, the html options are never applied.

Same for --html-lines-table, --html-highlight, --html-linkable-lines and the rest of the group.

The fix

A small usesHTMLFormatter() covering both cases, at the one call site.

Unchanged, checked before and after: -f html --html-prefix=zz- still emits zz-chroma, and a bare --html-styles with no other flags is byte-identical.

Verification

TestHTMLStylesAppliesHTMLOptions in cmd/chroma/main_test.go sets cli.Formatter = "terminal" with --html-styles, --html-prefix and --html-tab-width, then asserts both appear in the CSS.

Reverting the condition to cli.Formatter == "html" fails it:

--- FAIL: TestHTMLStylesAppliesHTMLOptions
    main_test.go:29: expected html formatter to be in use

go test ./... passes in both the root module and cmd/chroma, and golangci-lint run at the root is clean.

Disclosure: written with AI assistance (Claude Code). I built both binaries, produced the before and after above by running them, and ran the revert check myself.

Aligns cmd/chroma module with root module dependency version, fixing go build failures from version mismatch.
@alecthomas

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 139906dca7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants