Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed SVG image in GitHub wiki in 2016

Tags:

github

svg

wiki

Yes, there are questions about this. Unfortunately, the answers are all messy now with information about different things that worked differently across the past five or so years.

So how the heck am I to

  • embed
  • an svg image
  • in a GitHub .wiki folder
  • inside a GitHub .wiki page

I can't believe you need a PhD for this.

Here is my example page with broken embedding: - https://github.com/Sciss/ScalaCollider/wiki/Architecture/2413e094a59df4705e770b2a57ff84a8f0a1e7b4

Here is the actual thing: - https://raw.githubusercontent.com/wiki/Sciss/ScalaCollider/images/ScalaCollider_types.svg

I suppose the problem is this renders as raw text instead of being shown as svg image?

And no, I don't want to set up gh-pages. I want to use the bloody Wiki, because that is what it's supposed to do.

like image 230
0__ Avatar asked Apr 03 '16 23:04

0__


2 Answers

Ok, so apparently this is what happens:

  • GitHub doesn't want to render images properly from rawgithubcontent.
  • So forget about embedding them in the wiki
  • Create a gh-pages branch for the main project unless you already have one
  • Find or create an unused directory in that branch, and add the image there
  • Link to the gh-pages URL

E.g. https://sciss.github.io/ScalaCollider/images/ScalaCollider_types.svg

Not cool, but it works.

like image 97
0__ Avatar answered Oct 22 '22 00:10

0__


You can do that using jsdelivr.net.

Steps:

  1. Upload the file https://raw.githubusercontent.com/wiki/Sciss/ScalaCollider/images/ScalaCollider_types.svg to one folder under any repository.
  2. Find the svg link on GitHub, and click to the "Raw" version.
  3. Copy the URL.
  4. Change raw.githubusercontent.com to cdn.jsdelivr.net
  5. Insert /gh/ before your username.
  6. Remove the branch name.
  7. (Optional) Insert the version you want to link to, as @version (if you do not do this, you will get the latest - which may cause long-term caching)
  8. Using label image, then add ?sanitize=true to the path tail of the svg file.

For example,

If raw svg file path in github is:

https://raw.githubusercontent.com/yanglr/Beautify-cnblogs/master/images/github-pendant-rightCorner.svg

You can use below:

<a href="https://github.com/yanglr">
<img style="position: absolute; top: 76px; right: 0; border: 0" alt="Fork me on GitHub" 
src="https://cdn.jsdelivr.net/gh/yanglr/Beautify-cnblogs/images/github-pendant-rightCorner.svg?sanitize=true"></a>

The result:

enter image description here

Reference:

Link and execute external JavaScript file hosted on GitHub

like image 23
Bravo Yeung Avatar answered Oct 22 '22 00:10

Bravo Yeung