##// END OF EJS Templates
Merge pull request #1490 from minrk/raw...
Fernando Perez -
r6480:a0e0f391 merge
parent child Browse files
Show More
@@ -130,8 +130,8 b' var IPython = (function (IPython) {'
130 this.element.find('#to_markdown').click(function () {
130 this.element.find('#to_markdown').click(function () {
131 IPython.notebook.to_markdown();
131 IPython.notebook.to_markdown();
132 });
132 });
133 this.element.find('#to_plaintext').click(function () {
133 this.element.find('#to_raw').click(function () {
134 IPython.notebook.to_plaintext();
134 IPython.notebook.to_raw();
135 });
135 });
136 this.element.find('#to_heading1').click(function () {
136 this.element.find('#to_heading1').click(function () {
137 IPython.notebook.to_heading(undefined, 1);
137 IPython.notebook.to_heading(undefined, 1);
@@ -140,8 +140,8 b' var IPython = (function (IPython) {'
140 that.control_key_active = false;
140 that.control_key_active = false;
141 return false;
141 return false;
142 } else if (event.which === 84 && that.control_key_active) {
142 } else if (event.which === 84 && that.control_key_active) {
143 // To Plaintext = t
143 // To Raw = t
144 that.to_plaintext();
144 that.to_raw();
145 that.control_key_active = false;
145 that.control_key_active = false;
146 return false;
146 return false;
147 } else if (event.which === 49 && that.control_key_active) {
147 } else if (event.which === 49 && that.control_key_active) {
@@ -523,8 +523,8 b' var IPython = (function (IPython) {'
523 cell = new IPython.MarkdownCell(this);
523 cell = new IPython.MarkdownCell(this);
524 } else if (type === 'html') {
524 } else if (type === 'html') {
525 cell = new IPython.HTMLCell(this);
525 cell = new IPython.HTMLCell(this);
526 } else if (type === 'plaintext') {
526 } else if (type === 'raw') {
527 cell = new IPython.PlaintextCell(this);
527 cell = new IPython.RawCell(this);
528 } else if (type === 'heading') {
528 } else if (type === 'heading') {
529 cell = new IPython.HeadingCell(this);
529 cell = new IPython.HeadingCell(this);
530 };
530 };
@@ -557,8 +557,8 b' var IPython = (function (IPython) {'
557 cell = new IPython.MarkdownCell(this);
557 cell = new IPython.MarkdownCell(this);
558 } else if (type === 'html') {
558 } else if (type === 'html') {
559 cell = new IPython.HTMLCell(this);
559 cell = new IPython.HTMLCell(this);
560 } else if (type === 'plaintext') {
560 } else if (type === 'raw') {
561 cell = new IPython.PlaintextCell(this);
561 cell = new IPython.RawCell(this);
562 } else if (type === 'heading') {
562 } else if (type === 'heading') {
563 cell = new IPython.HeadingCell(this);
563 cell = new IPython.HeadingCell(this);
564 };
564 };
@@ -640,14 +640,14 b' var IPython = (function (IPython) {'
640 };
640 };
641
641
642
642
643 Notebook.prototype.to_plaintext = function (index) {
643 Notebook.prototype.to_raw = function (index) {
644 var i = this.index_or_selected(index);
644 var i = this.index_or_selected(index);
645 if (this.is_valid_cell_index(i)) {
645 if (this.is_valid_cell_index(i)) {
646 var source_element = this.get_cell_element(i);
646 var source_element = this.get_cell_element(i);
647 var source_cell = source_element.data("cell");
647 var source_cell = source_element.data("cell");
648 var target_cell = null;
648 var target_cell = null;
649 if (!(source_cell instanceof IPython.PlaintextCell)) {
649 if (!(source_cell instanceof IPython.RawCell)) {
650 target_cell = this.insert_cell_below('plaintext',i);
650 target_cell = this.insert_cell_below('raw',i);
651 var text = source_cell.get_text();
651 var text = source_cell.get_text();
652 if (text === source_cell.placeholder) {
652 if (text === source_cell.placeholder) {
653 text = '';
653 text = '';
@@ -1197,6 +1197,12 b' var IPython = (function (IPython) {'
1197 var new_cell = null;
1197 var new_cell = null;
1198 for (i=0; i<ncells; i++) {
1198 for (i=0; i<ncells; i++) {
1199 cell_data = new_cells[i];
1199 cell_data = new_cells[i];
1200 // VERSIONHACK: plaintext -> raw
1201 // handle never-released plaintext name for raw cells
1202 if (cell_data.cell_type === 'plaintext'){
1203 cell_data.cell_type = 'raw';
1204 }
1205
1200 new_cell = this.insert_cell_below(cell_data.cell_type);
1206 new_cell = this.insert_cell_below(cell_data.cell_type);
1201 new_cell.fromJSON(cell_data);
1207 new_cell.fromJSON(cell_data);
1202 };
1208 };
@@ -41,7 +41,7 b' var IPython = (function (IPython) {'
41 {key: 'Ctrl-m k', help: 'move cell up'},
41 {key: 'Ctrl-m k', help: 'move cell up'},
42 {key: 'Ctrl-m y', help: 'code cell'},
42 {key: 'Ctrl-m y', help: 'code cell'},
43 {key: 'Ctrl-m m', help: 'markdown cell'},
43 {key: 'Ctrl-m m', help: 'markdown cell'},
44 {key: 'Ctrl-m t', help: 'plaintext cell'},
44 {key: 'Ctrl-m t', help: 'raw cell'},
45 {key: 'Ctrl-m 1-6', help: 'heading 1-6 cell'},
45 {key: 'Ctrl-m 1-6', help: 'heading 1-6 cell'},
46 {key: 'Ctrl-m p', help: 'select previous'},
46 {key: 'Ctrl-m p', help: 'select previous'},
47 {key: 'Ctrl-m n', help: 'select next'},
47 {key: 'Ctrl-m n', help: 'select next'},
@@ -237,33 +237,33 b' var IPython = (function (IPython) {'
237 };
237 };
238
238
239
239
240 // PlaintextCell
240 // RawCell
241
241
242 var PlaintextCell = function (notebook) {
242 var RawCell = function (notebook) {
243 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
243 this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
244 this.code_mirror_mode = 'rst';
244 this.code_mirror_mode = 'rst';
245 IPython.TextCell.apply(this, arguments);
245 IPython.TextCell.apply(this, arguments);
246 this.cell_type = 'plaintext';
246 this.cell_type = 'raw';
247 };
247 };
248
248
249
249
250 PlaintextCell.prototype = new TextCell();
250 RawCell.prototype = new TextCell();
251
251
252
252
253 PlaintextCell.prototype.render = function () {
253 RawCell.prototype.render = function () {
254 this.rendered = true;
254 this.rendered = true;
255 this.edit();
255 this.edit();
256 };
256 };
257
257
258
258
259 PlaintextCell.prototype.select = function () {
259 RawCell.prototype.select = function () {
260 IPython.Cell.prototype.select.apply(this);
260 IPython.Cell.prototype.select.apply(this);
261 this.code_mirror.refresh();
261 this.code_mirror.refresh();
262 this.code_mirror.focus();
262 this.code_mirror.focus();
263 };
263 };
264
264
265
265
266 PlaintextCell.prototype.at_top = function () {
266 RawCell.prototype.at_top = function () {
267 var cursor = this.code_mirror.getCursor();
267 var cursor = this.code_mirror.getCursor();
268 if (cursor.line === 0) {
268 if (cursor.line === 0) {
269 return true;
269 return true;
@@ -273,7 +273,7 b' var IPython = (function (IPython) {'
273 };
273 };
274
274
275
275
276 PlaintextCell.prototype.at_bottom = function () {
276 RawCell.prototype.at_bottom = function () {
277 var cursor = this.code_mirror.getCursor();
277 var cursor = this.code_mirror.getCursor();
278 if (cursor.line === (this.code_mirror.lineCount()-1)) {
278 if (cursor.line === (this.code_mirror.lineCount()-1)) {
279 return true;
279 return true;
@@ -353,7 +353,7 b' var IPython = (function (IPython) {'
353 IPython.TextCell = TextCell;
353 IPython.TextCell = TextCell;
354 IPython.HTMLCell = HTMLCell;
354 IPython.HTMLCell = HTMLCell;
355 IPython.MarkdownCell = MarkdownCell;
355 IPython.MarkdownCell = MarkdownCell;
356 IPython.PlaintextCell = PlaintextCell;
356 IPython.RawCell = RawCell;
357 IPython.HeadingCell = HeadingCell;
357 IPython.HeadingCell = HeadingCell;
358
358
359
359
@@ -113,8 +113,8 b' var IPython = (function (IPython) {'
113 IPython.notebook.to_code();
113 IPython.notebook.to_code();
114 } else if (cell_type === 'markdown') {
114 } else if (cell_type === 'markdown') {
115 IPython.notebook.to_markdown();
115 IPython.notebook.to_markdown();
116 } else if (cell_type === 'plaintext') {
116 } else if (cell_type === 'raw') {
117 IPython.notebook.to_plaintext();
117 IPython.notebook.to_raw();
118 } else if (cell_type === 'heading1') {
118 } else if (cell_type === 'heading1') {
119 IPython.notebook.to_heading(undefined, 1);
119 IPython.notebook.to_heading(undefined, 1);
120 } else if (cell_type === 'heading2') {
120 } else if (cell_type === 'heading2') {
@@ -107,7 +107,7 b' data-notebook-id={{notebook_id}}'
107 <hr/>
107 <hr/>
108 <li id="to_code"><a href="#">Code</a></li>
108 <li id="to_code"><a href="#">Code</a></li>
109 <li id="to_markdown"><a href="#">Markdown </a></li>
109 <li id="to_markdown"><a href="#">Markdown </a></li>
110 <li id="to_plaintext"><a href="#">Plaintext</a></li>
110 <li id="to_raw"><a href="#">Raw Text</a></li>
111 <li id="to_heading1"><a href="#">Heading 1</a></li>
111 <li id="to_heading1"><a href="#">Heading 1</a></li>
112 <li id="to_heading2"><a href="#">Heading 2</a></li>
112 <li id="to_heading2"><a href="#">Heading 2</a></li>
113 <li id="to_heading3"><a href="#">Heading 3</a></li>
113 <li id="to_heading3"><a href="#">Heading 3</a></li>
@@ -171,7 +171,7 b' data-notebook-id={{notebook_id}}'
171 <select id="cell_type">
171 <select id="cell_type">
172 <option value="code">Code</option>
172 <option value="code">Code</option>
173 <option value="markdown">Markdown</option>
173 <option value="markdown">Markdown</option>
174 <option value="plaintext">Plaintext</option>
174 <option value="raw">Raw Text</option>
175 <option value="heading1">Heading 1</option>
175 <option value="heading1">Heading 1</option>
176 <option value="heading2">Heading 2</option>
176 <option value="heading2">Heading 2</option>
177 <option value="heading3">Heading 3</option>
177 <option value="heading3">Heading 3</option>
@@ -114,6 +114,10 b' def new_code_cell(input=None, prompt_number=None, outputs=None,'
114 def new_text_cell(cell_type, source=None, rendered=None):
114 def new_text_cell(cell_type, source=None, rendered=None):
115 """Create a new text cell."""
115 """Create a new text cell."""
116 cell = NotebookNode()
116 cell = NotebookNode()
117 # VERSIONHACK: plaintext -> raw
118 # handle never-released plaintext name for raw cells
119 if cell_type == 'plaintext':
120 cell_type = 'raw'
117 if source is not None:
121 if source is not None:
118 cell.source = unicode(source)
122 cell.source = unicode(source)
119 if rendered is not None:
123 if rendered is not None:
@@ -68,11 +68,12 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'# <plaintextcell>'):
71 # VERSIONHACK: plaintext -> raw
72 elif line.startswith(u'# <rawcell>') or line.startswith(u'# <plaintextcell>'):
72 cell = self.new_cell(state, cell_lines, **kwargs)
73 cell = self.new_cell(state, cell_lines, **kwargs)
73 if cell is not None:
74 if cell is not None:
74 cells.append(cell)
75 cells.append(cell)
75 state = u'plaintextcell'
76 state = u'rawcell'
76 cell_lines = []
77 cell_lines = []
77 kwargs = {}
78 kwargs = {}
78 elif line.startswith(u'# <headingcell'):
79 elif line.startswith(u'# <headingcell'):
@@ -113,10 +114,10 b' class PyReader(NotebookReader):'
113 text = self._remove_comments(lines)
114 text = self._remove_comments(lines)
114 if text:
115 if text:
115 return new_text_cell(u'markdown',source=text)
116 return new_text_cell(u'markdown',source=text)
116 elif state == u'plaintextcell':
117 elif state == u'rawcell':
117 text = self._remove_comments(lines)
118 text = self._remove_comments(lines)
118 if text:
119 if text:
119 return new_text_cell(u'plaintext',source=text)
120 return new_text_cell(u'raw',source=text)
120 elif state == u'headingcell':
121 elif state == u'headingcell':
121 text = self._remove_comments(lines)
122 text = self._remove_comments(lines)
122 level = kwargs.get('level',1)
123 level = kwargs.get('level',1)
@@ -172,10 +173,10 b' class PyWriter(NotebookWriter):'
172 lines.extend([u'# <markdowncell>',u''])
173 lines.extend([u'# <markdowncell>',u''])
173 lines.extend([u'# ' + line for line in input.splitlines()])
174 lines.extend([u'# ' + line for line in input.splitlines()])
174 lines.append(u'')
175 lines.append(u'')
175 elif cell.cell_type == u'plaintext':
176 elif cell.cell_type == u'raw':
176 input = cell.get(u'source')
177 input = cell.get(u'source')
177 if input is not None:
178 if input is not None:
178 lines.extend([u'# <plaintextcell>',u''])
179 lines.extend([u'# <rawcell>',u''])
179 lines.extend([u'# ' + line for line in input.splitlines()])
180 lines.extend([u'# ' + line for line in input.splitlines()])
180 lines.append(u'')
181 lines.append(u'')
181 elif cell.cell_type == u'heading':
182 elif cell.cell_type == u'heading':
@@ -35,7 +35,7 b' ws.cells.append(new_text_cell('
35 ))
35 ))
36
36
37 ws.cells.append(new_text_cell(
37 ws.cells.append(new_text_cell(
38 u'plaintext',
38 u'raw',
39 source='A random array',
39 source='A random array',
40 ))
40 ))
41
41
@@ -116,7 +116,7 b' import numpy'
116
116
117 # A random array
117 # A random array
118
118
119 # <plaintextcell>
119 # <rawcell>
120
120
121 # A random array
121 # A random array
122
122
@@ -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_plaintext_cell(self):
62 def test_empty_raw_cell(self):
63 tc = new_text_cell(u'plaintext')
63 tc = new_text_cell(u'raw')
64 self.assertEquals(tc.cell_type, u'plaintext')
64 self.assertEquals(tc.cell_type, u'raw')
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_plaintext_cell(self):
68 def test_raw_cell(self):
69 tc = new_text_cell(u'plaintext', 'hi', 'hi')
69 tc = new_text_cell(u'raw', '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