sphinx.ext.ifconfig – 根据配置包含内容¶
这个扩展非常简单,只有一个指令:
-
.. ifconfig::¶ 仅当作为参数给出的Python表达式为
True时,才包含该指令的内容,在项目配置的命名空间中进行评估(即,所有已注册的变量来自conf.py都可用)。例如,人们可以写:
.. ifconfig:: releaselevel in ('alpha', 'beta', 'rc') This stuff is only included in the built docs for unstable versions.
要使Sphinx知道自定义配置值,请在
conf.py的设置函数中使用add_config_value(),例如:def setup(app): app.add_config_value('releaselevel', '', 'env')第二个参数是默认值,第三个参数应始终为
'env'这些值(如果值发生变化,它会选择Sphinx是否重新读取文档)。