##// END OF EJS Templates
'Download as' script
Thomas Kluyver -
Show More
@@ -129,10 +129,6 b' define(['
129 129 that._nbconvert('html', false);
130 130 });
131 131
132 this.element.find('#download_py').click(function () {
133 that._nbconvert('python', true);
134 });
135
136 132 this.element.find('#download_html').click(function () {
137 133 that._nbconvert('html', true);
138 134 });
@@ -308,6 +304,16 b' define(['
308 304 this.events.on('checkpoint_created.Notebook', function (event, data) {
309 305 that.update_restore_checkpoint(that.notebook.checkpoints);
310 306 });
307
308 this.events.on('notebook_loaded.Notebook', function() {
309 var langinfo = that.notebook.metadata.language_info || {};
310 that.update_nbconvert_script(langinfo);
311 });
312
313 this.events.on('kernel_ready.Kernel', function(event, data) {
314 var langinfo = data.kernel.info_reply.language_info || {};
315 that.update_nbconvert_script(langinfo);
316 });
311 317 };
312 318
313 319 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
@@ -340,6 +346,31 b' define(['
340 346 );
341 347 });
342 348 };
349
350 MenuBar.prototype.update_nbconvert_script = function(langinfo) {
351 // Set the 'Download as foo' menu option for the relevant language.
352 var el = this.element.find('#download_script');
353 var that = this;
354
355 // Set menu entry text to e.g. "Python (.py)"
356 var langname = (langinfo.name || 'Script')
357 langname = langname.charAt(0).toUpperCase()+langname.substr(1) // Capitalise
358 el.find('a').text(langname + ' (.'+(langinfo.file_extension || 'txt')+')');
359
360 // Unregister any previously registered handlers
361 el.off('click');
362 if (langinfo.nbconvert_exporter) {
363 // Metadata specifies a specific exporter, e.g. 'python'
364 el.click(function() {
365 that._nbconvert(langinfo.nbconvert_exporter, true);
366 });
367 } else {
368 // Use generic 'script' exporter
369 el.click(function() {
370 that._nbconvert('script', true);
371 });
372 }
373 };
343 374
344 375 // Backwards compatability.
345 376 IPython.MenuBar = MenuBar;
@@ -105,7 +105,7 b' class="notebook_app"'
105 105 <li class="dropdown-submenu"><a href="#">Download as</a>
106 106 <ul class="dropdown-menu">
107 107 <li id="download_ipynb"><a href="#">IPython Notebook (.ipynb)</a></li>
108 <li id="download_py"><a href="#">Python (.py)</a></li>
108 <li id="download_script"><a href="#">Script</a></li>
109 109 <li id="download_html"><a href="#">HTML (.html)</a></li>
110 110 <li id="download_rst"><a href="#">reST (.rst)</a></li>
111 111 <li id="download_pdf"><a href="#">PDF (.pdf)</a></li>
@@ -75,6 +75,8 b' class IPythonKernel(KernelBase):'
75 75 'codemirror_mode': {'name': 'ipython',
76 76 'version': sys.version_info[0]},
77 77 'pygments_lexer': 'ipython%d' % (3 if PY3 else 2),
78 'nbconvert_exporter': 'python',
79 'file_extension': 'py'
78 80 }
79 81 @property
80 82 def banner(self):
General Comments 0
You need to be logged in to leave comments. Login now