Start with the source.
A heading. A code block. A few lines of Rust. Comfit starts with the text you already have.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```Tree-sitter syntax highlighting for Rust, JavaScript, and Python.
Turn source code into highlighted tokens, HTML, or terminal output.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```A heading. A code block. A few lines of Rust. Comfit starts with the text you already have.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```A Rust code block is still Rust, even inside Markdown.
Comfit follows embedded languages so each part gets its own highlighting.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```Keywords, strings, functions, and local references have different jobs.
Tree-sitter queries identify what to highlight. Comfit resolves overlapping captures and carries local-binding styles through their references.
Here, let is a keyword, "Comfit" is a string, and name is a local binding.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```Keep the highlighting. Change the presentation.
Apply a theme, color nested brackets, or emphasize the lines you want readers to notice.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```Render HTML for a website, ANSI for a terminal, or tokens for your own interface.
The shared highlighting engine is available through Rust, JavaScript, and Python integrations.
# Hello, Comfit
```rust
fn main() {
let name = "Comfit";
println!("{:?}", [name]);
}
```Install Comfit and render a short Rust snippet as highlighted HTML from your own project.
cargo add comfit --features rust,render-html
fn main() -> Result<(), comfit::Error> {
let mut highlighter = comfit::Highlighter::new()?;
let result = highlighter.highlight("fn main() {}", "rust", &Default::default())?;
println!("{}", result.render_html_classes(&Default::default()));
Ok(())
}
The HTML uses classes you can style with CSS. Rust API reference
npm install @comfit/node
import { renderHtml, RenderHtmlConfig, RenderHtmlStyle } from "@comfit/node";
const config = new RenderHtmlConfig();
config.style = RenderHtmlStyle.Inline;
console.log(renderHtml("fn main() {}", "rust", "catppuccin-mocha", config));
The HTML includes inline theme styles. Node.js API reference
python -m pip install comfit-hl
import comfit
config = comfit.RenderHtmlConfig(style=comfit.RenderHtmlStyle.Inline)
print(comfit.render_html("fn main() {}", "rust", "catppuccin-mocha", config))
The HTML includes inline theme styles. Python API reference
Highlight code when you build a site, in the browser, or directly in a terminal.
Add Comfit after remark-rehype and before rendering HTML in your unified pipeline.
pipeline.use(rehypeComfit, { theme: "catppuccin-mocha" });
Initialize the runtime, load the Rust grammar, and highlight source in the browser.
const tokens = highlighter.highlight(source, "rust");
Use comfit-cli to print a source file with ANSI colors and line numbers.
comfit ansi main.rs --theme catppuccin-mocha --line-numbers
Convert a local VS Code theme to Comfit’s TOML format, then use it to color the same Rust snippet in your terminal.
comfit convert theme.json --name "Custom" -o custom.toml
printf 'fn main() {}\n' |
comfit ansi --language rust --theme-file custom.toml
Pick a language, paste a snippet, and see what Comfit highlights.
Open the playground