From b0e516c2693e7017ad9a39e8c6d4f131e4a3d8f7 2011-08-08 15:44:51 From: Brian E. Granger Date: 2011-08-08 15:44:51 Subject: [PATCH] Starting to rename text cell to html cell. --- diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/htmlcell.js similarity index 100% rename from IPython/frontend/html/notebook/static/js/textcell.js rename to IPython/frontend/html/notebook/static/js/htmlcell.js diff --git a/IPython/nbformat/current.py b/IPython/nbformat/current.py index 757c20e..840cb5d 100644 --- a/IPython/nbformat/current.py +++ b/IPython/nbformat/current.py @@ -7,7 +7,7 @@ from IPython.nbformat import v1 from IPython.nbformat.v2 import ( NotebookNode, - new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet + new_code_cell, new_html_cell, new_notebook, new_output, new_worksheet ) diff --git a/IPython/nbformat/v2/__init__.py b/IPython/nbformat/v2/__init__.py index 4f71ce5..449b634 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_text_cell, new_notebook, new_output, new_worksheet + new_code_cell, new_html_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 7ab5908..55f3dd3 100644 --- a/IPython/nbformat/v2/convert.py +++ b/IPython/nbformat/v2/convert.py @@ -1,5 +1,5 @@ from .nbbase import ( - new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output ) def convert_to_this_nbformat(nb, orig_version=1): @@ -10,7 +10,7 @@ def convert_to_this_nbformat(nb, orig_version=1): if cell.cell_type == 'code': newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number')) elif cell.cell_type == 'text': - newcell = new_text_cell(text=cell.get('text')) + newcell = new_html_cell(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 b2256cb..598f0ab 100644 --- a/IPython/nbformat/v2/nbbase.py +++ b/IPython/nbformat/v2/nbbase.py @@ -65,12 +65,12 @@ def new_code_cell(input=None, prompt_number=None, outputs=None, language=u'pytho return cell -def new_text_cell(text=None): +def new_html_cell(source=None): """Create a new text cell.""" cell = NotebookNode() - if text is not None: - cell.text = unicode(text) - cell.cell_type = u'text' + if source is not None: + cell.source = unicode(source) + cell.cell_type = u'html' return cell diff --git a/IPython/nbformat/v2/nbxml.py b/IPython/nbformat/v2/nbxml.py index 2eabb3d..976ca08 100644 --- a/IPython/nbformat/v2/nbxml.py +++ b/IPython/nbformat/v2/nbxml.py @@ -5,7 +5,7 @@ from xml.etree import ElementTree as ET from .rwbase import NotebookReader, NotebookWriter from .nbbase import ( - new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output ) def indent(elem, level=0): @@ -87,7 +87,7 @@ class XMLReader(NotebookReader): language = _get_text(cell_e,'language') outputs = [] for output_e in cell_e.find('outputs').getiterator('output'): - prompt_number = _get_int(output_e,'prompt_number') + out_prompt_number = _get_int(output_e,'prompt_number') output_type = _get_text(output_e,'output_type') output_text = _get_text(output_e,'text') output_png = _get_binary(output_e,'png') @@ -100,15 +100,15 @@ class XMLReader(NotebookReader): output_text=output_text,output_svg=output_svg, output_html=output_html,output_latex=output_latex, output_json=output_json,output_javascript=output_javascript, - prompt_number=prompt_number + prompt_number=out_prompt_number ) outputs.append(output) cc = new_code_cell(input=input,prompt_number=prompt_number, language=language,outputs=outputs) cells.append(cc) - if cell_e.tag == 'textcell': - text = _get_text(cell_e,'text') - cells.append(new_text_cell(text=text)) + if cell_e.tag == 'htmlcell': + source = _get_text(cell_e,'source') + cells.append(new_html_cell(source=source)) ws = new_worksheet(name=wsname,cells=cells) worksheets.append(ws) @@ -138,7 +138,7 @@ class XMLWriter(NotebookWriter): outputs_e = ET.SubElement(cell_e, 'outputs') for output in cell.outputs: output_e = ET.SubElement(outputs_e, 'output') - _set_int(cell,'prompt_number',output_e,'prompt_number') + _set_int(output,'prompt_number',output_e,'prompt_number') _set_text(output,'output_type',output_e,'output_type') _set_text(output,'text',output_e,'text') _set_binary(output,'png',output_e,'png') @@ -147,9 +147,9 @@ class XMLWriter(NotebookWriter): _set_text(output,'latex',output_e,'latex') _set_text(output,'json',output_e,'json') _set_text(output,'javascript',output_e,'javascript') - elif cell_type == 'text': - cell_e = ET.SubElement(cells_e, 'textcell') - _set_text(cell,'text',cell_e,'text') + elif cell_type == 'html': + cell_e = ET.SubElement(cells_e, 'htmlcell') + _set_text(cell,'source',cell_e,'source') 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 57a3cbb..6671e37 100644 --- a/IPython/nbformat/v2/tests/nbexamples.py +++ b/IPython/nbformat/v2/tests/nbexamples.py @@ -1,14 +1,14 @@ from ..nbbase import ( NotebookNode, - new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output ) ws = new_worksheet(name='worksheet1') -ws.cells.append(new_text_cell( - text='Some NumPy Examples' +ws.cells.append(new_html_cell( + source='Some NumPy Examples' )) @@ -33,7 +33,8 @@ ws.cells.append(new_code_cell( output_png=b'data', output_svg=u'', output_json=u'json data', - output_javascript=u'var i=0;' + output_javascript=u'var i=0;', + prompt_number=3 ),new_output( output_type=u'display_data', output_text=u'', @@ -42,7 +43,8 @@ ws.cells.append(new_code_cell( output_png=b'data', output_svg=u'', output_json=u'json data', - output_javascript=u'var i=0;' + output_javascript=u'var i=0;', + prompt_number=4 )] )) diff --git a/IPython/nbformat/v2/tests/test_nbbase.py b/IPython/nbformat/v2/tests/test_nbbase.py index 06607f8..a13c76a 100644 --- a/IPython/nbformat/v2/tests/test_nbbase.py +++ b/IPython/nbformat/v2/tests/test_nbbase.py @@ -2,7 +2,7 @@ from unittest import TestCase from ..nbbase import ( NotebookNode, - new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output + new_code_cell, new_html_cell, new_worksheet, new_notebook, new_output ) class TestCell(TestCase): @@ -16,21 +16,23 @@ class TestCell(TestCase): def test_code_cell(self): cc = new_code_cell(input='a=10', prompt_number=0) - cc.outputs = [new_output(output_type='pyout',output_svg='foo',output_text='10')] + cc.outputs = [new_output(output_type='pyout', + output_svg='foo',output_text='10',prompt_number=0)] self.assertEquals(cc.input, u'a=10') self.assertEquals(cc.prompt_number, 0) self.assertEquals(cc.language, u'python') self.assertEquals(cc.outputs[0].svg, u'foo') self.assertEquals(cc.outputs[0].text, u'10') + self.assertEquals(cc.outputs[0].prompt_number, 0) - def test_empty_text_cell(self): - tc = new_text_cell() - self.assertEquals(tc.cell_type, 'text') - self.assertEquals('text' not in tc, True) + def test_empty_html_cell(self): + tc = new_html_cell() + self.assertEquals(tc.cell_type, 'html') + self.assertEquals('source' not in tc, True) - def test_text_cell(self): - tc = new_text_cell('hi') - self.assertEquals(tc.text, u'hi') + def test_html_cell(self): + tc = new_html_cell('hi') + self.assertEquals(tc.source, u'hi') class TestWorksheet(TestCase): @@ -41,7 +43,7 @@ class TestWorksheet(TestCase): self.assertEquals('name' not in ws, True) def test_worksheet(self): - cells = [new_code_cell(), new_text_cell()] + cells = [new_code_cell(), new_html_cell()] 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 4c12c4e..d060d29 100644 --- a/IPython/nbformat/v2/tests/test_nbpy.py +++ b/IPython/nbformat/v2/tests/test_nbpy.py @@ -2,7 +2,7 @@ from unittest import TestCase from ..nbbase import ( NotebookNode, - new_code_cell, new_text_cell, new_worksheet, new_notebook + new_code_cell, new_html_cell, new_worksheet, new_notebook ) from ..nbpy import reads, writes