Expand description
Arborium — High-performance syntax highlighting
Arborium provides batteries-included syntax highlighting powered by tree-sitter. It supports 60+ languages with automatic language injection (e.g., CSS/JS in HTML).
§Quick Start
ⓘ
use arborium::Highlighter;
let mut hl = Highlighter::new();
let html = hl.highlight("rust", "fn main() {}")?;
// Output: <a-k>fn</a-k> <a-f>main</a-f>() {}§HTML vs ANSI Output
Use Highlighter for HTML output (web pages, documentation):
ⓘ
use arborium::{Highlighter, Config, HtmlFormat};
// Default: custom elements (<a-k>, <a-f>, etc.)
let mut hl = Highlighter::new();
// Or use class-based output for CSS compatibility
let config = Config {
html_format: HtmlFormat::ClassNames,
..Default::default()
};
let mut hl = Highlighter::with_config(config);Use AnsiHighlighter for terminal output:
ⓘ
use arborium::AnsiHighlighter;
use arborium::theme::builtin;
let theme = builtin::catppuccin_mocha().clone();
let mut hl = AnsiHighlighter::new(theme);
let colored = hl.highlight("rust", "fn main() {}")?;
println!("{}", colored);§Language Support
Enable languages via feature flags:
[dependencies]
arborium = { version = "0.1", features = ["lang-rust", "lang-python"] }Or enable all languages:
[dependencies]
arborium = { version = "0.1", features = ["all-languages"] }§Advanced Usage
For building custom grammar providers or working with raw spans, see the
advanced module.
Re-exports§
pub use arborium_tree_sitter as tree_sitter;
Modules§
Structs§
- Ansi
Highlighter - High-level syntax highlighter for ANSI terminal output.
- Config
- Configuration for highlighting.
- Grammar
Store - Thread-safe cache of compiled grammars.
- Highlighter
- High-level syntax highlighter for HTML output.
Enums§
- Error
- Error type for highlighting operations.
- Html
Format - HTML output format for syntax highlighting.
Constants§
- HIGHLIGHT_
NAMES - Standard highlight names used for syntax highlighting.
Functions§
- detect_
language - Detect the language from a file path or name.