diff --git a/IPython/frontend/html/notebook/static/js/cell.js b/IPython/frontend/html/notebook/static/js/cell.js
index 68c8769..9536c9b 100644
--- a/IPython/frontend/html/notebook/static/js/cell.js
+++ b/IPython/frontend/html/notebook/static/js/cell.js
@@ -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;
+ }
};
diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js
index 2754937..1e8b155 100644
--- a/IPython/frontend/html/notebook/static/js/codecell.js
+++ b/IPython/frontend/html/notebook/static/js/codecell.js
@@ -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) {
diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js
index ef44f78..5ccfb1a 100644
--- a/IPython/frontend/html/notebook/static/js/notebook.js
+++ b/IPython/frontend/html/notebook/static/js/notebook.js
@@ -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;
diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js
index 38b302e..3225faa 100644
--- a/IPython/frontend/html/notebook/static/js/textcell.js
+++ b/IPython/frontend/html/notebook/static/js/textcell.js
@@ -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;
diff --git a/IPython/nbformat/v3/nbbase.py b/IPython/nbformat/v3/nbbase.py
index 2bc2fd4..118163c 100644
--- a/IPython/nbformat/v3/nbbase.py
+++ b/IPython/nbformat/v3/nbbase.py
@@ -92,7 +92,7 @@ def new_output(output_type=None, output_text=None, output_png=None,
def new_code_cell(input=None, prompt_number=None, outputs=None,
- language=u'python', collapsed=False):
+ language=u'python', collapsed=False, metadata=None):
"""Create a new code cell with input and output"""
cell = NotebookNode()
cell.cell_type = u'code'
@@ -108,10 +108,11 @@ def new_code_cell(input=None, prompt_number=None, outputs=None,
cell.outputs = outputs
if collapsed is not None:
cell.collapsed = bool(collapsed)
+ cell.metadata = NotebookNode(metadata or {})
return cell
-def new_text_cell(cell_type, source=None, rendered=None):
+def new_text_cell(cell_type, source=None, rendered=None, metadata=None):
"""Create a new text cell."""
cell = NotebookNode()
# VERSIONHACK: plaintext -> raw
@@ -122,11 +123,12 @@ def new_text_cell(cell_type, source=None, rendered=None):
cell.source = unicode(source)
if rendered is not None:
cell.rendered = unicode(rendered)
+ cell.metadata = NotebookNode(metadata or {})
cell.cell_type = cell_type
return cell
-def new_heading_cell(source=None, rendered=None, level=1):
+def new_heading_cell(source=None, rendered=None, level=1, metadata=None):
"""Create a new section cell with a given integer level."""
cell = NotebookNode()
cell.cell_type = u'heading'
@@ -135,10 +137,11 @@ def new_heading_cell(source=None, rendered=None, level=1):
if rendered is not None:
cell.rendered = unicode(rendered)
cell.level = int(level)
+ cell.metadata = NotebookNode(metadata or {})
return cell
-def new_worksheet(name=None, cells=None):
+def new_worksheet(name=None, cells=None, metadata=None):
"""Create a worksheet by name with with a list of cells."""
ws = NotebookNode()
if name is not None:
@@ -147,6 +150,7 @@ def new_worksheet(name=None, cells=None):
ws.cells = []
else:
ws.cells = list(cells)
+ ws.metadata = NotebookNode(metadata or {})
return ws