有条件地包括扩展?

2024-10-03 06:23:58 发布

您现在位置:Python中文网/ 问答频道 /正文

有一个ifconfigsphinx扩展——它允许有条件地包含内容。我在寻找一种有条件地包含扩展的方法。我的最佳尝试是给-D选项的扩展列表sphinx-build

sphinx-build -b singlehtml -d _build/doctrees -D html_theme=empty -D "extensions=['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.numfig', 'sphinx.ext.ifconfig', 'cloud_sptheme.ext.table_styling', 'sphinx.ext.htmlmath']" . _build/wkA

但它不起作用。在

问题是有条件地包含sphinx.ext.htmlmath或{}。在


Tags: 方法build内容列表html选项sphinx条件
2条回答

conf.py是一个python模块,extensions是一个列表,因此您只需根据一个条件将扩展附加到extensions中:

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']

my_condition = 1

if my_condition == 1:
    extensions.append('sphinx.ext.htmlmath')
elif my_condition == 2:
    extensions.append('sphinxcontrib-mathml')
elif my_condition == 3:
    extensions.append('sphinx.ext.mathjax')
else:
    print "Didn't found a suitable extension"

但是,您必须在生成过程开始之前了解您的条件。在

使用-t <tag>http://sphinx-doc.org/invocation.html#cmdoption-sphinx-build-t

例如,像这样调用sphinx(参见-t use_htmlmath):

sphinx-build -b singlehtml -d _build/doctrees \
   -D html_theme=empty -t use_htmlmath . _build/wkA

将此代码保存在conf.py

^{pr2}$

相关问题 更多 >