From 4565b731951f73c00f0666e7dce9d167d95f0fa3 2013-08-16 07:50:34 From: Matthias Bussonnier Date: 2013-08-16 07:50:34 Subject: [PATCH] Merge pull request #3863 from damianavila/speaker_notes Added working speaker notes for slides. To resume, I fetch the cdn containing the files we need to make speaker notes works. Then I pass this info using the resources dict to the write which output the files in the correct path... I make some other additions to make this feature an option from the command line, ie: if you want a simple slideshow: ipython nbconvert your_slides.ipynb --to slides if you want a simple served slideshow: ipython nbconvert your_slides.ipynb --to slides --post serve if you want to use a local copy of the reveal.js library: ipython nbconvert your_slides.ipynb --to slides --post serve --local reveal.js and if you want to use speaker notes: ipython nbconvert your_slides.ipynb --to slides --post serve --notes True or ipython nbconvert your_slides.ipynb --to slides --post serve --notes True --local reveal.js but this last one is redundant because if you are using a local reveal.js library the speaker notes are functional by default. --- diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 9f5529c..df8da61 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -61,7 +61,9 @@ nbconvert_aliases.update({ 'template' : 'Exporter.template_file', 'writer' : 'NbConvertApp.writer_class', 'post': 'NbConvertApp.post_processor_class', - 'output': 'NbConvertApp.output_base' + 'output': 'NbConvertApp.output_base', + 'offline-slides': 'RevealHelpTransformer.url_prefix', + 'slide-notes': 'RevealHelpTransformer.speaker_notes' }) nbconvert_flags = {} diff --git a/IPython/nbconvert/templates/slides_reveal.tpl b/IPython/nbconvert/templates/slides_reveal.tpl index 2581c4d..72444c5 100644 --- a/IPython/nbconvert/templates/slides_reveal.tpl +++ b/IPython/nbconvert/templates/slides_reveal.tpl @@ -135,7 +135,7 @@ transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/c dependencies: [ { src: "{{resources.reveal.url_prefix}}/lib/js/classList.js", condition: function() { return !document.body.classList; } }, { src: "{{resources.reveal.url_prefix}}/plugin/highlight/highlight.js", async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, -{ src: "{{resources.reveal.url_prefix}}/plugin/notes/notes.js", async: true, condition: function() { return !!document.body.classList; } } +{ src: "{{resources.reveal.notes_prefix}}/plugin/notes/notes.js", async: true, condition: function() { return !!document.body.classList; } } // { src: 'http://s7.addthis.com/js/300/addthis_widget.js', async: true}, ] }); diff --git a/IPython/nbconvert/transformers/revealhelp.py b/IPython/nbconvert/transformers/revealhelp.py index 7e79f1f..e49dbdc 100755 --- a/IPython/nbconvert/transformers/revealhelp.py +++ b/IPython/nbconvert/transformers/revealhelp.py @@ -12,8 +12,11 @@ # Imports #----------------------------------------------------------------------------- +import os +import urllib2 + from .base import Transformer -from IPython.utils.traitlets import Unicode +from IPython.utils.traitlets import Unicode, Bool #----------------------------------------------------------------------------- # Classes and functions @@ -26,6 +29,11 @@ class RevealHelpTransformer(Transformer): help="""If you want to use a local reveal.js library, use 'url_prefix':'reveal.js' in your config object.""") + speaker_notes = Bool(False, + config=True, + help="""If you want to use the speaker notes + set this to True.""") + def call(self, nb, resources): """ Called once to 'transform' contents of the notebook. @@ -57,5 +65,30 @@ class RevealHelpTransformer(Transformer): if not isinstance(resources['reveal'], dict): resources['reveal'] = {} resources['reveal']['url_prefix'] = self.url_prefix + resources['reveal']['notes_prefix'] = self.url_prefix + + cdn = 'http://cdn.jsdelivr.net/reveal.js/2.4.0' + local = 'local' + html_path = 'plugin/notes/notes.html' + js_path = 'plugin/notes/notes.js' + + html_infile = os.path.join(cdn, html_path) + js_infile = os.path.join(cdn, js_path) + html_outfile = os.path.join(local, html_path) + js_outfile = os.path.join(local, js_path) + + if self.speaker_notes: + if 'outputs' not in resources: + resources['outputs'] = {} + resources['outputs'][html_outfile] = self.notes_helper(html_infile) + resources['outputs'][js_outfile] = self.notes_helper(js_infile) + resources['reveal']['notes_prefix'] = local return nb, resources + + def notes_helper(self, infile): + """Helper function to get the content from an url.""" + + content = urllib2.urlopen(infile).read() + + return content diff --git a/docs/source/interactive/nbconvert.rst b/docs/source/interactive/nbconvert.rst index 6736277..fc437a1 100644 --- a/docs/source/interactive/nbconvert.rst +++ b/docs/source/interactive/nbconvert.rst @@ -63,7 +63,12 @@ The currently supported export formats are: This generates a Reveal.js HTML slideshow. It must be served by an HTTP server. The easiest way to get this is to add ``--post serve`` on the command-line. - + If you want to use the speaker notes plugin, just add + ``--slide-notes=True`` on the command-line. + For low connectivity environments, you can use a local copy of the reveal.js library, + just add ``--offline-slides=reveal.js`` on the command-line, and do not forget to move + your downloaded ``reveal.js`` library to the same folder where your slides are located. + * ``--to markdown`` Simple markdown output. Markdown cells are unaffected,