@@ -0,0 +1,2126 @@
+%22%22%22This preprocessor removes lines in code cells that have been marked as %60folded%60%0Aby the codefolding extension%0A%22%22%22%0A%0A#-----------------------------------------------------------------------------%0A# Copyright (c) 2014, Juergen Hasch%0A#%0A# Distributed under the terms of the Modified BSD License.%0A#%0A#-----------------------------------------------------------------------------%0A%0Afrom IPython.nbconvert.preprocessors import *%0Aimport StringIO%0A%0Aclass CodeFoldingPreprocessor(Preprocessor):%0A%0A    def fold_cell(self,cell,folded):%0A        %22%22%22%0A        Remove folded lines and add a '%3C-%3E' at the parent line%0A        %22%22%22%0A        f = StringIO.StringIO(cell)%0A        lines = f.readlines()%0A    %0A        if folded%5B0%5D == 0 and lines%5B0%5D%5B0%5D == '#':%0A            self.log.info(%22folded: %25s, %25s%22 %25 (folded%5B0%5D,lines%5B0%5D%5B0%5D))%0A            return lines%5B0%5D.rstrip('%5Cn') + '%3C-%3E%5Cn'%0A        fold_indent = 0%0A        fold = False%0A        fcell = %22%22%0A        for i,l in enumerate(lines):%0A            indent = len(l)-len(l.lstrip(' '))%0A            if indent %3C= fold_indent:%0A                fold = False%0A                fold_indent = 0%0A            if i in folded:%0A                fold = True%0A                fold_indent = indent%0A                fcell += l.rstrip('%5Cn') + '%3C-%3E%5Cn'%0A            if fold is False:%0A                fcell += l%0A        return fcell%0A%0A    def preprocess_cell(self, cell, resources, index):%0A        %22%22%22%0A        Read out metadata and remove lines if marked as %60folded%60 in cell metadata.%0A%0A        Parameters%0A        ----------%0A        cell : NotebookNode cell%0A            Notebook cell being processed%0A        resources : dictionary%0A            Additional resources used in the conversion process.  Allows%0A            preprocessors to pass variables into the Jinja engine.%0A        cell_index : int%0A            Index of the cell being processed (see base.py)%0A        %22%22%22%0A        if hasattr(cell, %22input%22) and cell.cell_type == %22code%22:%0A            if hasattr(cell%5B'metadata'%5D, 'code_folding'):%0A                folded = cell%5B'metadata'%5D%5B'code_folding'%5D%0A                cell.input = self.fold_cell(cell.input, folded)%0A        return cell, resources%0A

Add preprocessor for codefolding extension