pygmentize
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).
Rendered HTML Output
Rendered example of examples/html.rs.
Example
use ;
let code = r#"fn main() {
println!("Hello, world!");
}"#;
let html = highlight?;
println!;
Output
(whitespace added to improve clarity)
fn
main
()
{
println!
(
"Hello, world!"
);
}
Rendered
(with the Dracula theme)

Override Pygmentize Path
The path to the pygmentize binary, can be overridden using pygmentize::set_bin_path(). The default path is "pygmentize".
If pygmentize is installed in a virtual environment, within your crate directory,
i.e. Cargo.lock and env/ being within the same directory. Then assuming that
the current directory is the same. Then the path can be overridden by doing:
set_bin_path;
Install
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.
pip install Pygments