Show More
@@ -1,62 +1,68 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 | # Get the slide type. If type is start, subslide, or slide, |
|
39 | # Get the slide type. If type is start, subslide, or slide, | |
40 | # end the last subslide/slide. |
|
40 | # end the last subslide/slide. | |
41 | if cell.metadata.slide_type in ['slide']: |
|
41 | if cell.metadata.slide_type in ['slide']: | |
42 | nb.cells[index - 1].metadata.slide_helper = 'slide_end' |
|
42 | nb.cells[index - 1].metadata.slide_helper = 'slide_end' | |
43 | if cell.metadata.slide_type in ['subslide']: |
|
43 | if cell.metadata.slide_type in ['subslide']: | |
44 | nb.cells[index - 1].metadata.slide_helper = 'subslide_end' |
|
44 | nb.cells[index - 1].metadata.slide_helper = 'subslide_end' | |
45 | # Prevent the rendering of "do nothing" cells before fragments |
|
45 | # Prevent the rendering of "do nothing" cells before fragments | |
46 | # Group fragments passing frag_number to the data-fragment-index |
|
46 | # Group fragments passing frag_number to the data-fragment-index | |
47 | if cell.metadata.slide_type in ['fragment']: |
|
47 | if cell.metadata.slide_type in ['fragment']: | |
48 | nb.cells[index].metadata.frag_number = index |
|
48 | nb.cells[index].metadata.frag_number = index | |
49 | i = 1 |
|
49 | i = 1 | |
50 | while i < len(nb.cells) - index: |
|
50 | while i < len(nb.cells) - index: | |
|
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: | |||
51 | nb.cells[index + i].metadata.frag_helper = 'fragment_end' |
|
57 | nb.cells[index + i].metadata.frag_helper = 'fragment_end' | |
52 | nb.cells[index + i].metadata.frag_number = index |
|
58 | nb.cells[index + i].metadata.frag_number = index | |
53 | i += 1 |
|
59 | i += 1 | |
54 | # Restart the slide_helper when the cell status is changed |
|
60 | # Restart the slide_helper when the cell status is changed | |
55 | # to other types. |
|
61 | # to other types. | |
56 | if cell.metadata.slide_type in ['-', 'skip', 'notes', 'fragment']: |
|
62 | if cell.metadata.slide_type in ['-', 'skip', 'notes', 'fragment']: | |
57 | nb.cells[index - 1].metadata.slide_helper = '-' |
|
63 | nb.cells[index - 1].metadata.slide_helper = '-' | |
58 |
|
64 | |||
59 | if not isinstance(resources['reveal'], dict): |
|
65 | if not isinstance(resources['reveal'], dict): | |
60 | resources['reveal'] = {} |
|
66 | resources['reveal'] = {} | |
61 | resources['reveal']['url_prefix'] = self.url_prefix |
|
67 | resources['reveal']['url_prefix'] = self.url_prefix | |
62 | return nb, resources |
|
68 | return nb, resources |
General Comments 0
You need to be logged in to leave comments.
Login now