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

Is it possible to include external rst files in my documentation?

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

我尝试了以下方法:

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

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

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

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

的文档

The directive argument is the path to the file to be included, relative to the document containing the directive.

还有其他选择,包括 this one

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

conf.py文件中我复制了github

的文件内容

be careful and use the raw.githubusercontent.com link to avoid importing 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 下创建,我可以安全地访问它。

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