Expand description
Syntax highlighter powered by Tree-sitter and Neovim themes.
§Quick Start
Highlight code in three steps: pick a formatter, configure it, format your code.
use lumis::{HtmlInlineBuilder, languages::Language, themes, formatters::Formatter};
let code = "fn main() { println!(\"Hello, world!\"); }";
let theme = themes::get("dracula").unwrap();
let formatter = HtmlInlineBuilder::new()
.language(Language::Rust)
.theme(Some(theme))
.build()
.unwrap();
let mut output = Vec::new();
lumis::write_highlight(&mut output, code, formatter).unwrap();
let html = String::from_utf8(output).unwrap();§Alternative: Using highlight() and write_highlight()
use lumis::{highlight, HtmlInlineBuilder, languages::Language, themes};
let code = "print('Hello')";
let theme = themes::get("dracula").unwrap();
let formatter = HtmlInlineBuilder::new()
.language(Language::Python)
.theme(Some(theme))
.build()
.unwrap();
let html = highlight(code, formatter);For large outputs, use write_highlight() to stream directly to a writer:
use lumis::{write_highlight, TerminalBuilder, languages::Language};
use std::fs::File;
let mut file = File::create("output.txt").unwrap();
write_highlight(&mut file, code, formatter).unwrap();§Language Feature Flags
By default, Lumis includes support for all languages, which can result in longer compilation times. You can reduce compilation time and binary size by enabling only the languages you need:
[dependencies]
lumis = { version = "0.1", default-features = false, features = ["lang-rust", "lang-javascript", "lang-bundle-web"] }Available features include per-language flags like lang-rust, lang-javascript,
lang-html, and bundle flags like lang-bundle-web, lang-bundle-web-extra,
lang-bundle-system, lang-bundle-backend, and lang-bundle-full.
Use all-languages to enable all language support:
[dependencies]
lumis = { version = "0.1", features = ["all-languages"] }§Formatters
| Formatter | Output | Use When |
|---|---|---|
HtmlInlineBuilder | HTML with inline styles | Need standalone HTML, email, no external CSS |
HtmlMultiThemesBuilder | HTML (inline) with multiple themes | Support light/dark mode, theme switching |
HtmlLinkedBuilder | HTML with CSS classes | Multiple code blocks, custom styling |
TerminalBuilder | ANSI escape codes | CLI tools, terminal output |
BBCodeScopedBuilder | BBCode with highlight scope tags | Scope-aware BBCode parsers, BBCode-based platforms |
See the formatters module for advanced features like line highlighting and custom formatters.
§Themes
120+ themes from popular Neovim colorschemes. Use with HTML inline and terminal formatters.
use lumis::themes;
// Get a theme by name
let theme = themes::get("dracula").unwrap();
// Or parse from string
let theme: themes::Theme = "catppuccin_mocha".parse().unwrap();See the themes module for loading custom themes from JSON files.
Available themes are listed below.
§Languages available
See Languages for every supported language and the files each one detects.
§Themes available
See Themes for every built-in
theme with the plugin it comes from and its license. themes::Theme::license
holds the same license at runtime.
Re-exports§
pub use formatters as formatter;pub use formatters::ansi;pub use formatters::html;pub use crate::highlight::Budget;pub use crate::highlight::HighlightOptions;
Modules§
- annotations
- Caller-provided semantic ranges for formatter event streams.
- decorations
- Lumis-owned overlays the built-in formatters render.
- formatters
- Formatter implementations for generating syntax highlighted output.
- highlight
- Core highlighting API that abstracts away tree-sitter complexity.
- highlights
- languages
- Language detection and Tree-sitter configuration.
- themes
- Theme system for syntax highlighting.
Structs§
- Annotation
- A caller-provided semantic range with arbitrary typed data.
- BBCode
Scoped Builder - Builder for
BBCodeScoped. - Html
Inline Builder - Builder for
HtmlInline. - Html
Linked Builder - Builder for
HtmlLinked. - Html
Multi Themes Builder - Builder for
HtmlMultiThemes. - Terminal
Builder - Builder for
Terminal.
Enums§
- Annotation
Error - An annotation range is invalid for construction or for a specific source.
- Annotation
Range - A half-open annotation range expressed as offsets or source positions.
- Budget
Exhausted - Which limit bound a render.
- Terminal
Background - Background fill behavior for terminal output.
Functions§
- highlight
- Highlights source code and returns it as a string.
- highlight_
with_ options - Highlights source code with per-operation options and returns it as a string.
- write_
highlight - Write syntax highlighted output directly to a writer.
- write_
highlight_ with_ options - Writes syntax highlighted output with per-operation options.