mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-05 12:19:58 +08:00
'Download as' script
This commit is contained in:
parent
2414db41e6
commit
800e2ad25a
@ -129,10 +129,6 @@ define([
|
||||
that._nbconvert('html', false);
|
||||
});
|
||||
|
||||
this.element.find('#download_py').click(function () {
|
||||
that._nbconvert('python', true);
|
||||
});
|
||||
|
||||
this.element.find('#download_html').click(function () {
|
||||
that._nbconvert('html', true);
|
||||
});
|
||||
@ -308,6 +304,16 @@ define([
|
||||
this.events.on('checkpoint_created.Notebook', function (event, data) {
|
||||
that.update_restore_checkpoint(that.notebook.checkpoints);
|
||||
});
|
||||
|
||||
this.events.on('notebook_loaded.Notebook', function() {
|
||||
var langinfo = that.notebook.metadata.language_info || {};
|
||||
that.update_nbconvert_script(langinfo);
|
||||
});
|
||||
|
||||
this.events.on('kernel_ready.Kernel', function(event, data) {
|
||||
var langinfo = data.kernel.info_reply.language_info || {};
|
||||
that.update_nbconvert_script(langinfo);
|
||||
});
|
||||
};
|
||||
|
||||
MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
|
||||
@ -340,6 +346,31 @@ define([
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
MenuBar.prototype.update_nbconvert_script = function(langinfo) {
|
||||
// Set the 'Download as foo' menu option for the relevant language.
|
||||
var el = this.element.find('#download_script');
|
||||
var that = this;
|
||||
|
||||
// Set menu entry text to e.g. "Python (.py)"
|
||||
var langname = (langinfo.name || 'Script')
|
||||
langname = langname.charAt(0).toUpperCase()+langname.substr(1) // Capitalise
|
||||
el.find('a').text(langname + ' (.'+(langinfo.file_extension || 'txt')+')');
|
||||
|
||||
// Unregister any previously registered handlers
|
||||
el.off('click');
|
||||
if (langinfo.nbconvert_exporter) {
|
||||
// Metadata specifies a specific exporter, e.g. 'python'
|
||||
el.click(function() {
|
||||
that._nbconvert(langinfo.nbconvert_exporter, true);
|
||||
});
|
||||
} else {
|
||||
// Use generic 'script' exporter
|
||||
el.click(function() {
|
||||
that._nbconvert('script', true);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Backwards compatability.
|
||||
IPython.MenuBar = MenuBar;
|
||||
|
@ -105,7 +105,7 @@ class="notebook_app"
|
||||
<li class="dropdown-submenu"><a href="#">Download as</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li id="download_ipynb"><a href="#">IPython Notebook (.ipynb)</a></li>
|
||||
<li id="download_py"><a href="#">Python (.py)</a></li>
|
||||
<li id="download_script"><a href="#">Script</a></li>
|
||||
<li id="download_html"><a href="#">HTML (.html)</a></li>
|
||||
<li id="download_rst"><a href="#">reST (.rst)</a></li>
|
||||
<li id="download_pdf"><a href="#">PDF (.pdf)</a></li>
|
||||
|
Loading…
Reference in New Issue
Block a user