comparison docs/filters.rst @ 294:a094305c5708

Docs. More cross-refs.
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 23 May 2026 11:43:21 +0200
parents f506d752e801
children
comparison
equal deleted inserted replaced
293:6d5d630506e4 294:a094305c5708
20 20
21 .. raw:: latex 21 .. raw:: latex
22 22
23 } 23 }
24 24
25 The "normal" AlgPseudocode lexer yields an error token for the code block 25 The :ref:`AlgPseudocode lexer <lexer-algpseudocode>` by default yields an
26 below; 26 error token for the code block below because it encounters an unknown command.
27 `Sphinx`_ warns about this and---as a consequence---suppresses highlighting 27 When used within `Sphinx`_ it warns about this
28 for this code block completely: 28 and---as a consequence---suppresses highlighting for this code block
29 completely (see also :ref:`this note <note-raiseonerror-filter>`):
29 30
30 .. code-block:: none 31 .. code-block:: none
31 32
32 \nonexisting{TEST} 33 \nonexisting{TEST}
33 34
34 With a custom AlgPseudocode lexer that has ``prohibit_raiseonerror_filter`` 35 This may be changed by using a custom AlgPseudocode lexer that has
35 activated the output in `Sphinx`_ is as: 36 the ``prohibit_raiseonerror_filter`` lexer option enabled.
37 Then the the output in `Sphinx`_ is as follows:
36 38
37 .. code-block:: no-raiseonerror-algpseudocode 39 .. code-block:: no-raiseonerror-algpseudocode
38 40
39 \nonexisting{TEST} 41 \nonexisting{TEST}
40 42
41 43
42 With the "errortogenericerror" filter the very same block is highlighted 44 Alternatively---with the "errortogenericerror" filter applied the very same
43 as: 45 block is highlighted as:
44 46
45 .. code-block:: genericerror-algpseudocode 47 .. code-block:: genericerror-algpseudocode
46 48
47 \nonexisting{TEST} 49 \nonexisting{TEST}
48 50
49 The above custom lexer has been defined for `Sphinx`_ using: 51 The above custom lexer is to be defined in `Sphinx`_ using:
50 52
51 .. code-block:: python 53 .. code-block:: python
52 54
53 import functools 55 import functools
54 from pygments_lexer_pseudocode2.filters import ErrorToGenericErrorTokenFilter 56 from pygments_lexer_pseudocode2.filters import ErrorToGenericErrorTokenFilter
59 "genericerror-algpseudocode", 61 "genericerror-algpseudocode",
60 functools.partial( 62 functools.partial(
61 AlgPseudocodeLexer, 63 AlgPseudocodeLexer,
62 filters=[ErrorToGenericErrorTokenFilter])) 64 filters=[ErrorToGenericErrorTokenFilter]))
63 65
64 66
65 .. _tokenreplacefilter: 67 .. _tokenreplacefilter:
66 68
67 TokenReplaceFilter 69 TokenReplaceFilter
68 ================== 70 ==================
69 71
94 Replace all token types given as `replacements` keys or in `token_from` 96 Replace all token types given as `replacements` keys or in `token_from`
95 with the token types given in `replacements` values or in `token_to`. 97 with the token types given in `replacements` values or in `token_to`.
96 98
97 The values in the token stream are retained. 99 The values in the token stream are retained.
98 100
101 All :py:class:`str` types in any of the filter options are converted to
102 real tokens using `Pygments`_ function
103 :py:func:`pygments.token.string_to_tokentype`.
104
99 105
100 ErrorToGenericErrorTokenFilter 106 ErrorToGenericErrorTokenFilter
101 ============================== 107 ==============================
102 108
103 :Name: errortogenericerror 109 :Name: errortogenericerror