Skip to content

Instantly share code, notes, and snippets.

@masnick
Last active November 22, 2015 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masnick/9bb5590b426b7ae87ad3 to your computer and use it in GitHub Desktop.
Save masnick/9bb5590b426b7ae87ad3 to your computer and use it in GitHub Desktop.
Hide code blocks in IPython HTML output
import IPython.core.display as di
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment