mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
add empty metadata field on cells/worksheets
These are unused for now, but will allow adding data to the notebook without a full version bump.
This commit is contained in:
parent
b5e488d78c
commit
362feaa295
@ -19,6 +19,7 @@ var IPython = (function (IPython) {
|
||||
this.read_only = false;
|
||||
this.selected = false;
|
||||
this.element = null;
|
||||
this.metadata = {};
|
||||
this.create_element();
|
||||
if (this.element !== null) {
|
||||
this.element.data("cell", this);
|
||||
@ -90,10 +91,16 @@ var IPython = (function (IPython) {
|
||||
|
||||
|
||||
Cell.prototype.toJSON = function () {
|
||||
var data = {};
|
||||
data.metadata = this.metadata;
|
||||
return data;
|
||||
};
|
||||
|
||||
|
||||
Cell.prototype.fromJSON = function (data) {
|
||||
if (data.metadata !== undefined) {
|
||||
this.metadata = data.metadata;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -264,6 +264,7 @@ var IPython = (function (IPython) {
|
||||
// JSON serialization
|
||||
|
||||
CodeCell.prototype.fromJSON = function (data) {
|
||||
IPython.Cell.prototype.fromJSON.apply(this, arguments);
|
||||
if (data.cell_type === 'code') {
|
||||
if (data.input !== undefined) {
|
||||
this.set_text(data.input);
|
||||
@ -286,7 +287,7 @@ var IPython = (function (IPython) {
|
||||
|
||||
|
||||
CodeCell.prototype.toJSON = function () {
|
||||
var data = {};
|
||||
var data = IPython.Cell.prototype.toJSON.apply(this);
|
||||
data.input = this.get_text();
|
||||
data.cell_type = 'code';
|
||||
if (this.input_prompt_number) {
|
||||
|
@ -25,6 +25,8 @@ var IPython = (function (IPython) {
|
||||
this.paste_enabled = false;
|
||||
this.dirty = false;
|
||||
this.metadata = {};
|
||||
// single worksheet for now
|
||||
this.worksheet_metadata = {};
|
||||
this.control_key_active = false;
|
||||
this.notebook_id = null;
|
||||
this.notebook_name = null;
|
||||
@ -1003,6 +1005,9 @@ var IPython = (function (IPython) {
|
||||
// Only handle 1 worksheet for now.
|
||||
var worksheet = data.worksheets[0];
|
||||
if (worksheet !== undefined) {
|
||||
if (worksheet.metadata) {
|
||||
this.worksheet_metadata = worksheet.metadata;
|
||||
}
|
||||
var new_cells = worksheet.cells;
|
||||
ncells = new_cells.length;
|
||||
var cell_data = null;
|
||||
@ -1031,7 +1036,10 @@ var IPython = (function (IPython) {
|
||||
};
|
||||
var data = {
|
||||
// Only handle 1 worksheet for now.
|
||||
worksheets : [{cells:cell_array}],
|
||||
worksheets : [{
|
||||
cells: cell_array,
|
||||
metadata: this.worksheet_metadata
|
||||
}],
|
||||
metadata : this.metadata
|
||||
};
|
||||
return data;
|
||||
|
@ -155,6 +155,7 @@ var IPython = (function (IPython) {
|
||||
|
||||
|
||||
TextCell.prototype.fromJSON = function (data) {
|
||||
IPython.Cell.prototype.fromJSON.apply(this, arguments);
|
||||
if (data.cell_type === this.cell_type) {
|
||||
if (data.source !== undefined) {
|
||||
this.set_text(data.source);
|
||||
@ -167,7 +168,7 @@ var IPython = (function (IPython) {
|
||||
|
||||
|
||||
TextCell.prototype.toJSON = function () {
|
||||
var data = {};
|
||||
var data = IPython.Cell.prototype.toJSON.apply(this);
|
||||
data.cell_type = this.cell_type;
|
||||
data.source = this.get_text();
|
||||
return data;
|
||||
|
Loading…
Reference in New Issue
Block a user