11

关于在使用 Sphinx 记录时如何参考在线图像的任何想法?

这不起作用:

.. image:: http://www.mysite.com/images/someimage.png

给我:

/home/user/proj/2010/11/08/the_forever_war.rst:11: WARNING: nonlocal image URI found: http://www.mysite.com/images/someimage.png

谢谢...

4

3 回答 3

20

从 sphinx 1.4 开始,您可以docs/conf.py像这样从文件中“猴子补丁”sphinx:

import sphinx.environment
from docutils.utils import get_source_line

def _warn_node(self, msg, node, **kwargs):
    if not msg.startswith('nonlocal image URI found:'):
        self._warnfunc(msg, '%s:%s' % get_source_line(node), **kwargs)

sphinx.environment.BuildEnvironment.warn_node = _warn_node

此答案的先前版本提供了一个与最新的 sphinx 1.4 版本不兼容的补丁 [1]。此外,下一个版本的 sphinx 应该支持这个配置选项[2]:

suppress_warnings = ['image.nonlocal_uri']

这将排除“找到非本地图像 URI”的任何警告。

我发现这是必要的,因为我希望在sphinx-build -W我的测试和构建基础架构中发出“错误警告”,以确保文档中没有错误——我非常清楚我正在使用非本地图像 URI,而且我没关系,但我不想忽略其他警告。

[1] https://github.com/sphinx-doc/sphinx/issues/2429#issuecomment-210255983

[2] https://github.com/sphinx-doc/sphinx/issues/2466

于 2015-02-28T06:40:17.233 回答
6

我为此使用原始 html 代码,例如:

.. raw:: html

   <p style="height:22px">
     <a href="https://travis-ci.org/aio-libs/aiozmq" >
       <img src="https://travis-ci.org/aio-libs/aiozmq.svg?branch=master"/>
     </a>
   </p>
于 2014-03-27T18:41:32.880 回答
4

真是太丢人了……

正如德尔南在他的评论中提到的那样,我只会收到警告。

在我的辩护中,我在确定图像指令之前尝试了一些非常复杂的原始指令,我只是在查看 Sphinx 的输出而不是在渲染的页面上。当我看到 Sphinx 的长输出时,我以为我又遇到了另一个错误。

尽管如此,我应该受到责备......图像加载正常。

于 2012-10-07T21:46:48.533 回答