pygments: Because everyone loves color

I have, on occasion, let slip the fact that terminal application that employ color win my favor more easily. I suppose I should keep that quiet, but it would be dishonest to do otherwise.

It might follow that applications that add color to things get an extra thumbs-up from me. Well, sometimes yes. pygments gets a thumbs-up either way.


pygments is sort of twofold: Not only does it colorize text, like you see above, but it can also set up text to appear colorized in other formats. So you can output, for example, your text file re-encoded to appear colorized in html. As an illustration, this …

pygmentize -f html coreutils.htm

changes this …

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="" xml:lang="en" lang="en">
  <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see" />

to this …

<div class="highlight"><pre><span class="cp">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span>
<span class="cp">    &quot;;&gt;</span>

<span class="nt">&lt;html</span> <span class="na">xmlns=</span><span class="s">&quot;;</span> <span class="na">xml:lang=</span><span class="s">&quot;en&quot;</span> <span class="na">lang=</span><span class="s">&quot;en&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;head&gt;</span>
  <span class="nt">&lt;meta</span> <span class="na">name=</span><span class="s">&quot;generator&quot;</span> <span class="na">content=</span><span class="s">&quot;HTML Tidy for Linux (vers 25 March 2009), see;</span> <span class="nt">/&gt;</span>

That might be a little dense to look at, but take my word for it. 🙄

(Of course, if that’s the direction you’re going, then perhaps the web interface is easier to copy-and-paste. 😉 )

I like pygments for doing a little more than colout or highlighter, and having the extra option to “convert” the product to a different “format.” It’s not often that I need to colorize files but I intend to employ this when the time comes. 😉

3 thoughts on “pygments: Because everyone loves color

  1. livibetter

    Pygments is more than just a command-line tool, I think it’s more of a highlighting library, that’s the library comes first and the pygmentize arrives second. Many programs or websites rely on Pygment to help spice up the presentation.

    I for one also use it for my own blogging program to render the code block in pretty colors.

  2. Pingback: rainbow: Color filtering in a different way | Inconsolation

  3. Pingback: clog: Custom color for logs | Inconsolation

Comments are closed.