Pygments
Available lexers
« Back To IndexContents
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:
Lexers for agile languages
LuaLexer
For Lua source code.
Additional options accepted:
- 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
PerlLexer
For Perl source code.
Aliases: perl, pl Filename patterns: *.pl, *.pm Mimetypes: text/x-perl, application/x-perl
PythonConsoleLexer
For Python console output or doctests, such as:
>>> a = 'foo' >>> print a foo >>> 1 / 0 Traceback (most recent call last): File "<stdin>", line 1, in <module> ZeroDivisionError: integer division or modulo by zero
Aliases: pycon Filename patterns: None Mimetypes: text/x-python-doctest
PythonLexer
For Python source code.
Aliases: python, py Filename patterns: *.py, *.pyw Mimetypes: text/x-python, application/x-python
PythonTracebackLexer
For Python tracebacks.
New in Pygments 0.7.
Aliases: pytb Filename patterns: *.pytb Mimetypes: text/x-python-traceback
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: text/x-ruby-shellsession
RubyLexer
For Ruby source code.
Aliases: rb, ruby Filename patterns: *.rb, *.rbw, Rakefile, *.rake, *.gemspec, *.rbx Mimetypes: text/x-ruby, application/x-ruby
SchemeLexer
A Scheme lexer, parsing a stream and outputting the tokens needed to highlight scheme code. This lexer could be most probably easily subclassed to parse other LISP-Dialects like Common Lisp, Emacs Lisp or AutoLisp.
This parser is checked with pastes from the LISP pastebin at http://paste.lisp.org/ to cover as much syntax as possible.
It supports the full Scheme syntax as defined in R5RS.
New in Pygments 0.6.
Aliases: scheme Filename patterns: *.scm Mimetypes: text/x-scheme, application/x-scheme
Lexers for 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), Turbo Pascal and Free Pascal source code.
Additional options accepted:
- turbopascal
- Highlight Turbo Pascal specific keywords (default: True).
- delphi
- Highlight Borland Delphi specific keywords (default: True).
- freepascal
- Highlight Free Pascal specific keywords (default: True).
- units
- A list of units that should be considered builtin, supported are System, SysUtils, Classes and Math. Default is to consider all of them builtin.
Aliases: delphi, pas, pascal, objectpascal Filename patterns: *.pas Mimetypes: text/x-pascal
DylanLexer
For the Dylan language.
New in Pygments 0.7.
Aliases: dylan Filename patterns: *.dylan Mimetypes: text/x-dylan
JavaLexer
For Java source code.
Aliases: java Filename patterns: *.java Mimetypes: text/x-java
OcamlLexer
For the OCaml language.
New in Pygments 0.7.
Aliases: ocaml Filename patterns: *.ml, *.mli Mimetypes: text/x-ocaml
Lexers for .net languages
BooLexer
For Boo source code.
Aliases: boo Filename patterns: *.boo Mimetypes: text/x-boo
CSharpLexer
For C# source code.
Aliases: csharp, c# Filename patterns: *.cs Mimetypes: text/x-csharp
VbNetLexer
For Visual Basic.NET source code.
Aliases: vb.net, vbnet Filename patterns: *.vb, *.bas Mimetypes: text/x-vbnet, text/x-vba
Lexers for other languages
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
BatchLexer
Lexer for the DOS/Windows Batch file format.
New in Pygments 0.7.
Aliases: bat Filename patterns: *.bat, *.cmd Mimetypes: application/x-dos-batch
BefungeLexer
Lexer for the esoteric Befunge language.
New in Pygments 0.7.
Aliases: befunge Filename patterns: *.befunge Mimetypes: application/x-befunge
BrainfuckLexer
Lexer for the esoteric BrainFuck language.
Aliases: brainfuck, bf Filename patterns: *.bf, *.b Mimetypes: application/x-brainfuck
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
Special lexers
RawTokenLexer
Recreate a token stream formatted with the RawTokenFormatter.
Additional options accepted:
- 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
TextLexer
"Null" lexer, doesn't highlight anything.
Aliases: text Filename patterns: *.txt Mimetypes: text/plain
Lexers for various template engines' markup
CssDjangoLexer
Subclass of the DjangoLexer that highlights unlexed data with the CssLexer.
Aliases: css+django, css+jinja Filename patterns: None Mimetypes: text/css+django, text/css+jinja
CssErbLexer
Subclass of ErbLexer which highlights unlexed data with the CssLexer.
Aliases: css+erb, css+ruby Filename patterns: None Mimetypes: text/css+ruby
CssGenshiLexer
A lexer that highlights CSS definitions in genshi text templates.
Aliases: css+genshitext, css+genshi Filename patterns: None Mimetypes: text/css+genshi
CssPhpLexer
Subclass of PhpLexer which highlights unmatched data with the CssLexer.
Aliases: css+php Filename patterns: None Mimetypes: text/css+php
CssSmartyLexer
Subclass of the SmartyLexer that highlights unlexed data with the CssLexer.
Aliases: css+smarty Filename patterns: None Mimetypes: text/css+smarty
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 Mimetypes: application/x-django-templating, application/x-jinja
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 Mimetypes: application/x-ruby-templating
GenshiLexer
A lexer that highlights genshi and kid kid XML templates.
Aliases: genshi, kid, xml+genshi, xml+kid Filename patterns: *.kid Mimetypes: application/x-genshi, application/x-kid
GenshiTextLexer
A lexer that highlights genshi text templates.
Aliases: genshitext Filename patterns: None Mimetypes: application/x-genshi-text, text/x-genshi
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 Mimetypes: text/html+django, text/html+jinja
HtmlGenshiLexer
A lexer that highlights genshi and kid kid HTML templates.
Aliases: html+genshi, html+kid Filename patterns: None Mimetypes: text/html+genshi
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: application/x-php, application/x-httpd-php, application/x-httpd-php3, application/x-httpd-php4, application/x-httpd-php5
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 Mimetypes: text/html+smarty
JavascriptDjangoLexer
Subclass of the DjangoLexer that highlights unlexed data with the JavascriptLexer.
Aliases: js+django, javascript+django, js+jinja, javascript+jinja Filename patterns: None Mimetypes: application/x-javascript+django, application/x-javascript+jinja, text/x-javascript+django, text/x-javascript+jinja, text/javascript+django, text/javascript+jinja
JavascriptErbLexer
Subclass of ErbLexer which highlights unlexed data with the JavascriptLexer.
Aliases: js+erb, javascript+erb, js+ruby, javascript+ruby Filename patterns: None Mimetypes: application/x-javascript+ruby, text/x-javascript+ruby, text/javascript+ruby
JavascriptGenshiLexer
A lexer that highlights javascript code in genshi text templates.
Aliases: js+genshitext, js+genshi, javascript+genshitext, javascript+genshi Filename patterns: None Mimetypes: application/x-javascript+genshi, text/x-javascript+genshi, text/javascript+genshi
JavascriptPhpLexer
Subclass of PhpLexer which highlights unmatched data with the JavascriptLexer.
Aliases: js+php, javascript+php Filename patterns: None Mimetypes: application/x-javascript+php, text/x-javascript+php, text/javascript+php
JavascriptSmartyLexer
Subclass of the SmartyLexer that highlights unlexed data with the JavascriptLexer.
Aliases: js+smarty, javascript+smarty Filename patterns: None Mimetypes: application/x-javascript+smarty, text/x-javascript+smarty, text/javascript+smarty
JspLexer
Lexer for Java Server Pages.
New in Pygments 0.7.
Aliases: jsp Filename patterns: *.jsp Mimetypes: application/x-jsp
MakoCssLexer
Subclass of the MakoLexer that highlights unlexer data with the CssLexer.
New in Pygments 0.7.
Aliases: css+mako Filename patterns: None Mimetypes: text/css+mako
MakoHtmlLexer
Subclass of the MakoLexer that highlights unlexed data with the HtmlLexer.
New in Pygments 0.7.
Aliases: html+mako Filename patterns: None Mimetypes: text/html+mako
MakoJavascriptLexer
Subclass of the MakoLexer that highlights unlexer data with the JavascriptLexer.
New in Pygments 0.7.
Aliases: js+mako, javascript+mako Filename patterns: None Mimetypes: application/x-javascript+mako, text/x-javascript+mako, text/javascript+mako
MakoLexer
Generic mako templates lexer. Code that isn't Mako markup is yielded as Token.Other.
New in Pygments 0.7.
Aliases: mako Filename patterns: *.mao Mimetypes: application/x-mako
MakoXmlLexer
Subclass of the MakoLexer that highlights unlexer data with the XmlLexer.
New in Pygments 0.7.
Aliases: xml+mako Filename patterns: None Mimetypes: application/xml+mako
MyghtyCssLexer
Subclass of the MyghtyLexer that highlights unlexer data with the CssLexer.
New in Pygments 0.6.
Aliases: css+myghty Filename patterns: None Mimetypes: text/css+myghty
MyghtyHtmlLexer
Subclass of the MyghtyLexer that highlights unlexer data with the HtmlLexer.
New in Pygments 0.6.
Aliases: html+myghty Filename patterns: None Mimetypes: text/html+myghty
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 Mimetypes: application/x-javascript+myghty, text/x-javascript+myghty, text/javascript+mygthy
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 Mimetypes: application/x-myghty
MyghtyXmlLexer
Subclass of the MyghtyLexer that highlights unlexer data with the XmlLexer.
New in Pygments 0.6.
Aliases: xml+myghty Filename patterns: None Mimetypes: application/xml+myghty
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 Mimetypes: text/html+ruby
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: *.tpl Mimetypes: application/x-smarty
XmlDjangoLexer
Subclass of the DjangoLexer that highlights unlexed data with the XmlLexer.
Aliases: xml+django, xml+jinja Filename patterns: None Mimetypes: application/xml+django, application/xml+jinja
XmlErbLexer
Subclass of ErbLexer which highlights data outside preprocessor directives with the XmlLexer.
Aliases: xml+erb, xml+ruby Filename patterns: None Mimetypes: application/xml+ruby
XmlPhpLexer
Subclass of PhpLexer that higlights unhandled data with the XmlLexer.
Aliases: xml+php Filename patterns: None Mimetypes: application/xml+php
XmlSmartyLexer
Subclass of the SmartyLexer that highlights unlexed data with the XmlLexer.
Aliases: xml+smarty Filename patterns: None Mimetypes: application/xml+smarty
Lexers for non-source code file types
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: text/x-apacheconf
BBCodeLexer
A lexer that highlights BBCode(-like) syntax.
New in Pygments 0.6.
Aliases: bbcode Filename patterns: None Mimetypes: text/x-bbcode
DiffLexer
Lexer for unified or context-style diffs or patches.
Aliases: diff Filename patterns: *.diff, *.patch Mimetypes: text/x-diff, text/x-patch
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: application/x-troff, text/troff
IniLexer
Lexer for configuration files in INI style.
Aliases: ini, cfg Filename patterns: *.ini, *.cfg Mimetypes: text/x-ini
IrcLogsLexer
Lexer for IRC logs in irssi or xchat style.
Aliases: irc Filename patterns: None Mimetypes: text/x-irclog
MakefileLexer
Lexer for Makefiles.
Aliases: make, makefile, mf Filename patterns: *.mak, Makefile, makefile Mimetypes: text/x-makefile
MoinWikiLexer
For MoinMoin (and Trac) Wiki markup.
New in Pygments 0.7.
Aliases: trac-wiki, moin Filename patterns: None Mimetypes: text/x-trac-wiki
RstLexer
For reStructuredText markup.
New in Pygments 0.7.
Aliases: rst, restructuredtext Filename patterns: *.rst, *.rest Mimetypes: text/x-rst
SourcesListLexer
Lexer that highlights debian sources.list files.
New in Pygments 0.7.
Aliases: sourceslist, sources.list Filename patterns: sources.list 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
Lexers for web-related languages and markup
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
JavascriptLexer
For JavaScript source code.
Aliases: js, javascript Filename patterns: *.js Mimetypes: application/x-javascript, text/x-javascript, text/javascript
PhpLexer
For PHP source code. For PHP embedded in HTML, use the HtmlPhpLexer.
Additional options accepted:
- 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: text/x-php
XmlLexer
Generic lexer for XML (eXtensible Markup Language).
Aliases: xml Filename patterns: *.xml, *.xsl, *.rss Mimetypes: text/xml, application/xml, image/svg+xml, application/rss+xml, application/atom+xml, application/xsl+xml, application/xslt+xml
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).