view docs/filters.rst @ 263:2e78e255b54e

Make a link to the reST source where appropriate to learn about the lexer syntax
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 19 May 2026 18:03:48 +0200
parents e03e8cfdcece
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.