Skip to content

Themes

Themes map syntax captures, such as keyword or function.call, to colors and font styles. How you provide a theme depends on the package and HTML style mode.

Node.js, Python, and the CLI accept bundled theme IDs. Rust selects bundled themes through Cargo features and also supports TOML themes. In the browser, use a stylesheet for class output, a theme object for inline output, or your own CSS variables.

Choose a bundled theme

Choose an ID from the bundled theme catalog, or compare palettes in the playground. Use the examples below to find or apply a theme.

JavaScript
JavaScript
import { themes } from "@comfit/node";

console.log(themes());

See HTML and CSS for stylesheet installation and layout.

Color nested brackets

Highlighting collects bracket depth by default. Visible bracket colors still need a palette: set rainbow on a theme, or define .rainbow-N classes or --comfit-rainbow-N variables.

Class and variable output can cycle bracket indices through a fixed number of colors. When rendering class-based HTML without a supplied theme, set the wrapping count to the palette size in the catalog so the indices match the available CSS classes.

These examples configure a six-color stylesheet such as Nord. The configuration alone does not load a stylesheet.

JavaScript
JavaScript
import { RenderHtmlConfig } from "@comfit/node";

const config = new RenderHtmlConfig();
config.rainbowColors = 6;

In class and inline modes, a nonempty supplied theme palette takes precedence. Bundled Catppuccin Mocha has no rainbow palette, so enabling bracket collection alone does not color its brackets.

Emphasize lines

Line numbers are one-based. These examples select line 2.

Pass the configuration to the corresponding highlight or render call.

JavaScript
JavaScript
import { RenderHtmlConfig } from "@comfit/node";

const config = new RenderHtmlConfig();
config.highlightedLines = [2];

Selecting a line marks it for emphasis without assigning a background color. Supply a theme line-highlight style, a .line-highlight CSS rule, or line-highlight variables. For full-width backgrounds, make the rendered line spans block-level.

To change themes without parsing or highlighting again, render an existing document result. To change line emphasis, highlight the document with a new line selection. This reuses cached highlighting when the source and rainbow option are unchanged.

Bundled themes

Every theme below is available as a bundled theme ID and an @comfit/css stylesheet. Follow the class-based HTML guide to load a stylesheet and match its outer class. Use the playground to compare palettes.

Appearance describes the theme's background. A stylesheet applies one palette and does not switch automatically with your site's light or dark mode.

Rainbow colors is the size of the bundled bracket palette. None means you need to supply a palette to color brackets.

The bundled themes do not define line-highlight styles. See Emphasize lines to make selected lines visible.

The playground supplements themes with fallback bracket and line-emphasis colors. The catalog describes the bundled theme files, without those additions.

ThemeIDAppearanceCSS importOuter classRainbow colors
Atom One Darkone-darkDark@comfit/css/one-dark.csscomfit-one-darkNone
Atom One Lightone-lightLight@comfit/css/one-light.csscomfit-one-lightNone
Ayu Darkayu-darkDark@comfit/css/ayu-dark.csscomfit-ayu-darkNone
Ayu Lightayu-lightLight@comfit/css/ayu-light.csscomfit-ayu-lightNone
Ayu Mirageayu-mirageDark@comfit/css/ayu-mirage.csscomfit-ayu-mirageNone
Catppina Darkcatppina-darkDark@comfit/css/catppina-dark.csscomfit-catppina-darkNone
Catppina Lightcatppina-lightLight@comfit/css/catppina-light.csscomfit-catppina-lightNone
Catppuccin Frappécatppuccin-frappeDark@comfit/css/catppuccin-frappe.csscomfit-catppuccin-frappeNone
Catppuccin Lattecatppuccin-latteLight@comfit/css/catppuccin-latte.csscomfit-catppuccin-latteNone
Catppuccin Macchiatocatppuccin-macchiatoDark@comfit/css/catppuccin-macchiato.csscomfit-catppuccin-macchiatoNone
Catppuccin Mochacatppuccin-mochaDark@comfit/css/catppuccin-mocha.csscomfit-catppuccin-mochaNone
DraculadraculaDark@comfit/css/dracula.csscomfit-draculaNone
Dracula Softdracula-softDark@comfit/css/dracula-soft.csscomfit-dracula-softNone
GitHub Darkgithub-darkDark@comfit/css/github-dark.csscomfit-github-darkNone
GitHub Dark Colorblindgithub-dark-colorblindDark@comfit/css/github-dark-colorblind.csscomfit-github-dark-colorblindNone
GitHub Dark Defaultgithub-dark-defaultDark@comfit/css/github-dark-default.csscomfit-github-dark-defaultNone
GitHub Dark Dimmedgithub-dark-dimmedDark@comfit/css/github-dark-dimmed.csscomfit-github-dark-dimmedNone
GitHub Dark High Contrastgithub-dark-high-contrastDark@comfit/css/github-dark-high-contrast.csscomfit-github-dark-high-contrastNone
GitHub Lightgithub-lightLight@comfit/css/github-light.csscomfit-github-lightNone
GitHub Light Colorblindgithub-light-colorblindLight@comfit/css/github-light-colorblind.csscomfit-github-light-colorblindNone
GitHub Light Defaultgithub-light-defaultLight@comfit/css/github-light-default.csscomfit-github-light-defaultNone
GitHub Light High Contrastgithub-light-high-contrastLight@comfit/css/github-light-high-contrast.csscomfit-github-light-high-contrastNone
Night Owlnight-owlDark@comfit/css/night-owl.csscomfit-night-owlNone
Night Owl (No Italics)night-owl-no-italicsDark@comfit/css/night-owl-no-italics.csscomfit-night-owl-no-italicsNone
NordnordDark@comfit/css/nord.csscomfit-nord6
One Dark Proone-dark-proDark@comfit/css/one-dark-pro.csscomfit-one-dark-pro3
One Dark Pro Darkerone-dark-pro-darkerDark@comfit/css/one-dark-pro-darker.csscomfit-one-dark-pro-darker3
One Dark Pro Flatone-dark-pro-flatDark@comfit/css/one-dark-pro-flat.csscomfit-one-dark-pro-flat3
One Dark Pro Mixone-dark-pro-mixDark@comfit/css/one-dark-pro-mix.csscomfit-one-dark-pro-mix3
One Dark Pro Night Flatone-dark-pro-night-flatDark@comfit/css/one-dark-pro-night-flat.csscomfit-one-dark-pro-night-flat3
Rosé Pinerose-pineDark@comfit/css/rose-pine.csscomfit-rose-pine6
Rosé Pine (no italics)rose-pine-no-italicsDark@comfit/css/rose-pine-no-italics.csscomfit-rose-pine-no-italics6
Rosé Pine Dawnrose-pine-dawnLight@comfit/css/rose-pine-dawn.csscomfit-rose-pine-dawn6
Rosé Pine Dawn (no italics)rose-pine-dawn-no-italicsLight@comfit/css/rose-pine-dawn-no-italics.csscomfit-rose-pine-dawn-no-italics6
Rosé Pine Moonrose-pine-moonDark@comfit/css/rose-pine-moon.csscomfit-rose-pine-moon6
Rosé Pine Moon (no italics)rose-pine-moon-no-italicsDark@comfit/css/rose-pine-moon-no-italics.csscomfit-rose-pine-moon-no-italics6
Tokyo Nighttokyo-nightDark@comfit/css/tokyo-night.csscomfit-tokyo-night6
Tokyo Night Lighttokyo-night-lightLight@comfit/css/tokyo-night-light.csscomfit-tokyo-night-light6
Tokyo Night Stormtokyo-night-stormDark@comfit/css/tokyo-night-storm.csscomfit-tokyo-night-storm6
Vitesse Blackvitesse-blackDark@comfit/css/vitesse-black.csscomfit-vitesse-black6
Vitesse Darkvitesse-darkDark@comfit/css/vitesse-dark.csscomfit-vitesse-dark6
Vitesse Dark Softvitesse-dark-softDark@comfit/css/vitesse-dark-soft.csscomfit-vitesse-dark-soft6
Vitesse Lightvitesse-lightLight@comfit/css/vitesse-light.csscomfit-vitesse-light6
Vitesse Light Softvitesse-light-softLight@comfit/css/vitesse-light-soft.csscomfit-vitesse-light-soft6

Custom colors in the browser

With an initialized highlighter that has Rust loaded:

TypeScript
import type { Theme } from "@comfit/wasm";

const theme: Theme = {
  name: "Custom",
  default: { fg: "#cdd6f4", bg: "#1e1e2e" },
  styles: {
    keyword: { fg: "#cba6f7" },
    string: { fg: "#a6e3a1" },
    function: { fg: "#89b4fa" },
  },
  rainbow: ["#f38ba8", "#a6e3a1", "#89b4fa"],
  lineHighlight: { bg: "#313244" },
};

const html = highlighter.renderHtml("fn main() {}", "rust", {
  style: "inline",
  theme,
  highlightedLines: [1],
});

The theme option belongs to inline mode. Class and variables modes do not accept it in the browser API. Node.js and Python rendering functions accept bundled theme IDs, not this object.

Load a TOML theme in Rust

Save the theme as custom.toml, then load it using the Rust or CLI example below.

custom.tomltoml
name = "Custom"
rainbow = ["#f38ba8", "#a6e3a1", "#89b4fa"]
line_highlight = { bg = "#313244" }

[default]
fg = "#cdd6f4"
bg = "#1e1e2e"

[styles]
keyword = { fg = "#cba6f7" }
string = { fg = "#a6e3a1" }
function = { fg = "#89b4fa" }

TOML uses line_highlight. Browser theme objects use lineHighlight. Dotted capture names such as "function.call" must be quoted as TOML keys.

Load the file in Rust or pass it to the CLI:

Rust

Enable theme-toml on comfit to parse the file with Theme::from_toml.

Rust
let source = std::fs::read_to_string("custom.toml")?;
let theme = comfit::Theme::from_toml(&source)?;

Convert a VS Code theme

Shell
comfit convert vscode-theme.json --report-unmapped -o custom.toml
comfit ansi main.rs --theme-file custom.toml

The converter accepts JSON5 and resolves local include files relative to each theme file. It does not download parent themes.

Use --report-unmapped to report unsupported selectors. Review the converted palette before using it.