在RST中嵌入html文档

2024-06-06 08:38:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个基于Sphinx的网站,有一些特定的页面,我想在这些页面上显示预定义的html文件,这些文件存储在指定的目录中,如_static。在Django中,可以简单地使用{{%include}}标记从模板引用文件,StructuredText是否存在类似的情况

我想做一些像

.. title:: Example Page

=============
Example Page
=============

Introduction to page

<insert html reference to _static folder here>

Description

建立网站后,让它将RST生成的html与指定的html文件结合起来


Tags: 文件todjango标记目录模板include网站
1条回答
网友
1楼 · 发布于 2024-06-06 08:38:41

从文档docs for the ^{} directive

Raw data can also be read from an external file, specified in a directive option. In this case, the content block must be empty. For example:

.. raw:: html
    :file: inclusion.html

Inline equivalents of the "raw" directive can be defined via custom interpreted text roles derived from the "raw" role.

The following options are recognized:

file : string (newlines removed) The local filesystem path of a raw data file to be included.

如果您只嵌入片段,而不是完整的有效HTML页面,那么这就是您想要使用的。对于后者,您仍然可以使用raw,但可以使用<iframe>

.. raw:: html

    <iframe src="inclusion.html"></iframe>

相关问题 更多 >