Rust library and wrapper around the pygmentize CLI. Apply syntax highlighting to over 500 languages and other text formatted. Render into HTML, SVG, LaTeX, and Terminal (ANSI color sequences).
```rust use pygmentize::{HtmlFormatter, PygmentizeError};
let code = r#"fn main() { println!("Hello, world!"); }"#;
let html = pygmentize::highlight(code, Some("rust"), &HtmlFormatter::default())?; println!("{html}"); ```
(whitespace added to improve clarity)
```html
fn
main
()
{
println!
(
"Hello, world!"
);
}
```
(with the Dracula theme)
The library is a wrapper around the pygmentize CLI, and as such it must be available in the system PATH. The easiest way to install pygmentize is through Python.
console
pip install Pygments