| 1 |
===================== |
| 2 |
The full Pygments API |
| 3 |
===================== |
| 4 |
|
| 5 |
This page describes the Pygments API. |
| 6 |
|
| 7 |
High-level API |
| 8 |
============== |
| 9 |
|
| 10 |
.. module:: pygments |
| 11 |
|
| 12 |
Functions from the :mod:`pygments` module: |
| 13 |
|
| 14 |
.. autofunction:: lex |
| 15 |
.. autofunction:: format |
| 16 |
.. autofunction:: highlight |
| 17 |
|
| 18 |
|
| 19 |
.. module:: pygments.lexers |
| 20 |
|
| 21 |
Functions from :mod:`pygments.lexers`: |
| 22 |
|
| 23 |
.. autofunction:: get_lexer_by_name |
| 24 |
.. autofunction:: get_lexer_for_filename |
| 25 |
.. autofunction:: get_lexer_for_mimetype |
| 26 |
.. autofunction:: load_lexer_from_file |
| 27 |
.. autofunction:: guess_lexer |
| 28 |
.. autofunction:: guess_lexer_for_filename |
| 29 |
.. autofunction:: get_all_lexers |
| 30 |
.. autofunction:: find_lexer_class_by_name |
| 31 |
.. autofunction:: find_lexer_class |
| 32 |
|
| 33 |
|
| 34 |
.. module:: pygments.formatters |
| 35 |
|
| 36 |
Functions from :mod:`pygments.formatters`: |
| 37 |
|
| 38 |
.. autofunction:: get_formatter_by_name |
| 39 |
.. autofunction:: get_formatter_for_filename |
| 40 |
.. autofunction:: load_formatter_from_file |
| 41 |
|
| 42 |
|
| 43 |
.. module:: pygments.styles |
| 44 |
|
| 45 |
Functions from :mod:`pygments.styles`: |
| 46 |
|
| 47 |
.. autofunction:: get_style_by_name |
| 48 |
.. autofunction:: get_all_styles |
| 49 |
.. autodata:: STYLE_MAP |
| 50 |
|
| 51 |
.. module:: pygments.lexer |
| 52 |
|
| 53 |
Lexers |
| 54 |
====== |
| 55 |
|
| 56 |
The base lexer class from which all lexers are derived is: |
| 57 |
|
| 58 |
.. autoclass:: Lexer |
| 59 |
:members: __init__, add_filter, get_tokens, get_tokens_unprocessed, analyse_text |
| 60 |
|
| 61 |
There are several base class derived from ``Lexer`` you can use to build your lexer from: |
| 62 |
|
| 63 |
.. autoclass:: pygments.lexer.RegexLexer |
| 64 |
.. autoclass:: pygments.lexer.ExtendedRegexLexer |
| 65 |
.. autoclass:: pygments.lexer.DelegatingLexer |
| 66 |
|
| 67 |
|
| 68 |
.. module:: pygments.formatter |
| 69 |
|
| 70 |
Formatters |
| 71 |
========== |
| 72 |
|
| 73 |
A formatter is derived from this class: |
| 74 |
|
| 75 |
|
| 76 |
.. autoclass:: Formatter |
| 77 |
:members: __init__, get_style_defs, format |
| 78 |
|
| 79 |
|
| 80 |
.. module:: pygments.util |
| 81 |
|
| 82 |
Utilities |
| 83 |
========= |
| 84 |
|
| 85 |
The :mod:`pygments.util` module has some utility functions usable for processing |
| 86 |
command line options. All of the following functions get values from a |
| 87 |
dictionary of options. If the value is already in the type expected by the |
| 88 |
option, it is returned as-is. Otherwise, if the value is a string, it is first |
| 89 |
converted to the expected type if possible. |
| 90 |
|
| 91 |
.. autoexception:: OptionError |
| 92 |
.. autofunction:: get_bool_opt |
| 93 |
.. autofunction:: get_int_opt |
| 94 |
.. autofunction:: get_list_opt |
| 95 |
.. autofunction:: get_choice_opt |
| 96 |
|
| 97 |
It also defines an exception: |
| 98 |
|
| 99 |
.. autoexception:: ClassNotFound |