Program code

Pygments – general-purpose syntax highlighter

Pygments is a syntax-highlighting library for displaying source code and other structured text in different output formats. It is widely applicable to documentation, code hosting, publishing systems and development tools that need to distinguish language constructs visually. Its language definitions cover programming languages, markup formats, configuration files and interactive command sessions.

The library processes source text through a lexer that identifies tokens such as keywords, strings, comments and operators. Those tokens can then pass through optional filters before being converted into the requested output by a formatter. This architecture allows the same source text to be rendered as HTML, LaTeX, RTF, terminal colours or other representations. Pygments includes numerous colour styles and options for controlling line numbering, highlighting and layout. Developers can use its API directly or run the pygmentize command-line tool. Custom lexers, filters, formatters and styles can be added to support specialised workflows without modifying the core library.

This is free and open source software.

Key Features

  • Syntax highlighting – recognises and categorises programming language constructs.
  • Extensive language support – includes hundreds of lexers for source code and structured text.
  • Automatic lexer selection – identifies supported languages from filenames and source content.
  • Explicit language selection – uses a specified lexer when automatic detection is unsuitable.
  • Custom lexers – allows developers to define recognition rules for additional languages.
  • Token processing – converts source code into reusable syntax token streams.
  • Token filters – modifies or annotates recognised tokens before formatting.
  • Custom filters – supports user-defined token-processing operations.
  • HTML output – generates highlighted code for web pages.
  • Standalone HTML – creates complete documents containing code and styling information.
  • LaTeX output – formats highlighted source for use in typeset documents.
  • RTF output – produces highlighted content for rich-text documents.
  • SVG output – renders highlighted source as vector graphics.
  • Terminal colours – supports ANSI-coloured output in terminal applications.
  • Image output – renders code as an image through the appropriate formatter.
  • Line numbering – includes options for displaying source line numbers.
  • Line highlighting – emphasises specific lines or ranges.
  • Custom colour schemes – selects from built-in and user-defined styles.
  • Custom formatters – supports additional output formats.
  • Terminal-session lexers – recognises supported shell sessions and interactive interpreter output.
  • Command-line interface – processes source files and standard input using pygmentize.
  • Library API – integrates highlighting into applications and publishing systems.
  • Plugin support – permits external extensions to provide additional components.

Website: github.com/pygments/pygments
Support:
Developer: Georg Brandl, Matthäus Chajdas, Jean Abou-Samra and contributors
License: BSD 2-Clause ‘Simplified’ License

Pygments is written in Python. Learn Python with our recommended free books and free tutorials.


Related Software

Syntax Highlighters
PrismLightweight, extensible syntax highlighter, with modern web standards in mind
Highlight.jsJavaScript syntax highlighter with language auto-detection
ShikiThemeable code rendering powered by TextMate grammars
ChromaGeneral purpose syntax highlighter
RougePure Ruby syntax highlighter
PygmentsGeneric syntax highlighter
starry-nightGitHub-style code colouring for JavaScript projects
HighlightTransforms source code into polished, readable output
Re-HighlightPowerful syntax highlighter

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted