##// END OF EJS Templates
preprocessing and namespace fix...
Matthias BUSSONNIER -
Show More
@@ -104,6 +104,20 b" env.filters['markdown'] = markdown"
104 env.filters['highlight'] = highlight
104 env.filters['highlight'] = highlight
105 env.filters['ansi2html'] = ansi2html
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 class ConverterTemplate(Configurable):
121 class ConverterTemplate(Configurable):
108
122
109 display_data_priority = ['pdf', 'svg', 'png', 'jpg', 'text']
123 display_data_priority = ['pdf', 'svg', 'png', 'jpg', 'text']
@@ -127,27 +141,17 b' class ConverterTemplate(Configurable):'
127 self.template = env.get_template(tplfile+'.tpl')
141 self.template = env.get_template(tplfile+'.tpl')
128 self.nb = None
142 self.nb = None
129 self.preprocessors = preprocessors
143 self.preprocessors = preprocessors
144 self.preprocessors.append(haspyout_transformer)
130 super(ConverterTemplate, self).__init__(config=config, **kw)
145 super(ConverterTemplate, self).__init__(config=config, **kw)
131
146
147
132 def process(self):
148 def process(self):
133 nb = self.nb
149 nb = self.nb
134
150
135 for preprocessor in self.preprocessors:
151 for preprocessor in self.preprocessors:
136 nb = preprocessor(nb,{})
152 nb = preprocessor(nb,{})
137
153
138 worksheets = []
154 return nb
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
151
155
152 def convert(self):
156 def convert(self):
153 """ convert the ipynb file
157 """ convert the ipynb file
@@ -155,7 +159,7 b' class ConverterTemplate(Configurable):'
155 return both the converted ipynb file and a dict containing potential
159 return both the converted ipynb file and a dict containing potential
156 other resources
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 def read(self, filename):
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 {%- block header -%}
24 {%- block header -%}
25 {%- endblock header -%}
25 {%- endblock header -%}
26 {%- block body -%}
26 {%- block body -%}
27 {%- for worksheet in worksheets -%}
27 {%- for worksheet in nb.worksheets -%}
28 {%- for cell in worksheet.cells -%}
28 {%- for cell in worksheet.cells -%}
29 {%- block any_cell scoped -%}
29 {%- block any_cell scoped -%}
30 {%- if cell.type in ['code'] -%}
30 {%- if cell.type in ['code'] -%}
General Comments 0
You need to be logged in to leave comments. Login now