【问题标题】:How can I display externally hosted images in my Sphinx (reStructured Text) document?如何在我的 Sphinx(重构文本)文档中显示外部托管的图像?
【发布时间】:2014-10-16 04:19:54
【问题描述】:

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

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

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

【问题讨论】:

    标签: python-sphinx restructuredtext


    【解决方案1】:

    要包含来自 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 put:

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

    【讨论】:

    • 有什么方法可以消除我从使用 URL 得到的构建警告吗?顺便说一句,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2022-09-23
    • 2020-12-08
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多