revealhelp.py
75 lines
| 3.3 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r10674 | """Module that pre-processes the notebook for export via Reveal. | ||
""" | ||||
#----------------------------------------------------------------------------- | ||||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Paul Ivanov
|
r12219 | from .base import Preprocessor | ||
Thomas Kluyver
|
r13397 | from IPython.utils.traitlets import Unicode | ||
damianavila
|
r11181 | |||
Jonathan Frederic
|
r10674 | #----------------------------------------------------------------------------- | ||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
Paul Ivanov
|
r12219 | class RevealHelpPreprocessor(Preprocessor): | ||
Jonathan Frederic
|
r10437 | |||
MinRK
|
r12443 | url_prefix = Unicode('reveal.js', config=True, | ||
MinRK
|
r12439 | help="""The URL prefix for reveal.js. | ||
This can be a a relative URL for a local copy of reveal.js, | ||||
or point to a CDN. | ||||
MinRK
|
r12443 | For speaker notes to work, a local reveal.js prefix must be used. | ||
MinRK
|
r12439 | """ | ||
) | ||||
damianavila
|
r11179 | |||
Paul Ivanov
|
r12219 | def preprocess(self, nb, resources): | ||
Jonathan Frederic
|
r10674 | """ | ||
Paul Ivanov
|
r12219 | Called once to 'preprocess' contents of the notebook. | ||
damianavila
|
r11183 | |||
Jonathan Frederic
|
r10674 | Parameters | ||
---------- | ||||
nb : NotebookNode | ||||
Notebook being converted | ||||
resources : dictionary | ||||
Additional resources used in the conversion process. Allows | ||||
Paul Ivanov
|
r12219 | preprocessors to pass variables into the Jinja engine. | ||
Jonathan Frederic
|
r10674 | """ | ||
damianavila
|
r11183 | |||
damianavila
|
r13846 | for worksheet in nb.worksheets: | ||
Jonathan Frederic
|
r11367 | for index, cell in enumerate(worksheet.cells): | ||
damianavila
|
r10823 | |||
#Make sure the cell has slideshow metadata. | ||||
cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-') | ||||
damianavila
|
r16867 | #Get the slide type. If type is start of subslide or slide, | ||
Jonathan Frederic
|
r10674 | #end the last subslide/slide. | ||
Jonathan Frederic
|
r10437 | if cell.metadata.slide_type in ['slide']: | ||
Jonathan Frederic
|
r11367 | worksheet.cells[index - 1].metadata.slide_helper = 'slide_end' | ||
Jonathan Frederic
|
r10437 | if cell.metadata.slide_type in ['subslide']: | ||
Jonathan Frederic
|
r11367 | worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end' | ||
damianavila
|
r16867 | #Prevent the rendering of "do nothing" cells before fragments | ||
damianavila
|
r16868 | #Group fragments passing frag_number to the data-fragment-index | ||
damianavila
|
r16866 | if cell.metadata.slide_type in ['fragment']: | ||
damianavila
|
r16868 | worksheet.cells[index].metadata.frag_number = index | ||
damianavila
|
r16867 | i = 1 | ||
while i < len(worksheet.cells) - index: | ||||
worksheet.cells[index + i].metadata.frag_helper = 'fragment_end' | ||||
damianavila
|
r16868 | worksheet.cells[index + i].metadata.frag_number = index | ||
damianavila
|
r16867 | i += 1 | ||
#Restart the slide_helper when the cell status is changed | ||||
damianavila
|
r16869 | #to other types. | ||
if cell.metadata.slide_type in ['-', 'skip', 'notes', 'fragment']: | ||||
damianavila
|
r16867 | worksheet.cells[index - 1].metadata.slide_helper = '-' | ||
damianavila
|
r11183 | |||
Jonathan Frederic
|
r12143 | if not isinstance(resources['reveal'], dict): | ||
damianavila
|
r11184 | resources['reveal'] = {} | ||
damianavila
|
r11183 | resources['reveal']['url_prefix'] = self.url_prefix | ||
Jonathan Frederic
|
r10674 | return nb, resources | ||