##// END OF EJS Templates
nbconvert --to script dispatches to custom nbconvert exporter in metadata
Min RK -
Show More
@@ -1,14 +1,33 b''
1 """Generic script exporter class for any kernel language"""
1 """Generic script exporter class for any kernel language"""
2
2
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
5
3 from .templateexporter import TemplateExporter
6 from .templateexporter import TemplateExporter
4
7
8 from IPython.utils.traitlets import Dict
9
5 class ScriptExporter(TemplateExporter):
10 class ScriptExporter(TemplateExporter):
11
12 _exporters = Dict()
13
6 def _template_file_default(self):
14 def _template_file_default(self):
7 return 'script'
15 return 'script'
8
16
9 def from_notebook_node(self, nb, resources=None, **kw):
17 def from_notebook_node(self, nb, resources=None, **kw):
10 langinfo = nb.metadata.get('language_info', {})
18 langinfo = nb.metadata.get('language_info', {})
19
20 # delegate to custom exporter, if specified
21 exporter_name = langinfo.get('nbconvert_exporter')
22 if exporter_name and exporter_name != 'script':
23 self.log.debug("Loading script exporter: %s", exporter_name)
24 from .export import exporter_map
25 if exporter_name not in self._exporters:
26 Exporter = exporter_map[exporter_name]
27 self._exporters[exporter_name] = Exporter(parent=self)
28 exporter = self._exporters[exporter_name]
29 return exporter.from_notebook_node(nb, resources, **kw)
30
11 self.file_extension = langinfo.get('file_extension', '.txt')
31 self.file_extension = langinfo.get('file_extension', '.txt')
12 self.output_mimetype = langinfo.get('mimetype', 'text/plain')
32 self.output_mimetype = langinfo.get('mimetype', 'text/plain')
13
14 return super(ScriptExporter, self).from_notebook_node(nb, resources, **kw)
33 return super(ScriptExporter, self).from_notebook_node(nb, resources, **kw)
General Comments 0
You need to be logged in to leave comments. Login now