【问题标题】:python-sphinx extension, extra html filespython-sphinx 扩展,额外的 html 文件
【发布时间】:2018-07-20 08:40:22
【问题描述】:

我正在开发 sphinx 文档生成器的扩展。

我想在文档的 html 构建中添加一些 html、js、css 和 json 文件。

它们不是模板的一部分,它们不应受到 sphinx 模板中的任何内容的影响。它们只是我想添加到下载文件夹中的文件的查看器。 (我也不怎么样。)

如何在 sphinx 扩展中包含额外的 html 文件? 可以按照https://docs.readthedocs.io/en/latest/guides/adding-custom-css.html 的说明添加 JS/CSS,但没有 html 的功能。

def setup(app):
    app.add_stylesheet('css/custom.css')
    app.add_javascript("js/custom.js")
    # and custom html or any generic file ? 

【问题讨论】:

  • sphinx-doc.org/en/master/… 你有_templates 目录吗?
  • "(我也不知道如何。)" 你的意思是你不知道如何将文件从源文件复制到构建目录,这实际上是你的问题?

标签: python python-sphinx


【解决方案1】:

conf.py 中有一个 html_static_path(它是路径列表)。您可以在那里添加静态文件(按文件夹)。

为了动态生成静态文件。 没有明确的方式函数来添加静态文件。相反,静态文件可以通过 python 复制到 html_static_path。

在哪里可以找到 html_static_path?

class Node(nodes.TextElement):
    @staticmethod
    def visit_html(self, node), 
        self.document.settings.env.config.html_static_path

class Direc(Directive):
    def run(self):
        self.state.document.settings.env.config.html_static_path

html_static_path 也是相对于

self.document.settings.env.app.confdir

构建目录可以通过

document.settings.env.app.builder.outdir

http://www.sphinx-doc.org/en/master/usage/configuration.html中有更多html相关配置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多