##// END OF EJS Templates
Minor changes to heading cell in nbformat.
Brian Granger -
Show More
@@ -119,12 +119,14 b' def new_text_cell(cell_type, source=None, rendered=None):'
119 return cell
119 return cell
120
120
121
121
122 def new_heading_cell(source=None, level=1):
122 def new_heading_cell(source=None, rendered=None, level=1):
123 """Create a new section cell with a given integer level."""
123 """Create a new section cell with a given integer level."""
124 cell = NotebookNode()
124 cell = NotebookNode()
125 cell.cell_type = u'heading'
125 cell.cell_type = u'heading'
126 if source is not None:
126 if source is not None:
127 cell.source = unicode(source)
127 cell.source = unicode(source)
128 if rendered is not None:
129 cell.rendered = unicode(rendered)
128 cell.level = int(level)
130 cell.level = int(level)
129 return cell
131 return cell
130
132
@@ -64,9 +64,7 b' def rejoin_lines(nb):'
64 item = output.get(key, None)
64 item = output.get(key, None)
65 if isinstance(item, list):
65 if isinstance(item, list):
66 output[key] = u'\n'.join(item)
66 output[key] = u'\n'.join(item)
67 elif cell.cell_type == 'heading':
67 else: # text, heading cell
68 pass
69 else: # text cell
70 for key in ['source', 'rendered']:
68 for key in ['source', 'rendered']:
71 item = cell.get(key, None)
69 item = cell.get(key, None)
72 if isinstance(item, list):
70 if isinstance(item, list):
@@ -92,9 +90,7 b' def split_lines(nb):'
92 item = output.get(key, None)
90 item = output.get(key, None)
93 if isinstance(item, basestring):
91 if isinstance(item, basestring):
94 output[key] = item.splitlines()
92 output[key] = item.splitlines()
95 elif cell.cell_type == 'heading':
93 else: # text, heading cell
96 pass
97 else: # text cell
98 for key in ['source', 'rendered']:
94 for key in ['source', 'rendered']:
99 item = cell.get(key, None)
95 item = cell.get(key, None)
100 if isinstance(item, basestring):
96 if isinstance(item, basestring):
@@ -74,10 +74,12 b' class TestCell(TestCase):'
74 tc = new_heading_cell()
74 tc = new_heading_cell()
75 self.assertEquals(tc.cell_type, u'heading')
75 self.assertEquals(tc.cell_type, u'heading')
76 self.assertEquals(u'source' not in tc, True)
76 self.assertEquals(u'source' not in tc, True)
77 self.assertEquals(u'rendered' not in tc, True)
77
78
78 def test_heading_cell(self):
79 def test_heading_cell(self):
79 tc = new_heading_cell(u'My Heading', level=2)
80 tc = new_heading_cell(u'hi', u'hi', level=2)
80 self.assertEquals(tc.source, u'My Heading')
81 self.assertEquals(tc.source, u'hi')
82 self.assertEquals(tc.rendered, u'hi')
81 self.assertEquals(tc.level, 2)
83 self.assertEquals(tc.level, 2)
82
84
83
85
General Comments 0
You need to be logged in to leave comments. Login now