##// END OF EJS Templates
Fix propagation of fragments across multiple slides/subslides.
damianavila -
Show More
@@ -1,62 +1,68 b''
1 1 """Module that pre-processes the notebook for export via Reveal."""
2 2
3 3 # Copyright (c) IPython Development Team.
4 4 # Distributed under the terms of the Modified BSD License.
5 5
6 6 from .base import Preprocessor
7 7 from IPython.utils.traitlets import Unicode
8 8
9 9
10 10 class RevealHelpPreprocessor(Preprocessor):
11 11
12 12 url_prefix = Unicode('reveal.js', config=True,
13 13 help="""The URL prefix for reveal.js.
14 14 This can be a a relative URL for a local copy of reveal.js,
15 15 or point to a CDN.
16 16
17 17 For speaker notes to work, a local reveal.js prefix must be used.
18 18 """
19 19 )
20 20
21 21 def preprocess(self, nb, resources):
22 22 """
23 23 Called once to 'preprocess' contents of the notebook.
24 24
25 25 Parameters
26 26 ----------
27 27 nb : NotebookNode
28 28 Notebook being converted
29 29 resources : dictionary
30 30 Additional resources used in the conversion process. Allows
31 31 preprocessors to pass variables into the Jinja engine.
32 32 """
33 33
34 34 for index, cell in enumerate(nb.cells):
35 35
36 36 #Make sure the cell has slideshow metadata.
37 37 cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
38 38
39 39 # Get the slide type. If type is start, subslide, or slide,
40 40 # end the last subslide/slide.
41 41 if cell.metadata.slide_type in ['slide']:
42 42 nb.cells[index - 1].metadata.slide_helper = 'slide_end'
43 43 if cell.metadata.slide_type in ['subslide']:
44 44 nb.cells[index - 1].metadata.slide_helper = 'subslide_end'
45 45 # Prevent the rendering of "do nothing" cells before fragments
46 46 # Group fragments passing frag_number to the data-fragment-index
47 47 if cell.metadata.slide_type in ['fragment']:
48 48 nb.cells[index].metadata.frag_number = index
49 49 i = 1
50 50 while i < len(nb.cells) - index:
51 nb.cells[index + i].metadata.frag_helper = 'fragment_end'
52 nb.cells[index + i].metadata.frag_number = index
53 i += 1
51 # We need to break the loop when a new slide or subslide is
52 # found to avoid the propagation of the data-fragment-index
53 # across multiple slides/subslides
54 if nb.cells[index + i].metadata.slideshow.slide_type in ['slide', 'subslide']:
55 break
56 else:
57 nb.cells[index + i].metadata.frag_helper = 'fragment_end'
58 nb.cells[index + i].metadata.frag_number = index
59 i += 1
54 60 # Restart the slide_helper when the cell status is changed
55 61 # to other types.
56 62 if cell.metadata.slide_type in ['-', 'skip', 'notes', 'fragment']:
57 63 nb.cells[index - 1].metadata.slide_helper = '-'
58 64
59 65 if not isinstance(resources['reveal'], dict):
60 66 resources['reveal'] = {}
61 67 resources['reveal']['url_prefix'] = self.url_prefix
62 68 return nb, resources
General Comments 0
You need to be logged in to leave comments. Login now