##// END OF EJS Templates
Fix #4777 and #7887...
Fix #4777 and #7887 The function in charge of actually converting cursor offset to CodeMirror line number and character number was actually crashing when the cursor was at the last character (loop until undefined, then access length of variable, which is undefined). This was hiding a bug in which when you would completer to a single completion pressing tab after as-you-type filtering, the completion would be completed twice. The logic that was supposed to detect whether or not all completions had a common prefix was actually faulty as the common prefix used to be a string but was then changed to an object. Hence the logic to check whether or not there was actually a common prefix was always true, even for empty string, leading to the deletion of the line (replace by '') in some cases.

File last commit:

r18580:ba8461eb
r20538:ae7f6d6a
Show More
revealhelp.py
62 lines | 2.6 KiB | text/x-python | PythonLexer
"""Module that pre-processes the notebook for export via Reveal."""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from .base import Preprocessor
from IPython.utils.traitlets import Unicode
class RevealHelpPreprocessor(Preprocessor):
url_prefix = Unicode('reveal.js', config=True,
help="""The URL prefix for reveal.js.
This can be a a relative URL for a local copy of reveal.js,
or point to a CDN.
For speaker notes to work, a local reveal.js prefix must be used.
"""
)
def preprocess(self, nb, resources):
"""
Called once to 'preprocess' contents of the notebook.
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
"""
for index, cell in enumerate(nb.cells):
#Make sure the cell has slideshow metadata.
cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
# Get the slide type. If type is start, subslide, or slide,
# end the last subslide/slide.
if cell.metadata.slide_type in ['slide']:
nb.cells[index - 1].metadata.slide_helper = 'slide_end'
if cell.metadata.slide_type in ['subslide']:
nb.cells[index - 1].metadata.slide_helper = 'subslide_end'
# Prevent the rendering of "do nothing" cells before fragments
# Group fragments passing frag_number to the data-fragment-index
if cell.metadata.slide_type in ['fragment']:
nb.cells[index].metadata.frag_number = index
i = 1
while i < len(nb.cells) - index:
nb.cells[index + i].metadata.frag_helper = 'fragment_end'
nb.cells[index + i].metadata.frag_number = index
i += 1
# Restart the slide_helper when the cell status is changed
# to other types.
if cell.metadata.slide_type in ['-', 'skip', 'notes', 'fragment']:
nb.cells[index - 1].metadata.slide_helper = '-'
if not isinstance(resources['reveal'], dict):
resources['reveal'] = {}
resources['reveal']['url_prefix'] = self.url_prefix
return nb, resources