如何在Sphinx(reStructured Text)文档中显示外部托管图像?

Ham*_*lee 3 restructuredtext python-sphinx

Sphinx(http://sphinx-doc.org/index.html)使用重组文本来定义内容.有指令显示来自本地文件系统的图像(使用相对和绝对路径).

我希望能够做的是使用URL声明图像并将其显示为内嵌.我能看到这一点的唯一方法是指定原始HTML,这看起来有点粗糙.有没有替代方案 - 也许是另一个"隐藏"指令或插件来支持这个?

我需要这个的原因是我有很多图像.如果我将它们存储在github上,我将强迫我的用户下载相当大的文件进行同步.我很欣赏我会失去Sphinx警告丢失文件的好处.

Edo*_*iel 9

要包含来自网址的图片,您可以将其放入source.rst:

.. image:: http://my.url.com/my-picture1.png
    :alt: my-picture1
Run Code Online (Sandbox Code Playgroud)

你也可以放在最后conf.py:

# A string of reStructuredText that will be included at the end of every source 
# file that is read.
rst_epilog = """

.. |pic2| image:: http://my.url.com/my-picture2.png
           :alt: my-picture2

"""
Run Code Online (Sandbox Code Playgroud)

并在source.rst:

|pic2|
Run Code Online (Sandbox Code Playgroud)

最后,如果你在同一个地方有很多图像,你可以这样做:in conf.pyput:

# The URL base of images
url_base = "http://my.url.com"

# A string of reStructuredText that will be included at the end of every source 
# file that is read.
rst_epilog = """

.. |pic3| image::{url_base}/my-picture3.png
           :alt: my-picture3
.. |pic4| image::{url_base}/my-picture4.png
           :alt: my-picture4

""".format(url_base=url_base)
Run Code Online (Sandbox Code Playgroud)

并在source.rst:

|pic3|

|pic4|
Run Code Online (Sandbox Code Playgroud)

  • 有什么办法可以消除我使用 URL 时收到的构建警告吗?顺便说一句,谢谢你! (3认同)