By Forrest Cook
May 7, 2008
Pygments is a multi-language
syntax highlighter that is written in Python and distributed under
the BSD license. The project description states:
It is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code. Highlights are:
- a wide range of common languages and markup formats is supported
- special attention is paid to details that increase highlighting quality
- support for new languages and formats are added easily; most languages use a simple regex-based lexing mechanism
- a number of output formats is available, among them HTML, RTF, LaTeX and ANSI sequences
- it is usable as a command-line tool and as a library
- ... and it highlights even Brainf*ck!
![[Pygments]](/images/ns/pygmentslogo.png)
The project
FAQ notes that
Pygments supports a long (and expandable)
collection of input languages.
It can produce output as HTML, LaTeX, RTF and ANSI sequences for
console output. The software can be run from the
pygmentize
command-line tool, or accessed from your own Python code. See the
command line reference
for details on running pygmentize.
Pygments version 0.10 was recently
announced.
Changes include the addition of 15 new language
lexers, expansion
of the Makefile lexer's capabilities, the ability to output in several
image formats, a new style and other enhancements and fixes.
Installation of Pygments was straightforward on an Ubuntu 7.04 system.
A tar.gz file was downloaded from the
Python package
site. The file was uncompressed with gunzip and extracted with tar.
Running python setup.py install as root on the setup script
installed the software and it was ready to run.
After a quick read of the
Command Line Usage document, your author was able to run
pygmentize on some Python code and produce some rather pleasing
colorized html output.
The project's demo
page has a number of examples of Pygment's output, it also allows
you to upload your own code to see how it looks after formatting.
Pygments looks to be a well designed generic tool.
It could useful for online and offline documentation, code analysis,
education and much more. This
list of projects
is already putting Pygments to use, perhaps your project could
make use of it as well.
(
Log in to post comments)