如何使用 sphinx 链接到 rst 中的文件? [英] How to do a link to a file in rst with sphinx?

查看:83
本文介绍了如何使用 sphinx 链接到 rst 中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写文档,并且希望包含指向 pdf 文件或 zip 档案的链接.我如何使用 rst 语言和 sphinx 实现这一目标?

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 ?

如果我这样做

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

它不起作用,因为在编译 sphinx 期间不复制 doc 目录的包含(我使用 sphinx-quickstart 生成的 makefile).

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

相反,使用 image 指令:

.. image:: img/plop.png

sphinx 确实复制了构建目录中的 plop.png 图像.如何为 pdf 或 zip 存档获得相同的行为?

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

推荐答案

一个解决方案是使用:download:角色"(在关于角色的 sphinx 文档).

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

这里是一个简短的示例,假设您在目录 doc 中有一个文件 mypdf.pdf.目录 doc 和您的 rst 文件必须在同一目录中:

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

请注意,:download: 和文件路径之间不能有空格.

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

这篇关于如何使用 sphinx 链接到 rst 中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆