Coming soon: The Renovate bot (GitHub App) will be renamed to Mend. PRs from Renovate will soon appear from 'Mend'. Learn more [here](https://redirect.github.com/renovatebot/renovate/discussions/37842). This PR contains the following updates: | Package | Type | Update | Change | Age | Confidence | |---|---|---|---|---|---| | [biome](https://redirect.github.com/biomejs/biome) | | patch | `2.2.3` -> `2.2.4` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [github.com/alecthomas/repr](https://redirect.github.com/alecthomas/repr) | require | patch | `v0.5.1` -> `v0.5.2` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | | [uv](https://redirect.github.com/astral-sh/uv) | | patch | `0.8.15` -> `0.8.17` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>biomejs/biome (biome)</summary> ### [`v2.2.4`](https://redirect.github.com/biomejs/biome/releases/tag/%40biomejs/biome%402.2.4): Biome CLI v2.2.4 #### 2.2.4 ##### Patch Changes - [#​7453](https://redirect.github.com/biomejs/biome/pull/7453) [ `aa8cea3`](aa8cea31af
) Thanks [@​arendjr](https://redirect.github.com/arendjr)! - Fixed [#​7242](https://redirect.github.com/biomejs/biome/issues/7242): Aliases specified in `package.json`'s `imports` section now support having multiple targets as part of an array. - [#​7454](https://redirect.github.com/biomejs/biome/pull/7454) [ `ac17183`](ac171839a3
) Thanks [@​arendjr](https://redirect.github.com/arendjr)! - Greatly improved performance of `noImportCycles` by eliminating allocations. In one repository, the total runtime of Biome with only `noImportCycles` enabled went from \~23s down to \~4s. - [#​7447](https://redirect.github.com/biomejs/biome/pull/7447) [ `7139aad`](7139aad75b
) Thanks [@​rriski](https://redirect.github.com/rriski)! - Fixes [#​7446](https://redirect.github.com/biomejs/biome/issues/7446). The GritQL `$...` spread metavariable now correctly matches members in object literals, aligning its behavior with arrays and function calls. - [#​6710](https://redirect.github.com/biomejs/biome/pull/6710) [ `98cf9af`](98cf9af0a4
) Thanks [@​arendjr](https://redirect.github.com/arendjr)! - Fixed [#​4723](https://redirect.github.com/biomejs/biome/issues/7423): Type inference now recognises *index signatures* and their accesses when they are being indexed as a string. ##### Example ```ts type BagOfPromises = { // This is an index signature definition. It declares that instances of type // `BagOfPromises` can be indexed using arbitrary strings. [property: string]: Promise<void>; }; let bag: BagOfPromises = {}; // Because `bag.iAmAPromise` is equivalent to `bag["iAmAPromise"]`, this is // considered an access to the string index, and a Promise is expected. bag.iAmAPromise; ``` - [#​7415](https://redirect.github.com/biomejs/biome/pull/7415) [ `d042f18`](d042f18f55
) Thanks [@​qraqras](https://redirect.github.com/qraqras)! - Fixed [#​7212](https://redirect.github.com/biomejs/biome/issues/7212), now the [ `useOptionalChain`](https://biomejs.dev/linter/rules/use-optional-chain/) rule recognizes optional chaining using `typeof` (e.g., `typeof foo !== 'undefined' && foo.bar`). - [#​7419](https://redirect.github.com/biomejs/biome/pull/7419) [ `576baf4`](576baf4faf
) Thanks [@​Conaclos](https://redirect.github.com/Conaclos)! - Fixed [#​7323](https://redirect.github.com/biomejs/biome/issues/7323). [ `noUnusedPrivateClassMembers`](https://biomejs.dev/linter/rules/no-unused-private-class-members/) no longer reports as unused TypeScript `private` members if the rule encounters a computed access on `this`. In the following example, `member` as previously reported as unused. It is no longer reported. ```ts class TsBioo { private member: number; set_with_name(name: string, value: number) { this[name] = value; } } ``` - [ `351bccd`](351bccdfe4
) Thanks [@​ematipico](https://redirect.github.com/ematipico)! - Added the new nursery lint rule `noJsxLiterals`, which disallows the use of string literals inside JSX. The rule catches these cases: ```jsx <> <div>test</div> {/* test is invalid */} <>test</> <div> {/* this string is invalid */} asdjfl test foo </div> </> ``` - [#​7406](https://redirect.github.com/biomejs/biome/pull/7406) [ `b906112`](b90611223d
) Thanks [@​mdevils](https://redirect.github.com/mdevils)! - Fixed an issue ([#​6393](https://redirect.github.com/biomejs/biome/issues/6393)) where the [useHookAtTopLevel](https://biomejs.dev/linter/rules/use-hook-at-top-level/) rule reported excessive diagnostics for nested hook calls. The rule now reports only the offending top-level call site, not sub-hooks of composite hooks. ```js // Before: reported twice (useFoo and useBar). function useFoo() { return useBar(); } function Component() { if (cond) useFoo(); } // After: reported once at the call to useFoo(). ``` - [#​7461](https://redirect.github.com/biomejs/biome/pull/7461) [ `ea585a9`](ea585a9394
) Thanks [@​arendjr](https://redirect.github.com/arendjr)! - Improved performance of `noPrivateImports` by eliminating allocations. In one repository, the total runtime of Biome with only `noPrivateImports` enabled went from \~3.2s down to \~1.4s. - [ `351bccd`](351bccdfe4
) Thanks [@​ematipico](https://redirect.github.com/ematipico)! - Fixed [#​7411](https://redirect.github.com/biomejs/biome/issues/7411). The Biome Language Server had a regression where opening an editor with a file already open wouldn't load the project settings correctly. - [#​7142](https://redirect.github.com/biomejs/biome/pull/7142) [ `53ff5ae`](53ff5ae344
) Thanks [@​Netail](https://redirect.github.com/Netail)! - Added the new nursery rule [ `noDuplicateDependencies`](https://biomejs.dev/linter/rules/no-duplicate-dependencies/), which verifies that no dependencies are duplicated between the `bundledDependencies`, `bundleDependencies`, `dependencies`, `devDependencies`, `overrides`, `optionalDependencies`, and `peerDependencies` sections. For example, the following snippets will trigger the rule: ```json { "dependencies": { "foo": "" }, "devDependencies": { "foo": "" } } ``` ```json { "dependencies": { "foo": "" }, "optionalDependencies": { "foo": "" } } ``` ```json { "dependencies": { "foo": "" }, "peerDependencies": { "foo": "" } } ``` - [ `351bccd`](351bccdfe4
) Thanks [@​ematipico](https://redirect.github.com/ematipico)! - Fixed [#​3824](https://redirect.github.com/biomejs/biome/issues/3824). Now the option CLI `--color` is correctly applied to logging too. </details> <details> <summary>alecthomas/repr (github.com/alecthomas/repr)</summary> ### [`v0.5.2`](https://redirect.github.com/alecthomas/repr/compare/v0.5.1...v0.5.2) [Compare Source](https://redirect.github.com/alecthomas/repr/compare/v0.5.1...v0.5.2) </details> <details> <summary>astral-sh/uv (uv)</summary> ### [`v0.8.17`](https://redirect.github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0817) [Compare Source](https://redirect.github.com/astral-sh/uv/compare/0.8.16...0.8.17) Released on 2025-09-10. ##### Enhancements - Improve error message for HTTP validation in auth services ([#​15768](https://redirect.github.com/astral-sh/uv/pull/15768)) - Respect `PYX_API_URL` when suggesting `uv auth login` on 401 ([#​15774](https://redirect.github.com/astral-sh/uv/pull/15774)) - Add pyx as a supported PyTorch index URL ([#​15769](https://redirect.github.com/astral-sh/uv/pull/15769)) ##### Bug fixes - Avoid initiating login flow for invalid API keys ([#​15773](https://redirect.github.com/astral-sh/uv/pull/15773)) - Do not search for a password for requests with a token attached already ([#​15772](https://redirect.github.com/astral-sh/uv/pull/15772)) - Filter pre-release Python versions in `uv init --script` ([#​15747](https://redirect.github.com/astral-sh/uv/pull/15747)) ### [`v0.8.16`](https://redirect.github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0816) [Compare Source](https://redirect.github.com/astral-sh/uv/compare/0.8.15...0.8.16) ##### Enhancements - Allow `--editable` to override `editable = false` annotations ([#​15712](https://redirect.github.com/astral-sh/uv/pull/15712)) - Allow `editable = false` for workspace sources ([#​15708](https://redirect.github.com/astral-sh/uv/pull/15708)) - Show a dedicated error for virtual environments in source trees on build ([#​15748](https://redirect.github.com/astral-sh/uv/pull/15748)) - Support Android platform tags ([#​15646](https://redirect.github.com/astral-sh/uv/pull/15646)) - Support iOS platform tags ([#​15640](https://redirect.github.com/astral-sh/uv/pull/15640)) - Support scripts with inline metadata in `--with-requirements` and `--requirements` ([#​12763](https://redirect.github.com/astral-sh/uv/pull/12763)) ##### Preview features - Support `--no-project` in `uv format` ([#​15572](https://redirect.github.com/astral-sh/uv/pull/15572)) - Allow `uv format` in unmanaged projects ([#​15553](https://redirect.github.com/astral-sh/uv/pull/15553)) ##### Bug fixes - Avoid erroring when `match-runtime` target is optional ([#​15671](https://redirect.github.com/astral-sh/uv/pull/15671)) - Ban empty usernames and passwords in `uv auth` ([#​15743](https://redirect.github.com/astral-sh/uv/pull/15743)) - Error early for parent path in build backend ([#​15733](https://redirect.github.com/astral-sh/uv/pull/15733)) - Retry on IO errors during HTTP/2 streaming ([#​15675](https://redirect.github.com/astral-sh/uv/pull/15675)) - Support recursive requirements and constraints inclusion ([#​15657](https://redirect.github.com/astral-sh/uv/pull/15657)) - Use token store credentials for `uv publish` ([#​15759](https://redirect.github.com/astral-sh/uv/pull/15759)) - Fix virtual environment activation script compatibility with latest nushell ([#​15272](https://redirect.github.com/astral-sh/uv/pull/15272)) - Skip Python interpreters that cannot be queried with permission errors ([#​15685](https://redirect.github.com/astral-sh/uv/pull/15685)) ##### Documentation - Clarify that `uv auth` commands take a URL ([#​15664](https://redirect.github.com/astral-sh/uv/pull/15664)) - Improve the CLI help for options that accept requirements files ([#​15706](https://redirect.github.com/astral-sh/uv/pull/15706)) - Adds example for caching for managed Python downloads in Docker builds ([#​15689](https://redirect.github.com/astral-sh/uv/pull/15689)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM, only on Monday ( * 0-3 * * 1 ) (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/alecthomas/chroma). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS45Ny4xMCIsInVwZGF0ZWRJblZlciI6IjQxLjk3LjEwIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
A general purpose syntax highlighter in pure Go
Chroma takes source code and other structured text and converts it into syntax highlighted HTML, ANSI-coloured text, etc.
Chroma is based heavily on Pygments, and includes translators for Pygments lexers and styles.
Table of Contents
- Supported languages
- Try it
- Using the library
- More detail
- Command-line interface
- Testing lexers
- What's missing compared to Pygments?
Supported languages
Prefix | Language |
---|---|
A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Agda, AL, Alloy, Angular2, ANTLR, ApacheConf, APL, AppleScript, ArangoDB AQL, Arduino, ArmAsm, ATL, AutoHotkey, AutoIt, Awk |
B | Ballerina, Bash, Bash Session, Batchfile, Beef, BibTeX, Bicep, BlitzBasic, BNF, BQN, Brainfuck |
C | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Chapel, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Core, Crystal, CSS, CSV, CUE, Cython |
D | D, Dart, Dax, Desktop file, Diff, Django/Jinja, dns, Docker, DTD, Dylan |
E | EBNF, Elixir, Elm, EmacsLisp, Erlang |
F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp |
G | GAS, GDScript, GDScript3, Gemtext, Genshi, Genshi HTML, Genshi Text, Gherkin, Gleam, GLSL, Gnuplot, Go, Go HTML Template, Go Template, Go Text Template, GraphQL, Groff, Groovy |
H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
I | Idris, Igor, INI, Io, ISCdhcpd |
J | J, Janet, Java, JavaScript, JSON, JSONata, Jsonnet, Julia, Jungle |
K | Kotlin |
L | Lean4, Lighttpd configuration file, LLVM, lox, Lua |
M | Makefile, Mako, markdown, Mason, Materialize SQL dialect, Mathematica, Matlab, MCFunction, Meson, Metal, MiniZinc, MLIR, Modula-2, Mojo, MonkeyC, MoonScript, MorrowindScript, Myghty, MySQL |
N | NASM, Natural, NDISASM, Newspeak, Nginx configuration file, Nim, Nix, NSIS, Nu |
O | Objective-C, ObjectPascal, OCaml, Octave, Odin, OnesEnterprise, OpenEdge ABL, OpenSCAD, Org Mode |
P | PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Plutus Core, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerQuery, PowerShell, Prolog, Promela, PromQL, properties, Protocol Buffer, PRQL, PSL, Puppet, Python, Python 2 |
Q | QBasic, QML |
R | R, Racket, Ragel, Raku, react, ReasonML, reg, Rego, reStructuredText, Rexx, RPGLE, RPMSpec, Ruby, Rust |
S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Sed, Sieve, Smali, Smalltalk, Smarty, SNBT, Snobol, Solidity, SourcePawn, SPARQL, SQL, SquidConf, Standard ML, stas, Stylus, Svelte, Swift, SYSTEMD, systemverilog |
T | TableGen, Tal, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData, Typst |
U | ucode |
V | V, V shell, Vala, VB.net, verilog, VHDL, VHS, VimL, vue |
W | WDTE, WebGPU Shading Language, WebVTT, Whiley |
X | XML, Xorg |
Y | YAML, YANG |
Z | Z80 Assembly, Zed, Zig |
I will attempt to keep this section up to date, but an authoritative list can be
displayed with chroma --list
.
Try it
Try out various languages and styles on the Chroma Playground.
Using the library
This is version 2 of Chroma, use the import path:
import "github.com/alecthomas/chroma/v2"
Chroma, like Pygments, has the concepts of lexers, formatters and styles.
Lexers convert source text into a stream of tokens, styles specify how token types are mapped to colours, and formatters convert tokens and styles into formatted output.
A package exists for each of these, containing a global Registry
variable
with all of the registered implementations. There are also helper functions
for using the registry in each package, such as looking up lexers by name or
matching filenames, etc.
In all cases, if a lexer, formatter or style can not be determined, nil
will
be returned. In this situation you may want to default to the Fallback
value in each respective package, which provides sane defaults.
Quick start
A convenience function exists that can be used to simply format some source text, without any effort:
err := quick.Highlight(os.Stdout, someSourceCode, "go", "html", "monokai")
Identifying the language
To highlight code, you'll first have to identify what language the code is written in. There are three primary ways to do that:
-
Detect the language from its filename.
lexer := lexers.Match("foo.go")
-
Explicitly specify the language by its Chroma syntax ID (a full list is available from
lexers.Names()
).lexer := lexers.Get("go")
-
Detect the language from its content.
lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n")
In all cases, nil
will be returned if the language can not be identified.
if lexer == nil {
lexer = lexers.Fallback
}
At this point, it should be noted that some lexers can be extremely chatty. To mitigate this, you can use the coalescing lexer to coalesce runs of identical token types into a single token:
lexer = chroma.Coalesce(lexer)
Formatting the output
Once a language is identified you will need to pick a formatter and a style (theme).
style := styles.Get("swapoff")
if style == nil {
style = styles.Fallback
}
formatter := formatters.Get("html")
if formatter == nil {
formatter = formatters.Fallback
}
Then obtain an iterator over the tokens:
contents, err := ioutil.ReadAll(r)
iterator, err := lexer.Tokenise(nil, string(contents))
And finally, format the tokens from the iterator:
err := formatter.Format(w, style, iterator)
The HTML formatter
By default the html
registered formatter generates standalone HTML with
embedded CSS. More flexibility is available through the formatters/html
package.
Firstly, the output generated by the formatter can be customised with the following constructor options:
Standalone()
- generate standalone HTML with embedded CSS.WithClasses()
- use classes rather than inlined style attributes.ClassPrefix(prefix)
- prefix each generated CSS class.TabWidth(width)
- Set the rendered tab width, in characters.WithLineNumbers()
- Render line numbers (style withLineNumbers
).WithLinkableLineNumbers()
- Make the line numbers linkable and be a link to themselves.HighlightLines(ranges)
- Highlight lines in these ranges (style withLineHighlight
).LineNumbersInTable()
- Use a table for formatting line numbers and code, rather than spans.
If WithClasses()
is used, the corresponding CSS can be obtained from the formatter with:
formatter := html.New(html.WithClasses(true))
err := formatter.WriteCSS(w, style)
More detail
Lexers
See the Pygments documentation for details on implementing lexers. Most concepts apply directly to Chroma, but see existing lexer implementations for real examples.
In many cases lexers can be automatically converted directly from Pygments by
using the included Python 3 script pygments2chroma_xml.py
. I use something like
the following:
uv run --script _tools/pygments2chroma_xml.py \
pygments.lexers.jvm.KotlinLexer \
> lexers/embedded/kotlin.xml
A list of all lexers available in Pygments can be found in pygments-lexers.txt.
Formatters
Chroma supports HTML output, as well as terminal output in 8 colour, 256 colour, and true-colour.
A noop
formatter is included that outputs the token text only, and a tokens
formatter outputs raw tokens. The latter is useful for debugging lexers.
Styles
Chroma styles are defined in XML. The style entries use the same syntax as Pygments.
All Pygments styles have been converted to Chroma using the _tools/style.py
script.
When you work with one of Chroma's styles,
know that the Background
token type provides the default style for tokens. It does so
by defining a foreground color and background color.
For example, this gives each token name not defined in the style a default color
of #f8f8f8
and uses #000000
for the highlighted code block's background:
<entry type="Background" style="#f8f8f2 bg:#000000"/>
Also, token types in a style file are hierarchical. For instance, when CommentSpecial
is not defined, Chroma uses the token style from Comment
. So when several comment tokens use the same color, you'll only need to define Comment
and override the one that has a different color.
For a quick overview of the available styles and how they look, check out the Chroma Style Gallery.
Command-line interface
A command-line interface to Chroma is included.
Binaries are available to install from the releases page.
The CLI can be used as a preprocessor to colorise output of less(1)
,
see documentation for the LESSOPEN
environment variable.
The --fail
flag can be used to suppress output and return with exit status
1 to facilitate falling back to some other preprocessor in case chroma
does not resolve a specific lexer to use for the given file. For example:
export LESSOPEN='| p() { chroma --fail "$1" || cat "$1"; }; p "%s"'
Replace cat
with your favourite fallback preprocessor.
When invoked as .lessfilter
, the --fail
flag is automatically turned
on under the hood for easy integration with lesspipe shipping with
Debian and derivatives;
for that setup the chroma
executable can be just symlinked to ~/.lessfilter
.
Projects using Chroma
moor
is a full-blown pager that colorizes its input using Chroma- Hugo is a static site generator that uses Chroma for syntax highlighting code examples
Testing lexers
If you edit some lexers and want to try it, open a shell in cmd/chromad
and run:
go run . --csrf-key=securekey
A Link will be printed. Open it in your Browser. Now you can test on the Playground with your local changes.
If you want to run the tests and the lexers, open a shell in the root directory and run:
go test ./lexers
When updating or adding a lexer, please add tests. See lexers/README.md for more.
What's missing compared to Pygments?
- Quite a few lexers, for various reasons (pull-requests welcome):
- Pygments lexers for complex languages often include custom code to handle certain aspects, such as Raku's ability to nest code inside regular expressions. These require time and effort to convert.
- I mostly only converted languages I had heard of, to reduce the porting cost.
- Some more esoteric features of Pygments are omitted for simplicity.
- Though the Chroma API supports content detection, very few languages support them. I have plans to implement a statistical analyser at some point, but not enough time.