mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-11 12:30:51 +08:00
Preserve nbformat_minor from the future
warn on click of unrecognized elements, rather than on load.
This commit is contained in:
parent
bb23105fdd
commit
88219df674
@ -636,7 +636,7 @@ define([
|
||||
} else {
|
||||
data.metadata = this.metadata;
|
||||
}
|
||||
this.element.find('.inner_cell').text("Unrecognized cell type: " + data.cell_type);
|
||||
this.element.find('.inner_cell').find("a").text("Unrecognized cell type: " + data.cell_type);
|
||||
};
|
||||
|
||||
UnrecognizedCell.prototype.create_element = function () {
|
||||
@ -647,10 +647,23 @@ define([
|
||||
var prompt = $('<div/>').addClass('prompt input_prompt');
|
||||
cell.append(prompt);
|
||||
var inner_cell = $('<div/>').addClass('inner_cell');
|
||||
inner_cell.text("Unrecognized cell type");
|
||||
inner_cell.append(
|
||||
$("<a>")
|
||||
.attr("href", "#")
|
||||
.text("Unrecognized cell type")
|
||||
);
|
||||
cell.append(inner_cell);
|
||||
this.element = cell;
|
||||
};
|
||||
|
||||
UnrecognizedCell.prototype.bind_events = function () {
|
||||
Cell.prototype.bind_events.apply(this, arguments);
|
||||
var cell = this;
|
||||
|
||||
this.element.find('.inner_cell').find("a").click(function () {
|
||||
cell.events.trigger('unrecognized_cell.Cell', {cell: cell})
|
||||
});
|
||||
};
|
||||
|
||||
// Backwards compatibility.
|
||||
IPython.Cell = Cell;
|
||||
|
@ -147,7 +147,7 @@ define([
|
||||
this.minimum_autosave_interval = 120000;
|
||||
this.notebook_name_blacklist_re = /[\/\\:]/;
|
||||
this.nbformat = 4; // Increment this when changing the nbformat
|
||||
this.nbformat_minor = 0; // Increment this when changing the nbformat
|
||||
this.nbformat_minor = this.current_nbformat_minor = 0; // Increment this when changing the nbformat
|
||||
this.codemirror_mode = 'ipython';
|
||||
this.create_elements();
|
||||
this.bind_events();
|
||||
@ -207,6 +207,14 @@ define([
|
||||
that.dirty = true;
|
||||
});
|
||||
|
||||
this.events.on('unrecognized_cell.Cell', function () {
|
||||
that.warn_nbformat_minor();
|
||||
});
|
||||
|
||||
this.events.on('unrecognized_output.OutputArea', function () {
|
||||
that.warn_nbformat_minor();
|
||||
});
|
||||
|
||||
this.events.on('set_dirty.Notebook', function (event, data) {
|
||||
that.dirty = data.value;
|
||||
});
|
||||
@ -300,6 +308,28 @@ define([
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
Notebook.prototype.warn_nbformat_minor = function (event) {
|
||||
// trigger a warning dialog about missing functionality from newer minor versions
|
||||
var v = 'v' + this.nbformat + '.';
|
||||
var orig_vs = v + this.nbformat_minor;
|
||||
var this_vs = v + this.current_nbformat_minor;
|
||||
var msg = "This notebook is version " + orig_vs + ", but we only fully support up to " +
|
||||
this_vs + ". You can still work with this notebook, but cell and output types " +
|
||||
"introduced in later notebook versions will not be available.";
|
||||
|
||||
dialog.modal({
|
||||
notebook: this,
|
||||
keyboard_manager: this.keyboard_manager,
|
||||
title : "Newer Notebook",
|
||||
body : msg,
|
||||
buttons : {
|
||||
OK : {
|
||||
"class" : "btn-danger"
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dirty flag, and trigger the set_dirty.Notebook event
|
||||
@ -2234,26 +2264,8 @@ define([
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (orig_nbformat_minor !== undefined && nbmodel.nbformat_minor < orig_nbformat_minor) {
|
||||
var that = this;
|
||||
var orig_vs = 'v' + nbmodel.nbformat + '.' + orig_nbformat_minor;
|
||||
var this_vs = 'v' + nbmodel.nbformat + '.' + this.nbformat_minor;
|
||||
msg = "This notebook is version " + orig_vs + ", but we only fully support up to " +
|
||||
this_vs + ". You can still work with this notebook, but some features " +
|
||||
"introduced in later notebook versions may not be available.";
|
||||
|
||||
dialog.modal({
|
||||
notebook: this,
|
||||
keyboard_manager: this.keyboard_manager,
|
||||
title : "Newer Notebook",
|
||||
body : msg,
|
||||
buttons : {
|
||||
OK : {
|
||||
class : "btn-danger"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else if (this.nbformat_minor < nbmodel.nbformat_minor) {
|
||||
this.nbformat_minor = nbmodel.nbformat_minor;
|
||||
}
|
||||
|
||||
// Create the session after the notebook is completely loaded to prevent
|
||||
|
@ -271,7 +271,6 @@ define([
|
||||
}
|
||||
|
||||
var record_output = true;
|
||||
console.log("appending", json);
|
||||
switch(json.output_type) {
|
||||
case 'execute_result':
|
||||
json = this.validate_mimebundle(json);
|
||||
@ -490,10 +489,18 @@ define([
|
||||
|
||||
|
||||
OutputArea.prototype.append_unrecognized = function (json) {
|
||||
var that = this;
|
||||
var toinsert = this.create_output_area();
|
||||
var subarea = $('<div/>').addClass('output_subarea output_unrecognized');
|
||||
toinsert.append(subarea);
|
||||
subarea.text("Unrecognized output: " + json.output_type);
|
||||
subarea.append(
|
||||
$("<a>")
|
||||
.attr("href", "#")
|
||||
.text("Unrecognized output: " + json.output_type)
|
||||
.click(function () {
|
||||
that.events.trigger('unrecognized_output.OutputArea', {output: json})
|
||||
})
|
||||
);
|
||||
this._safe_append(toinsert);
|
||||
};
|
||||
|
||||
|
@ -74,6 +74,16 @@ div.unrecognized_cell {
|
||||
color: red;
|
||||
border: 1px solid @light_border_color;
|
||||
background: darken(@cell_background, 5%);
|
||||
// remove decoration from link
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
|
@ -177,4 +177,14 @@ div.output_unrecognized {
|
||||
padding: 5px;
|
||||
font-weight: bold;
|
||||
color: red;
|
||||
// remove decoration from link
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
}
|
17
IPython/html/static/style/ipython.min.css
vendored
17
IPython/html/static/style/ipython.min.css
vendored
@ -444,6 +444,14 @@ div.unrecognized_cell .inner_cell {
|
||||
border: 1px solid #cfcfcf;
|
||||
background: #eaeaea;
|
||||
}
|
||||
div.unrecognized_cell .inner_cell a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
div.unrecognized_cell .inner_cell a:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
div.unrecognized_cell > div.prompt {
|
||||
display: none;
|
||||
@ -919,11 +927,18 @@ p.p-space {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
div.output_unrecognized {
|
||||
border-radius: 4px;
|
||||
padding: 5px;
|
||||
font-weight: bold;
|
||||
color: red;
|
||||
}
|
||||
div.output_unrecognized a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
div.output_unrecognized a:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
.rendered_html {
|
||||
color: #000000;
|
||||
/* any extras will just be numbers: */
|
||||
|
17
IPython/html/static/style/style.min.css
vendored
17
IPython/html/static/style/style.min.css
vendored
@ -8313,6 +8313,14 @@ div.unrecognized_cell .inner_cell {
|
||||
border: 1px solid #cfcfcf;
|
||||
background: #eaeaea;
|
||||
}
|
||||
div.unrecognized_cell .inner_cell a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
div.unrecognized_cell .inner_cell a:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
div.unrecognized_cell > div.prompt {
|
||||
display: none;
|
||||
@ -8788,11 +8796,18 @@ p.p-space {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
div.output_unrecognized {
|
||||
border-radius: 4px;
|
||||
padding: 5px;
|
||||
font-weight: bold;
|
||||
color: red;
|
||||
}
|
||||
div.output_unrecognized a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
div.output_unrecognized a:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
.rendered_html {
|
||||
color: #000000;
|
||||
/* any extras will just be numbers: */
|
||||
|
Loading…
Reference in New Issue
Block a user