Skip to content

Instantly share code, notes, and snippets.

@ryhmrt
Created July 5, 2011 08:37
Show Gist options
  • Save ryhmrt/1064493 to your computer and use it in GitHub Desktop.
Save ryhmrt/1064493 to your computer and use it in GitHub Desktop.
include gist code via anchor tag.
<html>
<head>
<link rel="stylesheet" href="https://gist.github.com/stylesheets/gist/embed.css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/gist/1064493/gisthere.js"></script>
</head>
<body>
↓↓↓ gist here! ↓↓↓
<hr/>
<a href="https://raw.github.com/gist/1064493/gisthere.js">gisthere.js</a>
<hr/>
↑↑↑ gist here! ↑↑↑
</body>
</html>
$(function(){
document.write = function(html){
var matched = html.match('^<div id="gist-([0-9]+)" class="gist">');
if (matched) {
var id = matched[1];
$('#gist-' + id + '-container').append(html);
}
};
$('a').each(function(){
var matched = this.href.match('https://(gist\.github\.com/raw|raw\.github\.com/gist)/([^/]+)/([^/]+/)?(.+)');
if (!matched) return;
var id = matched[2];
var file = matched[4];
var self = $(this);
self.after($('<div id="gist-' + id + '-container" />'));
self.remove();
$('body').append($('<script/>').attr('src', 'https://gist.github.com/' + id + '.js?file=' + file));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment