Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
view docs/filters.rst @ 258:e03e8cfdcece
Make the TokenReplaceFilter more flexible by allowing a replacement map
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 17 May 2026 16:08:34 +0200 |
| parents | 4e4c83a87387 |
| children | e5ea2f955986 |
line wrap: on
line source
.. -*- coding: utf-8; indent-tabs-mode: nil; -*- ********* Filters ********* The package contains the following filters: .. raw:: latex {\footnotesize .. include:: filterlist.rst .. raw:: latex } The AlgPseudocode lexer yields an error token for the following code block. `Sphinx`_ therefore suppresses highlighting completely: .. code-block:: none \nonexisting{TEST} With a custom AlgPseudocode lexer that has ``prohibit_raiseonerror_filter`` activated the output in `Sphinx`_ is as: .. code-block:: no-raiseonerror-algpseudocode \nonexisting{TEST} With the "errortogenericerror" filter the very same block is highlighted as: .. code-block:: genericerror-algpseudocode \nonexisting{TEST} ErrorToGenericErrorTokenFilter ============================== :Name: errortogenericerror :Filter Options: none Replace all :py:class:`pygments.token.Token.Error` tokens in a stream by :py:class:`pygments.token.Token.Generic.Error` tokens. TokenReplaceFilter ================== :Name: tokenreplace :Filter Options: ``replacements`` **Type:** :py:class:`dict[str | pygments.token.Token, str | pygments.token.Token]` A map from tokens to their replacements. ``token_from`` **Type:** :py:class:`str` or :py:class:`pygments.token.Token` The name of a token type (like ``Error``) or a token object (like :py:class:`pygments.token.Token.Error`). If given the `token_to` options is required and `replacements` will be augmented with their respective values. ``token_to`` **Type:** :py:class:`str` or :py:class:`pygments.token.Token` The name of a token type (like ``Generic.Error``) or a token object (like :py:class:`pygments.token.Token.Generic.Error`). This option is required if `token_from` is given. Replace all token types given as `replacements` keys or in `token_from` with the token types given in `replacements` values or in `token_to`. The values in the token stream are retained.
