##// END OF EJS Templates
Use globals dict to find right export function instead of...
Jonathan Frederic -
Show More
@@ -1,487 +1,483 b''
1 """
1 """
2 Module containing single call export functions.
2 Module containing single call export functions.
3 """
3 """
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2013, the IPython Development Team.
5 # Copyright (c) 2013, the IPython Development Team.
6 #
6 #
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8 #
8 #
9 # The full license is in the file COPYING.txt, distributed with this software.
9 # The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15
15
16 import sys
16 import sys
17 import inspect
17 import inspect
18
18
19 from IPython.nbformat.v3.nbbase import NotebookNode
19 from IPython.nbformat.v3.nbbase import NotebookNode
20
20
21 from .exporters.exporter import Exporter
21 from .exporters.exporter import Exporter
22 from .exporters.basichtml import BasicHtmlExporter
22 from .exporters.basichtml import BasicHtmlExporter
23 from .exporters.fullhtml import FullHtmlExporter
23 from .exporters.fullhtml import FullHtmlExporter
24 from .exporters.latex import LatexExporter
24 from .exporters.latex import LatexExporter
25 from .exporters.markdown import MarkdownExporter
25 from .exporters.markdown import MarkdownExporter
26 from .exporters.python import PythonExporter
26 from .exporters.python import PythonExporter
27 from .exporters.python_armor import PythonArmorExporter
27 from .exporters.python_armor import PythonArmorExporter
28 from .exporters.reveal import RevealExporter
28 from .exporters.reveal import RevealExporter
29 from .exporters.rst import RstExporter
29 from .exporters.rst import RstExporter
30 from .exporters.sphinx_howto import SphinxHowtoExporter
30 from .exporters.sphinx_howto import SphinxHowtoExporter
31 from .exporters.sphinx_manual import SphinxManualExporter
31 from .exporters.sphinx_manual import SphinxManualExporter
32
32
33
33
34 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
35 # Functions
35 # Functions
36 #-----------------------------------------------------------------------------
36 #-----------------------------------------------------------------------------
37
37
38 def export(nb, config=None, transformers=None, filters=None, exporter_type=Exporter):
38 def export(nb, config=None, transformers=None, filters=None, exporter_type=Exporter):
39 """
39 """
40 Export a notebook object using specific exporter class.
40 Export a notebook object using specific exporter class.
41
41
42 Parameters
42 Parameters
43 ----------
43 ----------
44 config : config
44 config : config
45 User configuration instance.
45 User configuration instance.
46 transformers : list[of transformer]
46 transformers : list[of transformer]
47 Custom transformers to apply to the notebook prior to engaging
47 Custom transformers to apply to the notebook prior to engaging
48 the Jinja template engine. Any transformers specified here
48 the Jinja template engine. Any transformers specified here
49 will override existing transformers if a naming conflict
49 will override existing transformers if a naming conflict
50 occurs.
50 occurs.
51 filters : list[of filter]
51 filters : list[of filter]
52 Custom filters to make accessible to the Jinja templates. Any
52 Custom filters to make accessible to the Jinja templates. Any
53 filters specified here will override existing filters if a
53 filters specified here will override existing filters if a
54 naming conflict occurs.
54 naming conflict occurs.
55 exporter_type:
55 exporter_type:
56 Class type of the exporter that should be used. This method
56 Class type of the exporter that should be used. This method
57 will initialize it's own instance of the class. It is
57 will initialize it's own instance of the class. It is
58 ASSUMED that the class type provided exposes a
58 ASSUMED that the class type provided exposes a
59 constructor (__init__) with the same signature as the
59 constructor (__init__) with the same signature as the
60 base Exporter class.
60 base Exporter class.
61
61
62 Returns
62 Returns
63 ----------
63 ----------
64 tuple- output, resources, exporter_instance
64 tuple- output, resources, exporter_instance
65 output : str
65 output : str
66 Jinja 2 output. This is the resulting converted notebook.
66 Jinja 2 output. This is the resulting converted notebook.
67 resources : dictionary
67 resources : dictionary
68 Dictionary of resources used prior to and during the conversion
68 Dictionary of resources used prior to and during the conversion
69 process.
69 process.
70 exporter_instance : Exporter
70 exporter_instance : Exporter
71 Instance of the Exporter class used to export the document. Useful
71 Instance of the Exporter class used to export the document. Useful
72 to caller because it provides a 'file_extension' property which
72 to caller because it provides a 'file_extension' property which
73 specifies what extension the output should be saved as.
73 specifies what extension the output should be saved as.
74 """
74 """
75
75
76 #Check arguments
76 #Check arguments
77 if exporter_type is None:
77 if exporter_type is None:
78 raise TypeError("Exporter is None")
78 raise TypeError("Exporter is None")
79 elif not issubclass(exporter_type, Exporter):
79 elif not issubclass(exporter_type, Exporter):
80 raise TypeError("Exporter type does not inherit from Exporter (base)")
80 raise TypeError("Exporter type does not inherit from Exporter (base)")
81
81
82 if nb is None:
82 if nb is None:
83 raise TypeError("nb is None")
83 raise TypeError("nb is None")
84
84
85 #Create the exporter
85 #Create the exporter
86 exporter_instance = exporter_type(preprocessors=transformers,
86 exporter_instance = exporter_type(preprocessors=transformers,
87 jinja_filters=filters, config=config)
87 jinja_filters=filters, config=config)
88
88
89 #Try to convert the notebook using the appropriate conversion function.
89 #Try to convert the notebook using the appropriate conversion function.
90 if isinstance(nb, NotebookNode):
90 if isinstance(nb, NotebookNode):
91 output, resources = exporter_instance.from_notebook_node(nb)
91 output, resources = exporter_instance.from_notebook_node(nb)
92 elif isinstance(nb, basestring):
92 elif isinstance(nb, basestring):
93 output, resources = exporter_instance.from_filename(nb)
93 output, resources = exporter_instance.from_filename(nb)
94 else:
94 else:
95 output, resources = exporter_instance.from_file(nb)
95 output, resources = exporter_instance.from_file(nb)
96 return output, resources, exporter_instance
96 return output, resources, exporter_instance
97
97
98
98
99 def export_sphinx_manual(nb, config=None, transformers=None, filters=None):
99 def export_sphinx_manual(nb, config=None, transformers=None, filters=None):
100 """
100 """
101 Export a notebook object to Sphinx Manual LaTeX
101 Export a notebook object to Sphinx Manual LaTeX
102
102
103 Parameters
103 Parameters
104 ----------
104 ----------
105 config : config
105 config : config
106 User configuration instance.
106 User configuration instance.
107 transformers : list[of transformer]
107 transformers : list[of transformer]
108 Custom transformers to apply to the notebook prior to engaging
108 Custom transformers to apply to the notebook prior to engaging
109 the Jinja template engine. Any transformers specified here
109 the Jinja template engine. Any transformers specified here
110 will override existing transformers if a naming conflict
110 will override existing transformers if a naming conflict
111 occurs.
111 occurs.
112 filters : list[of filter]
112 filters : list[of filter]
113 Custom filters to make accessible to the Jinja templates. Any
113 Custom filters to make accessible to the Jinja templates. Any
114 filters specified here will override existing filters if a
114 filters specified here will override existing filters if a
115 naming conflict occurs.
115 naming conflict occurs.
116
116
117 Returns
117 Returns
118 ----------
118 ----------
119 tuple- output, resources, exporter_instance
119 tuple- output, resources, exporter_instance
120 output : str
120 output : str
121 Jinja 2 output. This is the resulting converted notebook.
121 Jinja 2 output. This is the resulting converted notebook.
122 resources : dictionary
122 resources : dictionary
123 Dictionary of resources used prior to and during the conversion
123 Dictionary of resources used prior to and during the conversion
124 process.
124 process.
125 exporter_instance : Exporter
125 exporter_instance : Exporter
126 Instance of the Exporter class used to export the document. Useful
126 Instance of the Exporter class used to export the document. Useful
127 to caller because it provides a 'file_extension' property which
127 to caller because it provides a 'file_extension' property which
128 specifies what extension the output should be saved as.
128 specifies what extension the output should be saved as.
129 """
129 """
130 return export(nb, config, transformers, filters, SphinxManualExporter)
130 return export(nb, config, transformers, filters, SphinxManualExporter)
131
131
132
132
133 def export_sphinx_howto(nb, config=None, transformers=None, filters=None):
133 def export_sphinx_howto(nb, config=None, transformers=None, filters=None):
134 """
134 """
135 Export a notebook object to Sphinx HowTo LaTeX
135 Export a notebook object to Sphinx HowTo LaTeX
136
136
137 Parameters
137 Parameters
138 ----------
138 ----------
139 config : config
139 config : config
140 User configuration instance.
140 User configuration instance.
141 transformers : list[of transformer]
141 transformers : list[of transformer]
142 Custom transformers to apply to the notebook prior to engaging
142 Custom transformers to apply to the notebook prior to engaging
143 the Jinja template engine. Any transformers specified here
143 the Jinja template engine. Any transformers specified here
144 will override existing transformers if a naming conflict
144 will override existing transformers if a naming conflict
145 occurs.
145 occurs.
146 filters : list[of filter]
146 filters : list[of filter]
147 Custom filters to make accessible to the Jinja templates. Any
147 Custom filters to make accessible to the Jinja templates. Any
148 filters specified here will override existing filters if a
148 filters specified here will override existing filters if a
149 naming conflict occurs.
149 naming conflict occurs.
150
150
151 Returns
151 Returns
152 ----------
152 ----------
153 tuple- output, resources, exporter_instance
153 tuple- output, resources, exporter_instance
154 output : str
154 output : str
155 Jinja 2 output. This is the resulting converted notebook.
155 Jinja 2 output. This is the resulting converted notebook.
156 resources : dictionary
156 resources : dictionary
157 Dictionary of resources used prior to and during the conversion
157 Dictionary of resources used prior to and during the conversion
158 process.
158 process.
159 exporter_instance : Exporter
159 exporter_instance : Exporter
160 Instance of the Exporter class used to export the document. Useful
160 Instance of the Exporter class used to export the document. Useful
161 to caller because it provides a 'file_extension' property which
161 to caller because it provides a 'file_extension' property which
162 specifies what extension the output should be saved as.
162 specifies what extension the output should be saved as.
163 """
163 """
164 return export(nb, config, transformers, filters, SphinxHowtoExporter)
164 return export(nb, config, transformers, filters, SphinxHowtoExporter)
165
165
166
166
167 def export_basic_html(nb, config=None, transformers=None, filters=None):
167 def export_basic_html(nb, config=None, transformers=None, filters=None):
168 """
168 """
169 Export a notebook object to Basic HTML
169 Export a notebook object to Basic HTML
170
170
171 Parameters
171 Parameters
172 ----------
172 ----------
173 config : config
173 config : config
174 User configuration instance.
174 User configuration instance.
175 transformers : list[of transformer]
175 transformers : list[of transformer]
176 Custom transformers to apply to the notebook prior to engaging
176 Custom transformers to apply to the notebook prior to engaging
177 the Jinja template engine. Any transformers specified here
177 the Jinja template engine. Any transformers specified here
178 will override existing transformers if a naming conflict
178 will override existing transformers if a naming conflict
179 occurs.
179 occurs.
180 filters : list[of filter]
180 filters : list[of filter]
181 Custom filters to make accessible to the Jinja templates. Any
181 Custom filters to make accessible to the Jinja templates. Any
182 filters specified here will override existing filters if a
182 filters specified here will override existing filters if a
183 naming conflict occurs.
183 naming conflict occurs.
184
184
185 Returns
185 Returns
186 ----------
186 ----------
187 tuple- output, resources, exporter_instance
187 tuple- output, resources, exporter_instance
188 output : str
188 output : str
189 Jinja 2 output. This is the resulting converted notebook.
189 Jinja 2 output. This is the resulting converted notebook.
190 resources : dictionary
190 resources : dictionary
191 Dictionary of resources used prior to and during the conversion
191 Dictionary of resources used prior to and during the conversion
192 process.
192 process.
193 exporter_instance : Exporter
193 exporter_instance : Exporter
194 Instance of the Exporter class used to export the document. Useful
194 Instance of the Exporter class used to export the document. Useful
195 to caller because it provides a 'file_extension' property which
195 to caller because it provides a 'file_extension' property which
196 specifies what extension the output should be saved as.
196 specifies what extension the output should be saved as.
197 """
197 """
198 return export(nb, config, transformers, filters, BasicHtmlExporter)
198 return export(nb, config, transformers, filters, BasicHtmlExporter)
199
199
200
200
201 def export_full_html(nb, config=None, transformers=None, filters=None):
201 def export_full_html(nb, config=None, transformers=None, filters=None):
202 """
202 """
203 Export a notebook object to Full HTML
203 Export a notebook object to Full HTML
204
204
205 Parameters
205 Parameters
206 ----------
206 ----------
207 config : config
207 config : config
208 User configuration instance.
208 User configuration instance.
209 transformers : list[of transformer]
209 transformers : list[of transformer]
210 Custom transformers to apply to the notebook prior to engaging
210 Custom transformers to apply to the notebook prior to engaging
211 the Jinja template engine. Any transformers specified here
211 the Jinja template engine. Any transformers specified here
212 will override existing transformers if a naming conflict
212 will override existing transformers if a naming conflict
213 occurs.
213 occurs.
214 filters : list[of filter]
214 filters : list[of filter]
215 Custom filters to make accessible to the Jinja templates. Any
215 Custom filters to make accessible to the Jinja templates. Any
216 filters specified here will override existing filters if a
216 filters specified here will override existing filters if a
217 naming conflict occurs.
217 naming conflict occurs.
218
218
219 Returns
219 Returns
220 ----------
220 ----------
221 tuple- output, resources, exporter_instance
221 tuple- output, resources, exporter_instance
222 output : str
222 output : str
223 Jinja 2 output. This is the resulting converted notebook.
223 Jinja 2 output. This is the resulting converted notebook.
224 resources : dictionary
224 resources : dictionary
225 Dictionary of resources used prior to and during the conversion
225 Dictionary of resources used prior to and during the conversion
226 process.
226 process.
227 exporter_instance : Exporter
227 exporter_instance : Exporter
228 Instance of the Exporter class used to export the document. Useful
228 Instance of the Exporter class used to export the document. Useful
229 to caller because it provides a 'file_extension' property which
229 to caller because it provides a 'file_extension' property which
230 specifies what extension the output should be saved as.
230 specifies what extension the output should be saved as.
231 """
231 """
232 return export(nb, config, transformers, filters, FullHtmlExporter)
232 return export(nb, config, transformers, filters, FullHtmlExporter)
233
233
234
234
235 def export_latex(nb, config=None, transformers=None, filters=None):
235 def export_latex(nb, config=None, transformers=None, filters=None):
236 """
236 """
237 Export a notebook object to LaTeX
237 Export a notebook object to LaTeX
238
238
239 Parameters
239 Parameters
240 ----------
240 ----------
241 config : config
241 config : config
242 User configuration instance.
242 User configuration instance.
243 transformers : list[of transformer]
243 transformers : list[of transformer]
244 Custom transformers to apply to the notebook prior to engaging
244 Custom transformers to apply to the notebook prior to engaging
245 the Jinja template engine. Any transformers specified here
245 the Jinja template engine. Any transformers specified here
246 will override existing transformers if a naming conflict
246 will override existing transformers if a naming conflict
247 occurs.
247 occurs.
248 filters : list[of filter]
248 filters : list[of filter]
249 Custom filters to make accessible to the Jinja templates. Any
249 Custom filters to make accessible to the Jinja templates. Any
250 filters specified here will override existing filters if a
250 filters specified here will override existing filters if a
251 naming conflict occurs.
251 naming conflict occurs.
252
252
253 Returns
253 Returns
254 ----------
254 ----------
255 tuple- output, resources, exporter_instance
255 tuple- output, resources, exporter_instance
256 output : str
256 output : str
257 Jinja 2 output. This is the resulting converted notebook.
257 Jinja 2 output. This is the resulting converted notebook.
258 resources : dictionary
258 resources : dictionary
259 Dictionary of resources used prior to and during the conversion
259 Dictionary of resources used prior to and during the conversion
260 process.
260 process.
261 exporter_instance : Exporter
261 exporter_instance : Exporter
262 Instance of the Exporter class used to export the document. Useful
262 Instance of the Exporter class used to export the document. Useful
263 to caller because it provides a 'file_extension' property which
263 to caller because it provides a 'file_extension' property which
264 specifies what extension the output should be saved as.
264 specifies what extension the output should be saved as.
265 """
265 """
266 return export(nb, config, transformers, filters, LatexExporter)
266 return export(nb, config, transformers, filters, LatexExporter)
267
267
268
268
269 def export_markdown(nb, config=None, transformers=None, filters=None):
269 def export_markdown(nb, config=None, transformers=None, filters=None):
270 """
270 """
271 Export a notebook object to Markdown
271 Export a notebook object to Markdown
272
272
273 Parameters
273 Parameters
274 ----------
274 ----------
275 config : config
275 config : config
276 User configuration instance.
276 User configuration instance.
277 transformers : list[of transformer]
277 transformers : list[of transformer]
278 Custom transformers to apply to the notebook prior to engaging
278 Custom transformers to apply to the notebook prior to engaging
279 the Jinja template engine. Any transformers specified here
279 the Jinja template engine. Any transformers specified here
280 will override existing transformers if a naming conflict
280 will override existing transformers if a naming conflict
281 occurs.
281 occurs.
282 filters : list[of filter]
282 filters : list[of filter]
283 Custom filters to make accessible to the Jinja templates. Any
283 Custom filters to make accessible to the Jinja templates. Any
284 filters specified here will override existing filters if a
284 filters specified here will override existing filters if a
285 naming conflict occurs.
285 naming conflict occurs.
286
286
287 Returns
287 Returns
288 ----------
288 ----------
289 tuple- output, resources, exporter_instance
289 tuple- output, resources, exporter_instance
290 output : str
290 output : str
291 Jinja 2 output. This is the resulting converted notebook.
291 Jinja 2 output. This is the resulting converted notebook.
292 resources : dictionary
292 resources : dictionary
293 Dictionary of resources used prior to and during the conversion
293 Dictionary of resources used prior to and during the conversion
294 process.
294 process.
295 exporter_instance : Exporter
295 exporter_instance : Exporter
296 Instance of the Exporter class used to export the document. Useful
296 Instance of the Exporter class used to export the document. Useful
297 to caller because it provides a 'file_extension' property which
297 to caller because it provides a 'file_extension' property which
298 specifies what extension the output should be saved as.
298 specifies what extension the output should be saved as.
299 """
299 """
300 return export(nb, config, transformers, filters, MarkdownExporter)
300 return export(nb, config, transformers, filters, MarkdownExporter)
301
301
302
302
303 def export_python(nb, config=None, transformers=None, filters=None):
303 def export_python(nb, config=None, transformers=None, filters=None):
304 """
304 """
305 Export a notebook object to Python
305 Export a notebook object to Python
306
306
307 Parameters
307 Parameters
308 ----------
308 ----------
309 config : config
309 config : config
310 User configuration instance.
310 User configuration instance.
311 transformers : list[of transformer]
311 transformers : list[of transformer]
312 Custom transformers to apply to the notebook prior to engaging
312 Custom transformers to apply to the notebook prior to engaging
313 the Jinja template engine. Any transformers specified here
313 the Jinja template engine. Any transformers specified here
314 will override existing transformers if a naming conflict
314 will override existing transformers if a naming conflict
315 occurs.
315 occurs.
316 filters : list[of filter]
316 filters : list[of filter]
317 Custom filters to make accessible to the Jinja templates. Any
317 Custom filters to make accessible to the Jinja templates. Any
318 filters specified here will override existing filters if a
318 filters specified here will override existing filters if a
319 naming conflict occurs.
319 naming conflict occurs.
320
320
321 Returns
321 Returns
322 ----------
322 ----------
323 tuple- output, resources, exporter_instance
323 tuple- output, resources, exporter_instance
324 output : str
324 output : str
325 Jinja 2 output. This is the resulting converted notebook.
325 Jinja 2 output. This is the resulting converted notebook.
326 resources : dictionary
326 resources : dictionary
327 Dictionary of resources used prior to and during the conversion
327 Dictionary of resources used prior to and during the conversion
328 process.
328 process.
329 exporter_instance : Exporter
329 exporter_instance : Exporter
330 Instance of the Exporter class used to export the document. Useful
330 Instance of the Exporter class used to export the document. Useful
331 to caller because it provides a 'file_extension' property which
331 to caller because it provides a 'file_extension' property which
332 specifies what extension the output should be saved as.
332 specifies what extension the output should be saved as.
333 """
333 """
334 return export(nb, config, transformers, filters, PythonExporter)
334 return export(nb, config, transformers, filters, PythonExporter)
335
335
336
336
337 def export_python_armor(nb, config=None, transformers=None, filters=None):
337 def export_python_armor(nb, config=None, transformers=None, filters=None):
338 """
338 """
339 Export a notebook object to Python (Armor)
339 Export a notebook object to Python (Armor)
340
340
341 Parameters
341 Parameters
342 ----------
342 ----------
343 config : config
343 config : config
344 User configuration instance.
344 User configuration instance.
345 transformers : list[of transformer]
345 transformers : list[of transformer]
346 Custom transformers to apply to the notebook prior to engaging
346 Custom transformers to apply to the notebook prior to engaging
347 the Jinja template engine. Any transformers specified here
347 the Jinja template engine. Any transformers specified here
348 will override existing transformers if a naming conflict
348 will override existing transformers if a naming conflict
349 occurs.
349 occurs.
350 filters : list[of filter]
350 filters : list[of filter]
351 Custom filters to make accessible to the Jinja templates. Any
351 Custom filters to make accessible to the Jinja templates. Any
352 filters specified here will override existing filters if a
352 filters specified here will override existing filters if a
353 naming conflict occurs.
353 naming conflict occurs.
354
354
355 Returns
355 Returns
356 ----------
356 ----------
357 tuple- output, resources, exporter_instance
357 tuple- output, resources, exporter_instance
358 output : str
358 output : str
359 Jinja 2 output. This is the resulting converted notebook.
359 Jinja 2 output. This is the resulting converted notebook.
360 resources : dictionary
360 resources : dictionary
361 Dictionary of resources used prior to and during the conversion
361 Dictionary of resources used prior to and during the conversion
362 process.
362 process.
363 exporter_instance : Exporter
363 exporter_instance : Exporter
364 Instance of the Exporter class used to export the document. Useful
364 Instance of the Exporter class used to export the document. Useful
365 to caller because it provides a 'file_extension' property which
365 to caller because it provides a 'file_extension' property which
366 specifies what extension the output should be saved as.
366 specifies what extension the output should be saved as.
367 """
367 """
368 return export(nb, config, transformers, filters, PythonArmorExporter)
368 return export(nb, config, transformers, filters, PythonArmorExporter)
369
369
370
370
371 def export_reveal(nb, config=None, transformers=None, filters=None):
371 def export_reveal(nb, config=None, transformers=None, filters=None):
372 """
372 """
373 Export a notebook object to Reveal
373 Export a notebook object to Reveal
374
374
375 Parameters
375 Parameters
376 ----------
376 ----------
377 config : config
377 config : config
378 User configuration instance.
378 User configuration instance.
379 transformers : list[of transformer]
379 transformers : list[of transformer]
380 Custom transformers to apply to the notebook prior to engaging
380 Custom transformers to apply to the notebook prior to engaging
381 the Jinja template engine. Any transformers specified here
381 the Jinja template engine. Any transformers specified here
382 will override existing transformers if a naming conflict
382 will override existing transformers if a naming conflict
383 occurs.
383 occurs.
384 filters : list[of filter]
384 filters : list[of filter]
385 Custom filters to make accessible to the Jinja templates. Any
385 Custom filters to make accessible to the Jinja templates. Any
386 filters specified here will override existing filters if a
386 filters specified here will override existing filters if a
387 naming conflict occurs.
387 naming conflict occurs.
388
388
389 Returns
389 Returns
390 ----------
390 ----------
391 tuple- output, resources, exporter_instance
391 tuple- output, resources, exporter_instance
392 output : str
392 output : str
393 Jinja 2 output. This is the resulting converted notebook.
393 Jinja 2 output. This is the resulting converted notebook.
394 resources : dictionary
394 resources : dictionary
395 Dictionary of resources used prior to and during the conversion
395 Dictionary of resources used prior to and during the conversion
396 process.
396 process.
397 exporter_instance : Exporter
397 exporter_instance : Exporter
398 Instance of the Exporter class used to export the document. Useful
398 Instance of the Exporter class used to export the document. Useful
399 to caller because it provides a 'file_extension' property which
399 to caller because it provides a 'file_extension' property which
400 specifies what extension the output should be saved as.
400 specifies what extension the output should be saved as.
401 """
401 """
402 return export(nb, config, transformers, filters, RevealExporter)
402 return export(nb, config, transformers, filters, RevealExporter)
403
403
404
404
405 def export_rst(nb, config=None, transformers=None, filters=None):
405 def export_rst(nb, config=None, transformers=None, filters=None):
406 """
406 """
407 Export a notebook object to RST
407 Export a notebook object to RST
408
408
409 Parameters
409 Parameters
410 ----------
410 ----------
411 config : config
411 config : config
412 User configuration instance.
412 User configuration instance.
413 transformers : list[of transformer]
413 transformers : list[of transformer]
414 Custom transformers to apply to the notebook prior to engaging
414 Custom transformers to apply to the notebook prior to engaging
415 the Jinja template engine. Any transformers specified here
415 the Jinja template engine. Any transformers specified here
416 will override existing transformers if a naming conflict
416 will override existing transformers if a naming conflict
417 occurs.
417 occurs.
418 filters : list[of filter]
418 filters : list[of filter]
419 Custom filters to make accessible to the Jinja templates. Any
419 Custom filters to make accessible to the Jinja templates. Any
420 filters specified here will override existing filters if a
420 filters specified here will override existing filters if a
421 naming conflict occurs.
421 naming conflict occurs.
422
422
423 Returns
423 Returns
424 ----------
424 ----------
425 tuple- output, resources, exporter_instance
425 tuple- output, resources, exporter_instance
426 output : str
426 output : str
427 Jinja 2 output. This is the resulting converted notebook.
427 Jinja 2 output. This is the resulting converted notebook.
428 resources : dictionary
428 resources : dictionary
429 Dictionary of resources used prior to and during the conversion
429 Dictionary of resources used prior to and during the conversion
430 process.
430 process.
431 exporter_instance : Exporter
431 exporter_instance : Exporter
432 Instance of the Exporter class used to export the document. Useful
432 Instance of the Exporter class used to export the document. Useful
433 to caller because it provides a 'file_extension' property which
433 to caller because it provides a 'file_extension' property which
434 specifies what extension the output should be saved as.
434 specifies what extension the output should be saved as.
435 """
435 """
436 return export(nb, config, transformers, filters, RstExporter)
436 return export(nb, config, transformers, filters, RstExporter)
437
437
438
438
439 def export_by_name(nb, template_name, config=None, transformers=None, filters=None):
439 def export_by_name(nb, template_name, config=None, transformers=None, filters=None):
440 """
440 """
441 Export a notebook object to a template type by its name. Reflection
441 Export a notebook object to a template type by its name. Reflection
442 (Inspect) is used to find the template's corresponding explicit export
442 (Inspect) is used to find the template's corresponding explicit export
443 method defined in this module. That method is then called directly.
443 method defined in this module. That method is then called directly.
444
444
445 Parameters
445 Parameters
446 ----------
446 ----------
447 template_name : str
447 template_name : str
448 Name of the template style to export to.
448 Name of the template style to export to.
449 config : config
449 config : config
450 User configuration instance.
450 User configuration instance.
451 transformers : list[of transformer]
451 transformers : list[of transformer]
452 Custom transformers to apply to the notebook prior to engaging
452 Custom transformers to apply to the notebook prior to engaging
453 the Jinja template engine. Any transformers specified here
453 the Jinja template engine. Any transformers specified here
454 will override existing transformers if a naming conflict
454 will override existing transformers if a naming conflict
455 occurs.
455 occurs.
456 filters : list[of filter]
456 filters : list[of filter]
457 Custom filters to make accessible to the Jinja templates. Any
457 Custom filters to make accessible to the Jinja templates. Any
458 filters specified here will override existing filters if a
458 filters specified here will override existing filters if a
459 naming conflict occurs.
459 naming conflict occurs.
460
460
461 Returns
461 Returns
462 ----------
462 ----------
463 tuple- (output, resources, exporter_instance)
463 tuple- (output, resources, exporter_instance)
464 None- if template not found
464 None- if template not found
465
465
466 output : str
466 output : str
467 Jinja 2 output. This is the resulting converted notebook.
467 Jinja 2 output. This is the resulting converted notebook.
468 resources : dictionary
468 resources : dictionary
469 Dictionary of resources used prior to and during the conversion
469 Dictionary of resources used prior to and during the conversion
470 process.
470 process.
471 exporter_instance : Exporter
471 exporter_instance : Exporter
472 Instance of the Exporter class used to export the document. Useful
472 Instance of the Exporter class used to export the document. Useful
473 to caller because it provides a 'file_extension' property which
473 to caller because it provides a 'file_extension' property which
474 specifies what extension the output should be saved as.
474 specifies what extension the output should be saved as.
475 """
475 """
476
476
477 #Use reflection to get functions defined in this module.
477 function_name = "export_" + template_name.lower()
478 cls_functions = inspect.getmembers(sys.modules[__name__], inspect.isfunction)
479
478
480 #Check if the characters following "export_" (7 char) equals the template name.
479 if function_name in globals():
481 for (function_name, function_handle) in cls_functions:
480 return globals()[function_name](nb, config, transformers, filters)
482 function_name = function_name.lower()
481 else:
483 if (len(function_name) > 7 and function_name[7:] == template_name.lower()):
482 return None
484 return function_handle(nb, config, transformers, filters)
485
486 return None
487 No newline at end of file
483
General Comments 0
You need to be logged in to leave comments. Login now