Skip to content

Instantly share code, notes, and snippets.

@damianavila
Last active December 19, 2015 14:38
Show Gist options
  • Save damianavila/5970218 to your computer and use it in GitHub Desktop.
Save damianavila/5970218 to your computer and use it in GitHub Desktop.
Config the Reveal exporter to use a local reveal.js library instead of a CDN.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"IPython nbconvert slides exporter."
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Using a local copy of reveal.js library."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you have low connectivity, it is better to load a local copy of the reveal.js library.\n",
"You can easily configure this behaviour using a config object from the IPython machinery.\n",
"Below, you have one way to do it:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.nbconvert.exporters import SlidesExporter\n",
"from IPython.config import Config\n",
"\n",
"from IPython.nbformat import current as nbformat\n",
"\n",
"infile = \"your_slides.ipynb\" # load the name of your slideshow\n",
"outfile = \"your_slides.slides.html\"\n",
"\n",
"notebook = open(infile).read()\n",
"notebook_json = nbformat.reads_json(notebook)\n",
"\n",
"# This is the config object I talked before, in the 'url_prefix', \n",
"# you can set you proper location of your local reveal.js library,\n",
"# i.e. if the reveal.js is located in the same directory as your \n",
"# your_slideshow.reveal.html, then set 'url_prefix':'reveal.js'.\n",
"c = Config({\n",
" 'RevealHelpTransformer':{\n",
" 'enabled':True,\n",
" 'url_prefix':'reveal.js',\n",
" }, \n",
" })\n",
"\n",
"exportHtml = SlidesExporter(config=c)\n",
"(body,resources) = exportHtml.from_notebook_node(notebook_json)\n",
"\n",
"open(outfile, 'w').write(body.encode('utf-8'))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Enjoy!**\n",
"\n",
"**Dami\u00e1n Avila.**"
]
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment