view docs/conf.py @ 160:b4028838e0c8

Implement lexer option "prohibit_raiseonerror_filter". Sphinx raises by default when an Error token is seen (by means of the "raiseonerror" filter that is applied by default to lexers in Sphinx). This option skips this and allows error locations to be seen and highlighted properly. While there convert most Generic.Error tokens to Error tokens because now they can be handled by a lexer with "prohibit_raiseonerror_filter=True".
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 08 May 2026 17:46:28 +0200
parents 902147c24f9b
children a4317957148b
line wrap: on
line source

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import ast
import functools
import io
import os
import sys
import re

sys.path.insert(0, os.path.dirname(os.path.abspath('.')))

from pygments_lexer_pseudocode2.algpseudocode import AlgPseudocodeLexer


needs_sphinx = '2.1'
"""2.1: - :py:meth:Sphinx.add_lexer` takes a class as argument

"""


# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Pygments Pseudocode Lexer'
copyright = '2026 Franz Glasner. © Copyright 2015 Simon Wachter'
author = 'Franz Glasner'
# Determine "release" dynamically from the package's "__version__"
with io.open("../pygments_lexer_pseudocode2/__init__.py",
             "rt",
             encoding="utf-8") as relfp:
    release = ast.literal_eval(
        re.search(r"""^\s*__version__\s*=\s*(("|')[^"']*\2)""",
                  relfp.read(),
                  re.MULTILINE)
        .group(1)
        )
version = release
del relfp
primary_domain = None

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
    "sphinx.ext.todo",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'lexerlist.rst']

highlight_language = "none"

rst_prolog = """
.. role:: algpseudocode(code)
"""
rst_epilog = """
.. _Pygments: https://pygments.org/
.. _Sphinx: https://www.sphinx-doc.org
.. _Python: https://www.python.org/
.. _Algpseudocodex: https://ctan.org/pkg/algpseudocodex
"""


# --- Options for todo extension ---------------------------------------------
todo_include_todos = True


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_static_path = ['_static']
html_extra_path = ['../LICENSES', './examples']

#html_theme = 'alabaster'
html_theme = 'haiku'
html_title = 'The %s v%s' % (project, release)
html_short_title = html_title
#pygments_style = "sphinx"
pygments_style = "default"


def setup(app):
    #
    # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end"
    # Given lexer must be callable: so use an indirection with "partial".
    #
    # See also:
    # - https://stackoverflow.com/questions/11413203/sphinx-pygments-lexer-filter-extension
    #
    app.add_lexer("NoEndAlgPseudocode",
                  functools.partial(AlgPseudocodeLexer, no_end=True))
    # For developing a lexer with smoother error handling
    app.add_lexer("no-raiseonerror-algpseudocode",
                  functools.partial(AlgPseudocodeLexer,
                                    prohibit_raiseonerror_filter=True))