Smalto
A general-purpose syntax highlighting library for Gleam, with regex-based grammars for 30 languages.
Smalto tokenizes source code using Prism.js-inspired grammars and renders the result as HTML with CSS classes, ANSI terminal colors, or structured tokens for custom rendering.
Features
- Dual target — works on both Erlang and JavaScript targets
- 30 languages — Gleam, Erlang, Elixir, JavaScript, TypeScript, Python, Rust, Go, C, C++, HTML, CSS, JSON, TOML, YAML, Bash, SQL, Java, Ruby, PHP, Swift, Kotlin, Haskell, Lua, Markdown, Dockerfile, XML, Zig, Scala, Dart
- HTML output — tokens wrapped in
<span class="smalto-{name}">elements, ready for CSS theming - ANSI output — terminal-colored output with configurable themes
- Structured tokens — access the raw token list for custom rendering pipelines
- Custom grammars — define your own grammars with regex patterns, greedy matching, and nested rules
- Language inheritance — grammars can extend other grammars (e.g., TypeScript extends JavaScript)
- Configurable ANSI themes — customize terminal colors per token type, or use the built-in default
How it works
- You pick a language grammar (e.g.,
python.grammar()) - Smalto tokenizes the source code into a list of
Tokenvalues using a Prism.js-faithful engine - You choose an output format: HTML, ANSI, or raw tokens
Documentation
| Guide | Description |
|---|---|
| Getting started | Installation, quick examples |
| Lustre integration | Render highlighted tokens as Lustre elements |
| Tokens | Token types, names, and values |
| Grammars | Grammar structure, rules, and custom grammars |
| ANSI themes | Configuring terminal color themes |
| Supported languages | Full list of built-in language grammars |
API reference
Full API documentation is available on HexDocs.