Show More
@@ -1,64 +1,63 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 | #----------------------------------------------------------------------------- |
|
3 | #----------------------------------------------------------------------------- | |
4 | # Copyright (c) 2013, the IPython Development Team. |
|
4 | # Copyright (c) 2013, the IPython Development Team. | |
5 | # |
|
5 | # | |
6 | # Distributed under the terms of the Modified BSD License. |
|
6 | # Distributed under the terms of the Modified BSD License. | |
7 | # |
|
7 | # | |
8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
8 | # The full license is in the file COPYING.txt, distributed with this software. | |
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 |
|
10 | |||
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 | # Imports |
|
12 | # Imports | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | from .base import Preprocessor |
|
15 | from .base import Preprocessor | |
16 | from IPython.utils.traitlets import Unicode |
|
16 | from IPython.utils.traitlets import Unicode | |
17 |
|
17 | |||
18 | #----------------------------------------------------------------------------- |
|
18 | #----------------------------------------------------------------------------- | |
19 | # Classes and functions |
|
19 | # Classes and functions | |
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
21 |
|
21 | |||
22 | class RevealHelpPreprocessor(Preprocessor): |
|
22 | class RevealHelpPreprocessor(Preprocessor): | |
23 |
|
23 | |||
24 | url_prefix = Unicode('reveal.js', config=True, |
|
24 | url_prefix = Unicode('reveal.js', config=True, | |
25 | help="""The URL prefix for reveal.js. |
|
25 | help="""The URL prefix for reveal.js. | |
26 | This can be a a relative URL for a local copy of reveal.js, |
|
26 | This can be a a relative URL for a local copy of reveal.js, | |
27 | or point to a CDN. |
|
27 | or point to a CDN. | |
28 |
|
28 | |||
29 | For speaker notes to work, a local reveal.js prefix must be used. |
|
29 | For speaker notes to work, a local reveal.js prefix must be used. | |
30 | """ |
|
30 | """ | |
31 | ) |
|
31 | ) | |
32 |
|
32 | |||
33 | def preprocess(self, nb, resources): |
|
33 | def preprocess(self, nb, resources): | |
34 | """ |
|
34 | """ | |
35 | Called once to 'preprocess' contents of the notebook. |
|
35 | Called once to 'preprocess' contents of the notebook. | |
36 |
|
36 | |||
37 | Parameters |
|
37 | Parameters | |
38 | ---------- |
|
38 | ---------- | |
39 | nb : NotebookNode |
|
39 | nb : NotebookNode | |
40 | Notebook being converted |
|
40 | Notebook being converted | |
41 | resources : dictionary |
|
41 | resources : dictionary | |
42 | Additional resources used in the conversion process. Allows |
|
42 | Additional resources used in the conversion process. Allows | |
43 | preprocessors to pass variables into the Jinja engine. |
|
43 | preprocessors to pass variables into the Jinja engine. | |
44 | """ |
|
44 | """ | |
45 |
|
45 | |||
46 |
for worksheet in nb.worksheets |
|
46 | for worksheet in nb.worksheets: | |
47 | for index, cell in enumerate(worksheet.cells): |
|
47 | for index, cell in enumerate(worksheet.cells): | |
48 |
|
48 | |||
49 | #Make sure the cell has slideshow metadata. |
|
49 | #Make sure the cell has slideshow metadata. | |
50 | cell.metadata.align_type = cell.get('metadata', {}).get('slideshow', {}).get('align_type', 'Left') |
|
|||
51 | cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-') |
|
50 | cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-') | |
52 |
|
51 | |||
53 | #Get the slide type. If type is start of subslide or slide, |
|
52 | #Get the slide type. If type is start of subslide or slide, | |
54 | #end the last subslide/slide. |
|
53 | #end the last subslide/slide. | |
55 | if cell.metadata.slide_type in ['slide']: |
|
54 | if cell.metadata.slide_type in ['slide']: | |
56 | worksheet.cells[index - 1].metadata.slide_helper = 'slide_end' |
|
55 | worksheet.cells[index - 1].metadata.slide_helper = 'slide_end' | |
57 | if cell.metadata.slide_type in ['subslide']: |
|
56 | if cell.metadata.slide_type in ['subslide']: | |
58 | worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end' |
|
57 | worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end' | |
59 |
|
58 | |||
60 |
|
59 | |||
61 | if not isinstance(resources['reveal'], dict): |
|
60 | if not isinstance(resources['reveal'], dict): | |
62 | resources['reveal'] = {} |
|
61 | resources['reveal'] = {} | |
63 | resources['reveal']['url_prefix'] = self.url_prefix |
|
62 | resources['reveal']['url_prefix'] = self.url_prefix | |
64 | return nb, resources |
|
63 | return nb, resources |
General Comments 0
You need to be logged in to leave comments.
Login now