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.
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.
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
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
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.
For more detailed information on Pygmentize, including a list of supported lexers, formatters, and filters, refer to the official documentation: