Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code toggle for notebooks on nbviewer
// Builds on
// to inject a navbar button in the nbviewer UI and to make the snippet easily reusable across notebooks, i.e.:
// %%html
// <script src=""></script>
function onShow() {
$('div.input').show(100, function() {
$('div.cell').css({padding: '5px', border: '1px'});
function onHide() {
$('div.input').hide(100, function() {
$('div.cell').css({padding: 0, border: 0});
window.code_toggle = function() {
(window.code_shown) ? onHide() : onShow();
window.code_shown = !window.code_shown
if($('body.nbviewer').length) {
$('<li><a href="javascript:window.code_toggle()" title="Show/Hide Code"><span class="fa fa-eye fa-2x menu-icon"></span><span class="menu-text">Show/Hide Code</span></a></li>').appendTo('.navbar-right');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.