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