Skip to content

Instantly share code, notes, and snippets.

@Carreau
Created April 3, 2013 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Carreau/5305190 to your computer and use it in GitHub Desktop.
Save Carreau/5305190 to your computer and use it in GitHub Desktop.
autolink all ipynb link to nbviewer
url_root='http://nbviewer.ipython.org/';
url=null;
var transform_url = function(href){
if( href===undefined){return}
if (href.search(/^https?:\/\/nbviewer/) == 0 ){
console.log('case 1')
return null
} else if (href.search(/^https?:\/\/gist\.github\.com\/(?:\w+\/)?[a-f0-9]+$/) !== -1) {
console.log('case 2')
gist = href.match(/^https?:\/\/gist\.github\.com\/(?:\w+\/)?([a-f0-9]+)$/);
return url_root + gist[1];
} else if (href.search(/^https:\/\/.*\.ipynb$/) !== -1) {
console.log('case 3')
path = href.match(/^https:\/\/(.*\.ipynb)$/);
return url_root + 'urls/' + path[1];
} else if (href.search(/^http:\/\/.*\.ipynb$/) !== -1) {
console.log('case 4')
path = href.match(/^http:\/\/(.*\.ipynb)$/);
return url_root + 'url/' + path[1];
}
console.log('case none')
return null
}
autoviewlink = function(index,link){
var href = link.href
var nhref = transform_url(href)
console.log('nhref', nhref);
if(nhref != null){
$(link).after($('<a/>').attr('href',nhref).text(' (nbviewer)'))
}
}
$.each($('a'),autoviewlink)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment