Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从README.rst中的docs文件夹链接到图像?_Python_Github_Restructuredtext_Pypi - Fatal编程技术网

Python 如何从README.rst中的docs文件夹链接到图像?

Python 如何从README.rst中的docs文件夹链接到图像?,python,github,restructuredtext,pypi,Python,Github,Restructuredtext,Pypi,我正在努力寻找一种在我的README.rst中使用图像的方法,它将同时出现在github和PyPI上 目前,我正在使用以下标记: .. image:: https://github.com/thebjorn/pydeps/blob/master/docs/_static/pydeps.svg 它在github()上看起来很棒,但在PyPI()上显示为断开的链接 这是可能的,还是我需要在其他地方托管这些图像?您需要使用raw.githubusercontent.com而不是github.com:

我正在努力寻找一种在我的README.rst中使用图像的方法,它将同时出现在github和PyPI上

目前,我正在使用以下标记:

.. image:: https://github.com/thebjorn/pydeps/blob/master/docs/_static/pydeps.svg
它在github()上看起来很棒,但在PyPI()上显示为断开的链接


这是可能的,还是我需要在其他地方托管这些图像?

您需要使用
raw.githubusercontent.com
而不是
github.com

.. image:: https://github.com/thebjorn/pydeps/blob/master/docs/_static/pydeps-pylib.svg
将仅在Github本身上正确渲染,而

.. image:: https://raw.githubusercontent.com/thebjorn/pydeps/master/docs/_static/pydeps-pylib.svg?sanitize=true
将在任何网站上呈现


第一次尝试(断开并移除)
第二次尝试:
  • 正确替换URL(同时删除路径中的
    blob
    部分-我的坏!)
  • 在每个被替换的URL后面追加
    ?sanitize=true

  • 测试和测试,两者看起来都不错


    备选方案:使用 另一种可能是使用,虽然缺点是这是一个第三方服务,所以当它关闭时,图像不会被渲染,尽管它是可用的。然而,为了完整性:

    $ sed -i '' 's,.. image:: https://github.com/\(.*\)/blob/\(.*\)$,.. image:: https://cdn.rawgit.com/\1/\2,g' README.rst
    

    这似乎不起作用(它在github上提供了一个损坏的图像)。起初我认为这是因为内容类型是text/html,但我发现.png图像也有问题(例如)。实际上,如果你从我之前的评论中删除blob,它对.png文件有效。看起来github将.svg文件转换为数据url,而.rst似乎不喜欢…:-(现在获得了
    sed
    oneliner,请再次验证。很高兴我能提供帮助!
    $ sed -i '' 's,.. image:: https://github.com/\(.*\)/blob/\(.*\)$,.. image:: https://cdn.rawgit.com/\1/\2,g' README.rst