##// END OF EJS Templates
Peptified code to get a better visualization
damianavila -
Show More
@@ -5,9 +5,12 b' import os'
5 import itertools
5 import itertools
6
6
7 class ConverterReveal(ConverterMarkdown):
7 class ConverterReveal(ConverterMarkdown):
8 """Convert a notebook to a html slideshow.
8 """
9 Convert a notebook to a html slideshow.
9
10
10 It generates a static html slideshow based in markdown and reveal.js.
11 It generates a static html slideshow based in markdown and reveal.js.
12 The delimiters for each slide, subslide, and fragment are retrieved
13 from the 'slideshow' metadata.
11 """
14 """
12
15
13 def __init__(self, infile, highlight_source=False, show_prompts=True,
16 def __init__(self, infile, highlight_source=False, show_prompts=True,
@@ -25,7 +28,7 b' class ConverterReveal(ConverterMarkdown):'
25 return m_list
28 return m_list
26
29
27 def meta2str(self, meta):
30 def meta2str(self, meta):
28 "transform metadata dictionary to a string containing delimiters for slides"
31 "transform metadata dict to a string containing delimiters for slides"
29 try:
32 try:
30 meta_tuple = meta[u'slideshow'].items()
33 meta_tuple = meta[u'slideshow'].items()
31 except KeyError as e:
34 except KeyError as e:
@@ -35,14 +38,16 b' class ConverterReveal(ConverterMarkdown):'
35 return u'\n'.join(list(itertools.chain(*meta_list)))
38 return u'\n'.join(list(itertools.chain(*meta_list)))
36
39
37 def render_heading(self, cell):
40 def render_heading(self, cell):
38 return [self.meta2str(cell.metadata), '{0} {1}'.format('#' * cell.level, cell.source), '']
41 return [self.meta2str(cell.metadata),
42 '{0} {1}'.format('#' * cell.level, cell.source), '']
39
43
40 def render_markdown(self, cell):
44 def render_markdown(self, cell):
41 return [self.meta2str(cell.metadata), cell.source, '']
45 return [self.meta2str(cell.metadata), cell.source, '']
42
46
43 def render_raw(self, cell):
47 def render_raw(self, cell):
44 if self.raw_as_verbatim:
48 if self.raw_as_verbatim:
45 return [indent(self.meta2str(cell.metadata)), indent(cell.source), '']
49 return [indent(self.meta2str(cell.metadata)),
50 indent(cell.source), '']
46 else:
51 else:
47 return [self.meta2str(cell.metadata), cell.source, '']
52 return [self.meta2str(cell.metadata), cell.source, '']
48
53
@@ -77,11 +82,14 b' class ConverterReveal(ConverterMarkdown):'
77 def build_slides(self, cell_separator='\n'):
82 def build_slides(self, cell_separator='\n'):
78 "build the slides structure from text list and delimiters"
83 "build the slides structure from text list and delimiters"
79 text = self.main_body(cell_separator)
84 text = self.main_body(cell_separator)
80 delim_false = [u'new_section = False', u'new_subsection = False', u'new_fragment = False']
85 delim_false = [u'new_section = False',
86 u'new_subsection = False',
87 u'new_fragment = False']
81 text = [x for x in text if not x in delim_false]
88 text = [x for x in text if not x in delim_false]
82 left = '<section data-markdown><script type="text/template">'
89 left = '<section data-markdown><script type="text/template">'
83 right = '</script></section>'
90 right = '</script></section>'
84 slides = [list(x[1]) for x in itertools.groupby(text, lambda x: x==u'new_section = True') if not x[0]]
91 slides = [list(x[1]) for x in itertools.groupby(text,
92 lambda x: x == u'new_section = True') if not x[0]]
85 for slide in slides:
93 for slide in slides:
86 slide.insert(0, u'')
94 slide.insert(0, u'')
87 slide.insert(0,left)
95 slide.insert(0, left)
@@ -124,16 +132,18 b' class ConverterReveal(ConverterMarkdown):'
124 def template_read(self):
132 def template_read(self):
125 "read the reveal_template.html"
133 "read the reveal_template.html"
126 here = os.path.split(os.path.realpath(__file__))[0]
134 here = os.path.split(os.path.realpath(__file__))[0]
127 reveal_template = os.path.join(here, '..', 'templates', 'reveal_base.html')
135 reveal_template = os.path.join(here, '..', 'templates',
136 'reveal_base.html')
128 with io.open(reveal_template, 'r', encoding='utf-8') as f:
137 with io.open(reveal_template, 'r', encoding='utf-8') as f:
129 template = f.readlines()
138 template = f.readlines()
130 template = map(lambda s: s.strip(), template) # cosmetic one to get short html files
139 template = [s.strip() for s in template] # cosmetic one
131 return template
140 return template
132
141
133 def template_split(self):
142 def template_split(self):
134 "split the reveal_template.html in header and footer lists"
143 "split the reveal_template.html in header and footer lists"
135 temp = self.template_read()
144 temp = self.template_read()
136 splitted_temp = [list(x[1]) for x in itertools.groupby(temp, lambda x: x==u'%slides%') if not x[0]]
145 splitted_temp = [list(x[1]) for x in itertools.groupby(temp,
146 lambda x: x == u'%slides%') if not x[0]]
137 return splitted_temp
147 return splitted_temp
138
148
139 def optional_header(self):
149 def optional_header(self):
General Comments 0
You need to be logged in to leave comments. Login now