Display Github repository files directly in a blog

Issue

I have a blog and I’d like to add some code snippets in some of my posts.

I found this “gist” thing pretty handy but looks like it only works with code you directly paste in. I’m already familiar with syntax highlighter and similar tools but still doesn’t cover my requirement.

I’d find really useful a tool which allow you to display Github repository files directly within your blog. Imagine giving gist the url of your repository file and you pasting the source gist provides into your post.

Is there a way to link files in a public Github repository so I can display them in my blog as a code snippet?

Solution

You can actually do this using a tool called Gist-it.

Usage

Take a github file url and prefix it with http://gist-it.appspot.com and embed the result within a tag:

<script src="http://gist-it.appspot.com/http://github.com/$file"></script>

$file should follow the github repository pattern of
$user/$repository/raw/master/$path
github/$file is a shorthand for http://github.com/$file and works in the same way

Here’s a test I just made by following their guidelines.

enter image description here

Works!

Answered By – Dr. Andrew Burnett-Thompson

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.