Sphinx:链接到嵌入式二进制文件 (PDF)

Sli*_*SFT 7 restructuredtext python-2.7 python-sphinx read-the-docs

我正在使用sphinxRST将一些技术文档生成为 HTML,并且在将本地 PDF 引用用作超链接时遇到问题。我见过人们:download:用来链接到本地​​ PDF,但我将 PDF 嵌入到/docs目录中以供参考。我不喜欢,:download:因为它不会在浏览器中内嵌显示 PDF,这需要代表用户执行额外的步骤才能使用。

sphinx-build -b html除非在config.pyhookhtml_static_pathhtml_extra_path-中指定,否则不会复制任何文件,即使这样,它们也会被放到root目录或_static文件夹中。

是否有在 sphinx 中嵌入链接二进制文件的建议方法,或者这是一种不好的做法?通常,这些链接指向未托管在其他任何地方的幻灯片或设计图。

链接 PDF 的示例 RST

.. important:: View the agile course on scrum basics

    - View `these slides to dive deeper into Agile Basics <docs/agile-101.pdf>`_. 
Run Code Online (Sandbox Code Playgroud)

Sli*_*SFT 8

我想出的解决方案是将 PDF 添加到html_static_path并引用_static链接中的输出路径,而不是docs它在源中所在的路径。现在 PDF 可以在浏览器中打开,而无需下载即可查看。

如果有一个 sphinx 扩展/指令来处理这个 ( :download-inline:)会很棒。

配置文件

html_static_path = ['_static', 'agile-101/docs']
Run Code Online (Sandbox Code Playgroud)

敏捷 101.rst

.. important:: View the agile course on scrum basics

- View `these slides to dive deeper into Agile Basics <../_static/agile-101.pdf>`_. 
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你的回答。我现在将 PDF 文件放入“_assets”目录中。我已经设置了 `html_static_path = ['_static', '_assets']`,所以现在对 PDF 的引用/链接可以是 `.. _how to write maths: ../_static/how-to-write-mathematics-哈莫斯.pdf` (2认同)