Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
comparison docs/filters.rst @ 269:9790553d7225
More details on custom filters in the documentation
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 19 May 2026 21:54:10 +0200 |
| parents | 683c4b35ed26 |
| children | cb66de44a7b9 |
comparison
equal
deleted
inserted
replaced
| 268:ea19b621081d | 269:9790553d7225 |
|---|---|
| 1 .. -*- coding: utf-8; indent-tabs-mode: nil; -*- | 1 .. -*- coding: utf-8; indent-tabs-mode: nil; -*- |
| 2 | |
| 3 .. _filters: | |
| 2 | 4 |
| 3 ********* | 5 ********* |
| 4 Filters | 6 Filters |
| 5 ********* | 7 ********* |
| 6 | 8 |
| 7 .. only:: html | 9 .. only:: html |
| 8 | 10 |
| 9 .. contents:: | 11 .. contents:: |
| 10 | 12 |
| 11 The package contains the following filters: | 13 The package contains the following filters: |
| 12 | 14 |
| 13 .. raw:: latex | 15 .. raw:: latex |
| 14 | 16 |
| 18 | 20 |
| 19 .. raw:: latex | 21 .. raw:: latex |
| 20 | 22 |
| 21 } | 23 } |
| 22 | 24 |
| 23 The AlgPseudocode lexer yields an error token for the following code block. | 25 The "normal" AlgPseudocode lexer yields an error token for the code block |
| 24 `Sphinx`_ warns about this and---as a consequence--- suppresses highlighting | 26 below; |
| 27 `Sphinx`_ warns about this and---as a consequence---suppresses highlighting | |
| 25 for this code block completely: | 28 for this code block completely: |
| 26 | 29 |
| 27 .. code-block:: none | 30 .. code-block:: none |
| 28 | 31 |
| 29 \nonexisting{TEST} | 32 \nonexisting{TEST} |
| 40 as: | 43 as: |
| 41 | 44 |
| 42 .. code-block:: genericerror-algpseudocode | 45 .. code-block:: genericerror-algpseudocode |
| 43 | 46 |
| 44 \nonexisting{TEST} | 47 \nonexisting{TEST} |
| 48 | |
| 49 The above custom lexer has been defined for `Sphinx`_ using: | |
| 50 | |
| 51 .. code-block:: python | |
| 52 | |
| 53 import functools | |
| 54 from pygments_lexer_pseudocode2.filters import ErrorToGenericErrorTokenFilter | |
| 55 from pygments_lexer_pseudocode2.lexers.algpseudocode import AlgPseudocodeLexer | |
| 56 | |
| 57 def setup(app): | |
| 58 app.add_lexer( | |
| 59 "genericerror-algpseudocode", | |
| 60 functools.partial( | |
| 61 AlgPseudocodeLexer, | |
| 62 filters=[ErrorToGenericErrorTokenFilter])) | |
| 45 | 63 |
| 46 | 64 |
| 47 ErrorToGenericErrorTokenFilter | 65 ErrorToGenericErrorTokenFilter |
| 48 ============================== | 66 ============================== |
| 49 | 67 |
