diff --git a/liquid_tags/notebook.py b/liquid_tags/notebook.py index eacbff8..6887298 100644 --- a/liquid_tags/notebook.py +++ b/liquid_tags/notebook.py @@ -67,9 +67,6 @@ from copy import deepcopy from jinja2 import DictLoader -# assume not more than ten million cells in notebook -# this shouldn't ever be a problem -MAX_NB_CELLS = 9999999 #---------------------------------------------------------------------- # Some code that will be added to the header: @@ -147,21 +144,32 @@ CSS_WRAPPER = """ #---------------------------------------------------------------------- # Create a custom transformer +class SliceIndex(Integer): + """An integer trait that accepts None""" + default_value = None + + def validate(self, obj, value): + if value is None: + return value + else: + return super(SliceIndex, self).validate(obj, value) + + class SubCell(ActivatableTransformer): """A transformer to select a slice of the cells of a notebook""" - start = Integer(0, config=True, - help="first cell of notebook to be converted") - end = Integer(MAX_NB_CELLS, config=True, - help="last cell of notebook to be converted") - - def __call__(self, nb, resources): + start = SliceIndex(0, config=True, + help="first cell of notebook to be converted") + end = SliceIndex(None, config=True, + help="last cell of notebook to be converted") + + def call(self, nb, resources): nbc = deepcopy(nb) for worksheet in nbc.worksheets : cells = worksheet.cells[:] - end = min(len(cells), self.end) - worksheet.cells = cells[self.start:end] + worksheet.cells = cells[self.start:self.end] return nbc, resources + #---------------------------------------------------------------------- # Customize the html template: # This changes the
 tags in basic_html.tpl to