Permalink
Browse files

Starting to rename text cell to html cell.

  • Loading branch information...
1 parent 2a85499 commit b0e516c2693e7017ad9a39e8c6d4f131e4a3d8f7 @ellisonbg ellisonbg committed Aug 8, 2011
@@ -7,7 +7,7 @@
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
)
@@ -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
@@ -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
@@ -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
@@ -5,7 +5,7 @@
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 @@ def to_notebook(self, root, **kwargs):
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 @@ def to_notebook(self, root, **kwargs):
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 @@ def writes(self, nb, **kwargs):
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 @@ def writes(self, nb, **kwargs):
_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")
@@ -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 @@
output_png=b'data',
output_svg=u'<svg>',
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'<array a>',
@@ -42,7 +43,8 @@
output_png=b'data',
output_svg=u'<svg>',
output_json=u'json data',
- output_javascript=u'var i=0;'
+ output_javascript=u'var i=0;',
+ prompt_number=4
)]
))
@@ -2,7 +2,7 @@
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 @@ def test_empty_code_cell(self):
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 @@ def test_empty_worksheet(self):
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')
@@ -2,7 +2,7 @@
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

0 comments on commit b0e516c

Please sign in to comment.