##// END OF EJS Templates
Finished rename/refact on API namespace
Jonathan Frederic -
Show More
@@ -1,52 +1,55 b''
1 """
1 """
2 Exporter that exports Basic HTML.
2 Exporter that exports Basic HTML.
3 """
3 """
4
4
5 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
7 #
7 #
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9 #
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 from IPython.utils.traitlets import Unicode
17 from IPython.utils.traitlets import Unicode
18
18
19 import nbconvert.transformers.csshtmlheader
19 import nbconvert.transformers.csshtmlheader
20
20
21 # local import
21 # local import
22 import exporter
22 import exporter
23
23
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 # Classes
25 # Classes
26 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
27
27
28 class BasicHtmlExporter(exporter.Exporter):
28 class BasicHtmlExporter(exporter.Exporter):
29 """
29 """
30 Exports a basic HTML document. This exporter assists with the export of
30 Exports a basic HTML document. This exporter assists with the export of
31 HTML. Inherit from it if you are writing your own HTML template and need
31 HTML. Inherit from it if you are writing your own HTML template and need
32 custom tranformers/filters. If you don't need custom tranformers/
32 custom tranformers/filters. If you don't need custom tranformers/
33 filters, just change the 'template_file' config option.
33 filters, just change the 'template_file' config option.
34 """
34 """
35
35
36 file_extension = Unicode(
36 file_extension = Unicode(
37 'html', config=True,
37 'html', config=True,
38 help="Extension of the file that should be written to disk"
38 help="Extension of the file that should be written to disk"
39 )
39 )
40
40
41 template_file = Unicode(
41 template_file = Unicode(
42 'basichtml', config=True,
42 'basichtml', config=True,
43 help="Name of the template file to use")
43 help="Name of the template file to use")
44
44
45 def _register_transformers(self):
45 def _register_transformers(self):
46 """
47 Register all of the transformers needed for this exporter.
48 """
46
49
47 #Register the transformers of the base class.
50 #Register the transformers of the base class.
48 super(BasicHtmlExporter, self)._register_transformers()
51 super(BasicHtmlExporter, self)._register_transformers()
49
52
50 #Register latex transformer
53 #Register latex transformer
51 self.register_transformer(nbconvert.transformers.csshtmlheader.CSSHtmlHeaderTransformer)
54 self.register_transformer(nbconvert.transformers.csshtmlheader.CSSHtmlHeaderTransformer)
52 No newline at end of file
55
@@ -1,51 +1,483 b''
1 """
1 """
2 Module containing easy to use conversion 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 #-----------------------------------------------------------------------------
13 # Imports
14 #-----------------------------------------------------------------------------
15
16 import sys
17 import inspect
18
12 from .exporter import Exporter
19 from .exporter import Exporter
13
20
14 from IPython.nbformat.v3.nbbase import NotebookNode
21 from IPython.nbformat.v3.nbbase import NotebookNode
15
22
23 from .fullhtml import FullHtmlExporter
24 from .basichtml import BasicHtmlExporter
25 from .latex import LatexExporter
26 from .markdown import MarkdownExporter
27 from .python import PythonExporter
28 from .python_armor import PythonArmorExporter
29 from .reveal import RevealExporter
30 from .rst import RstExporter
31 from .sphinx_howto import SphinxHowtoExporter
32 from .sphinx_manual import SphinxManualExporter
33
16 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
17 # Functions
35 # Functions
18 #-----------------------------------------------------------------------------
36 #-----------------------------------------------------------------------------
19
37
20 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 """
40 Export a notebook object using specific exporter class.
41
42 Parameters
43 ----------
44 config : config
45 User configuration instance.
46 transformers : list[of transformer]
47 Custom transformers to apply to the notebook prior to engaging
48 the Jinja template engine. Any transformers specified here
49 will override existing transformers if a naming conflict
50 occurs.
51 filters : list[of filter]
52 Custom filters to make accessible to the Jinja templates. Any
53 filters specified here will override existing filters if a
54 naming conflict occurs.
55 exporter_type:
56 Class type of the exporter that should be used. This method
57 will initialize it's own instance of the class. It is
58 ASSUMED that the class type provided exposes a
59 constructor (__init__) with the same signature as the
60 base Exporter class.
61
62 Returns
63 ----------
64 tuple- output, resources, exporter_instance
65 output : str
66 Jinja 2 output. This is the resulting converted notebook.
67 resources : dictionary
68 Dictionary of resources used prior to and during the conversion
69 process.
70 exporter_instance : Exporter
71 Instance of the Exporter class used to export the document. Useful
72 to caller because it provides a 'file_extension' property which
73 specifies what extension the output should be saved as.
74 """
21
75
22 #Check arguments
76 #Check arguments
23 if exporter_type is None:
77 if exporter_type is None:
24 raise TypeError("Exporter is None")
78 raise TypeError("Exporter is None")
25 elif not issubclass(exporter_type, Exporter):
79 elif not issubclass(exporter_type, Exporter):
26 raise TypeError("Exporter type does not inherit from Exporter (base)")
80 raise TypeError("Exporter type does not inherit from Exporter (base)")
27
81
28 if nb is None:
82 if nb is None:
29 raise TypeError("nb is None")
83 raise TypeError("nb is None")
30
84
31 #Create the exporter
85 #Create the exporter
32 exporter_instance = exporter_type(preprocessors=transformers, jinja_filters=filters, config=config)
86 exporter_instance = exporter_type(preprocessors=transformers,
87 jinja_filters=filters, config=config)
33
88
34 #Try to convert the notebook using the appropriate conversion function.
89 #Try to convert the notebook using the appropriate conversion function.
35 if isinstance(nb, NotebookNode):
90 if isinstance(nb, NotebookNode):
36 output, resources = exporter_instance.from_notebook_node(nb)
91 output, resources = exporter_instance.from_notebook_node(nb)
37 elif isinstance(nb, basestring):
92 elif isinstance(nb, basestring):
38 output, resources = exporter_instance.from_filename(nb)
93 output, resources = exporter_instance.from_filename(nb)
39 else:
94 else:
40 output, resources = exporter_instance.from_file(nb)
95 output, resources = exporter_instance.from_file(nb)
41 return output, resources, exporter_instance
96 return output, resources, exporter_instance
42
97
43
98
44 def load_class(template_name):
99 def export_sphinx_manual(nb, config=None, transformers=None, filters=None):
45 class_name = template_name[0].upper() + template_name[1:] + "Exporter"
100 """
46 module = __import__('nbconvert.api.' + template_name, fromlist=[class_name])
101 Export a notebook object to Sphinx Manual LaTeX
47 return getattr(module, class_name)
102
103 Parameters
104 ----------
105 config : config
106 User configuration instance.
107 transformers : list[of transformer]
108 Custom transformers to apply to the notebook prior to engaging
109 the Jinja template engine. Any transformers specified here
110 will override existing transformers if a naming conflict
111 occurs.
112 filters : list[of filter]
113 Custom filters to make accessible to the Jinja templates. Any
114 filters specified here will override existing filters if a
115 naming conflict occurs.
116
117 Returns
118 ----------
119 tuple- output, resources, exporter_instance
120 output : str
121 Jinja 2 output. This is the resulting converted notebook.
122 resources : dictionary
123 Dictionary of resources used prior to and during the conversion
124 process.
125 exporter_instance : Exporter
126 Instance of the Exporter class used to export the document. Useful
127 to caller because it provides a 'file_extension' property which
128 specifies what extension the output should be saved as.
129 """
130 return export(nb, config, transformers, filters, SphinxManualExporter)
131
132
133 def export_sphinx_howto(nb, config=None, transformers=None, filters=None):
134 """
135 Export a notebook object to Sphinx HowTo LaTeX
136
137 Parameters
138 ----------
139 config : config
140 User configuration instance.
141 transformers : list[of transformer]
142 Custom transformers to apply to the notebook prior to engaging
143 the Jinja template engine. Any transformers specified here
144 will override existing transformers if a naming conflict
145 occurs.
146 filters : list[of filter]
147 Custom filters to make accessible to the Jinja templates. Any
148 filters specified here will override existing filters if a
149 naming conflict occurs.
150
151 Returns
152 ----------
153 tuple- output, resources, exporter_instance
154 output : str
155 Jinja 2 output. This is the resulting converted notebook.
156 resources : dictionary
157 Dictionary of resources used prior to and during the conversion
158 process.
159 exporter_instance : Exporter
160 Instance of the Exporter class used to export the document. Useful
161 to caller because it provides a 'file_extension' property which
162 specifies what extension the output should be saved as.
163 """
164 return export(nb, config, transformers, filters, SphinxHowtoExporter)
165
166
167 def export_basic_html(nb, config=None, transformers=None, filters=None):
168 """
169 Export a notebook object to Basic HTML
170
171 Parameters
172 ----------
173 config : config
174 User configuration instance.
175 transformers : list[of transformer]
176 Custom transformers to apply to the notebook prior to engaging
177 the Jinja template engine. Any transformers specified here
178 will override existing transformers if a naming conflict
179 occurs.
180 filters : list[of filter]
181 Custom filters to make accessible to the Jinja templates. Any
182 filters specified here will override existing filters if a
183 naming conflict occurs.
184
185 Returns
186 ----------
187 tuple- output, resources, exporter_instance
188 output : str
189 Jinja 2 output. This is the resulting converted notebook.
190 resources : dictionary
191 Dictionary of resources used prior to and during the conversion
192 process.
193 exporter_instance : Exporter
194 Instance of the Exporter class used to export the document. Useful
195 to caller because it provides a 'file_extension' property which
196 specifies what extension the output should be saved as.
197 """
198 return export(nb, config, transformers, filters, BasicHtmlExporter)
199
200
201 def export_full_html(nb, config=None, transformers=None, filters=None):
202 """
203 Export a notebook object to Full HTML
204
205 Parameters
206 ----------
207 config : config
208 User configuration instance.
209 transformers : list[of transformer]
210 Custom transformers to apply to the notebook prior to engaging
211 the Jinja template engine. Any transformers specified here
212 will override existing transformers if a naming conflict
213 occurs.
214 filters : list[of filter]
215 Custom filters to make accessible to the Jinja templates. Any
216 filters specified here will override existing filters if a
217 naming conflict occurs.
218
219 Returns
220 ----------
221 tuple- output, resources, exporter_instance
222 output : str
223 Jinja 2 output. This is the resulting converted notebook.
224 resources : dictionary
225 Dictionary of resources used prior to and during the conversion
226 process.
227 exporter_instance : Exporter
228 Instance of the Exporter class used to export the document. Useful
229 to caller because it provides a 'file_extension' property which
230 specifies what extension the output should be saved as.
231 """
232 return export(nb, config, transformers, filters, FullHtmlExporter)
233
234
235 def export_latex(nb, config=None, transformers=None, filters=None):
236 """
237 Export a notebook object to LaTeX
238
239 Parameters
240 ----------
241 config : config
242 User configuration instance.
243 transformers : list[of transformer]
244 Custom transformers to apply to the notebook prior to engaging
245 the Jinja template engine. Any transformers specified here
246 will override existing transformers if a naming conflict
247 occurs.
248 filters : list[of filter]
249 Custom filters to make accessible to the Jinja templates. Any
250 filters specified here will override existing filters if a
251 naming conflict occurs.
252
253 Returns
254 ----------
255 tuple- output, resources, exporter_instance
256 output : str
257 Jinja 2 output. This is the resulting converted notebook.
258 resources : dictionary
259 Dictionary of resources used prior to and during the conversion
260 process.
261 exporter_instance : Exporter
262 Instance of the Exporter class used to export the document. Useful
263 to caller because it provides a 'file_extension' property which
264 specifies what extension the output should be saved as.
265 """
266 return export(nb, config, transformers, filters, LatexExporter)
267
268
269 def export_markdown(nb, config=None, transformers=None, filters=None):
270 """
271 Export a notebook object to Markdown
272
273 Parameters
274 ----------
275 config : config
276 User configuration instance.
277 transformers : list[of transformer]
278 Custom transformers to apply to the notebook prior to engaging
279 the Jinja template engine. Any transformers specified here
280 will override existing transformers if a naming conflict
281 occurs.
282 filters : list[of filter]
283 Custom filters to make accessible to the Jinja templates. Any
284 filters specified here will override existing filters if a
285 naming conflict occurs.
286
287 Returns
288 ----------
289 tuple- output, resources, exporter_instance
290 output : str
291 Jinja 2 output. This is the resulting converted notebook.
292 resources : dictionary
293 Dictionary of resources used prior to and during the conversion
294 process.
295 exporter_instance : Exporter
296 Instance of the Exporter class used to export the document. Useful
297 to caller because it provides a 'file_extension' property which
298 specifies what extension the output should be saved as.
299 """
300 return export(nb, config, transformers, filters, MarkdownExporter)
301
302
303 def export_python(nb, config=None, transformers=None, filters=None):
304 """
305 Export a notebook object to Python
306
307 Parameters
308 ----------
309 config : config
310 User configuration instance.
311 transformers : list[of transformer]
312 Custom transformers to apply to the notebook prior to engaging
313 the Jinja template engine. Any transformers specified here
314 will override existing transformers if a naming conflict
315 occurs.
316 filters : list[of filter]
317 Custom filters to make accessible to the Jinja templates. Any
318 filters specified here will override existing filters if a
319 naming conflict occurs.
320
321 Returns
322 ----------
323 tuple- output, resources, exporter_instance
324 output : str
325 Jinja 2 output. This is the resulting converted notebook.
326 resources : dictionary
327 Dictionary of resources used prior to and during the conversion
328 process.
329 exporter_instance : Exporter
330 Instance of the Exporter class used to export the document. Useful
331 to caller because it provides a 'file_extension' property which
332 specifies what extension the output should be saved as.
333 """
334 return export(nb, config, transformers, filters, PythonExporter)
335
336
337 def export_python_armor(nb, config=None, transformers=None, filters=None):
338 """
339 Export a notebook object to Python (Armor)
340
341 Parameters
342 ----------
343 config : config
344 User configuration instance.
345 transformers : list[of transformer]
346 Custom transformers to apply to the notebook prior to engaging
347 the Jinja template engine. Any transformers specified here
348 will override existing transformers if a naming conflict
349 occurs.
350 filters : list[of filter]
351 Custom filters to make accessible to the Jinja templates. Any
352 filters specified here will override existing filters if a
353 naming conflict occurs.
354
355 Returns
356 ----------
357 tuple- output, resources, exporter_instance
358 output : str
359 Jinja 2 output. This is the resulting converted notebook.
360 resources : dictionary
361 Dictionary of resources used prior to and during the conversion
362 process.
363 exporter_instance : Exporter
364 Instance of the Exporter class used to export the document. Useful
365 to caller because it provides a 'file_extension' property which
366 specifies what extension the output should be saved as.
367 """
368 return export(nb, config, transformers, filters, PythonArmorExporter)
369
370
371 def export_reveal(nb, config=None, transformers=None, filters=None):
372 """
373 Export a notebook object to Reveal
374
375 Parameters
376 ----------
377 config : config
378 User configuration instance.
379 transformers : list[of transformer]
380 Custom transformers to apply to the notebook prior to engaging
381 the Jinja template engine. Any transformers specified here
382 will override existing transformers if a naming conflict
383 occurs.
384 filters : list[of filter]
385 Custom filters to make accessible to the Jinja templates. Any
386 filters specified here will override existing filters if a
387 naming conflict occurs.
388
389 Returns
390 ----------
391 tuple- output, resources, exporter_instance
392 output : str
393 Jinja 2 output. This is the resulting converted notebook.
394 resources : dictionary
395 Dictionary of resources used prior to and during the conversion
396 process.
397 exporter_instance : Exporter
398 Instance of the Exporter class used to export the document. Useful
399 to caller because it provides a 'file_extension' property which
400 specifies what extension the output should be saved as.
401 """
402 return export(nb, config, transformers, filters, RevealExporter)
403
404
405 def export_rst(nb, config=None, transformers=None, filters=None):
406 """
407 Export a notebook object to RST
408
409 Parameters
410 ----------
411 config : config
412 User configuration instance.
413 transformers : list[of transformer]
414 Custom transformers to apply to the notebook prior to engaging
415 the Jinja template engine. Any transformers specified here
416 will override existing transformers if a naming conflict
417 occurs.
418 filters : list[of filter]
419 Custom filters to make accessible to the Jinja templates. Any
420 filters specified here will override existing filters if a
421 naming conflict occurs.
422
423 Returns
424 ----------
425 tuple- output, resources, exporter_instance
426 output : str
427 Jinja 2 output. This is the resulting converted notebook.
428 resources : dictionary
429 Dictionary of resources used prior to and during the conversion
430 process.
431 exporter_instance : Exporter
432 Instance of the Exporter class used to export the document. Useful
433 to caller because it provides a 'file_extension' property which
434 specifies what extension the output should be saved as.
435 """
436 return export(nb, config, transformers, filters, RstExporter)
48
437
49
438
50 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):
51 return export(nb, config, transformers, filters, load_class(template_name)) No newline at end of file
440 """
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
443 method defined in this module. That method is then called directly.
444
445 Parameters
446 ----------
447 template_name : str
448 Name of the template style to export to.
449 config : config
450 User configuration instance.
451 transformers : list[of transformer]
452 Custom transformers to apply to the notebook prior to engaging
453 the Jinja template engine. Any transformers specified here
454 will override existing transformers if a naming conflict
455 occurs.
456 filters : list[of filter]
457 Custom filters to make accessible to the Jinja templates. Any
458 filters specified here will override existing filters if a
459 naming conflict occurs.
460
461 Returns
462 ----------
463 tuple- output, resources, exporter_instance
464 output : str
465 Jinja 2 output. This is the resulting converted notebook.
466 resources : dictionary
467 Dictionary of resources used prior to and during the conversion
468 process.
469 exporter_instance : Exporter
470 Instance of the Exporter class used to export the document. Useful
471 to caller because it provides a 'file_extension' property which
472 specifies what extension the output should be saved as.
473 """
474
475 #Use reflection to get functions defined in this module.
476 cls_functions = inspect.getmembers(sys.modules[__name__], inspect.isfunction)
477
478 #Check if the characters following "export_" (7 char) equals the template name.
479 for function in cls_functions:
480 function_name = function.__name__.lower()
481 if (len(function_name) > 7 and function_name[7:] == template_name.lower()):
482 return function(nb, config, transformers, filters)
483 No newline at end of file
@@ -1,205 +1,316 b''
1 """Exporter for the notebook conversion pipeline.
1 """This module defines Exporter, a highly configurable converter
2
2 that uses Jinja2 to export notebook files into different formats.
3 This module defines Exporter, a highly configurable converter
4 that uses Jinja2 to export notebook files into different format.
5
6 You can register both pre-transformers that will act on the notebook format
7 before conversion and jinja filter that would then be available in the templates
8 """
3 """
9
4
10 #-----------------------------------------------------------------------------
5 #-----------------------------------------------------------------------------
11 # Copyright (c) 2013, the IPython Development Team.
6 # Copyright (c) 2013, the IPython Development Team.
12 #
7 #
13 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
14 #
9 #
15 # The full license is in the file COPYING.txt, distributed with this software.
10 # The full license is in the file COPYING.txt, distributed with this software.
16 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
17
12
18 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
19 # Imports
14 # Imports
20 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
21
16
22 from __future__ import print_function, absolute_import
17 from __future__ import print_function, absolute_import
23
18
24 # Stdlib imports
19 # Stdlib imports
25 import io
20 import io
26 import os
21 import os
27 import inspect
22 import inspect
28
23
29 # IPython imports
24 # IPython imports
30 from IPython.config.configurable import Configurable
25 from IPython.config.configurable import Configurable
31 from IPython.nbformat import current as nbformat
26 from IPython.nbformat import current as nbformat
32 from IPython.utils.traitlets import MetaHasTraits, Unicode, List, Bool
27 from IPython.utils.traitlets import MetaHasTraits, Unicode, List, Bool
33 from IPython.utils.text import indent
28 from IPython.utils.text import indent
34
29
35 # other libs/dependencies
30 # other libs/dependencies
36 from jinja2 import Environment, FileSystemLoader
31 from jinja2 import Environment, FileSystemLoader
37 from markdown import markdown
32 from markdown import markdown
38
33
39 # local import
34 # local import
40 import nbconvert.filters.strings
35 import nbconvert.filters.strings
41 import nbconvert.filters.markdown
36 import nbconvert.filters.markdown
42 import nbconvert.filters.latex
37 import nbconvert.filters.latex
43 import nbconvert.filters.datatypefilter
38 import nbconvert.filters.datatypefilter
44 import nbconvert.filters.highlight
39 import nbconvert.filters.highlight
45 import nbconvert.filters.ansi
40 import nbconvert.filters.ansi
46
41
47 import nbconvert.transformers.extractfigure
42 import nbconvert.transformers.extractfigure
48 import nbconvert.transformers.coalescestreams
43 import nbconvert.transformers.coalescestreams
49
44
50
51 #-----------------------------------------------------------------------------
45 #-----------------------------------------------------------------------------
52 # Globals and constants
46 # Globals and constants
53 #-----------------------------------------------------------------------------
47 #-----------------------------------------------------------------------------
54
48
55 #Standard Jinja2 environment constants
56 TEMPLATE_PATH = "/../templates/"
57 TEMPLATE_SKELETON_PATH = "/../templates/skeleton/"
58
59 #Jinja2 extensions to load.
49 #Jinja2 extensions to load.
60 JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols']
50 JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols']
61
51
62 #-----------------------------------------------------------------------------
52 #-----------------------------------------------------------------------------
63 # Class
53 # Class
64 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
65
55
66 class Exporter(Configurable):
56 class Exporter(Configurable):
67
57 """
58 Exports notebooks into other file formats. Uses Jinja 2 templating engine
59 to output new formats. Inherit from this class if you are creating a new
60 template type along with new filters/transformers. If the filters/
61 transformers provided by default suffice, there is no need to inherit from
62 this class. Instead, override the template_file and file_extension
63 traits via a config file.
64 """
65
68 template_file = Unicode(
66 template_file = Unicode(
69 '', config=True,
67 '', config=True,
70 help="Name of the template file to use")
68 help="Name of the template file to use")
71
69
72 file_extension = Unicode(
70 file_extension = Unicode(
73 'txt', config=True,
71 'txt', config=True,
74 help="Extension of the file that should be written to disk"
72 help="Extension of the file that should be written to disk"
75 )
73 )
76
74
75 template_path = Unicode(
76 "/../templates/", config=True,
77 help="Path where the template files are located.")
78
79 template_skeleton_path = Unicode(
80 "/../templates/skeleton/", config=True,
81 help="Path where the template skeleton files are located.")
82
83 #Jinja block definitions
84 jinja_comment_block_start = Unicode(None, config=True)
85 jinja_comment_block_end = Unicode(None, config=True)
86 jinja_variable_block_start = Unicode(None, config=True)
87 jinja_variable_block_end = Unicode(None, config=True)
88 jinja_logic_block_start = Unicode(None, config=True)
89 jinja_logic_block_end = Unicode(None, config=True)
90
77 #Extension that the template files use.
91 #Extension that the template files use.
78 template_extension = ".tpl"
92 template_extension = Unicode(".tpl", config=True)
79
93
80 #Processors that process the input data prior to the export, set in the
94 #Processors that process the input data prior to the export, set in the
81 #constructor for this class.
95 #constructor for this class.
82 preprocessors = []
96 preprocessors = []
83
97
84 # Public Constructor #####################################################
85
98
86 def __init__(self, transformers=None, filters=None, config=None, **kw):
99 def __init__(self, transformers=None, filters=None, config=None, **kw):
100 """
101 Public constructor
87
102
103 Parameters
104 ----------
105 transformers : list[of transformer]
106 Custom transformers to apply to the notebook prior to engaging
107 the Jinja template engine. Any transformers specified here
108 will override existing transformers if a naming conflict
109 occurs.
110 filters : list[of filter]
111 Custom filters to make accessible to the Jinja templates. Any
112 filters specified here will override existing filters if a
113 naming conflict occurs.
114 config : config
115 User configuration instance.
116 """
117
88 #Call the base class constructor
118 #Call the base class constructor
89 super(Exporter, self).__init__(config=config, **kw)
119 super(Exporter, self).__init__(config=config, **kw)
90
120
91 #Standard environment
121 #Standard environment
92 self._init_environment()
122 self._init_environment()
93
123
94 #Add transformers
124 #Add transformers
95 self._register_transformers()
125 self._register_transformers()
96
126
97 #Add filters to the Jinja2 environment
127 #Add filters to the Jinja2 environment
98 self._register_filters()
128 self._register_filters()
99
129
100 #Load user transformers. Overwrite existing transformers if need be.
130 #Load user transformers. Overwrite existing transformers if need be.
101 if not transformers is None:
131 if not transformers is None:
102 for transformer in transformers:
132 for transformer in transformers:
103 self.register_transformer(transformer)
133 self.register_transformer(transformer)
104
134
105 #Load user filters. Overwrite existing filters if need be.
135 #Load user filters. Overwrite existing filters if need be.
106 if not filters is None:
136 if not filters is None:
107 for key, user_filter in filters.iteritems():
137 for key, user_filter in filters.iteritems():
108 if issubclass(user_filter, MetaHasTraits):
138 if issubclass(user_filter, MetaHasTraits):
109 self.environment.filters[key] = user_filter(config=config)
139 self.environment.filters[key] = user_filter(config=config)
110 else:
140 else:
111 self.environment.filters[key] = user_filter
141 self.environment.filters[key] = user_filter
112
142
113 # Public methods #########################################
114
143
115 def from_notebook_node(self, nb):
144 def from_notebook_node(self, nb):
145 """
146 Convert a notebook from a notebook node instance.
147
148 Parameters
149 ----------
150 nb : Notebook node
151 """
152
116 nb, resources = self._preprocess(nb)
153 nb, resources = self._preprocess(nb)
117
154
118 #Load the template file.
155 #Load the template file.
119 self.template = self.environment.get_template(self.template_file+self.template_extension)
156 self.template = self.environment.get_template(self.template_file+self.template_extension)
120
157
121 return self.template.render(nb=nb, resources=resources), resources
158 return self.template.render(nb=nb, resources=resources), resources
122
159
123
160
124 def from_filename(self, filename):
161 def from_filename(self, filename):
162 """
163 Convert a notebook from a notebook file.
164
165 Parameters
166 ----------
167 filename : str
168 Full filename of the notebook file to open and convert.
169 """
170
125 with io.open(filename) as f:
171 with io.open(filename) as f:
126 return self.from_notebook_node(nbformat.read(f, 'json'))
172 return self.from_notebook_node(nbformat.read(f, 'json'))
127
173
128
174
129 def from_file(self, file_stream):
175 def from_file(self, file_stream):
176 """
177 Convert a notebook from a notebook file.
178
179 Parameters
180 ----------
181 file_stream : file-like object
182 Notebook file-like object to convert.
183 """
130 return self.from_notebook_node(nbformat.read(file_stream, 'json'))
184 return self.from_notebook_node(nbformat.read(file_stream, 'json'))
131
185
132
186
133 def register_transformer(self, transformer):
187 def register_transformer(self, transformer):
188 """
189 Register a transformer.
190 Transformers are classes that act upon the notebook before it is
191 passed into the Jinja templating engine. Transformers are also
192 capable of passing additional information to the Jinja
193 templating engine.
194
195 Parameters
196 ----------
197 transformer : transformer
198 """
199
134 if inspect.isfunction(transformer):
200 if inspect.isfunction(transformer):
135 self.preprocessors.append(transformer)
201 self.preprocessors.append(transformer)
136 return transformer
202 return transformer
137 elif isinstance(transformer, MetaHasTraits):
203 elif isinstance(transformer, MetaHasTraits):
138 transformer_instance = transformer(config=self.config)
204 transformer_instance = transformer(config=self.config)
139 self.preprocessors.append(transformer_instance)
205 self.preprocessors.append(transformer_instance)
140 return transformer_instance
206 return transformer_instance
141 else:
207 else:
142 transformer_instance = transformer()
208 transformer_instance = transformer()
143 self.preprocessors.append(transformer_instance)
209 self.preprocessors.append(transformer_instance)
144 return transformer_instance
210 return transformer_instance
145
211
146
212
147 def register_filter(self, name, filter):
213 def register_filter(self, name, filter):
214 """
215 Register a filter.
216 A filter is a function that accepts and acts on one string.
217 The filters are accesible within the Jinja templating engine.
218
219 Parameters
220 ----------
221 name : str
222 name to give the filter in the Jinja engine
223 filter : filter
224 """
225
148 if inspect.isfunction(filter):
226 if inspect.isfunction(filter):
149 self.environment.filters[name] = filter
227 self.environment.filters[name] = filter
150 elif isinstance(filter, MetaHasTraits):
228 elif isinstance(filter, MetaHasTraits):
151 self.environment.filters[name] = filter(config=self.config)
229 self.environment.filters[name] = filter(config=self.config)
152 else:
230 else:
153 self.environment.filters[name] = filter()
231 self.environment.filters[name] = filter()
154 return self.environment.filters[name]
232 return self.environment.filters[name]
155
233
156
157 # Protected and Private methods #########################################
158
234
159 def _register_transformers(self):
235 def _register_transformers(self):
236 """
237 Register all of the transformers needed for this exporter.
238 """
239
160 self.register_transformer(nbconvert.transformers.coalescestreams.coalesce_streams)
240 self.register_transformer(nbconvert.transformers.coalescestreams.coalesce_streams)
161
241
162 #Remember the figure extraction transformer so it can be enabled and
242 #Remember the figure extraction transformer so it can be enabled and
163 #disabled easily later.
243 #disabled easily later.
164 self.extract_figure_transformer = self.register_transformer(nbconvert.transformers.extractfigure.ExtractFigureTransformer)
244 self.extract_figure_transformer = self.register_transformer(nbconvert.transformers.extractfigure.ExtractFigureTransformer)
165
245
166
246
167 def _register_filters(self):
247 def _register_filters(self):
248 """
249 Register all of the filters required for the exporter.
250 """
251
168 self.register_filter('indent', indent)
252 self.register_filter('indent', indent)
169 self.register_filter('markdown', markdown)
253 self.register_filter('markdown', markdown)
170 self.register_filter('ansi2html', nbconvert.filters.ansi.ansi2html)
254 self.register_filter('ansi2html', nbconvert.filters.ansi.ansi2html)
171 self.register_filter('filter_data_type', nbconvert.filters.datatypefilter.DataTypeFilter)
255 self.register_filter('filter_data_type', nbconvert.filters.datatypefilter.DataTypeFilter)
172 self.register_filter('get_lines', nbconvert.filters.strings.get_lines)
256 self.register_filter('get_lines', nbconvert.filters.strings.get_lines)
173 self.register_filter('highlight', nbconvert.filters.highlight.highlight)
257 self.register_filter('highlight', nbconvert.filters.highlight.highlight)
174 self.register_filter('highlight2html', nbconvert.filters.highlight.highlight)
258 self.register_filter('highlight2html', nbconvert.filters.highlight.highlight)
175 self.register_filter('highlight2latex', nbconvert.filters.highlight.highlight2latex)
259 self.register_filter('highlight2latex', nbconvert.filters.highlight.highlight2latex)
176 self.register_filter('markdown2latex', nbconvert.filters.markdown.markdown2latex)
260 self.register_filter('markdown2latex', nbconvert.filters.markdown.markdown2latex)
177 self.register_filter('markdown2rst', nbconvert.filters.markdown.markdown2rst)
261 self.register_filter('markdown2rst', nbconvert.filters.markdown.markdown2rst)
178 self.register_filter('pycomment', nbconvert.filters.strings.python_comment)
262 self.register_filter('pycomment', nbconvert.filters.strings.python_comment)
179 self.register_filter('rm_ansi', nbconvert.filters.ansi.remove_ansi)
263 self.register_filter('rm_ansi', nbconvert.filters.ansi.remove_ansi)
180 self.register_filter('rm_dollars', nbconvert.filters.strings.strip_dollars)
264 self.register_filter('rm_dollars', nbconvert.filters.strings.strip_dollars)
181 self.register_filter('rm_fake', nbconvert.filters.strings.rm_fake)
265 self.register_filter('rm_fake', nbconvert.filters.strings.rm_fake)
182 self.register_filter('rm_math_space', nbconvert.filters.latex.rm_math_space)
266 self.register_filter('rm_math_space', nbconvert.filters.latex.rm_math_space)
183 self.register_filter('wrap', nbconvert.filters.strings.wrap)
267 self.register_filter('wrap', nbconvert.filters.strings.wrap)
184
268
185
269
186 def _init_environment(self):
270 def _init_environment(self):
271 """
272 Create the Jinja templating environment.
273 """
274
187 self.environment = Environment(
275 self.environment = Environment(
188 loader=FileSystemLoader([
276 loader=FileSystemLoader([
189 os.path.dirname(os.path.realpath(__file__)) + TEMPLATE_PATH,
277 os.path.dirname(os.path.realpath(__file__)) + self.template_path,
190 os.path.dirname(os.path.realpath(__file__)) + TEMPLATE_SKELETON_PATH,
278 os.path.dirname(os.path.realpath(__file__)) + self.template_skeleton_path,
191 ]),
279 ]),
192 extensions=JINJA_EXTENSIONS
280 extensions=JINJA_EXTENSIONS
193 )
281 )
282
283 #Set special Jinja2 syntax that will not conflict with latex.
284 if not self.jinja_logic_block_start == None:
285 self.environment.block_start_string = self.jinja_logic_block_start
286 if not self.jinja_logic_block_end == None:
287 self.environment.block_end_string = self.jinja_logic_block_end
288 if not self.jinja_variable_block_start == None:
289 self.environment.variable_start_string = self.jinja_variable_block_start
290 if not self.jinja_variable_block_end == None:
291 self.environment.variable_end_string = self.jinja_variable_block_end
292 if not self.jinja_comment_block_start == None:
293 self.environment.comment_start_string = self.jinja_comment_block_start
294 if not self.jinja_comment_block_end == None:
295 self.environment.comment_end_string = self.jinja_comment_block_end
194
296
195
297
196 def _preprocess(self, nb):
298 def _preprocess(self, nb):
197
299 """
300 Preprocess the notebook before passing it into the Jinja engine.
301 To preprocess the notebook is to apply all of the
302
303 Parameters
304 ----------
305 nb : notebook node
306 notebook that is being exported.
307 """
308
198 #Dict of 'resources' that can be filled by the preprocessors.
309 #Dict of 'resources' that can be filled by the preprocessors.
199 resources = {}
310 resources = {}
200
311
201 #Run each transformer on the notebook. Carry the output along
312 #Run each transformer on the notebook. Carry the output along
202 #to each transformer
313 #to each transformer
203 for transformer in self.preprocessors:
314 for transformer in self.preprocessors:
204 nb, resources = transformer(nb, resources)
315 nb, resources = transformer(nb, resources)
205 return nb, resources
316 return nb, resources
@@ -1,117 +1,126 b''
1 """
1 """
2 Exporter that allows Latex Jinja templates to work. Contains logic to
2 Exporter that allows Latex Jinja templates to work. Contains logic to
3 appropriately prepare IPYNB files for export to LaTeX. Including but
3 appropriately prepare IPYNB files for export to LaTeX. Including but
4 not limited to escaping LaTeX, fixing math region tags, using special
4 not limited to escaping LaTeX, fixing math region tags, using special
5 tags to circumvent Jinja/Latex syntax conflicts.
5 tags to circumvent Jinja/Latex syntax conflicts.
6 """
6 """
7 #-----------------------------------------------------------------------------
7 #-----------------------------------------------------------------------------
8 # Copyright (c) 2013, the IPython Development Team.
8 # Copyright (c) 2013, the IPython Development Team.
9 #
9 #
10 # Distributed under the terms of the Modified BSD License.
10 # Distributed under the terms of the Modified BSD License.
11 #
11 #
12 # The full license is in the file COPYING.txt, distributed with this software.
12 # The full license is in the file COPYING.txt, distributed with this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 # Stdlib imports
19 # Stdlib imports
20 import os
20 import os
21
21
22 # IPython imports
22 # IPython imports
23 from IPython.utils.traitlets import Unicode
23 from IPython.utils.traitlets import Unicode
24
24
25 # other libs/dependencies
25 # other libs/dependencies
26 from jinja2 import Environment, FileSystemLoader
26 from jinja2 import Environment, FileSystemLoader
27
27
28 import nbconvert.filters.latex
28 import nbconvert.filters.latex
29 import nbconvert.filters.highlight
29 import nbconvert.filters.highlight
30 from nbconvert.transformers.latex import LatexTransformer
30 from nbconvert.transformers.latex import LatexTransformer
31
31
32 # local import
32 # local import
33 import exporter
33 import exporter
34
34
35 #-----------------------------------------------------------------------------
35 #-----------------------------------------------------------------------------
36 # Globals and constants
37 #-----------------------------------------------------------------------------
38
39 #Latex Jinja2 constants
40 LATEX_TEMPLATE_PATH = "/../templates/latex/"
41 LATEX_TEMPLATE_SKELETON_PATH = "/../templates/latex/skeleton/"
42
43 #Special Jinja2 syntax that will not conflict when exporting latex.
44 LATEX_JINJA_COMMENT_BLOCK = ["((=", "=))"]
45 LATEX_JINJA_VARIABLE_BLOCK = ["(((", ")))"]
46 LATEX_JINJA_LOGIC_BLOCK = ["((*", "*))"]
47
48 #-----------------------------------------------------------------------------
49 # Classes and functions
36 # Classes and functions
50 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
51
38
52 class LatexExporter(exporter.Exporter):
39 class LatexExporter(exporter.Exporter):
53 """
40 """
54 Exports to a Latex template. Inherit from this class if your template is
41 Exports to a Latex template. Inherit from this class if your template is
55 LaTeX based and you need custom tranformers/filters. Inherit from it if
42 LaTeX based and you need custom tranformers/filters. Inherit from it if
56 you are writing your own HTML template and need custom tranformers/filters.
43 you are writing your own HTML template and need custom tranformers/filters.
57 If you don't need custom tranformers/filters, just change the
44 If you don't need custom tranformers/filters, just change the
58 'template_file' config option. Place your template in the special "/latex"
45 'template_file' config option. Place your template in the special "/latex"
59 subfolder of the "../templates" folder.
46 subfolder of the "../templates" folder.
60 """
47 """
61
48
62 #Extension that the template files use.
63 template_extension = ".tplx"
64
65 file_extension = Unicode(
49 file_extension = Unicode(
66 'tex', config=True,
50 'tex', config=True,
67 help="Extension of the file that should be written to disk")
51 help="Extension of the file that should be written to disk")
68
52
69 template_file = Unicode(
53 template_file = Unicode(
70 'base', config=True,
54 'base', config=True,
71 help="Name of the template file to use")
55 help="Name of the template file to use")
56
57 #Latex constants
58 template_path = Unicode(
59 "/../templates/latex/", config=True,
60 help="Path where the template files are located.")
61
62 template_skeleton_path = Unicode(
63 "/../templates/latex/skeleton/", config=True,
64 help="Path where the template skeleton files are located.")
65
66 #Special Jinja2 syntax that will not conflict when exporting latex.
67 jinja_comment_block_start = Unicode("((=", config=True)
68 jinja_comment_block_end = Unicode("=))", config=True)
69 jinja_variable_block_start = Unicode("(((", config=True)
70 jinja_variable_block_end = Unicode(")))", config=True)
71 jinja_logic_block_start = Unicode("((*", config=True)
72 jinja_logic_block_end = Unicode("*))", config=True)
73
74 #Extension that the template files use.
75 template_extension = Unicode(".tplx", config=True)
72
76
73 def __init__(self, transformers=None, filters=None, config=None, **kw):
77 def __init__(self, transformers=None, filters=None, config=None, **kw):
78 """
79 Public constructor
80
81 Parameters
82 ----------
83 transformers : list[of transformer]
84 Custom transformers to apply to the notebook prior to engaging
85 the Jinja template engine. Any transformers specified here
86 will override existing transformers if a naming conflict
87 occurs.
88 filters : list[of filter]
89 Custom filters to make accessible to the Jinja templates. Any
90 filters specified here will override existing filters if a
91 naming conflict occurs.
92 config : config
93 User configuration instance.
94 """
74
95
75 #Call base class constructor.
96 #Call base class constructor.
76 super(LatexExporter, self).__init__(transformers, filters, config, **kw)
97 super(LatexExporter, self).__init__(transformers, filters, config, **kw)
77
98
78 self.extract_figure_transformer.display_data_priority = ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text']
99 self.extract_figure_transformer.display_data_priority = ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text']
79 self.extract_figure_transformer.extra_ext_map={'svg':'pdf'}
100 self.extract_figure_transformer.extra_ext_map={'svg':'pdf'}
80
81
82 def _init_environment(self):
83 self.environment = Environment(
84 loader=FileSystemLoader([
85 os.path.dirname(os.path.realpath(__file__)) + LATEX_TEMPLATE_PATH,
86 os.path.dirname(os.path.realpath(__file__)) + LATEX_TEMPLATE_SKELETON_PATH,
87 ]),
88 extensions=exporter.JINJA_EXTENSIONS
89 )
90
101
91 #Set special Jinja2 syntax that will not conflict with latex.
92 self.environment.block_start_string = LATEX_JINJA_LOGIC_BLOCK[0]
93 self.environment.block_end_string = LATEX_JINJA_LOGIC_BLOCK[1]
94 self.environment.variable_start_string = LATEX_JINJA_VARIABLE_BLOCK[0]
95 self.environment.variable_end_string = LATEX_JINJA_VARIABLE_BLOCK[1]
96 self.environment.comment_start_string = LATEX_JINJA_COMMENT_BLOCK[0]
97 self.environment.comment_end_string = LATEX_JINJA_COMMENT_BLOCK[1]
98
99
102
100 def _register_filters(self):
103 def _register_filters(self):
104 """
105 Register all of the filters required for the exporter.
106 """
101
107
102 #Register the filters of the base class.
108 #Register the filters of the base class.
103 super(LatexExporter, self)._register_filters()
109 super(LatexExporter, self)._register_filters()
104
110
105 #Add latex filters to the Jinja2 environment
111 #Add latex filters to the Jinja2 environment
106 self.register_filter('escape_tex', nbconvert.filters.latex.escape_latex)
112 self.register_filter('escape_tex', nbconvert.filters.latex.escape_latex)
107 self.register_filter('highlight', nbconvert.filters.highlight.highlight2latex)
113 self.register_filter('highlight', nbconvert.filters.highlight.highlight2latex)
108
114
109
115
110 def _register_transformers(self):
116 def _register_transformers(self):
117 """
118 Register all of the transformers needed for this exporter.
119 """
111
120
112 #Register the transformers of the base class.
121 #Register the transformers of the base class.
113 super(LatexExporter, self)._register_transformers()
122 super(LatexExporter, self)._register_transformers()
114
123
115 #Register latex transformer
124 #Register latex transformer
116 self.register_transformer(LatexTransformer)
125 self.register_transformer(LatexTransformer)
117 No newline at end of file
126
@@ -1,45 +1,62 b''
1 """
1 """
2 Python exporter which exports Notebook code into a PY file.
2 Python exporter which exports Notebook code into a PY file.
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 from IPython.utils.traitlets import Unicode
16 from IPython.utils.traitlets import Unicode
17
17
18 # local import
18 # local import
19 import exporter
19 import exporter
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Classes
22 # Classes
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 class PythonExporter(exporter.Exporter):
25 class PythonExporter(exporter.Exporter):
26 """
26 """
27 Exports a Python code file.
27 Exports a Python code file.
28 """
28 """
29
29
30 file_extension = Unicode(
30 file_extension = Unicode(
31 'py', config=True,
31 'py', config=True,
32 help="Extension of the file that should be written to disk")
32 help="Extension of the file that should be written to disk")
33
33
34 template_file = Unicode(
34 template_file = Unicode(
35 'python', config=True,
35 'python', config=True,
36 help="Name of the template file to use")
36 help="Name of the template file to use")
37
37
38 def __init__(self, transformers=None, filters=None, config=None, armor=False, **kw):
38 def __init__(self, transformers=None, filters=None, config=None, armor=False, **kw):
39 """
40 Public constructor
41
42 Parameters
43 ----------
44 transformers : list[of transformer]
45 Custom transformers to apply to the notebook prior to engaging
46 the Jinja template engine. Any transformers specified here
47 will override existing transformers if a naming conflict
48 occurs.
49 filters : list[of filter]
50 Custom filters to make accessible to the Jinja templates. Any
51 filters specified here will override existing filters if a
52 naming conflict occurs.
53 config : config
54 User configuration instance.
55 """
39
56
40 #Call base class constructor.
57 #Call base class constructor.
41 super(PythonExporter, self).__init__(transformers, filters, config, **kw)
58 super(PythonExporter, self).__init__(transformers, filters, config, **kw)
42
59
43 #Set defaults
60 #Set defaults
44 self.extract_figure_transformer.enabled = False
61 self.extract_figure_transformer.enabled = False
45
62
@@ -1,47 +1,50 b''
1 """
1 """
2 Reveal slide show exporter.
2 Reveal slide show exporter.
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 from IPython.utils.traitlets import Unicode
16 from IPython.utils.traitlets import Unicode
17
17
18 # local import
18 # local import
19 import basichtml
19 import basichtml
20
20
21 import nbconvert.transformers.revealhelp
21 import nbconvert.transformers.revealhelp
22
22
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 # Classes
24 # Classes
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26
26
27 class RevealExporter(basichtml.BasicHtmlExporter):
27 class RevealExporter(basichtml.BasicHtmlExporter):
28 """
28 """
29 Exports a Reveal slide show (.HTML) which may be rendered in a web browser.
29 Exports a Reveal slide show (.HTML) which may be rendered in a web browser.
30 """
30 """
31
31
32 file_extension = Unicode(
32 file_extension = Unicode(
33 'reveal.html', config=True,
33 'reveal.html', config=True,
34 help="Extension of the file that should be written to disk")
34 help="Extension of the file that should be written to disk")
35
35
36 template_file = Unicode(
36 template_file = Unicode(
37 'reveal', config=True,
37 'reveal', config=True,
38 help="Name of the template file to use")
38 help="Name of the template file to use")
39
39
40 def _register_transformers(self):
40 def _register_transformers(self):
41 """
42 Register all of the transformers needed for this exporter.
43 """
41
44
42 #Register the transformers of the base class.
45 #Register the transformers of the base class.
43 super(RevealExporter, self)._register_transformers()
46 super(RevealExporter, self)._register_transformers()
44
47
45 #Register reveal help transformer
48 #Register reveal help transformer
46 self.register_transformer(nbconvert.transformers.revealhelp.RevealHelpTransformer)
49 self.register_transformer(nbconvert.transformers.revealhelp.RevealHelpTransformer)
47 No newline at end of file
50
General Comments 0
You need to be logged in to leave comments. Login now