comparison docs/conf.py @ 250:5d3f7d80766f

Add application level custom variable substitions and get rid of rst_epilog
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 16 May 2026 22:28:55 +0200
parents feaa552cbe98
children 881ae18c07f8
comparison
equal deleted inserted replaced
249:feaa552cbe98 250:5d3f7d80766f
12 import re 12 import re
13 13
14 import pygments.lexers 14 import pygments.lexers
15 import pygments.filters 15 import pygments.filters
16 import sphinx.util.logging 16 import sphinx.util.logging
17 import sphinx.transforms
17 18
18 sys.path.insert(0, os.path.dirname(os.path.abspath('.'))) 19 sys.path.insert(0, os.path.dirname(os.path.abspath('.')))
19 20
20 from pygments_lexer_pseudocode2.lexers.algpseudocode import ( 21 from pygments_lexer_pseudocode2.lexers.algpseudocode import (
21 AlgPseudocodeLexer, AlgPseudocodeLexer_DE, AlgPseudocodeLexer_FR) 22 AlgPseudocodeLexer, AlgPseudocodeLexer_DE, AlgPseudocodeLexer_FR)
106 107
107 highlight_language = "none" 108 highlight_language = "none"
108 109
109 rst_prolog = """ 110 rst_prolog = """
110 .. role:: algpseudocode(code) 111 .. role:: algpseudocode(code)
111 .. |release_date| replace:: %s
112 .. |release_rev| replace:: %s
113 """ % (release_date, release_rev)
114 if define_rest_keywords:
115 rst_prolog += """\
116 .. |VCSJustDate| replace:: %s
117 .. |VCSRevision| replace:: %s
118 """ % (release_date, release_rev)
119 rst_epilog = """
120 .. _Pygments: https://pygments.org/ 112 .. _Pygments: https://pygments.org/
121 .. _Sphinx: https://www.sphinx-doc.org 113 .. _Sphinx: https://www.sphinx-doc.org
122 .. _Python: https://www.python.org/ 114 .. _Python: https://www.python.org/
123 .. _Algpseudocodex: https://ctan.org/pkg/algpseudocodex 115 .. _Algpseudocodex: https://ctan.org/pkg/algpseudocodex
124 """ 116 """
173 "examples/algorithm-ford-fulkerson.pseudocode", 165 "examples/algorithm-ford-fulkerson.pseudocode",
174 "examples/algorithm-edmonds-karp.pseudocode", 166 "examples/algorithm-edmonds-karp.pseudocode",
175 ] 167 ]
176 168
177 169
170 class IAMCustomSubstitutions(sphinx.transforms.SphinxTransform):
171
172 """Implement custom variable substitutions"""
173
174 default_priority = sphinx.transforms.DefaultSubstitutions.default_priority
175
176 _SUBSTITUTIONS = {
177 "release_date": release_date,
178 "release_rev": release_rev
179 }
180 if define_rest_keywords:
181 _SUBSTITUTIONS.update(
182 {"VCSJustDate": release_date,
183 "VCSRevision": release_rev,
184 "VCSHGRevision": release_rev})
185
186 def apply(self):
187 from docutils import nodes
188 for ref in self.document.traverse(nodes.substitution_reference):
189 refname = ref['refname']
190 if refname in self._SUBSTITUTIONS:
191 stext = self._SUBSTITUTIONS[refname]
192 ref.replace_self(nodes.Text(stext, stext))
193 #if refname in ('release_date' 'release_rev'):
194 # stext = self.config[refname]
195 # ref.replace_self(nodes.Text(stext, stext))
196
197
178 def setup(app): 198 def setup(app):
179 # 199 #
180 # Custom release_date and commit id variables with a custom substitution 200 # Custom release_date and commit id variables with a custom substitution
181 # |release_date| and |release_rev|'. 201 # |release_date| and |release_rev|'.
182 # 202 #
183 app.add_config_value('release_date', '', 'env') 203 app.add_config_value('release_date', '', 'env')
184 app.add_config_value('release_rev', '', 'env') 204 app.add_config_value('release_rev', '', 'env')
205 # Custom variable substitution
206 app.add_transform(IAMCustomSubstitutions)
185 207
186 # 208 #
187 # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end" 209 # Add a custom lexer: AlgPseudocodeLexer with custom init option "no_end"
188 # Given lexer must be callable: so use an indirection with "partial". 210 # Given lexer must be callable: so use an indirection with "partial".
189 # 211 #