Show More
@@ -21,10 +21,11 b' import json' | |||||
21 | from xml.etree import ElementTree as ET |
|
21 | from xml.etree import ElementTree as ET | |
22 | import re |
|
22 | import re | |
23 |
|
23 | |||
|
24 | from IPython.nbformat import v3 | |||
24 | from IPython.nbformat import v2 |
|
25 | from IPython.nbformat import v2 | |
25 | from IPython.nbformat import v1 |
|
26 | from IPython.nbformat import v1 | |
26 |
|
27 | |||
27 |
from IPython.nbformat.v |
|
28 | from IPython.nbformat.v3 import ( | |
28 | NotebookNode, |
|
29 | NotebookNode, | |
29 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
30 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, | |
30 | parse_filename, new_metadata, new_author |
|
31 | parse_filename, new_metadata, new_author |
@@ -68,11 +68,11 b' class PyReader(NotebookReader):' | |||||
68 | state = u'markdowncell' |
|
68 | state = u'markdowncell' | |
69 | cell_lines = [] |
|
69 | cell_lines = [] | |
70 | kwargs = {} |
|
70 | kwargs = {} | |
71 |
elif line.startswith(u'# < |
|
71 | elif line.startswith(u'# <plaintextcell>'): | |
72 | cell = self.new_cell(state, cell_lines, **kwargs) |
|
72 | cell = self.new_cell(state, cell_lines, **kwargs) | |
73 | if cell is not None: |
|
73 | if cell is not None: | |
74 | cells.append(cell) |
|
74 | cells.append(cell) | |
75 |
state = u' |
|
75 | state = u'plaintextcell' | |
76 | cell_lines = [] |
|
76 | cell_lines = [] | |
77 | kwargs = {} |
|
77 | kwargs = {} | |
78 | elif line.startswith(u'# <headingcell'): |
|
78 | elif line.startswith(u'# <headingcell'): | |
@@ -113,10 +113,10 b' class PyReader(NotebookReader):' | |||||
113 | text = self._remove_comments(lines) |
|
113 | text = self._remove_comments(lines) | |
114 | if text: |
|
114 | if text: | |
115 | return new_text_cell(u'markdown',source=text) |
|
115 | return new_text_cell(u'markdown',source=text) | |
116 |
elif state == u' |
|
116 | elif state == u'plaintextcell': | |
117 | text = self._remove_comments(lines) |
|
117 | text = self._remove_comments(lines) | |
118 | if text: |
|
118 | if text: | |
119 |
return new_text_cell(u' |
|
119 | return new_text_cell(u'plaintext',source=text) | |
120 | elif state == u'headingcell': |
|
120 | elif state == u'headingcell': | |
121 | text = self._remove_comments(lines) |
|
121 | text = self._remove_comments(lines) | |
122 | level = kwargs.get('level',1) |
|
122 | level = kwargs.get('level',1) | |
@@ -172,10 +172,10 b' class PyWriter(NotebookWriter):' | |||||
172 | lines.extend([u'# <markdowncell>',u'']) |
|
172 | lines.extend([u'# <markdowncell>',u'']) | |
173 | lines.extend([u'# ' + line for line in input.splitlines()]) |
|
173 | lines.extend([u'# ' + line for line in input.splitlines()]) | |
174 | lines.append(u'') |
|
174 | lines.append(u'') | |
175 |
elif cell.cell_type == u' |
|
175 | elif cell.cell_type == u'plaintext': | |
176 | input = cell.get(u'source') |
|
176 | input = cell.get(u'source') | |
177 | if input is not None: |
|
177 | if input is not None: | |
178 |
lines.extend([u'# < |
|
178 | lines.extend([u'# <plaintextcell>',u'']) | |
179 | lines.extend([u'# ' + line for line in input.splitlines()]) |
|
179 | lines.extend([u'# ' + line for line in input.splitlines()]) | |
180 | lines.append(u'') |
|
180 | lines.append(u'') | |
181 | elif cell.cell_type == u'heading': |
|
181 | elif cell.cell_type == u'heading': |
@@ -33,7 +33,7 b' ws.cells.append(new_text_cell(' | |||||
33 | )) |
|
33 | )) | |
34 |
|
34 | |||
35 | ws.cells.append(new_text_cell( |
|
35 | ws.cells.append(new_text_cell( | |
36 |
u' |
|
36 | u'plaintext', | |
37 | source='A random array', |
|
37 | source='A random array', | |
38 | )) |
|
38 | )) | |
39 |
|
39 | |||
@@ -106,7 +106,7 b' import numpy' | |||||
106 |
|
106 | |||
107 | # A random array |
|
107 | # A random array | |
108 |
|
108 | |||
109 |
# < |
|
109 | # <plaintextcell> | |
110 |
|
110 | |||
111 | # A random array |
|
111 | # A random array | |
112 |
|
112 |
@@ -59,14 +59,14 b' class TestCell(TestCase):' | |||||
59 | self.assertEquals(tc.source, u'hi') |
|
59 | self.assertEquals(tc.source, u'hi') | |
60 | self.assertEquals(tc.rendered, u'hi') |
|
60 | self.assertEquals(tc.rendered, u'hi') | |
61 |
|
61 | |||
62 |
def test_empty_ |
|
62 | def test_empty_plaintext_cell(self): | |
63 |
tc = new_text_cell(u' |
|
63 | tc = new_text_cell(u'plaintext') | |
64 |
self.assertEquals(tc.cell_type, u' |
|
64 | self.assertEquals(tc.cell_type, u'plaintext') | |
65 | self.assertEquals(u'source' not in tc, True) |
|
65 | self.assertEquals(u'source' not in tc, True) | |
66 | self.assertEquals(u'rendered' not in tc, True) |
|
66 | self.assertEquals(u'rendered' not in tc, True) | |
67 |
|
67 | |||
68 |
def test_ |
|
68 | def test_plaintext_cell(self): | |
69 |
tc = new_text_cell(u' |
|
69 | tc = new_text_cell(u'plaintext', 'hi', 'hi') | |
70 | self.assertEquals(tc.source, u'hi') |
|
70 | self.assertEquals(tc.source, u'hi') | |
71 | self.assertEquals(tc.rendered, u'hi') |
|
71 | self.assertEquals(tc.rendered, u'hi') | |
72 |
|
72 |
General Comments 0
You need to be logged in to leave comments.
Login now