Skip to main content

Crate lumis

Crate lumis 

Source
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

FormatterOutputUse When
HtmlInlineBuilderHTML with inline stylesNeed standalone HTML, email, no external CSS
HtmlMultiThemesBuilderHTML (inline) with multiple themesSupport light/dark mode, theme switching
HtmlLinkedBuilderHTML with CSS classesMultiple code blocks, custom styling
TerminalBuilderANSI escape codesCLI tools, terminal output
BBCodeScopedBuilderBBCode with highlight scope tagsScope-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.
BBCodeScopedBuilder
Builder for BBCodeScoped.
HtmlInlineBuilder
Builder for HtmlInline.
HtmlLinkedBuilder
Builder for HtmlLinked.
HtmlMultiThemesBuilder
Builder for HtmlMultiThemes.
TerminalBuilder
Builder for Terminal.

Enums§

AnnotationError
An annotation range is invalid for construction or for a specific source.
AnnotationRange
A half-open annotation range expressed as offsets or source positions.
BudgetExhausted
Which limit bound a render.
TerminalBackground
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.