Show More
@@ -624,6 +624,9 b' var IPython = (function (IPython) {' | |||
|
624 | 624 | } else if (cell_data.cell_type === 'html') { |
|
625 | 625 | new_cell = this.insert_html_cell_after(); |
|
626 | 626 | new_cell.fromJSON(cell_data); |
|
627 | } else if (cell_data.cell_type === 'markdown') { | |
|
628 | new_cell = this.insert_markdown_cell_after(); | |
|
629 | new_cell.fromJSON(cell_data); | |
|
627 | 630 | }; |
|
628 | 631 | }; |
|
629 | 632 | }; |
@@ -132,7 +132,7 b' var IPython = (function (IPython) {' | |||
|
132 | 132 | if (data.cell_type === this.cell_type) { |
|
133 | 133 | if (data.source !== undefined) { |
|
134 | 134 | this.set_source(data.source); |
|
135 |
this.set_rendered(data. |
|
|
135 | this.set_rendered(data.rendered); | |
|
136 | 136 | }; |
|
137 | 137 | }; |
|
138 | 138 | } |
@@ -7,7 +7,7 b' from IPython.nbformat import v1' | |||
|
7 | 7 | |
|
8 | 8 | from IPython.nbformat.v2 import ( |
|
9 | 9 | NotebookNode, |
|
10 |
new_code_cell, new_ |
|
|
10 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet | |
|
11 | 11 | ) |
|
12 | 12 | |
|
13 | 13 |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | |
|
2 | 2 | from .nbbase import ( |
|
3 | 3 | NotebookNode, |
|
4 |
new_code_cell, new_ |
|
|
4 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet | |
|
5 | 5 | ) |
|
6 | 6 | |
|
7 | 7 | from .nbjson import reads as reads_json, writes as writes_json |
@@ -1,5 +1,5 b'' | |||
|
1 | 1 | from .nbbase import ( |
|
2 |
new_code_cell, new_ |
|
|
2 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output | |
|
3 | 3 | ) |
|
4 | 4 | |
|
5 | 5 | def convert_to_this_nbformat(nb, orig_version=1): |
@@ -7,10 +7,10 b' def convert_to_this_nbformat(nb, orig_version=1):' | |||
|
7 | 7 | newnb = new_notebook() |
|
8 | 8 | ws = new_worksheet() |
|
9 | 9 | for cell in nb.cells: |
|
10 | if cell.cell_type == 'code': | |
|
10 | if cell.cell_type == u'code': | |
|
11 | 11 | newcell = new_code_cell(input=cell.get('code'),prompt_number=cell.get('prompt_number')) |
|
12 | elif cell.cell_type == 'text': | |
|
13 |
newcell = new_ |
|
|
12 | elif cell.cell_type == u'text': | |
|
13 | newcell = new_text_cell(u'markdown',source=cell.get('text')) | |
|
14 | 14 | ws.cells.append(newcell) |
|
15 | 15 | newnb.worksheets.append(ws) |
|
16 | 16 | return newnb |
@@ -65,12 +65,14 b" def new_code_cell(input=None, prompt_number=None, outputs=None, language=u'pytho" | |||
|
65 | 65 | |
|
66 | 66 | return cell |
|
67 | 67 | |
|
68 |
def new_ |
|
|
68 | def new_text_cell(cell_type, source=None, rendered=None): | |
|
69 | 69 | """Create a new text cell.""" |
|
70 | 70 | cell = NotebookNode() |
|
71 | 71 | if source is not None: |
|
72 | 72 | cell.source = unicode(source) |
|
73 | cell.cell_type = u'html' | |
|
73 | if rendered is not None: | |
|
74 | cell.rendered = unicode(rendered) | |
|
75 | cell.cell_type = cell_type | |
|
74 | 76 | return cell |
|
75 | 77 | |
|
76 | 78 |
@@ -5,7 +5,7 b' from xml.etree import ElementTree as ET' | |||
|
5 | 5 | |
|
6 | 6 | from .rwbase import NotebookReader, NotebookWriter |
|
7 | 7 | from .nbbase import ( |
|
8 |
new_code_cell, new_ |
|
|
8 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output | |
|
9 | 9 | ) |
|
10 | 10 | |
|
11 | 11 | def indent(elem, level=0): |
@@ -108,7 +108,12 b' class XMLReader(NotebookReader):' | |||
|
108 | 108 | cells.append(cc) |
|
109 | 109 | if cell_e.tag == 'htmlcell': |
|
110 | 110 | source = _get_text(cell_e,'source') |
|
111 | cells.append(new_html_cell(source=source)) | |
|
111 | rendered = _get_text(cell_e,'rendered') | |
|
112 | cells.append(new_text_cell(u'html', source=source, rendered=rendered)) | |
|
113 | if cell_e.tag == 'markdowncell': | |
|
114 | source = _get_text(cell_e,'source') | |
|
115 | rendered = _get_text(cell_e,'rendered') | |
|
116 | cells.append(new_text_cell(u'markdown', source=source, rendered=rendered)) | |
|
112 | 117 | ws = new_worksheet(name=wsname,cells=cells) |
|
113 | 118 | worksheets.append(ws) |
|
114 | 119 | |
@@ -150,6 +155,11 b' class XMLWriter(NotebookWriter):' | |||
|
150 | 155 | elif cell_type == 'html': |
|
151 | 156 | cell_e = ET.SubElement(cells_e, 'htmlcell') |
|
152 | 157 | _set_text(cell,'source',cell_e,'source') |
|
158 | _set_text(cell,'rendered',cell_e,'rendered') | |
|
159 | elif cell_type == 'markdown': | |
|
160 | cell_e = ET.SubElement(cells_e, 'markdowncell') | |
|
161 | _set_text(cell,'source',cell_e,'source') | |
|
162 | _set_text(cell,'rendered',cell_e,'rendered') | |
|
153 | 163 | |
|
154 | 164 | indent(nb_e) |
|
155 | 165 | txt = ET.tostring(nb_e, encoding="utf-8") |
@@ -1,14 +1,16 b'' | |||
|
1 | 1 | from ..nbbase import ( |
|
2 | 2 | NotebookNode, |
|
3 |
new_code_cell, new_ |
|
|
3 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output | |
|
4 | 4 | ) |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | ws = new_worksheet(name='worksheet1') |
|
9 | 9 | |
|
10 |
ws.cells.append(new_ |
|
|
11 | source='Some NumPy Examples' | |
|
10 | ws.cells.append(new_text_cell( | |
|
11 | u'html', | |
|
12 | source='Some NumPy Examples', | |
|
13 | rendered='Some NumPy Examples' | |
|
12 | 14 | )) |
|
13 | 15 | |
|
14 | 16 | |
@@ -17,6 +19,12 b' ws.cells.append(new_code_cell(' | |||
|
17 | 19 | prompt_number=1 |
|
18 | 20 | )) |
|
19 | 21 | |
|
22 | ws.cells.append(new_text_cell( | |
|
23 | u'markdown', | |
|
24 | source='Some NumPy Examples', | |
|
25 | rendered='Some NumPy Examples' | |
|
26 | )) | |
|
27 | ||
|
20 | 28 | ws.cells.append(new_code_cell( |
|
21 | 29 | input='a = numpy.random.rand(100)', |
|
22 | 30 | prompt_number=2 |
@@ -2,7 +2,7 b' from unittest import TestCase' | |||
|
2 | 2 | |
|
3 | 3 | from ..nbbase import ( |
|
4 | 4 | NotebookNode, |
|
5 |
new_code_cell, new_ |
|
|
5 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output | |
|
6 | 6 | ) |
|
7 | 7 | |
|
8 | 8 | class TestCell(TestCase): |
@@ -26,13 +26,26 b' class TestCell(TestCase):' | |||
|
26 | 26 | self.assertEquals(cc.outputs[0].prompt_number, 0) |
|
27 | 27 | |
|
28 | 28 | def test_empty_html_cell(self): |
|
29 |
tc = new_ |
|
|
30 | self.assertEquals(tc.cell_type, 'html') | |
|
29 | tc = new_text_cell(u'html') | |
|
30 | self.assertEquals(tc.cell_type, u'html') | |
|
31 | 31 | self.assertEquals('source' not in tc, True) |
|
32 | self.assertEquals('rendered' not in tc, True) | |
|
32 | 33 | |
|
33 | 34 | def test_html_cell(self): |
|
34 |
tc = new_ |
|
|
35 | tc = new_text_cell(u'html', 'hi', 'hi') | |
|
35 | 36 | self.assertEquals(tc.source, u'hi') |
|
37 | self.assertEquals(tc.rendered, u'hi') | |
|
38 | ||
|
39 | def test_empty_markdown_cell(self): | |
|
40 | tc = new_text_cell(u'markdown') | |
|
41 | self.assertEquals(tc.cell_type, u'markdown') | |
|
42 | self.assertEquals('source' not in tc, True) | |
|
43 | self.assertEquals('rendered' not in tc, True) | |
|
44 | ||
|
45 | def test_markdown_cell(self): | |
|
46 | tc = new_text_cell(u'markdown', 'hi', 'hi') | |
|
47 | self.assertEquals(tc.source, u'hi') | |
|
48 | self.assertEquals(tc.rendered, u'hi') | |
|
36 | 49 | |
|
37 | 50 | |
|
38 | 51 | class TestWorksheet(TestCase): |
@@ -43,7 +56,7 b' class TestWorksheet(TestCase):' | |||
|
43 | 56 | self.assertEquals('name' not in ws, True) |
|
44 | 57 | |
|
45 | 58 | def test_worksheet(self): |
|
46 |
cells = [new_code_cell(), new_ |
|
|
59 | cells = [new_code_cell(), new_text_cell(u'html')] | |
|
47 | 60 | ws = new_worksheet(cells=cells,name='foo') |
|
48 | 61 | self.assertEquals(ws.cells,cells) |
|
49 | 62 | self.assertEquals(ws.name,u'foo') |
General Comments 0
You need to be logged in to leave comments.
Login now