pygments.filters
Module containing filter lookup functions and default
filters.
copyright: | Copyright 2006-2013 by the Pygments team, see AUTHORS. |
license: | BSD, see LICENSE for details. |
-
class pygments.filters.CodeTagFilter(**options)[source]
Highlight special code tags in comments and docstrings.
Options accepted:
- codetags : list of strings
- A list of strings that are flagged as code tags. The default is to
highlight XXX, TODO, BUG and NOTE.
-
class pygments.filters.GobbleFilter(**options)[source]
Gobbles source code lines (eats initial characters).
This filter drops the first n characters off every line of code. This
may be useful when the source code fed to the lexer is indented by a fixed
amount of space that isn’t desired in the output.
Options accepted:
- n : int
- The number of characters to gobble.
New in Pygments 1.2.
-
class pygments.filters.KeywordCaseFilter(**options)[source]
Convert keywords to lowercase or uppercase or capitalize them, which
means first letter uppercase, rest lowercase.
This can be useful e.g. if you highlight Pascal code and want to adapt the
code to your styleguide.
Options accepted:
- case : string
- The casing to convert keywords to. Must be one of 'lower',
'upper' or 'capitalize'. The default is 'lower'.
-
class pygments.filters.NameHighlightFilter(**options)[source]
Highlight a normal Name token with a different token type.
Example:
filter = NameHighlightFilter(
names=['foo', 'bar', 'baz'],
tokentype=Name.Function,
)
This would highlight the names “foo”, “bar” and “baz”
as functions. Name.Function is the default token type.
Options accepted:
- names : list of strings
- A list of names that should be given the different token type.
There is no default.
- tokentype : TokenType or string
- A token type or a string containing a token type name that is
used for highlighting the strings in names. The default is
Name.Function.
-
class pygments.filters.RaiseOnErrorTokenFilter(**options)[source]
Raise an exception when the lexer generates an error token.
Options accepted:
- excclass : Exception class
- The exception class to raise.
The default is pygments.filters.ErrorToken.
New in Pygments 0.8.
-
class pygments.filters.TokenMergeFilter(**options)[source]
Merges consecutive tokens with the same token type in the output stream of a
lexer.
New in Pygments 1.2.
-
class pygments.filters.VisibleWhitespaceFilter(**options)[source]
Convert tabs, newlines and/or spaces to visible characters.
Options accepted:
- spaces : string or bool
- If this is a one-character string, spaces will be replaces by this string.
If it is another true value, spaces will be replaced by · (unicode
MIDDLE DOT). If it is a false value, spaces will not be replaced. The
default is False.
- tabs : string or bool
- The same as for spaces, but the default replacement character is »
(unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK). The default value
is False. Note: this will not work if the tabsize option for the
lexer is nonzero, as tabs will already have been expanded then.
- tabsize : int
- If tabs are to be replaced by this filter (see the tabs option), this
is the total number of characters that a tab should be expanded to.
The default is 8.
- newlines : string or bool
- The same as for spaces, but the default replacement character is ¶
(unicode PILCROW SIGN). The default value is False.
- wstokentype : bool
- If true, give whitespace the special Whitespace token type. This allows
styling the visible whitespace differently (e.g. greyed out), but it can
disrupt background colors. The default is True.
New in Pygments 0.8.
-
pygments.filters.find_filter_class(filtername)[source]
Lookup a filter by name. Return None if not found.
-
pygments.filters.get_all_filters()[source]
Return a generator of all filter names.
-
pygments.filters.get_filter_by_name(filtername, **options)[source]
Return an instantiated filter. Options are passed to the filter
initializer if wanted. Raise a ClassNotFound if not found.