diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 95e4f1c74a6..950f55e3eb0 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -624,6 +624,9 @@ var IPython = (function (IPython) { } else if (cell_data.cell_type === 'html') { new_cell = this.insert_html_cell_after(); new_cell.fromJSON(cell_data); + } else if (cell_data.cell_type === 'markdown') { + new_cell = this.insert_markdown_cell_after(); + new_cell.fromJSON(cell_data); }; }; }; diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 9f670daae71..1d4ff772db1 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -132,7 +132,7 @@ var IPython = (function (IPython) { if (data.cell_type === this.cell_type) { if (data.source !== undefined) { this.set_source(data.source); - this.set_rendered(data.source); + this.set_rendered(data.rendered); }; }; } diff --git a/IPython/nbformat/current.py b/IPython/nbformat/current.py index 840cb5d8e3a..757c20e0689 100644 --- a/IPython/nbformat/current.py +++ b/IPython/nbformat/current.py @@ -7,7 +7,7 @@ from IPython.nbformat.v2 import ( NotebookNode, - new_code_cell, new_html_cell, new_notebook, new_output, new_worksheet + new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet ) diff --git a/IPython/nbformat/v2/__init__.py b/IPython/nbformat/v2/__init__.py index 449b6343de5..4f71ce51af3 100644 --- a/IPython/nbformat/v2/__init__.py +++ b/IPython/nbformat/v2/__init__.py @@ -1,7 +1,7 @@ from .nbbase import ( NotebookNode, - new_code_cell, new_html_cell, new_notebook, new_output, new_worksheet + new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet ) from .nbjson import reads as reads_json, writes as writes_json diff --git a/IPython/nbformat/v2/convert.py b/IPython/nbformat/v2/convert.py index 55f3dd35cc1..97b67644212 100644 --- a/IPython/nbformat/v2/convert.py +++ b/IPython/nbformat/v2/convert.py @@ -1,5 +1,5 @@ from .nbbase import ( - new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output ) def convert_to_this_nbformat(nb, orig_version=1): @@ -7,10 +7,10 @@ def convert_to_this_nbformat(nb, orig_version=1): newnb = new_notebook() ws = new_worksheet() for cell in nb.cells: - if cell.cell_type == 'code': + if cell.cell_type == u'code': newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number')) - elif cell.cell_type == 'text': - newcell = new_html_cell(source=cell.get('text')) + elif cell.cell_type == u'text': + newcell = new_text_cell(u'markdown',source=cell.get('text')) ws.cells.append(newcell) newnb.worksheets.append(ws) return newnb diff --git a/IPython/nbformat/v2/nbbase.py b/IPython/nbformat/v2/nbbase.py index 598f0ab3469..021bc456bb5 100644 --- a/IPython/nbformat/v2/nbbase.py +++ b/IPython/nbformat/v2/nbbase.py @@ -65,12 +65,14 @@ def new_code_cell(input=None, prompt_number=None, outputs=None, language=u'pytho return cell -def new_html_cell(source=None): +def new_text_cell(cell_type, source=None, rendered=None): """Create a new text cell.""" cell = NotebookNode() if source is not None: cell.source = unicode(source) - cell.cell_type = u'html' + if rendered is not None: + cell.rendered = unicode(rendered) + cell.cell_type = cell_type return cell diff --git a/IPython/nbformat/v2/nbxml.py b/IPython/nbformat/v2/nbxml.py index 976ca08028b..bd1f878a4cb 100644 --- a/IPython/nbformat/v2/nbxml.py +++ b/IPython/nbformat/v2/nbxml.py @@ -5,7 +5,7 @@ from .rwbase import NotebookReader, NotebookWriter from .nbbase import ( - new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output ) def indent(elem, level=0): @@ -108,7 +108,12 @@ def to_notebook(self, root, **kwargs): cells.append(cc) if cell_e.tag == 'htmlcell': source = _get_text(cell_e,'source') - cells.append(new_html_cell(source=source)) + rendered = _get_text(cell_e,'rendered') + cells.append(new_text_cell(u'html', source=source, rendered=rendered)) + if cell_e.tag == 'markdowncell': + source = _get_text(cell_e,'source') + rendered = _get_text(cell_e,'rendered') + cells.append(new_text_cell(u'markdown', source=source, rendered=rendered)) ws = new_worksheet(name=wsname,cells=cells) worksheets.append(ws) @@ -150,6 +155,11 @@ def writes(self, nb, **kwargs): elif cell_type == 'html': cell_e = ET.SubElement(cells_e, 'htmlcell') _set_text(cell,'source',cell_e,'source') + _set_text(cell,'rendered',cell_e,'rendered') + elif cell_type == 'markdown': + cell_e = ET.SubElement(cells_e, 'markdowncell') + _set_text(cell,'source',cell_e,'source') + _set_text(cell,'rendered',cell_e,'rendered') indent(nb_e) txt = ET.tostring(nb_e, encoding="utf-8") diff --git a/IPython/nbformat/v2/tests/nbexamples.py b/IPython/nbformat/v2/tests/nbexamples.py index 6671e37a56a..a4a83f9d471 100644 --- a/IPython/nbformat/v2/tests/nbexamples.py +++ b/IPython/nbformat/v2/tests/nbexamples.py @@ -1,14 +1,16 @@ from ..nbbase import ( NotebookNode, - new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output ) ws = new_worksheet(name='worksheet1') -ws.cells.append(new_html_cell( - source='Some NumPy Examples' +ws.cells.append(new_text_cell( + u'html', + source='Some NumPy Examples', + rendered='Some NumPy Examples' )) @@ -17,6 +19,12 @@ prompt_number=1 )) +ws.cells.append(new_text_cell( + u'markdown', + source='Some NumPy Examples', + rendered='Some NumPy Examples' +)) + ws.cells.append(new_code_cell( input='a = numpy.random.rand(100)', prompt_number=2 diff --git a/IPython/nbformat/v2/tests/test_nbbase.py b/IPython/nbformat/v2/tests/test_nbbase.py index a13c76aa0b5..4eb42a2bbb0 100644 --- a/IPython/nbformat/v2/tests/test_nbbase.py +++ b/IPython/nbformat/v2/tests/test_nbbase.py @@ -2,7 +2,7 @@ from ..nbbase import ( NotebookNode, - new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output ) class TestCell(TestCase): @@ -26,13 +26,26 @@ def test_code_cell(self): self.assertEquals(cc.outputs[0].prompt_number, 0) def test_empty_html_cell(self): - tc = new_html_cell() - self.assertEquals(tc.cell_type, 'html') + tc = new_text_cell(u'html') + self.assertEquals(tc.cell_type, u'html') self.assertEquals('source' not in tc, True) + self.assertEquals('rendered' not in tc, True) def test_html_cell(self): - tc = new_html_cell('hi') + tc = new_text_cell(u'html', 'hi', 'hi') self.assertEquals(tc.source, u'hi') + self.assertEquals(tc.rendered, u'hi') + + def test_empty_markdown_cell(self): + tc = new_text_cell(u'markdown') + self.assertEquals(tc.cell_type, u'markdown') + self.assertEquals('source' not in tc, True) + self.assertEquals('rendered' not in tc, True) + + def test_markdown_cell(self): + tc = new_text_cell(u'markdown', 'hi', 'hi') + self.assertEquals(tc.source, u'hi') + self.assertEquals(tc.rendered, u'hi') class TestWorksheet(TestCase): @@ -43,7 +56,7 @@ def test_empty_worksheet(self): self.assertEquals('name' not in ws, True) def test_worksheet(self): - cells = [new_code_cell(), new_html_cell()] + cells = [new_code_cell(), new_text_cell(u'html')] ws = new_worksheet(cells=cells,name='foo') self.assertEquals(ws.cells,cells) self.assertEquals(ws.name,u'foo') diff --git a/IPython/nbformat/v2/tests/test_nbpy.py b/IPython/nbformat/v2/tests/test_nbpy.py index d060d2992ae..4c12c4e4b4e 100644 --- a/IPython/nbformat/v2/tests/test_nbpy.py +++ b/IPython/nbformat/v2/tests/test_nbpy.py @@ -2,7 +2,7 @@ from ..nbbase import ( NotebookNode, - new_code_cell, new_html_cell, new_worksheet, new_notebook + new_code_cell, new_text_cell, new_worksheet, new_notebook ) from ..nbpy import reads, writes