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