Skip to content

Instantly share code, notes, and snippets.

@juhasch
Last active January 9, 2020 02:28
Show Gist options
  • Save juhasch/2332190e19eb6276bed3 to your computer and use it in GitHub Desktop.
Save juhasch/2332190e19eb6276bed3 to your computer and use it in GitHub Desktop.
IPython extension snippet: Add answer buttons
"using strict";
var answer_buttons = (function() {
function add_buttons(){
console.log("runit");
$("div").each( function(){
if (this.className === 'answer') {
var button= '<input type="button" value="Answer" onclick="showHide(' + this.id + ')">';
this.insertAdjacentHTML("beforeBegin",button);
}
});
};
$([IPython.events]).on('notebook_loaded.Notebook',add_buttons());
IPython.toolbar.add_buttons_group([
{
id : 'add_buttons',
label : 'Add answer buttons',
icon : 'icon-list-alt',
callback : add_buttons
}
]);
})();
function showHide(e) {
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
@haoeric
Copy link

haoeric commented Jan 9, 2020

If anyone still wondering, simply enable "Exercise" and "Exercise 2" extension for your jupyter notebook will do now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment