【问题标题】:github svg not rendering at allgithub svg根本不渲染
【发布时间】:2022-01-27 04:01:23
【问题描述】:

我正在尝试在 github 中创建一个 markdown 文件,并想在其中放置一个 svg 图像。 github根本没有渲染图像。我试过<img />![]()。是根本不行!有人见过吗?

刚刚修改了存储库以便公开:https://github.com/michelucci/deepbook

提前致谢,翁贝托

【问题讨论】:

标签: svg github


【解决方案1】:

似乎 GitHub 现在需要在 SVG 字符串末尾添加 http 查询参数 sanitize=true。如果您从 wiki 链接到存储库中的图像,则 URL 末尾可能已经有参数。因此,如果没有查询参数,则添加?sanitize=true,否则添加&sanitize=true

<img alt="my image" src="https://raw.githubusercontent.com/user/branch/images/myimage.svg?example=foo&sanitize=true>

【讨论】:

    【解决方案2】:

    GitHub 的 markdown 似乎屏蔽了 SVG 文件,但您始终可以使用裸 HTML 标签:

    <img src="neuron_fig1.svg"/>
    

    【讨论】:

    • 谢谢。我试过(见存储库)。但是什么都没有出现!
    • @Umberto 如果你想使用完全限定链接而不是相对链接,你需要使用raw.githubusercontent.com,即:https://raw.githubusercontent.com/michelucci/deepbook/master/images/neuron_fig1.svg
    • 谢谢。我还在上面尝试了您的解决方案,只是指向文件本身,但没有显示任何内容。我将尝试使用完全限定的链接...
    【解决方案3】:

    2022 年更新:a simple drag & drop is enough


    原始答案(2017 年)

    有关任何内联 HTML,请参阅 issue 458,但由于这不是您的问题,您可以将 your pagethis one 进行比较:它确实显示了很多 svg 图片,以及它的 source is here

    "source": [
        "## Python Objects\n",
        "\n",
        "We begin with a look at a Python object. In Python, objects are stored in memory blocks independently allocated on the heap. A single floating point value looks something like this:\n",
        "\n",
        "![Python Float](fig/python_float.svg)\n",
        "\n",
        "This doesn’t look too bad, in a dynamically typed system we need to store some metadata about the type, and we need to store the data containing the value."
       ]
      },
    

    所以相对 URL(到 docs/intro-01/fig)确实有效。

    您的代码:

       "source": [
        " ![](neuron_fig1.svg) \n",
        " **Fig. 1** The structure of a neuron. $x_i$ are the input, $w_i$ are the weights."
       ]
    

    【讨论】:

    • 我相信你!但在我的情况下没有显示任何东西......也许是svg的编写方式。我用inkscape生成它们...
    • @Umberto 我已经添加了您当前的代码,以便与我发现有效的示例进行比较。
    • 谢谢,但![Python Float](fig/python_float.svg) 与我的相似(请注意,我将图像移动到我的根目录以查看是否有帮助)但仍然没有运气......我没有看到任何区别(除了我指的是同一根目录中的图像)......哦,顺便说一下png它完美地工作(我更新了文件)。
    • @Umberto 我同意。我所看到的只是你的字符串中有多余的空格。
    • 添加到它,它在我本地的笔记本电脑上完美运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2021-06-04
    • 2017-04-05
    • 2019-01-05
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多