python - 狮身人面像/rST : using configuration values in include statements?

标签 python python-sphinx restructuredtext

在我的主要 sphinx 项目中,我使用 include 语句来提取存储在我磁盘上另一个位置的文件的内容。

.. include:: //path/to/other/docs/file.rst

现在我希望能够在我的 conf.py 中设置一次基本路径,并在我的 include 语句中简单地引用它。

这可能吗?如果可能,我该如何实现?


供将来引用:我写了一个允许这样做的 Sphinx 扩展,请参阅: https://github.com/j0nes2k/sphinx-contrib-configurableinclude

最佳答案

你不能用 Vanilla 狮身人面像做到这一点。 include 指令的实现似乎不关心任何额外的配置选项:

但是您可以实现和设置自己的指令。查看Writing a simple extensionDeveloping extensions for Sphinx .

所以最简单的方法似乎是覆盖 sphinx.directives.other.Include。 (实际上,Sphinx 的 Include 也覆盖了标准的 include 指令 docutils.parsers.rst.directives.misc.Include 以获得更好和正确的路径解释。)

关于python - 狮身人面像/rST : using configuration values in include statements?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21327711/

相关文章:

python - 使条件 "with"更漂亮

python - 在 Python 中记录模块/类/函数体 Sphinx 文档

python - 在 OS X 上的 Python 上运行 32 位库和二进制文件

python - 数据库存储 : Why is Pipeline better than Feed Export?

python - 在python中读取文件后如何转换为列表列表

python - 正则表达式匹配太多括号

python-sphinx - 错误 "rubric"指令中没有内容被允许

python - Sphinx 卡在阅读资源索引上

python-sphinx - Sphinx 文档中人类可读的迭代

python - 我如何记录 :rtype: for a function that returns multiple possible data types?