Skip to content

@Carreau /autoipynb.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.