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, formatter::Formatter};
let code = "fn main() { println!(\"Hello, world!\"); }";
let theme = themes::get("dracula").unwrap();
let formatter = HtmlInlineBuilder::new()
.lang(Language::Rust)
.theme(Some(theme))
.build()
.unwrap();
let mut output = Vec::new();
formatter.format(code, &mut output).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()
.lang(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"] }Available language features include: lang-angular, lang-astro, lang-bash, lang-c,
lang-cpp, lang-css, lang-elixir, lang-go, lang-html, lang-java, lang-javascript,
lang-json, lang-markdown, lang-python, lang-rust, lang-typescript, and many more.
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 |
See the formatter 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
| Language | File Extensions |
|---|---|
| Angular | *.angular, component.html |
| Assembly | *.s, *.asm, *.assembly |
| Astro | *.astro |
| Bash | *.bash, *.bats, *.cgi, *.command, *.env, *.fcgi, *.ksh, *.sh, *.sh.in, *.tmux, *.tool, *.zsh, .bash_aliases, .bash_history, .bash_logout, .bash_profile, .bashrc, .cshrc, .env, .env.example, .flaskenv, .kshrc, .login, .profile, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, 9fs, PKGBUILD, bash_aliases, bash_logout, bash_profile, bashrc, cshrc, ebuild, eclass, gradlew, kshrc, login, man, profile, zlogin, zlogout, zprofile, zshenv, zshrc |
| C | *.c |
| Caddy | Caddyfile |
| CMake | *.cmake, *.cmake.in, CMakeLists.txt |
| C++ | *.cc, *.cpp, *.h, *.hh, *.hpp, *.ino, *.cxx, *.cu, *.hxx |
| CSS | *.css |
| CSV | *.csv |
| C# | *.cs |
| Clojure | *.bb, *.boot, *.clj, *.cljc, *.clje, *.cljs, *.cljx, *.edn, *.joke, *.joker |
| Comment | |
| Common Lisp | *.lisp, *.lsp, *.asd |
| Dart | *.dart |
| Diff | *.diff |
| Dockerfile | Dockerfile, dockerfile, docker, Containerfile, container, *.dockerfile, *.docker, *.container |
| EEx | *.eex |
| EJS | *.ejs |
| ERB | *.erb |
| Elixir | *.ex, *.exs |
| Elm | *.elm |
| Erlang | *.erl, *.app, *.app.src, *.es, *.escript, *.hrl, *.xrl, *.yrl, Emakefile, rebar.config |
| Fish | *.fish |
| F# | *.fs, *.fsx, *.fsi |
| Gleam | *.gleam |
| Glimmer | *.hbs, *.handlebars, *.html.handlebars, *.glimmer |
| Go | *.go |
| GraphQL | |
| HEEx | *.heex, *.neex |
| HTML | *.html, *.htm, *.xhtml |
| Haskell | *.hs, *.hs-boot |
| HCL | *.hcl, *.nomad, *.tf, *.tfvars, *.workflow |
| IEx | *.iex |
| JSON | *.json, *.avsc, *.geojson, *.gltf, *.har, *.ice, *.JSON-tmLanguage, *.jsonl, *.mcmeta, *.tfstate, *.tfstate.backup, *.topojson, *.webapp, *.webmanifest, .arcconfig, .auto-changelog, .c8rc, .htmlhintrc, .imgbotconfig, .nycrc, .tern-config, .tern-project, .watchmanconfig, Pipfile.lock, composer.lock, mcmod.info, flake.lock |
| Java | *.java |
| JavaScript | *.cjs, *.js, *.mjs, *.snap, *.jsx |
| Kotlin | *.kt, *.ktm, *.kts |
| LaTeX | *.aux, *.cls, *.sty, *.tex |
| Liquid | *liquid |
| LLVM | *.llvm, *.ll |
| Lua | *.lua |
| Make | *.mak, *.d, *.make, *.makefile, *.mk, *.mkfile, .dsp, BSDmakefile, GNUmakefile, Kbuild, Makefile, MAKEFILE, Makefile.am, Makefile.boot, Makefile.frag, Makefile.in, Makefile.inc, Makefile.wat, makefile, makefile.sco, mkfile |
| Markdown | *.md, README, LICENSE |
| Markdown Inline | |
| Nix | *.nix |
| OCaml | *.ml |
| OCaml Interface | *.mli |
| Objective-C | *.m, *.objc |
| Perl | *.pm, *.pl, *.t |
| PHP | *.php, *.phtml, *.php3, *.php4, *.php5, *.php7, *.phps |
| Plain Text | |
| PowerShell | *.ps1, *.psm1 |
| Protocol Buffer | *.proto, *.protobuf, *.proto2, *.proto3 |
| Python | *.py, *.py3, *.pyi, *.bzl, TARGETS, BUCK, DEPS |
| R | *.R, *.r, *.rd, *.rsx, .Rprofile, expr-dist |
| Regex | *.regex |
| Ruby | *.rb, *.builder, *.spec, *.rake, Gemfile, Rakefile |
| Rust | *.rs |
| SCSS | *.scss |
| SQL | *.sql, *.pgsql |
| Scala | *.scala, *.sbt, *.sc |
| Surface | *.surface, *.sface |
| Svelte | *.svelte |
| Swift | *.swift |
| TOML | *.toml, Cargo.lock, Gopkg.lock, Pipfile, pdm.lock, poetry.lock, uv.lock |
| TSX | *.tsx |
| TypeScript | *.ts |
| Typst | *.typ, *.typst |
| Vim | *.vim, *.viml |
| Vue | *.vue |
| XML | *.ant, *.csproj, *.mjml, *.plist, *.resx, *.svg, *.ui, *.vbproj, *.xaml, *.xml, *.xsd, *.xsl, *.xslt, *.zcml, *.rng, App.config, nuget.config, packages.config, .classpath, .cproject, .project |
| YAML | *.yaml, *.yml |
| Zig | *.zig |
§Themes available
| Theme Name |
|---|
| aura_dark |
| aura_dark_soft_text |
| aura_soft_dark |
| aura_soft_dark_soft_text |
| ayu_dark |
| ayu_light |
| ayu_mirage |
| bamboo_light |
| bamboo_multiplex |
| bamboo_vulgaris |
| bluloco_dark |
| bluloco_light |
| carbonfox |
| catppuccin_frappe |
| catppuccin_latte |
| catppuccin_macchiato |
| catppuccin_mocha |
| cyberdream_dark |
| cyberdream_light |
| darkplus |
| dawnfox |
| dayfox |
| dracula |
| dracula_soft |
| duskfox |
| edge_aura |
| edge_dark |
| edge_light |
| edge_neon |
| everforest_dark |
| everforest_light |
| flexoki_dark |
| flexoki_light |
| github_dark |
| github_dark_colorblind |
| github_dark_default |
| github_dark_dimmed |
| github_dark_high_contrast |
| github_dark_tritanopia |
| github_light |
| github_light_colorblind |
| github_light_default |
| github_light_high_contrast |
| github_light_tritanopia |
| horizon_dark |
| iceberg |
| gruvbox_dark |
| gruvbox_dark_hard |
| gruvbox_dark_soft |
| gruvbox_light |
| gruvbox_light_hard |
| gruvbox_light_soft |
| kanagawa_dragon |
| kanagawa_lotus |
| kanagawa_wave |
| material_darker |
| material_deep_ocean |
| material_lighter |
| material_oceanic |
| material_palenight |
| matte_black |
| melange_dark |
| melange_light |
| molokai |
| modus_operandi |
| modus_vivendi |
| monokai_pro_dark |
| monokai_pro_machine |
| monokai_pro_ristretto |
| monokai_pro_spectrum |
| moonfly |
| moonlight |
| neosolarized_dark |
| neosolarized_light |
| neovim_dark |
| neovim_light |
| nightfly |
| nightfox |
| nord |
| nordfox |
| nordic |
| onedark |
| onedark_cool |
| onedark_darker |
| onedark_deep |
| onedark_light |
| onedark_warm |
| onedark_warmer |
| onedarkpro_dark |
| onedarkpro_vivid |
| onelight |
| papercolor_dark |
| papercolor_light |
| rosepine_dark |
| rosepine_dawn |
| rosepine_moon |
| solarized_autumn_dark |
| solarized_autumn_light |
| solarized_spring_dark |
| solarized_spring_light |
| solarized_summer_dark |
| solarized_summer_light |
| solarized_winter_dark |
| solarized_winter_light |
| srcery |
| terafox |
| tokyonight_day |
| tokyonight_moon |
| tokyonight_night |
| tokyonight_storm |
| vscode_dark |
| vscode_light |
| xcode_dark |
| xcode_dark_hc |
| xcode_light |
| xcode_light_hc |
| xcode_wwdc |
| zenburn |
| zephyr_dark |
Re-exports§
pub use formatter::ansi;pub use formatter::html;pub use crate::formatter::HtmlInlineBuilder;pub use crate::formatter::HtmlLinkedBuilder;pub use crate::formatter::HtmlMultiThemesBuilder;pub use crate::formatter::TerminalBuilder;
Modules§
- constants
- Syntax highlighting scope names and CSS class mappings.
- formatter
- Formatter implementations for generating syntax highlighted output.
- highlight
- Core highlighting API that abstracts away tree-sitter complexity.
- languages
- Language detection and Tree-sitter configuration.
- themes
- Theme system for syntax highlighting.
- vendor
Functions§
- highlight
- Highlights source code and returns it as a string.
- write_
highlight - Write syntax highlighted output directly to a writer.