Search code examples
python-sphinxrestructuredtext

Sphinx link to static file


I have an RST document like this in source/chapter1/section1/intro.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>

But the output of sphinx make html command for this block doesn't run the pathto function and both video source and test section will be {{ pathto('_static/_resources/intro-01_v3.mp4') }} itself.

I want to show the video inside the browser, so I can't use :download: or .. image::.

Is there a way to get a link/path to a file in _static directory?

I need something to GENERATE ../../_static/_resources/intro-01_v3.mp4.


Solution

  • As mentioned by mzjn in comments, by configuring sphinx-jinja and using .. jinja:: directive, it will render pathto.