How to change <head> in Sphinx documentation so that relative links are updated?

I am using Sphinx to document a python project. I use canvas to visualize some of the results in the documentation. My documentation should support Firefox and IE. I need to include the excanvas.js library in the documentation, but only if brower is IE. How can I conditionally enable this library so that the relative paths are correct?

Example....

Documentation Folders

/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
   ...

In the notes on the Sphinx documentation pages, the layout.html file was modified. This modification was to insert an HTML conditional block into the head of the template, which adds excanvas.js if the page is viewed in IE.

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

work_test_page.rst non_working_test_page.rst . . - .

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

.. raw:: html
   :file: test_block_1.html

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
   ...

work_test_page.html excanvas.js . non_working_test_page.html excanvas.js .

exanvas.js , sphinx ?

+5
1

, pathto (...) HTML-snipet. . pathto (, 1).

{% extends "!layout.html" %}
{% block extrahead %}
    <!--[if IE]>
      <script type="text/javascript" src="{{pathto("_static/excanvas.js", 1)}}"></script>
    <![endif]-->
{% endblock %}
+4

All Articles