# HG changeset patch # User Franz Glasner # Date 1778963335 -7200 # Node ID 5d3f7d80766f1d05aedee50fa9765cd7dc561ca6 # Parent feaa552cbe989b533f0eb15aafbb83b013b9885c Add application level custom variable substitions and get rid of rst_epilog diff -r feaa552cbe98 -r 5d3f7d80766f docs/conf.py --- a/docs/conf.py Sat May 16 15:16:42 2026 +0200 +++ b/docs/conf.py Sat May 16 22:28:55 2026 +0200 @@ -14,6 +14,7 @@ import pygments.lexers import pygments.filters import sphinx.util.logging +import sphinx.transforms sys.path.insert(0, os.path.dirname(os.path.abspath('.'))) @@ -108,15 +109,6 @@ rst_prolog = """ .. role:: algpseudocode(code) -.. |release_date| replace:: %s -.. |release_rev| replace:: %s -""" % (release_date, release_rev) -if define_rest_keywords: - rst_prolog += """\ -.. |VCSJustDate| replace:: %s -.. |VCSRevision| replace:: %s -""" % (release_date, release_rev) -rst_epilog = """ .. _Pygments: https://pygments.org/ .. _Sphinx: https://www.sphinx-doc.org .. _Python: https://www.python.org/ @@ -175,6 +167,34 @@ ] +class IAMCustomSubstitutions(sphinx.transforms.SphinxTransform): + + """Implement custom variable substitutions""" + + default_priority = sphinx.transforms.DefaultSubstitutions.default_priority + + _SUBSTITUTIONS = { + "release_date": release_date, + "release_rev": release_rev + } + if define_rest_keywords: + _SUBSTITUTIONS.update( + {"VCSJustDate": release_date, + "VCSRevision": release_rev, + "VCSHGRevision": release_rev}) + + def apply(self): + from docutils import nodes + for ref in self.document.traverse(nodes.substitution_reference): + refname = ref['refname'] + if refname in self._SUBSTITUTIONS: + stext = self._SUBSTITUTIONS[refname] + ref.replace_self(nodes.Text(stext, stext)) + #if refname in ('release_date' 'release_rev'): + # stext = self.config[refname] + # ref.replace_self(nodes.Text(stext, stext)) + + def setup(app): # # Custom release_date and commit id variables with a custom substitution @@ -182,6 +202,8 @@ # app.add_config_value('release_date', '', 'env') app.add_config_value('release_rev', '', 'env') + # Custom variable substitution + app.add_transform(IAMCustomSubstitutions) # # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end"