revealhelp.py
61 lines
| 2.5 KiB
| text/x-python
|
PythonLexer
|
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 | ||||
#----------------------------------------------------------------------------- | ||||
|
r11452 | from .base import Transformer | ||
|
r11183 | from IPython.utils.traitlets import Unicode | ||
|
r11181 | |||
|
r10674 | #----------------------------------------------------------------------------- | ||
# Classes and functions | ||||
#----------------------------------------------------------------------------- | ||||
|
r11452 | class RevealHelpTransformer(Transformer): | ||
|
r10437 | |||
|
r11183 | 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.""") | ||||
|
r11179 | |||
|
r10851 | def call(self, nb, resources): | ||
|
r10674 | """ | ||
Called once to 'transform' contents of the notebook. | ||||
|
r11183 | |||
|
r10674 | Parameters | ||
---------- | ||||
nb : NotebookNode | ||||
Notebook being converted | ||||
resources : dictionary | ||||
Additional resources used in the conversion process. Allows | ||||
transformers to pass variables into the Jinja engine. | ||||
""" | ||||
|
r11183 | |||
|
r10437 | for worksheet in nb.worksheets : | ||
|
r11367 | for index, cell in enumerate(worksheet.cells): | ||
|
r10823 | |||
#Make sure the cell has slideshow metadata. | ||||
|
r10947 | cell.metadata.align_type = cell.get('metadata', {}).get('slideshow', {}).get('align_type', 'Left') | ||
|
r10823 | cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-') | ||
|
r10674 | #Get the slide type. If type is start of subslide or slide, | ||
#end the last subslide/slide. | ||||
|
r10437 | if cell.metadata.slide_type in ['slide']: | ||
|
r11367 | worksheet.cells[index - 1].metadata.slide_helper = 'slide_end' | ||
|
r10437 | if cell.metadata.slide_type in ['subslide']: | ||
|
r11367 | worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end' | ||
|
r11179 | |||
|
r11183 | |||
|
r12143 | if not isinstance(resources['reveal'], dict): | ||
|
r11184 | resources['reveal'] = {} | ||
|
r11183 | resources['reveal']['url_prefix'] = self.url_prefix | ||
|
r10674 | return nb, resources | ||