##// END OF EJS Templates
Merge pull request #7118 from minrk/script-dispatch...
Thomas Kluyver -
r19278:1b552dcd merge
parent child Browse files
Show More
@@ -154,6 +154,10 b' define(['
154 154 that._nbconvert('pdf', true);
155 155 });
156 156
157 this.element.find('#download_script').click(function () {
158 that._nbconvert('script', true);
159 });
160
157 161 this.element.find('#rename_notebook').click(function () {
158 162 that.save_widget.rename_notebook({notebook: that.notebook});
159 163 });
@@ -373,20 +377,6 b' define(['
373 377 var langname = (langinfo.name || 'Script')
374 378 langname = langname.charAt(0).toUpperCase()+langname.substr(1) // Capitalise
375 379 el.find('a').text(langname + ' ('+(langinfo.file_extension || 'txt')+')');
376
377 // Unregister any previously registered handlers
378 el.off('click');
379 if (langinfo.nbconvert_exporter) {
380 // Metadata specifies a specific exporter, e.g. 'python'
381 el.click(function() {
382 that._nbconvert(langinfo.nbconvert_exporter, true);
383 });
384 } else {
385 // Use generic 'script' exporter
386 el.click(function() {
387 that._nbconvert('script', true);
388 });
389 }
390 380 };
391 381
392 382 // Backwards compatability.
@@ -1,14 +1,33 b''
1 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 6 from .templateexporter import TemplateExporter
4 7
8 from IPython.utils.traitlets import Dict
9
5 10 class ScriptExporter(TemplateExporter):
11
12 _exporters = Dict()
13
6 14 def _template_file_default(self):
7 15 return 'script'
8 16
9 17 def from_notebook_node(self, nb, resources=None, **kw):
10 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 31 self.file_extension = langinfo.get('file_extension', '.txt')
12 32 self.output_mimetype = langinfo.get('mimetype', 'text/plain')
13
14 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