From 11e331d4312acedfb1276d3d7e1a478fd2156a34 2012-12-12 05:38:53 From: damianavila Date: 2012-12-12 05:38:53 Subject: [PATCH] Peptified code to get a better visualization --- diff --git a/converters/reveal.py b/converters/reveal.py index b9b1acd..cd3c8a8 100644 --- a/converters/reveal.py +++ b/converters/reveal.py @@ -5,9 +5,12 @@ import os import itertools class ConverterReveal(ConverterMarkdown): - """Convert a notebook to a html slideshow. + """ + Convert a notebook to a html slideshow. It generates a static html slideshow based in markdown and reveal.js. + The delimiters for each slide, subslide, and fragment are retrieved + from the 'slideshow' metadata. """ def __init__(self, infile, highlight_source=False, show_prompts=True, @@ -18,14 +21,14 @@ class ConverterReveal(ConverterMarkdown): self.inline_prompt = inline_prompt def switch_meta(self, m_list): - "switch metadata delimiters order to build properly the slides" + "switch metadata delimiters order to build properly the slides" if len(m_list) > 1: if not (len(m_list) == 2 and m_list[1] == [u'new_fragment = True']): m_list[0], m_list[1] = m_list[1], m_list[0] return m_list def meta2str(self, meta): - "transform metadata dictionary to a string containing delimiters for slides" + "transform metadata dict to a string containing delimiters for slides" try: meta_tuple = meta[u'slideshow'].items() except KeyError as e: @@ -35,14 +38,16 @@ class ConverterReveal(ConverterMarkdown): return u'\n'.join(list(itertools.chain(*meta_list))) def render_heading(self, cell): - return [self.meta2str(cell.metadata), '{0} {1}'.format('#' * cell.level, cell.source), ''] + return [self.meta2str(cell.metadata), + '{0} {1}'.format('#' * cell.level, cell.source), ''] def render_markdown(self, cell): return [self.meta2str(cell.metadata), cell.source, ''] def render_raw(self, cell): if self.raw_as_verbatim: - return [indent(self.meta2str(cell.metadata)), indent(cell.source), ''] + return [indent(self.meta2str(cell.metadata)), + indent(cell.source), ''] else: return [self.meta2str(cell.metadata), cell.source, ''] @@ -77,34 +82,37 @@ class ConverterReveal(ConverterMarkdown): def build_slides(self, cell_separator='\n'): "build the slides structure from text list and delimiters" text = self.main_body(cell_separator) - delim_false = [u'new_section = False', u'new_subsection = False', u'new_fragment = False'] + delim_false = [u'new_section = False', + u'new_subsection = False', + u'new_fragment = False'] text = [x for x in text if not x in delim_false] left = '
' - slides = [list(x[1]) for x in itertools.groupby(text, lambda x: x==u'new_section = True') if not x[0]] + slides = [list(x[1]) for x in itertools.groupby(text, + lambda x: x == u'new_section = True') if not x[0]] for slide in slides: slide.insert(0, u'') - slide.insert(0,left) + slide.insert(0, left) slide.append(right) if slide[2] == u'new_subsection = True': slide.pop(2) - slide.insert(0,'
') + slide.insert(0, '
') slide.append('
') - for i,j in enumerate(slide): + for i, j in enumerate(slide): if j == u'new_subsection = True': slide[i] = right + left slide.insert(i + 1, u'') elif slide[4] == u'new_subsection = True': slide[4] = right slide.insert(5, u'') - slide.insert(5,left) - slide.insert(5,'
') + slide.insert(5, left) + slide.insert(5, '
') slide.append('
') - for i,j in enumerate(slide): + for i, j in enumerate(slide): if j == u'new_subsection = True': slide[i] = right + left slide.insert(i + 1, u'') - for i,j in enumerate(slide): + for i, j in enumerate(slide): if j == u'new_fragment = True': slide[i] = '

' slide[i + 2] = '

' @@ -124,17 +132,19 @@ class ConverterReveal(ConverterMarkdown): def template_read(self): "read the reveal_template.html" here = os.path.split(os.path.realpath(__file__))[0] - reveal_template = os.path.join(here, '..', 'templates', 'reveal_base.html') + reveal_template = os.path.join(here, '..', 'templates', + 'reveal_base.html') with io.open(reveal_template, 'r', encoding='utf-8') as f: template = f.readlines() - template = map(lambda s: s.strip(), template) # cosmetic one to get short html files + template = [s.strip() for s in template] # cosmetic one return template def template_split(self): "split the reveal_template.html in header and footer lists" temp = self.template_read() - splitted_temp = [list(x[1]) for x in itertools.groupby(temp, lambda x: x==u'%slides%') if not x[0]] - return splitted_temp + splitted_temp = [list(x[1]) for x in itertools.groupby(temp, + lambda x: x == u'%slides%') if not x[0]] + return splitted_temp def optional_header(self): optional_header_body = self.template_split()