Embedding code snippets in your blog with Gist and 2 things to fix when nothing shows up

Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository.

To embed a gist, it’s (nearly) as simply as to copy the embed link Copy Link

And paste the HTML into your blog.

Here is an example

But if anything doesn’t show up, you may need to check two things.

// Copied code (not fixed)
<script src="https://gist.github.com/2603939.js?file=gist+example.m"></script>
// Fixed working HTML tag
<script src="https://gist.github.com/2603939.js?file=gist%2Bexample.m"> </script>
  • Escape the file name parameter, notice the + becomes %2B in my example
  • Add a white space between <script></script> tag so the the parsing engine won’t rewrite into <script src="..." />, which some browser has issues displaying naked HTML tags.

When I try blogging with jekyll and tumblr in my ioscodesnippet blog, I encountered these issues and got me some time to figure out what’s going wrong. So hope this would helps someone else!

Btw, remember that the gist won’t show up in tumblr’s preview mode.

Notes

  1. ratatatech reblogged this from mystcolor
  2. mystcolor posted this