From e389b2e01a67918e89135066911db1e4fd1c5adc 2013-07-31 22:55:08 From: damianavila Date: 2013-07-31 22:55:08 Subject: [PATCH] Added working speaker notes for slides. --- diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 312d4c7..028f09f 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -62,7 +62,9 @@ nbconvert_aliases.update({ 'notebooks' : 'NbConvertApp.notebooks', 'writer' : 'NbConvertApp.writer_class', 'post': 'NbConvertApp.post_processor_class', - 'output': 'NbConvertApp.output_base' + 'output': 'NbConvertApp.output_base', + 'local': 'RevealHelpTransformer.url_prefix', + '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 96d69f1..abc94f4 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 @@ -24,7 +27,12 @@ class RevealHelpTransformer(Transformer): url_prefix = Unicode('//cdn.jsdelivr.net/reveal.js/2.4.0', config=True, help="""If you want to use a local reveal.js library, - use 'url_prefix':'reveal.js' in your config object.""") + use 'url_prefix':'reveal.js' in your config object or + --local reveal.js in command line.""") + + speaker_notes = Bool(False, config=True, help=""" + If you want to use the speaker notes set speaker_notes:True + in your config object or --notes True in command line.""") def call(self, nb, resources): """ @@ -57,5 +65,30 @@ class RevealHelpTransformer(Transformer): if 'reveal' not in resources: 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 b3672d0..cb241fc 100644 --- a/docs/source/interactive/nbconvert.rst +++ b/docs/source/interactive/nbconvert.rst @@ -63,7 +63,11 @@ 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 + ``--notes True`` on the command-line. + For low connectivity environments, you can use a local copy of the reveal.js library, just add + ``--local 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,