python-sphinx - Sphinx 内联包括

标签 python-sphinx restructuredtext

我想使用内联的 .. include:: 函数,但是如果我用两行新行将它与前面的文本分开,我只能让它实际包含我想要的文件。

在有人问之前,我想包含的文件是一个协议(protocol)号,所以不,它根本不会从新行中受益。我希望能够轻松更改它,以便我可以在文档的多个位置使用它。我想一个例子是“我们当前使用协议(protocol)(proto.txt)”。我是 Sphinx 的新手,所以也许我还没有找到一个非常明显的解决方案。

最佳答案

Sphinx 无法进行内联包含。

但是,您可以定义全局 aliases (替换)在 build configuration filerst_epilog 变量中.

例如,您可以将以下行添加到 conf.py 文件中:

rst_epilog = """
  .. |version| replace:: 4.1
  .. |protocol| replace:: httpx
"""

现在,您可以从项目中的任何 .rst 文件访问变量 |version||protocol|,例如如下所示:

版本 |版本|使用|协议(protocol)|协议(protocol)。

变成了

4.1版本使用httpx协议(protocol)。

如果软件的其他部分需要以特定文件或格式指定协议(protocol)(或其他变量),您可以编写一个脚本以将其作为变量读取到 Sphinx 配置中文件。

关于python-sphinx - Sphinx 内联包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39187030/

相关文章:

flask - Flask运行的Web应用程序中的Sphinx文档

python-sphinx - “Title level inconsistent”是什么意思?

带有 Sphinx 文档的 Python 模块引用

python-sphinx - Sphinx 文档 (autodoc) 上传到 Github 后无法工作

python-sphinx - 如何在代码块中包含内部引用?

python - 忽略 autodoc 中的一些模块

restructuredtext - 如何禁用 rst2pdf 文档首页上的页眉?

bitbucket - 在 Bitbucket wiki 页面中调整图像大小

python-sphinx - Sphinx 的 "only"和 "ifconfig"指令有什么区别?

javascript - 使用 javascript 代替 Sphinx 的默认目录树