是否可以在我的文档中包含外部 rst 文件?

时间:2021-03-05 15:24:35

标签: python-sphinx read-the-docs

我正在为包含模块的平台构建文档。我想让文档存在于这些模块存储库中,并使用 include 命令将它们包含在“主”文档中。

我尝试了以下方法:

.. include:: https://github.com/12rambau/sepal_ui_template/blob/master/doc/en.rst

但没有向文件中添加任何内容

是否可以在include命令中使用绝对链接?

2 个答案:

答案 0 :(得分:1)

没有。完全限定的 URL 与文档无关。根据 include directive 的文档:

<块引用>

指令参数是要包含的文件的路径,相对于包含指令的文档。

还有其他选择,包括 this one

答案 1 :(得分:0)

我的主要目标不是使用 include 命令,而是避免代码重复并使用网络上可用的文件。根据 @Steve piercy 的回答,我想出了这个解决方案:

在conf.py文件中我从github复制文件内容

<块引用>

小心并使用 raw.githubusercontent.com 链接避免导入 html


# [...]
# -- Copy the modules documentation ------------------------------------------

from urllib.request import urlretrieve

urlretrieve (
    "https://raw.githubusercontent.com/12rambau/sepal_ui_template/master/doc/en.rst",
    "modules/sepal_ui_template.rst"
)

在我的文档中的 modules/sepal_ui_template.rst 下创建文件后,我可以安全地访问它。

每次我重建文档时都会重新下载。

相关问题