是否可以有条件地定义target https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#hyperlink-targets在 reStructuredText 文件中使用ifconfig https://www.sphinx-doc.org/en/master/usage/extensions/ifconfig.html?
我在我的狮身人面像中设置了一个变量conf.py
我想使用它来有条件地确定文档中目标的 URI:
def setup(app):
argv = ' '.join(sys.argv)
if '-b html' in argv:
app.add_config_value('buildername', 'html', 'env')
else:
app.add_config_value('buildername', 'not-html', 'env')
And my index.rst
文件包含以下内容:
test link to target1_
.. ifconfig:: buildername == 'html'
.. _target1: https://example.com/a
上面的工作按预期进行,“target1”成为一个超链接example.com/a
但如果我想真正定义target1
根据值有条件地设置为两个选项之一buildername
配置变量,然后我有
test link to target1_
.. ifconfig:: buildername == 'html'
.. _target1: https://example.com/a
.. ifconfig:: buildername != 'html'
.. _target1: https://example.com/b
上面的输出不仅不起作用example.com/b
,但它破坏了第一个链接并且target1
现在没有指向任何内容(实际上#id3
).
此外,我在我的应用程序中收到以下警告sphinx-build
output
user@host:~$ make clean && sphinx-build -b html . _build/html/
...
reading sources... [100%] support
.../index.rst:16: WARNING: Duplicate explicit target name: "target1".
.../index.rst:8: WARNING: Duplicate target name, cannot be used as a unique reference: "target1".
...
是否可以在同一个目标中定义两次.rst
文件,这样每个定义都包含在ifconfig
指示?