##// END OF EJS Templates
test_file extractor
Matthias BUSSONNIER -
Show More
@@ -92,6 +92,23 b' def header_body():'
92 header.append(pygments_css)
92 header.append(pygments_css)
93 return header
93 return header
94
94
95
96 def _new_figure(data, fmt, count):
97 """Create a new figure file in the given format.
98
99 Returns a path relative to the input file.
100 """
101 figname = '_fig_%02i.%s' % (count, fmt)
102
103 # Binary files are base64-encoded, SVG is already XML
104 if fmt in ('png', 'jpg', 'pdf'):
105 data = data.decode('base64')
106
107 return figname,data
108
109
110
111
95 inlining = {}
112 inlining = {}
96 inlining['css'] = header_body()
113 inlining['css'] = header_body()
97
114
@@ -145,9 +162,7 b' markdown2latex'
145
162
146
163
147 def haspyout_transformer(nb,_):
164 def haspyout_transformer(nb,_):
148 print('calling...')
149 for worksheet in nb.worksheets:
165 for worksheet in nb.worksheets:
150 print('worksheet')
151 for cell in worksheet.cells:
166 for cell in worksheet.cells:
152 cell.type = cell.cell_type
167 cell.type = cell.cell_type
153 cell.haspyout = False
168 cell.haspyout = False
@@ -155,7 +170,35 b' def haspyout_transformer(nb,_):'
155 if out.output_type == 'pyout':
170 if out.output_type == 'pyout':
156 cell.haspyout = True
171 cell.haspyout = True
157 break
172 break
158 return nb
173 return nb,_
174
175
176 def outline_figure_transformer(nb,other):
177 count=0
178 for worksheet in nb.worksheets:
179 for cell in worksheet.cells:
180 cell.type = cell.cell_type
181 for i,out in enumerate(cell.get('outputs', [])):
182 print('loop outputs',out.output_type)
183 for type in ['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg']:
184 if out.hasattr(type):
185 figname,data = _new_figure(out[type], type,count)
186 cell.outputs[i][type] = figname
187 out[type] = figname
188 print('set',type, 'to' ,figname)
189 other[figname] = data
190 count = count+1
191 return nb,other
192
193
194 def print_transformer(nb,other):
195 count=0
196 for worksheet in nb.worksheets:
197 for cell in worksheet.cells:
198 cell.type = cell.cell_type
199 for i,out in enumerate(cell.get('outputs', [])):
200 print(cell.outputs)
201 return nb,other
159
202
160 class ConverterTemplate(Configurable):
203 class ConverterTemplate(Configurable):
161 """ A Jinja2 base converter templates"""
204 """ A Jinja2 base converter templates"""
@@ -198,6 +241,8 b' class ConverterTemplate(Configurable):'
198 self.nb = None
241 self.nb = None
199 self.preprocessors = preprocessors
242 self.preprocessors = preprocessors
200 self.preprocessors.append(haspyout_transformer)
243 self.preprocessors.append(haspyout_transformer)
244 self.preprocessors.append(outline_figure_transformer)
245 self.preprocessors.append(print_transformer)
201 super(ConverterTemplate, self).__init__(config=config, **kw)
246 super(ConverterTemplate, self).__init__(config=config, **kw)
202 self.env.filters['filter_data_type'] = self.filter_data_type
247 self.env.filters['filter_data_type'] = self.filter_data_type
203 self.template = self.env.get_template(tplfile+self.ext)
248 self.template = self.env.get_template(tplfile+self.ext)
@@ -212,7 +257,7 b' class ConverterTemplate(Configurable):'
212 nb = self.nb
257 nb = self.nb
213
258
214 for preprocessor in self.preprocessors:
259 for preprocessor in self.preprocessors:
215 nb = preprocessor(nb,{})
260 nb,others = preprocessor(nb,{})
216
261
217 return nb
262 return nb
218
263
@@ -17,7 +17,7 b''
17 ((*- endblock -*))
17 ((*- endblock -*))
18 ((*- endif -*))
18 ((*- endif -*))
19 ((*- if type in ['png']*))
19 ((*- if type in ['png']*))
20 ((*- block data_png -*))
20 ((*- block data_png scoped-*))
21 ->> png
21 ->> png
22 ((*- endblock -*))
22 ((*- endblock -*))
23 ((*- endif -*))
23 ((*- endif -*))
@@ -35,6 +35,13 b' it introduces a new line'
35 ((( super() )))
35 ((( super() )))
36 \end{codeoutput}((* endblock *))
36 \end{codeoutput}((* endblock *))
37
37
38 ((*- block data_png -*))
39 ++(((output.png)))++
40 \begin{center}
41 \includegraphics[width=0.7\textwidth]{(((output.png)))}
42 \par
43 \end{center}
44 ((*- endblock -*))
38
45
39 ((* block pyout *))
46 ((* block pyout *))
40 ((( output.text)))
47 ((( output.text)))
General Comments 0
You need to be logged in to leave comments. Login now