##// END OF EJS Templates
Backport PR #8271: Allow to set same mode as existing if load fails....
Backport PR #8271: Allow to set same mode as existing if load fails. Setting the mode many times in a row, would fail to actually set the mode if it was failing to load the mode the first time. The prevent the above behavior by falling back **explicitly** to 'null' if mode does not exist yet, or can't be loaded. ...

File last commit:

r19276:24fd91f5
r21463:d66c4462
Show More
script.py
33 lines | 1.3 KiB | text/x-python | PythonLexer
Thomas Kluyver
nbconvert --to script...
r18966 """Generic script exporter class for any kernel language"""
Min RK
nbconvert --to script dispatches to custom nbconvert exporter in metadata
r19276 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Thomas Kluyver
nbconvert --to script...
r18966 from .templateexporter import TemplateExporter
Min RK
nbconvert --to script dispatches to custom nbconvert exporter in metadata
r19276 from IPython.utils.traitlets import Dict
Thomas Kluyver
nbconvert --to script...
r18966 class ScriptExporter(TemplateExporter):
Min RK
nbconvert --to script dispatches to custom nbconvert exporter in metadata
r19276
_exporters = Dict()
Thomas Kluyver
nbconvert --to script...
r18966 def _template_file_default(self):
return 'script'
def from_notebook_node(self, nb, resources=None, **kw):
langinfo = nb.metadata.get('language_info', {})
Min RK
nbconvert --to script dispatches to custom nbconvert exporter in metadata
r19276
# delegate to custom exporter, if specified
exporter_name = langinfo.get('nbconvert_exporter')
if exporter_name and exporter_name != 'script':
self.log.debug("Loading script exporter: %s", exporter_name)
from .export import exporter_map
if exporter_name not in self._exporters:
Exporter = exporter_map[exporter_name]
self._exporters[exporter_name] = Exporter(parent=self)
exporter = self._exporters[exporter_name]
return exporter.from_notebook_node(nb, resources, **kw)
Thomas Kluyver
Add the . into file_extension
r19027 self.file_extension = langinfo.get('file_extension', '.txt')
Thomas Kluyver
nbconvert --to script...
r18966 self.output_mimetype = langinfo.get('mimetype', 'text/plain')
return super(ScriptExporter, self).from_notebook_node(nb, resources, **kw)