Crate autumnus

Crate autumnus 

Source
Expand description

Syntax highlighter powered by Tree-sitter and Neovim themes.

§Quick Start

Use the builder pattern for type-safe, ergonomic formatter creation:

use autumnus::{HtmlInlineBuilder, languages::Language, themes, formatter::Formatter};
use std::io::Write;

let code = "fn main() { println!(\"Hello, world!\"); }";
let theme = themes::get("dracula").unwrap();

let formatter = HtmlInlineBuilder::new()
    .source(code)
    .lang(Language::Rust)
    .theme(Some(theme))
    .pre_class(Some("code-block"))
    .build()
    .unwrap();

let mut output = Vec::new();
formatter.format(&mut output).unwrap();
let html = String::from_utf8(output).unwrap();

§Language Feature Flags

By default, Autumnus 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]
autumnus = { version = "0.3", 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]
autumnus = { version = "0.3", features = ["all-languages"] }

§Available Builders

§More Examples

See the formatter module for detailed examples and usage patterns.

§Languages available

LanguageFile 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
CaddyCaddyfile
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
DockerfileDockerfile, 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
horizon_light
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 crate::formatter::HtmlInlineBuilder;
pub use crate::formatter::HtmlLinkedBuilder;
pub use crate::formatter::TerminalBuilder;

Modules§

formatter
Formatter implementations for generating syntax highlighted output.
languages
Language detection and Tree-sitter configuration.
themes
Theme system for syntax highlighting.

Structs§

Options
Configuration options for syntax highlighting.

Enums§

FormatterOption
Output formatter configuration for syntax highlighting.

Functions§

highlight
Highlights source code and returns it as a string with syntax highlighting.
write_highlight
Write syntax highlighted output directly to a writer.