##// END OF EJS Templates
add possibility to preprocess ipynb files
Matthias BUSSONNIER -
Show More
@@ -116,14 +116,27 b' class ConverterTemplate(Configurable):'
116
116
117 infile_dir = Unicode()
117 infile_dir = Unicode()
118
118
119 def __init__(self, tplfile='fullhtml', config=None, **kw):
119 def __init__(self, tplfile='fullhtml', preprocessors=[], config=None, **kw):
120 """
121 preprocessors: list of function to run on ipynb json data before conversion
122 to extract/inline file,
123
124
125
126 """
120 self.template = env.get_template(tplfile+'.tpl')
127 self.template = env.get_template(tplfile+'.tpl')
121 self.nb = None
128 self.nb = None
129 self.preprocessors = preprocessors
122 super(ConverterTemplate, self).__init__(config=config, **kw)
130 super(ConverterTemplate, self).__init__(config=config, **kw)
123
131
124 def process(self):
132 def process(self):
125 converted_cells = []
133 nb = self.nb
126 for worksheet in self.nb.worksheets:
134
135 for preprocessor in self.preprocessors:
136 nb = preprocessor(nb,{})
137
138 worksheets = []
139 for worksheet in nb.worksheets:
127 for cell in worksheet.cells:
140 for cell in worksheet.cells:
128 cell.type = cell.cell_type
141 cell.type = cell.cell_type
129 cell.haspyout = False
142 cell.haspyout = False
@@ -131,9 +144,10 b' class ConverterTemplate(Configurable):'
131 if out.output_type == 'pyout':
144 if out.output_type == 'pyout':
132 cell.haspyout = True
145 cell.haspyout = True
133 break
146 break
134 converted_cells.append(worksheet)
147 worksheets.append(worksheet)
148
135
149
136 return converted_cells
150 return worksheets
137
151
138 def convert(self):
152 def convert(self):
139 """ convert the ipynb file
153 """ convert the ipynb file
General Comments 0
You need to be logged in to leave comments. Login now