问题描述
我有一个基于 Sphinx 的网站,并且有特定的页面,我想在这些页面上显示存储在指定目录(如 _static)中的预定义 html 文件。在 Django 中,可以使用 {{%include}} 标签简单地从模板中引用文件,ReStructuredText 是否存在类似的东西?
我想做类似的事情
.. title:: Example Page
=============
Example Page
=============
Introduction to page
<insert html reference to _static folder here>
Description
建立网站后,将 RST 生成的 html 和指定的 html 文件结合起来。
解决方法
来自 docutils docs for the raw
directive:
原始数据也可以从外部文件中读取,在指令选项中指定。在这种情况下,内容块必须为空。例如:
.. raw:: html
:file: inclusion.html
“raw”指令的内联等效项可以通过从 custom interpreted text roles 派生的 "raw" role 定义。
识别以下选项:
file
: 字符串(删除换行符)
要包含的原始数据文件的本地文件系统路径。
如果您只嵌入片段,而不是完整的有效 HTML 页面,那么这就是您想要使用的。对于后者,您仍然可以使用 raw
,但使用 <iframe>
:
.. raw:: html
<iframe src="inclusion.html"></iframe>