问题描述
我知道可以使用 
或 
,但我很难在代码托管在 GitHub 上的 MD 中放置 SVG.
最终使用 rails3,并且现在经常更改模型,所以我使用 ::
raw.github.com
的目的是让用户查看一个文件的内容,所以对于基于文本的文件这个意味着(对于某些内容类型)您可能会收到错误的标题并且浏览器中的内容会中断.
当(2012 年)提出这个问题时,SVG 不起作用.从那时起,Github 实施了各种改进.现在(至少对于 SVG),将发送正确的 Content-Type 标头.
示例
下面提到的所有方法都有效.
Linking to files using relative paths (Works, but obviously only on github.com / github.io)
Code

<img src="./controllers_brief.svg">
Result
See the working example on github.com.
Linking to RAW files
Code

<img src="https://raw.github.com/potherca-blog/StackOverflow/master/question.13808020.include-an-svg-hosted-on-github-in-markdown/controllers_brief.svg">
Result
Linking to RAW files using ?sanitize=true
Code

<img src="https://raw.github.com/potherca-blog/StackOverflow/master/question.13808020.include-an-svg-hosted-on-github-in-markdown/controllers_brief.svg?sanitize=true">
Result
Linking to files hosted on github.io
Code

<img src="https://potherca-blog.github.io/StackOverflow/question.13808020.include-an-svg-hosted-on-github-in-markdown/controllers_brief.svg">
Result
Some comments regarding changes that happened along the way:
Github has implemented a feature which makes it possible for SVG's to be used with the Markdown image syntax. The SVG image will be sanitized and displayed with the correct HTTP header. Certain tags (like
<script>
) are removed.To view the sanitized SVG or to achieve this effect from other places (i.e. from markdown files not hosted in repos on http://github.com/) simply append
?sanitize=true
to the SVG's raw URL.As stated by AdamKatz in the comments, using a source other than github.io can introduce potentially privacy and security risks. See the answer by CiroSantilli and the answer by DavidChambers for more details.
The issue to resolve this was opened on Github on October 13th 2015 and was resolved on August 31th 2017
这篇关于在 MarkDown 中包含一个 SVG(托管在 GitHub 上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!