##// END OF EJS Templates
Fixed restarting cell to (-) type. Added a final point to the while cycle.
damianavila -
Show More
@@ -1,70 +1,72 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.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
50 cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
51
51
52 #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,
53 #end the last subslide/slide.
53 #end the last subslide/slide.
54 if cell.metadata.slide_type in ['slide']:
54 if cell.metadata.slide_type in ['slide']:
55 worksheet.cells[index - 1].metadata.slide_helper = 'slide_end'
55 worksheet.cells[index - 1].metadata.slide_helper = 'slide_end'
56 if cell.metadata.slide_type in ['subslide']:
56 if cell.metadata.slide_type in ['subslide']:
57 worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end'
57 worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end'
58 #Prevent the rendering of "do nothing" cells before fragments
58 if cell.metadata.slide_type in ['fragment']:
59 if cell.metadata.slide_type in ['fragment']:
59 try:
60 i = 1
60 i = 1
61 while i < len(worksheet.cells) - index:
61 while 1:
62 worksheet.cells[index + i].metadata.frag_helper = 'fragment_end'
62 worksheet.cells[index + i].metadata.frag_helper = 'fragment_end'
63 i += 1
63 i += 1
64 #Restart the slide_helper when the cell status is changed
64 except IndexError as e:
65 #to "do nothing".
65 pass #Last cell doesn't have a next one
66 if cell.metadata.slide_type in ['-']:
67 worksheet.cells[index - 1].metadata.slide_helper = '-'
66
68
67 if not isinstance(resources['reveal'], dict):
69 if not isinstance(resources['reveal'], dict):
68 resources['reveal'] = {}
70 resources['reveal'] = {}
69 resources['reveal']['url_prefix'] = self.url_prefix
71 resources['reveal']['url_prefix'] = self.url_prefix
70 return nb, resources
72 return nb, resources
General Comments 0
You need to be logged in to leave comments. Login now