Pygments

Available lexers

« Back To Index

Contents

This page lists all available builtin lexers and the options they take.

Currently, all lexers support these options:

stripnl
Strip leading and trailing newlines from the input (default: True)
stripall
Strip all leading and trailing whitespace from the input (default: False).
tabsize
If given and greater than 0, expand tabs in the input (default: 0).
encoding

New in Pygments 0.6.

If given, must be an encoding name (such as "utf-8"). This encoding will be used to convert the input string to Unicode (if it is not already a Unicode string). The default is "latin1".

If this option is set to "guess", a simple UTF-8 vs. Latin-1 detection is used, if it is set to "chardet", the chardet library is used to guess the encoding of the input.

These lexers are builtin and can be imported from pygments.lexers:

Special lexers

TextLexer

"Null" lexer, doesn't highlight anything.

Aliases:text
Filename patterns:*.txt
Mimetypes:text/plain

RawTokenLexer

Recreates a token stream formatted with the RawTokenFormatter.

Additional option:

compress
If set to 'gz' or 'bz2', decompress the token stream with the given compression algorithm before lexing (default: '').
Aliases:raw
Filename patterns:*.raw
Mimetypes:application/x-pygments/tokens

Agile languages

PythonLexer

For Python source code.

Aliases:python, py
Filename patterns:*.py, *.pyw
Mimetypes:text/x-python, application/x-python

PythonConsoleLexer

For Python console output or doctests, such as:

>>> a = 'foo'
>>> print a
'foo'
>>> 1/0
Traceback (most recent call last):
...
Aliases:pycon
Filename patterns:None
Mimetypes:None

RubyLexer

For Ruby source code.

Aliases:ruby, rb
Filename patterns:*.rb
Mimetypes:text/x-ruby, application/x-ruby

RubyConsoleLexer

For Ruby interactive console (irb) output like:

irb(main):001:0> a = 1
=> 1
irb(main):002:0> puts a
1
=> nil
Aliases:rbcon, irb
Filename patterns:None
Mimetypes:None

PerlLexer

For Perl source code.

Aliases:perl, pl
Filename patterns:*.pl, *.pm
Mimetypes:text/x-perl, application/x-perl

LuaLexer

For Lua source code.

Additional options:

func_name_highlighting
If given and True, highlight builtin function names (default: True).
disabled_modules

If given, must be a list of module names whose function names should not be highlighted. By default all modules are highlighted.

To get a list of allowed modules have a look into the _luabuiltins module:

>>> from pygments.lexers._luabuiltins import MODULES
>>> MODULES.keys()
['string', 'coroutine', 'modules', 'io', 'basic', ...]
Aliases:lua
Filename patterns:*.lua
Mimetypes:text/x-lua, application/x-lua

SchemeLexer

For Scheme source code. It supports the whole R5RS specification.

New in Pygments 0.6.

Aliases:scheme
Filename patterns:*.scm
Mimetypes:text/x-scheme, application/x-scheme

Compiled languages

CLexer

For C source code with preprocessor directives.

Aliases:c
Filename patterns:*.c, *.h
Mimetypes:text/x-chdr, text/x-csrc

CppLexer

For C++ source code with preprocessor directives.

Aliases:cpp, c++
Filename patterns:*.cpp, *.hpp, *.c++, *.h++
Mimetypes:text/x-c++hdr, text/x-c++src

DelphiLexer

For Delphi (Borland Object Pascal) source code.

Aliases:delphi, pas, pascal, objectpascal
Filename patterns:*.pas
Mimetypes:text/x-pascal

JavaLexer

For Java source code.

Aliases:java
Filename patterns:*.java
Mimetypes:text/x-java

.NET languages

CSharpLexer

For C# source code.

Aliases:c#, csharp
Filename patterns:*.cs
Mimetypes:text/x-csharp

BooLexer

For Boo source code.

Aliases:boo
Filename patterns:*.boo
Mimetypes:text/x-boo

VbNetLexer

For Visual Basic.NET source code.

Aliases:vbnet, vb.net
Filename patterns:*.vb, *.bas
Mimetypes:text/x-vbnet, text/x-vba

Web-related languages

JavascriptLexer

For JavaScript source code.

Aliases:js, javascript
Filename patterns:*.js
Mimetypes:text/x-javascript, application/x-javascript, text/javascript

CssLexer

For CSS (Cascading Style Sheets).

Aliases:css
Filename patterns:*.css
Mimetypes:text/css

HtmlLexer

For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted by the appropriate lexer.

Aliases:html
Filename patterns:*.html, *.htm, *.xhtml
Mimetypes:text/html, application/xhtml+xml

PhpLexer

For PHP source code. For PHP embedded in HTML, use the HtmlPhpLexer.

Additional options:

startinline
If given and True the lexer starts highlighting with php code. (i.e.: no starting <?php required)
funcnamehighlighting
If given and True, highlight builtin function names (default: True).
disabledmodules

If given, must be a list of module names whose function names should not be highlighted. By default all modules are highlighted except the special 'unknown' module that includes functions that are known to php but are undocumented.

To get a list of allowed modules have a look into the _phpbuiltins module:

>>> from pygments.lexers._phpbuiltins import MODULES
>>> MODULES.keys()
['PHP Options/Info', 'Zip', 'dba', ...]

In fact the names of those modules match the module names from the php documentation.

Aliases:php, php3, php4, php5
Filename patterns:*.php, *.php[345]
Mimetypes:None

XmlLexer

Generic lexer for XML (extensible markup language).

Aliases:xml
Filename patterns:*.xml
Mimetypes:text/xml, application/xml, image/svg+xml, application/rss+xml, application/atom+xml, application/xsl+xml, application/xslt+xml

Template languages

ErbLexer

Generic ERB (Ruby Templating) lexer.

Just highlights ruby code between the preprocessor directives, other data is left untouched by the lexer.

All options are also forwarded to the RubyLexer.

Aliases:erb
Filename patterns:None

RhtmlLexer

Subclass of the ERB lexer that highlights the unlexed data with the html lexer.

Nested Javascript and CSS is highlighted too.

Aliases:rhtml, html+erb, html+ruby
Filename patterns:*.rhtml

XmlErbLexer

Subclass of ErbLexer which highlights data outside preprocessor directives with the XmlLexer.

Aliases:xml+erb, xml+ruby
Filename patterns:None

CssErbLexer

Subclass of ErbLexer which highlights unlexed data with the CssLexer.

Aliases:css+erb, css+ruby
Filename patterns:None

JavascriptErbLexer

Subclass of ErbLexer which highlights unlexed data with the JavascriptLexer.

Aliases:js+erb, javascript+erb, js+ruby, javascript+ruby
Filename patterns:None

HtmlPhpLexer

Subclass of PhpLexer that highlights unhandled data with the HtmlLexer.

Nested Javascript and CSS is highlighted too.

Aliases:html+php
Filename patterns:*.phtml
Mimetypes:text/x-php, application/x-php, application/x-httpd-php, application/x-httpd-php3, application/x-httpd-php4, application/x-httpd-php5

XmlPhpLexer

Subclass of PhpLexer that higlights unhandled data with the XmlLexer.

Aliases:xml+php
Filename patterns:None

CssPhpLexer

Subclass of PhpLexer which highlights unmatched data with the CssLexer.

Aliases:css+php
Filename patterns:None

JavascriptPhpLexer

Subclass of PhpLexer which highlights unmatched data with the JavascriptLexer.

Aliases:js+php, javascript+php
Filename patterns:None

DjangoLexer

Generic django and jinja template lexer.

It just highlights django/jinja code between the preprocessor directives, other data is left untouched by the lexer.

Aliases:django, jinja
Filename patterns:None

HtmlDjangoLexer

Subclass of the DjangoLexer that highighlights unlexed data with the HtmlLexer.

Nested Javascript and CSS is highlighted too.

Aliases:html+django, html+jinja
Filename patterns:None

XmlDjangoLexer

Subclass of the DjangoLexer that highlights unlexed data with the XmlLexer.

Aliases:xml+django, xml+jinja
Filename patterns:None

CssDjangoLexer

Subclass of the DjangoLexer that highlights unlexed data with the CssLexer.

Aliases:css+django, css+jinja
Filename patterns:None

JavascriptDjangoLexer

Subclass of the DjangoLexer that highlights unlexed data with the JavascriptLexer.

Aliases:javascript+django, js+django, javascript+jinja, js+jinja
Filename patterns:None

SmartyLexer

Generic Smarty template lexer.

Just highlights smarty code between the preprocessor directives, other data is left untouched by the lexer.

Aliases:smarty
Filename patterns:None

HtmlSmartyLexer

Subclass of the SmartyLexer that highighlights unlexed data with the HtmlLexer.

Nested Javascript and CSS is highlighted too.

Aliases:html+smarty
Filename patterns:None

XmlSmartyLexer

Subclass of the SmartyLexer that highlights unlexed data with the XmlLexer.

Aliases:xml+smarty
Filename patterns:None

CssSmartyLexer

Subclass of the SmartyLexer that highlights unlexed data with the CssLexer.

Aliases:css+smarty
Filename patterns:None

JavascriptSmartyLexer

Subclass of the SmartyLexer that highlights unlexed data with the JavascriptLexer.

Aliases:javascript+smarty
Filename patterns:None

GenshiTextLexer

A lexer that highlights genshi text templates.

Aliases:genshitext
Filename patterns:None

HtmlGenshiLexer

A lexer that highlights genshi and kid kid HTML templates.

Aliases:html+genshi, html+kid
Filename patterns:None

GenshiLexer

A lexer that highlights genshi and kid kid XML templates.

Aliases:genshi, kid, xml+genshi, xml.kid
Filename patterns:*.kid

JavascriptGenshiLexer

A lexer that highlights javascript code in genshi text templates.

Aliases:js+genshitext, js+genshi, javascript+genshitext, javascript+genshi
Filename patterns:None

CssGenshiLexer

A lexer that highlights CSS definitions in genshi text templates.

Aliases:css+genshitext, css+genshi
Filename patterns:None

MyghtyLexer

Generic myghty templates lexer. Code that isn't Myghty markup is yielded as Token.Other.

New in Pygments 0.6.

Aliases:myghty
Filename patterns:*.myt, autodelegate

MyghtyHtmlLexer

Subclass of the MyghtyLexer that highlights unlexer data with the HtmlLexer.

New in Pygments 0.6.

Aliases:html+myghty
Filename patterns:None

MyghtyXmlLexer

Subclass of the MyghtyLexer that highlights unlexer data with the XmlLexer.

New in Pygments 0.6.

Aliases:xml+myghty
Filename patterns:None

MyghtyJavascriptLexer

Subclass of the MyghtyLexer that highlights unlexer data with the JavascriptLexer.

New in Pygments 0.6.

Aliases:js+myghty, javascript+myghty
Filename patterns:None

MyghtyCssLexer

Subclass of the MyghtyLexer that highlights unlexer data with the CssLexer.

New in Pygments 0.6.

Aliases:css+myghty
Filename patterns:None

Other languages

SqlLexer

Lexer for Structured Query Language. Currently, this lexer does not recognize any special syntax except ANSI SQL.

Aliases:sql
Filename patterns:*.sql
Mimetypes:text/x-sql

BrainfuckLexer

Lexer for the esoteric BrainFuck language.

Aliases:brainfuck
Filename patterns:*.bf, *.b
Mimetypes:None

BashLexer

Lexer for (ba)sh shell scripts.

New in Pygments 0.6.

Aliases:bash, sh
Filename patterns:*.sh
Mimetypes:application/x-sh, application/x-shellscript

Text lexers

IniLexer

Lexer for configuration files in INI style.

Aliases:ini, cfg
Filename patterns:*.ini, *.cfg
Mimetypes:None

MakefileLexer

Lexer for Makefiles.

Aliases:make, makefile, mf
Filename patterns:*.mak, Makefile, makefile
Mimetypes:text/x-makefile

DiffLexer

Lexer for unified or context-style diffs.

Aliases:diff
Filename patterns:*.diff, *.patch
Mimetypes:text/x-diff, text/x-patch

IrcLogsLexer

Lexer for IRC logs in irssi or xchat style.

Aliases:irc
Filename patterns:None
Mimetypes:None

TexLexer

Lexer for the TeX and LaTeX typesetting languages.

Aliases:tex, latex
Filename patterns:*.tex, *.aux, *.toc
Mimetypes:text/x-tex, text/x-latex

GroffLexer

Lexer for the (g)roff typesetting language, supporting groff extensions. Mainly useful for highlighting manpage sources.

New in Pygments 0.6.

Aliases:groff, nroff, man
Filename patterns:*.[1234567], *.man
Mimetypes:text/troff, application/x-troff

ApacheConfLexer

Lexer for configuration files following the Apache config file format.

New in Pygments 0.6.

Aliases:apacheconf, aconf, apache
Filename patterns:.htaccess, apache.conf, apache2.conf
Mimetypes:None

BBCodeLexer

A Lexer that highlights BBCode(-like) syntax.

New in Pygments 0.6.

Aliases:bbcode
Filename patterns:None
Mimetypes:None

Iterating over all lexers

New in Pygments 0.6.

To get all lexers (both the builtin and the plugin ones), you can use the get_all_lexers() function from the pygments.lexers module:

>>> from pygments.lexers import get_all_lexers
>>> i = get_all_lexers()
>>> i.next()
('Diff', ('diff',), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch'))
>>> i.next()
('Delphi', ('delphi', 'objectpascal', 'pas', 'pascal'), ('*.pas',), ('text/x-pascal',))
>>> i.next()
('XML+Ruby', ('xml+erb', 'xml+ruby'), (), ())

As you can see, the return value is an iterator which yields tuples in the form (name, aliases, filetypes, mimetypes).