Created
April 3, 2013 20:54
-
-
Save Carreau/5305190 to your computer and use it in GitHub Desktop.
autolink all ipynb link to nbviewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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