str*_*ear 11 restructuredtext directive image python-sphinx
有关如何在使用Sphinx进行记录时参考在线图像的任何想法?
这不起作用:
.. image:: http://www.mysite.com/images/someimage.png
Run Code Online (Sandbox Code Playgroud)
给我:
/home/user/proj/2010/11/08/the_forever_war.rst:11: WARNING: nonlocal image URI found: http://www.mysite.com/images/someimage.png
Run Code Online (Sandbox Code Playgroud)
谢谢...
小智 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
Run Code Online (Sandbox Code Playgroud)
此答案的先前版本提供了与最新的sphinx 1.4版本[1]不兼容的补丁.此外,sphinx的下一个版本应该支持这个配置选项[2]:
suppress_warnings = ['image.nonlocal_uri']
Run Code Online (Sandbox Code Playgroud)
这将排除"找到的非本地图像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
我使用原始的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>
Run Code Online (Sandbox Code Playgroud)
这实在是太尴尬了……
正如德尔南在上面的评论中提到的,我只收到警告。
在我的辩护中,在确定图像指令之前,我尝试了一些相当复杂的原始指令,并且我只是查看 Sphinx 的输出而不是渲染的页面。当我看到 Sphinx 的长输出时,我以为我又遇到了另一个错误。
尽管如此,这都是我的错……图像加载得很好。