小编Ed *_*ate的帖子

如何修改Sphinx文档中的<head>以更新相关链接?

我正在使用Sphinx来记录python项目.我正在使用画布来显示文档中的一些结果.我的文档需要支持Firefox和IE.我需要在文档中包含excanvas.js库,但前提是浏览器是IE.如何有条件地包含此库以使相对路径正确?

例....

文档文件夹

/sphinx
   /source
   working_test_page.rst
   test_block.html
   /nested
      non_working_test_page.rst
      test_block_copy.html
   /_templates
      layout.html
   /_static
      excanvas.js
   ...
Run Code Online (Sandbox Code Playgroud)

根据Sphinx文档页面上的说明,文件layout.html已被修改.此修改是在模板头中插入HTML的条件块,如果在IE上查看页面,则会添加excanvas.js.

{% extends "!layout.html" %} 
{% block extrahead %} 
  <!--[if IE]>
    <script type="text/javascript" src="_static/excanvas.js"></script>
  <![endif]--> 
{% endblock %} 
Run Code Online (Sandbox Code Playgroud)

文件working_test_page.rst和non_working_test_page.rst具有相同的内容.内容如下.唯一的区别是文件的位置.

Script Test
==========

.. raw:: html
   :file: test_block_1.html
Run Code Online (Sandbox Code Playgroud)

test_block.html和test_block_copy.html文件具有相同的内容.这两个文件包含一些HTML,用于设置画布并使用它.

当sphinx将第一个文件编译到HTML构建目录中时,会产生以下文件结果:

/sphinx
   /build
   working_test_page.html
   /nested
      non_working_test_page.html
   /_static
      excanvas.js
   ...
Run Code Online (Sandbox Code Playgroud)

文件working_test_page.html具有正确的excanvas.js路径并正确加载.文件non_working_test_page.html具有错误的excanvas.js路径,并且未正确加载.

如何有条件地加载excanvas.js,以便sphinx文档中的相对路径是正确的,无论第一个文件的位置如何?

python python-sphinx

6
推荐指数
1
解决办法
1009
查看次数

标签 统计

python ×1

python-sphinx ×1