##// END OF EJS Templates
preserve trailing newlines in ipynb...
MinRK -
Show More
@@ -86,17 +86,17 b' def split_lines(nb):'
86 for cell in ws.cells:
86 for cell in ws.cells:
87 if cell.cell_type == 'code':
87 if cell.cell_type == 'code':
88 if 'input' in cell and isinstance(cell.input, basestring):
88 if 'input' in cell and isinstance(cell.input, basestring):
89 cell.input = cell.input.splitlines()
89 cell.input = (cell.input + '\n').splitlines()
90 for output in cell.outputs:
90 for output in cell.outputs:
91 for key in _multiline_outputs:
91 for key in _multiline_outputs:
92 item = output.get(key, None)
92 item = output.get(key, None)
93 if isinstance(item, basestring):
93 if isinstance(item, basestring):
94 output[key] = item.splitlines()
94 output[key] = (item + '\n').splitlines()
95 else: # text, heading cell
95 else: # text, heading cell
96 for key in ['source', 'rendered']:
96 for key in ['source', 'rendered']:
97 item = cell.get(key, None)
97 item = cell.get(key, None)
98 if isinstance(item, basestring):
98 if isinstance(item, basestring):
99 cell[key] = item.splitlines()
99 cell[key] = (item + '\n').splitlines()
100 return nb
100 return nb
101
101
102 # b64 encode/decode are never actually used, because all bytes objects in
102 # b64 encode/decode are never actually used, because all bytes objects in
@@ -49,6 +49,14 b' ws.cells.append(new_code_cell('
49 prompt_number=2,
49 prompt_number=2,
50 collapsed=True
50 collapsed=True
51 ))
51 ))
52 ws.cells.append(new_code_cell(
53 input='a = 10\nb = 5\n',
54 prompt_number=3,
55 ))
56 ws.cells.append(new_code_cell(
57 input='a = 10\nb = 5',
58 prompt_number=4,
59 ))
52
60
53 ws.cells.append(new_code_cell(
61 ws.cells.append(new_code_cell(
54 input=u'print "ünîcødé"',
62 input=u'print "ünîcødé"',
@@ -122,6 +130,16 b' a = numpy.random.rand(100)'
122
130
123 # <codecell>
131 # <codecell>
124
132
133 a = 10
134 b = 5
135
136 # <codecell>
137
138 a = 10
139 b = 5
140
141 # <codecell>
142
125 print "ünîcødé"
143 print "ünîcødé"
126
144
127 """ % nbformat
145 """ % nbformat
@@ -28,6 +28,11 b' class TestPy(formattest.NBFormatTestCase):'
28 for a,b in zip(da, db):
28 for a,b in zip(da, db):
29 self.assertSubset(a,b)
29 self.assertSubset(a,b)
30 else:
30 else:
31 if isinstance(da, basestring) and isinstance(db, basestring):
32 # pyfile is not sensitive to preserving leading/trailing
33 # newlines in blocks through roundtrip
34 da = da.strip('\n')
35 db = db.strip('\n')
31 self.assertEquals(da, db)
36 self.assertEquals(da, db)
32 return True
37 return True
33
38
General Comments 0
You need to be logged in to leave comments. Login now