gpt4 book ai didi

python-sphinx - 如何在我的 Sphinx(重构文本)文档中显示外部托管的图像?

转载 作者:行者123 更新时间:2023-12-01 08:57:25 25 4
gpt4 key购买 nike

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

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

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

最佳答案

要包含来自 URL 的图像,您可以将其放入 source.rst :

.. image:: http://my.url.com/my-picture1.png
:alt: my-picture1

你也可以在 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

"""

source.rst 中:
|pic2|

最后,如果你在同一个地方有很多图像,你可以这样做:在 conf.py 中:
# 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)

source.rst 中:
|pic3|

|pic4|

关于python-sphinx - 如何在我的 Sphinx(重构文本)文档中显示外部托管的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26396163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com