【问题标题】:Sphinx link to static file狮身人面像链接到静态文件
【发布时间】:2021-08-22 18:32:35
【问题描述】:

我在source/chapter1/section1/intro.rst 中有一个这样的 RST 文档:

Test Static Path:
=================

{{ pathto('_static/_resources/intro-01_v3.mp4') }}


What I Need:
============

.. raw:: html

   <video width="100%" height="540" controls>
      <source src="{{ pathto('_static/_resources/intro-01_v3.mp4') }}" type="video/mp4">
      Your browser does not support the video tag.
   </video>

但是这个块的 sphinx make html 命令的输出不运行 pathto function 并且 video sourcetest section 将是 {{ pathto('_static/_resources/intro-01_v3.mp4') }} 本身.

我想在浏览器中显示视频,所以我不能使用:download:.. image::

有没有办法获得_static 目录中文件的链接/路径?

我需要一些东西来生成 ../../_static/_resources/intro-01_v3.mp4

【问题讨论】:

  • raw 指令不解释 reST 或 MyST 语法。它的名字很好。而是使用根相对 URL:&lt;source src="/_static/_resources/intro-01_v3.mp4" blah blah blah&gt;
  • 该页面未在 Web 服务器的根目录上提供,因此 /_static/_resources/intro-01_v3.mp4 不起作用。
  • 我已经在 raw 指令之外测试了pathto,这也不起作用。
  • Sphinx 不会自动处理 .rst 文件中出现的 Jinja 模板。我想你需要ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinxpypi.org/project/sphinx-jinja 之类的东西。
  • 如果那个路径不起作用,那么你没有配置html_static_path in conf.py

标签: python-sphinx restructuredtext


【解决方案1】:

正如cmets中mzjn所说,通过配置sphinx-jinja并使用.. jinja::指令,它将渲染pathto

【讨论】:

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