How to do a link to a file in rst with sphinx?

前提是你 提交于 2019-12-03 11:33:30

问题


I am writing a documentation and I would like to include links to pdf files or zip archives. How can I achieve that using rst language and sphinx ?

If I do that

here is a pdf file : `pdf <doc/mypdf.pdf>`_

It does not work because, during the compilation sphinx do not copy the contains of the doc directory (I use the makefile generated by sphinx-quickstart).

On the contrary, using the image directive :

.. image:: img/plop.png

sphinx does copy the plop.png image in build directory. How can I obtain the same behavior for pdf or zip archive ?


回答1:


A solution is to use the :download: “role” (detailed in the sphinx documentation on roles).

Here is a short example assuming you have a file mypdf.pdf in a directory doc. The directory doc and your rst file must be in the same directory:

here is a pdf file :download:`pdf <doc/mypdf.pdf>`

Note that you mustn't put a blank space between :download: and the path to the file.




回答2:


The image directive also works for PDF files.

.. image:: doc/mypdf.pdf


来源:https://stackoverflow.com/questions/14345922/how-to-do-a-link-to-a-file-in-rst-with-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!