##// END OF EJS Templates
preprocessing and namespace fix...
Matthias BUSSONNIER -
Show More
@@ -104,6 +104,20 b" env.filters['markdown'] = markdown"
104 104 env.filters['highlight'] = highlight
105 105 env.filters['ansi2html'] = ansi2html
106 106
107
108 def haspyout_transformer(nb,_):
109 print('calling...')
110 for worksheet in nb.worksheets:
111 print('worksheet')
112 for cell in worksheet.cells:
113 cell.type = cell.cell_type
114 cell.haspyout = False
115 for out in cell.get('outputs', []):
116 if out.output_type == 'pyout':
117 cell.haspyout = True
118 break
119 return nb
120
107 121 class ConverterTemplate(Configurable):
108 122
109 123 display_data_priority = ['pdf', 'svg', 'png', 'jpg', 'text']
@@ -127,27 +141,17 b' class ConverterTemplate(Configurable):'
127 141 self.template = env.get_template(tplfile+'.tpl')
128 142 self.nb = None
129 143 self.preprocessors = preprocessors
144 self.preprocessors.append(haspyout_transformer)
130 145 super(ConverterTemplate, self).__init__(config=config, **kw)
131 146
147
132 148 def process(self):
133 149 nb = self.nb
134 150
135 151 for preprocessor in self.preprocessors:
136 152 nb = preprocessor(nb,{})
137 153
138 worksheets = []
139 for worksheet in nb.worksheets:
140 for cell in worksheet.cells:
141 cell.type = cell.cell_type
142 cell.haspyout = False
143 for out in cell.get('outputs', []):
144 if out.output_type == 'pyout':
145 cell.haspyout = True
146 break
147 worksheets.append(worksheet)
148
149
150 return worksheets
154 return nb
151 155
152 156 def convert(self):
153 157 """ convert the ipynb file
@@ -155,7 +159,7 b' class ConverterTemplate(Configurable):'
155 159 return both the converted ipynb file and a dict containing potential
156 160 other resources
157 161 """
158 return self.template.render(worksheets=self.process(), inlining=inlining), {}
162 return self.template.render(nb=self.process(), inlining=inlining), {}
159 163
160 164
161 165 def read(self, filename):
@@ -24,7 +24,7 b' consider calling super even if block is leave block, we might insert more block '
24 24 {%- block header -%}
25 25 {%- endblock header -%}
26 26 {%- block body -%}
27 {%- for worksheet in worksheets -%}
27 {%- for worksheet in nb.worksheets -%}
28 28 {%- for cell in worksheet.cells -%}
29 29 {%- block any_cell scoped -%}
30 30 {%- if cell.type in ['code'] -%}
General Comments 0
You need to be logged in to leave comments. Login now