mirror of
https://github.com/wassname/jupyter_contrib_nbextensions.git
synced 2026-08-17 11:20:38 +08:00
35 lines
992 B
JavaScript
35 lines
992 B
JavaScript
// convert current notebook to html by calling "ipython nbconvert" and open static html file in new tab
|
|
"using strict";
|
|
|
|
nbconvertPrintView = function(){
|
|
var kernel = IPython.notebook.kernel;
|
|
var name = IPython.notebook.notebook_name;
|
|
|
|
if (IPython.version[0] == "2") {
|
|
var path = IPython.notebook.notebookPath();
|
|
if (path.length > 0) { path = path.concat('/'); }
|
|
} else {
|
|
var path = "";
|
|
}
|
|
|
|
var command = 'import os; os.system(\"ipython nbconvert --to html ' + name + '\")';
|
|
function callback(out_type, out_data)
|
|
{
|
|
var url = '/files/' + path + name.split('.ipynb')[0] + '.html';
|
|
var win=window.open(url, '_blank');
|
|
win.focus();
|
|
}
|
|
kernel.execute(command, { shell: { reply : callback } });
|
|
};
|
|
|
|
IPython.toolbar.add_buttons_group([
|
|
{
|
|
id : 'doPrintView',
|
|
label : 'Create static print view',
|
|
icon : 'icon-print',
|
|
callback : nbconvertPrintView
|
|
}
|
|
]);
|
|
|
|
|