pygmentize 0.1.0

pygmentize wrapper for syntax highlighting
Documentation

pygmentize

Latest Version Docs Pygmentize Version License

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).

Example

use pygmentize::{HtmlFormatter, PygmentizeError};

let code = r#"fn main() {
    println!("Hello, world!");
}"#;

let html = pygmentize::highlight(code, Some("rust"), &HtmlFormatter::default())?;
println!("{html}");

Output

(whitespace added to improve clarity)

<div class="highlight">
<pre>
    <span></span>

    <span class="k">fn</span>
    <span class="nf">main</span>
    <span class="p">()</span>
    <span class="w"> </span>
    <span class="p">{</span>

    <span class="w">    </span>
    <span class="fm">println!</span>
    <span class="p">(</span>
    <span class="s">&quot;Hello, world!&quot;</span>
    <span class="p">);</span>

    <span class="p">}</span>
</pre>
</div>

Rendered

(with the Dracula theme)

image

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