【问题标题】:Embedding a html document inside of RST在 RST 中嵌入 html 文档
【发布时间】:2021-09-07 11:00:49
【问题描述】:

我有一个基于 Sphinx 的网站,并且有一些特定的页面,我希望在这些页面上显示预定义的 html 文件,这些文件存储在指定目录(如 _static)中。在 Django 中,可以使用 {{%include}} 标签从模板中简单地引用文件,ReStructuredText 是否存在类似的东西?

我想做类似的事情

.. title:: Example Page

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

Introduction to page

<insert html reference to _static folder here>

Description

在建立网站后,将 RST 生成的 html 和指定的 html 文件结合起来。

【问题讨论】:

    标签: python html django python-sphinx restructuredtext


    【解决方案1】:

    来自 docutils docs for the raw directive:

    原始数据也可以从外部文件中读取,在指令选项中指定。在这种情况下,内容块必须为空。例如:

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

    “raw”指令的内联等效项可以通过派生自"raw" rolecustom interpreted text roles 定义。

    以下选项被识别:

    file : 字符串(已删除换行符) 要包含的原始数据文件的本地文件系统路径。

    如果您只嵌入 sn-ps 而不是完整的有效 HTML 页面,那么这就是您想要使用的。对于后者,您仍然可以使用raw,但使用&lt;iframe&gt;

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

    【讨论】:

      猜你喜欢
      • 2011-04-03
      • 2012-12-10
      • 2013-03-13
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 2011-03-10
      • 2022-06-18
      相关资源
      最近更新 更多