Pygmentize - Syntax Highlighter Tool

Use Pygmentize to highlight code syntax for various programming languages. Convert code to HTML, terminal output, and more with customizable styles.

Pygmentize

Pygmentize is a powerful command-line tool for syntax highlighting. It allows developers to easily format code snippets for various programming languages, making them more readable and presentable in different output formats.

Syntax Highlighting Examples

Below are examples of how to use Pygmentize for syntax highlighting. You can specify the output format, the programming language lexer, and various styling options.

Terminal Output with Custom Style

This command highlights Go code for a 256-color terminal, using the Monokai style.

# highlight syntax: use go lexer, style monokai, 256 colors terminal
pygmentize -f terminal256 -l go -g -P style=monokai

HTML Output with Keyword Formatting

This example converts Pascal code to HTML format and uses a filter to convert keywords to uppercase.

# use filter (keywordcase), will change keywords to upper case
pygmentize -f html -l pascal -F keywordcase:case=upper main.pas

Key Features and Usage

Pygmentize supports a wide range of lexers for different programming languages and offers various formatters, including HTML, LaTeX, RTF, and terminal output. You can also apply filters to modify the highlighted code, such as changing case, adding line numbers, or replacing specific tokens.

Further Resources

For more detailed information on Pygmentize, including a list of supported lexers, formatters, and filters, refer to the official documentation: