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