HTML Multi-Themes Formatter
One HTML block that supports multiple themes via CSS custom properties. Useful for light/dark mode.
Options
| Runtime | Options |
|---|---|
| Rust | language, themes, default_theme, pre_class, italic, include_highlights, highlight_lines, header |
| Elixir | language, themes, default_theme, css_variable_prefix, pre_class, italic, include_highlights, highlight_lines, header |
| JavaScript | language, themes, defaultTheme, cssVariablePrefix, preClass, italic, includeHighlights, highlightLines, header |
| Java | Not currently supported in lumis4j |
| CLI | --themes, --default-theme, --css-variable-prefix, --highlight-lines |
Basic example
- JavaScript
- Rust
- Elixir
- Java
- CLI
import {highlight} from '@lumis-sh/lumis'
import {htmlMultiThemes} from '@lumis-sh/lumis/formatters'
import javascript from '@lumis-sh/lumis/langs/javascript'
import githubLight from '@lumis-sh/themes/github_light'
import githubDark from '@lumis-sh/themes/github_dark'
const html = await highlight(
'const x = 1',
htmlMultiThemes({
language: javascript,
themes: {light: githubLight, dark: githubDark},
defaultTheme: 'light-dark()',
})
)
use lumis::{highlight, HtmlMultiThemesBuilder, languages::Language, themes};
use std::collections::HashMap;
let mut theme_map = HashMap::new();
theme_map.insert("light".to_string(), themes::get("github_light").unwrap());
theme_map.insert("dark".to_string(), themes::get("github_dark").unwrap());
let html = highlight(
"const x = 1",
HtmlMultiThemesBuilder::new()
.language(Language::Javascript)
.themes(theme_map)
.default_theme("light-dark()")
.build()
.unwrap(),
);
Lumis.highlight!(
"const x = 1",
formatter: {:html_multi_themes,
language: "javascript",
themes: [light: "github_light", dark: "github_dark"],
default_theme: "light-dark()"
}
)
HTML Multi-Themes is not currently supported in lumis4j.
lumis highlight main.rs \
--formatter html-multi-themes \
--themes light:github_light \
--themes dark:github_dark \
--default-theme light-dark()
cssVariablePrefix
By default, CSS variables are prefixed with --lumis (e.g., --lumis-light, --lumis-dark-bg). Override the prefix if it conflicts with your CSS. Produces variables like --code-light, --code-dark-bg, etc.
- JavaScript
- Rust
- Elixir
- Java
- CLI
const html = await highlight(
'const x = 1',
htmlMultiThemes({
language: javascript,
themes: {light: githubLight, dark: githubDark},
cssVariablePrefix: '--code',
})
)
let formatter = HtmlMultiThemesBuilder::new()
.language(Language::Javascript)
.themes(theme_map)
.css_variable_prefix("--code")
.build()
.unwrap();
let html = highlight("const x = 1", formatter);
Lumis.highlight!(
"const x = 1",
formatter: {:html_multi_themes,
language: "javascript",
themes: [light: "github_light", dark: "github_dark"],
css_variable_prefix: "--code"
}
)
HTML Multi-Themes is not currently supported in lumis4j.
lumis highlight index.js \
--formatter html-multi-themes \
--themes light:github_light \
--themes dark:github_dark \
--css-variable-prefix "--code"
defaultTheme
Controls what color values appear inline (not just as CSS variables):
| Value | Behavior |
|---|---|
omitted / null | CSS variables only, no inline colors |
"light" | Inline colors from the light theme, CSS variables for all themes |
"light-dark()" | Uses CSS light-dark() function for automatic OS-level switching |
Output format
HTML Multi-Themes keeps the same HTML structure, but each token carries CSS variables for one or more themes:
<pre class="lumis" style="--lumis-light-bg: #ffffff; --lumis-dark-bg: #0d1117;">
<code class="language-javascript" translate="no" tabindex="0">
<div class="line" data-line="1">
<span style="--lumis-light: #cf222e; --lumis-dark: #ff7b72; color: light-dark(var(--lumis-light), var(--lumis-dark));">const</span>
</div>
</code>
</pre>
<pre class="lumis">carries shared background and theme variables<code class="language-*">identifies the language and keeps the block focusable<div class="line" data-line="N">wraps each line<span style="--lumis-...">carries per-theme token colors and font styles
Good uses
- light/dark mode
- user-selectable theme switching
- one HTML block shared across themes