##// END OF EJS Templates
fix latex base template :...
fix latex base template : wrap traceback in correct env, add extract jpeg, fix coalesce stream add data_latex

File last commit:

r9821:6bff5e7e
r9884:ad1df49b
Show More
reveal.py
248 lines | 9.3 KiB | text/x-python | PythonLexer
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 from __future__ import absolute_import
Matthias BUSSONNIER
fix absolute import
r9821 from .html import ConverterHTML
from .utils import text_cell
from .utils import highlight, coalesce_streams
damianavila
Added ipython styling through a method inside the converter. Modified the template to adjust to the new method. Rewritten of some css slyling through reveal_html.css.
r8918
from IPython.utils import path
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 from markdown import markdown
damianavila
Cleaning of reveal converter to make the PR
r8910
damianavila
Addednew slider converter based in reveal.js
r8815 import os
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 import io
damianavila
Moved the html code to a template file and added functions to read the template
r8843 import itertools
damianavila
Addednew slider converter based in reveal.js
r8815
damianavila
Major change to read metadata from each cell and build the proper slides
r8848
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 class ConverterReveal(ConverterHTML):
damianavila
Uncommented docstring.
r9383 """
Convert a ipython notebook to a html slideshow
based in reveal.js library.
"""
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899
@text_cell
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 def render_heading(self, cell):
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 marker = cell.level
damianavila
Peptified code to get a better visualization
r8860 return [self.meta2str(cell.metadata),
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 u'<h{1}>\n {0}\n</h{1}>'.format(cell.source, marker)]
damianavila
Major change to read metadata from each cell and build the proper slides
r8848
damianavila
Added support to render code properly
r8871 def render_code(self, cell):
if not cell.input:
return []
lines = []
meta_code = self.meta2str(cell.metadata)
lines.extend([meta_code])
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 lines.extend(['<div class="cell border-box-sizing code_cell vbox">'])
lines.append('<div class="input hbox">')
damianavila
Added support to render code properly
r8871 n = self._get_prompt_number(cell)
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 lines.append(
'<div class="prompt input_prompt">In&nbsp;[%s]:</div>' % n
)
lines.append('<div class="input_area box-flex1">')
lines.append(highlight(cell.input))
lines.append('</div>') # input_area
lines.append('</div>') # input
if cell.outputs:
lines.append('<div class="vbox output_wrapper">')
lines.append('<div class="output vbox">')
for output in coalesce_streams(cell.outputs):
conv_fn = self.dispatch(output.output_type)
lines.extend(conv_fn(output))
lines.append('</div>') # output
lines.append('</div>') # output_wrapper
lines.append('</div>') # cell
damianavila
Added support to render code properly
r8871 return lines
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 @text_cell
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 def render_markdown(self, cell):
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 return [self.meta2str(cell.metadata), markdown(cell.source)]
damianavila
Major change to read metadata from each cell and build the proper slides
r8848
def render_raw(self, cell):
if self.raw_as_verbatim:
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 return [self.in_tag('pre', self.meta2str(cell.metadata)),
damianavila
Cleaning of reveal converter to make the PR
r8910 self.in_tag('pre', cell.source)]
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 else:
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 return [self.meta2str(cell.metadata), cell.source]
def meta2str(self, meta):
"transform metadata dict (containing slides delimiters) to string "
try:
meta_tuple = meta[u'slideshow'].items()
except KeyError as e: # if there is not slideshow metadata
meta_tuple = [(u'slide_type', u'untouched')]
meta_list = [[x + ' = ' + unicode(y)] for x, y in meta_tuple]
return u'\n'.join(list(itertools.chain(*meta_list)))
damianavila
Implemented loading of pyerr, images and videos outside the markdown cell
r8873
damianavila
Addednew slider converter based in reveal.js
r8815 def convert(self, cell_separator='\n'):
"""
damianavila
Added some comments to specific pieces of code
r8863 Specific method to converts notebook to a string representation.
damianavila
Addednew slider converter based in reveal.js
r8815
Parameters
----------
cell_separator : string
Character or string to join cells with. Default is "\n"
Returns
-------
out : string
"""
damianavila
Added some comments to specific pieces of code
r8863
damianavila
Addednew slider converter based in reveal.js
r8815 lines = []
lines.extend(self.optional_header())
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 begin = ['<div class="reveal"><div class="slides">']
lines.extend(begin)
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 slides_list = self.build_slides()
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 lines.extend(slides_list)
end = ['</div></div>']
damianavila
Moved the html code to a template file and added functions to read the template
r8843 lines.extend(end)
damianavila
Addednew slider converter based in reveal.js
r8815 lines.extend(self.optional_footer())
return u'\n'.join(lines)
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 def clean_text(self, cell_separator='\n'):
"clean and reorganize the text list to be slided"
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 text = self.main_body(cell_separator)
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 self.delim = [u'slide_type = untouched',
u'slide_type = -',
u'slide_type = slide',
damianavila
Deleted example notebook and references. Modified names of slides in reveal converter.
r9104 u'slide_type = subslide',
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 u'slide_type = fragment',
damianavila
Added support for speaker notes at the end of each slide.
r8927 u'slide_type = notes',
damianavila
Added important comment
r8924 u'slide_type = skip'] # keep this one the last
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 text_cell_render = \
u'<div class="text_cell_render border-box-sizing rendered_html">'
for i, j in enumerate(text):
if j in self.delim and text[i - 1] == text_cell_render:
if j == self.delim[0]:
text[i - 1] = self.delim[0]
elif j == self.delim[1]:
text[i - 1] = self.delim[1]
elif j == self.delim[2]:
text[i - 1] = self.delim[2]
elif j == self.delim[3]:
text[i - 1] = self.delim[3]
elif j == self.delim[4]:
text[i - 1] = self.delim[4]
damianavila
Added support for speaker notes at the end of each slide.
r8927 elif j == self.delim[5]:
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 text[i - 1] = self.delim[5]
damianavila
Added support for speaker notes at the end of each slide.
r8927 else:
text[i - 1] = self.delim[6]
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 text[i] = text_cell_render
return text
def build_slides(self):
"build the slides structure from text list and delimiters"
text = self.clean_text()
left = '<section>'
right = '</section>'
damianavila
Added support for speaker notes at the end of each slide.
r8927 notes_start = '<aside class="notes">'
notes_end = '</aside>'
damianavila
Skipped cells are now hided instead of deleted.
r9232 #encapsulation of skipped cells
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 for i, j in enumerate(text):
if j == u'slide_type = skip':
text.pop(i)
damianavila
Skipped cells are now hided instead of deleted.
r9232 text[i] = text[i][:4] + \
' style=display:none' + text[i][4:]
damianavila
Added support for speaker notes cells in the any place of the slides and adjacent speaker notes cells.
r8936 #encapsulation of notes cells
for i, j in enumerate(text):
if j == u'slide_type = notes':
text.pop(i)
temp_list = []
damianavila
Skipped cells are now hided instead of deleted.
r9232 while not text[i] in self.delim[:6]:
damianavila
Added support for speaker notes cells in the any place of the slides and adjacent speaker notes cells.
r8936 temp_list.append(text.pop(i))
else:
temp_list.insert(0, notes_start)
temp_list.append(notes_end)
text[i:i] = temp_list
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 # elimination of none names
for i, j in enumerate(text):
if j in [u'slide_type = untouched', u'slide_type = -']:
text.pop(i)
#generation of slides as a list of list
damianavila
Peptified code to get a better visualization
r8860 slides = [list(x[1]) for x in itertools.groupby(text,
damianavila
Deleted example notebook and references. Modified names of slides in reveal converter.
r9104 lambda x: x == u'slide_type = slide') if not x[0]]
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 for slide in slides:
damianavila
Peptified code to get a better visualization
r8860 slide.insert(0, left)
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 slide.append(right)
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 # encapsulation of each fragment
for i, j in enumerate(slide):
if j == u'slide_type = fragment':
slide.pop(i)
damianavila
Added support for speaker notes at the end of each slide.
r8927 slide[i] = slide[i][:4] + \
' class="fragment"' + slide[i][4:]
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 # encapsulation of each nested slide
damianavila
Deleted example notebook and references. Modified names of slides in reveal converter.
r9104 if u'slide_type = subslide' in slide:
damianavila
Replacement of text with vaiable containing text.
r9096 slide.insert(0, left)
slide.append(right)
damianavila
Peptified code to get a better visualization
r8860 for i, j in enumerate(slide):
damianavila
Deleted example notebook and references. Modified names of slides in reveal converter.
r9104 if j == u'slide_type = subslide':
damianavila
New implementation for reveal option in nbconvert bypassing markdown step. The structure behind the implementaion follows the discussion in IPEP 9
r8899 slide[i] = right + left
damianavila
Major change to read metadata from each cell and build the proper slides
r8848 return list(itertools.chain(*slides))
damianavila
Added complete support for notes, with names acordingly with the title of the notebook currently being converted.
r8937 def render(self):
"read, convert, and save self.infile"
if not hasattr(self, 'nb'):
self.read()
self.output = self.convert()
assert(type(self.output) == unicode)
return self.save()
damianavila
Addednew slider converter based in reveal.js
r8815 def save(self, outfile=None, encoding=None):
"read and parse notebook into self.nb"
if outfile is None:
outfile = self.outbase + '_slides.' + 'html'
if encoding is None:
encoding = self.default_encoding
with io.open(outfile, 'w', encoding=encoding) as f:
f.write(self.output)
return os.path.abspath(outfile)
damianavila
Added ipython styling through a method inside the converter. Modified the template to adjust to the new method. Rewritten of some css slyling through reveal_html.css.
r8918 def header_body(self):
damianavila
Fixed comments and comment in the mouse click functionality
r8921 "return the body of the header as a list of strings"
damianavila
Added ipython styling through a method inside the converter. Modified the template to adjust to the new method. Rewritten of some css slyling through reveal_html.css.
r8918 from pygments.formatters import HtmlFormatter
header = []
static = os.path.join(path.get_ipython_package_dir(),
damianavila
Fixed comments and comment in the mouse click functionality
r8921 'frontend', 'html', 'notebook', 'static',)
damianavila
Added ipython styling through a method inside the converter. Modified the template to adjust to the new method. Rewritten of some css slyling through reveal_html.css.
r8918 here = os.path.split(os.path.realpath(__file__))[0]
css = os.path.join(static, 'css')
for sheet in [
# do we need jquery and prettify?
# os.path.join(static, 'jquery', 'css', 'themes', 'base',
# 'jquery-ui.min.css'),
# os.path.join(static, 'prettify', 'prettify.css'),
os.path.join(css, 'boilerplate.css'),
damianavila
Fixed to work with new ipython css.
r9561 os.path.join(css, 'style.min.css'),
damianavila
Added ipython styling through a method inside the converter. Modified the template to adjust to the new method. Rewritten of some css slyling through reveal_html.css.
r8918 # our overrides:
os.path.join(here, '..', 'css', 'reveal_html.css'),
]:
header.extend(self._stylesheet(sheet))
# pygments css
pygments_css = HtmlFormatter().get_style_defs('.highlight')
header.extend(['<meta charset="UTF-8">'])
header.extend(self.in_tag('style', pygments_css,
dict(type='"text/css"')))
return header
damianavila
Added complete support for notes, with names acordingly with the title of the notebook currently being converted.
r8937 def template_read(self, templ):
damianavila
Moved the html code to a template file and added functions to read the template
r8843 "read the reveal_template.html"
here = os.path.split(os.path.realpath(__file__))[0]
damianavila
Peptified code to get a better visualization
r8860 reveal_template = os.path.join(here, '..', 'templates',
damianavila
Added complete support for notes, with names acordingly with the title of the notebook currently being converted.
r8937 templ)
damianavila
Moved the html code to a template file and added functions to read the template
r8843 with io.open(reveal_template, 'r', encoding='utf-8') as f:
template = f.readlines()
damianavila
Added some comments to specific pieces of code
r8863 template = [s.strip() for s in template]
damianavila
Moved the html code to a template file and added functions to read the template
r8843 return template
def template_split(self):
"split the reveal_template.html in header and footer lists"
damianavila
Added complete support for notes, with names acordingly with the title of the notebook currently being converted.
r8937 temp = self.template_read('reveal_base.html')
damianavila
Peptified code to get a better visualization
r8860 splitted_temp = [list(x[1]) for x in itertools.groupby(temp,
lambda x: x == u'%slides%') if not x[0]]
return splitted_temp
damianavila
Addednew slider converter based in reveal.js
r8815
damianavila
Moved the html code to a template file and added functions to read the template
r8843 def optional_header(self):
optional_header_body = self.template_split()
damianavila
Added ipython styling through a method inside the converter. Modified the template to adjust to the new method. Rewritten of some css slyling through reveal_html.css.
r8918 return ['<!DOCTYPE html>', '<html>', '<head>'] + \
optional_header_body[0] + self.header_body() + \
['</head>', '<body>']
damianavila
Addednew slider converter based in reveal.js
r8815
def optional_footer(self):
damianavila
Moved the html code to a template file and added functions to read the template
r8843 optional_footer_body = self.template_split()
Matthias BUSSONNIER
fix absolute import
r9821 return optional_footer_body[1] + ['</body>', '</html>']