Show More
@@ -129,6 +129,9 var IPython = (function (IPython) { | |||
|
129 | 129 | this.element.find('#to_markdown').click(function () { |
|
130 | 130 | IPython.notebook.to_markdown(); |
|
131 | 131 | }); |
|
132 | this.element.find('#to_rst').click(function () { | |
|
133 | IPython.notebook.to_rst(); | |
|
134 | }); | |
|
132 | 135 | this.element.find('#toggle_output').click(function () { |
|
133 | 136 | IPython.notebook.toggle_output(); |
|
134 | 137 | }); |
@@ -135,6 +135,11 var IPython = (function (IPython) { | |||
|
135 | 135 | that.to_markdown(); |
|
136 | 136 | that.control_key_active = false; |
|
137 | 137 | return false; |
|
138 | } else if (event.which === 82 && that.control_key_active) { | |
|
139 | // To RST = r | |
|
140 | that.to_rst(); | |
|
141 | that.control_key_active = false; | |
|
142 | return false; | |
|
138 | 143 | } else if (event.which === 84 && that.control_key_active) { |
|
139 | 144 | // Toggle output = t |
|
140 | 145 | that.toggle_output(); |
@@ -467,15 +472,17 var IPython = (function (IPython) { | |||
|
467 | 472 | // type = ('code','html','markdown') |
|
468 | 473 | // index = cell index or undefined to insert below selected |
|
469 | 474 | index = this.index_or_selected(index); |
|
475 | var cell = null; | |
|
470 | 476 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { |
|
471 | var cell = null; | |
|
472 | 477 | if (type === 'code') { |
|
473 |
|
|
|
478 | cell = new IPython.CodeCell(this); | |
|
474 | 479 | cell.set_input_prompt(); |
|
475 | 480 | } else if (type === 'markdown') { |
|
476 |
|
|
|
481 | cell = new IPython.MarkdownCell(this); | |
|
477 | 482 | } else if (type === 'html') { |
|
478 |
|
|
|
483 | cell = new IPython.HTMLCell(this); | |
|
484 | } else if (type === 'rst') { | |
|
485 | cell = new IPython.RSTCell(this); | |
|
479 | 486 | }; |
|
480 | 487 | if (cell !== null) { |
|
481 | 488 | if (this.ncells() === 0) { |
@@ -489,6 +496,7 var IPython = (function (IPython) { | |||
|
489 | 496 | return cell; |
|
490 | 497 | }; |
|
491 | 498 | }; |
|
499 | return cell; | |
|
492 | 500 | }; |
|
493 | 501 | |
|
494 | 502 | |
@@ -496,15 +504,17 var IPython = (function (IPython) { | |||
|
496 | 504 | // type = ('code','html','markdown') |
|
497 | 505 | // index = cell index or undefined to insert above selected |
|
498 | 506 | index = this.index_or_selected(index); |
|
507 | var cell = null; | |
|
499 | 508 | if (this.ncells() === 0 || this.is_valid_cell_index(index)) { |
|
500 | var cell = null; | |
|
501 | 509 | if (type === 'code') { |
|
502 |
|
|
|
510 | cell = new IPython.CodeCell(this); | |
|
503 | 511 | cell.set_input_prompt(); |
|
504 | 512 | } else if (type === 'markdown') { |
|
505 |
|
|
|
513 | cell = new IPython.MarkdownCell(this); | |
|
506 | 514 | } else if (type === 'html') { |
|
507 |
|
|
|
515 | cell = new IPython.HTMLCell(this); | |
|
516 | } else if (type === 'rst') { | |
|
517 | cell = new IPython.RSTCell(this); | |
|
508 | 518 | }; |
|
509 | 519 | if (cell !== null) { |
|
510 | 520 | if (this.ncells() === 0) { |
@@ -518,6 +528,7 var IPython = (function (IPython) { | |||
|
518 | 528 | return cell; |
|
519 | 529 | }; |
|
520 | 530 | }; |
|
531 | return cell; | |
|
521 | 532 | }; |
|
522 | 533 | |
|
523 | 534 | |
@@ -534,8 +545,8 var IPython = (function (IPython) { | |||
|
534 | 545 | } |
|
535 | 546 | target_cell.set_text(text); |
|
536 | 547 | source_element.remove(); |
|
548 | this.dirty = true; | |
|
537 | 549 | }; |
|
538 | this.dirty = true; | |
|
539 | 550 | }; |
|
540 | 551 | }; |
|
541 | 552 | |
@@ -545,19 +556,16 var IPython = (function (IPython) { | |||
|
545 | 556 | if (this.is_valid_cell_index(i)) { |
|
546 | 557 | var source_element = this.get_cell_element(i); |
|
547 | 558 | var source_cell = source_element.data("cell"); |
|
548 | var target_cell = null; | |
|
549 | 559 | if (!(source_cell instanceof IPython.MarkdownCell)) { |
|
550 | 560 | target_cell = this.insert_cell_below('markdown',i); |
|
551 | 561 | var text = source_cell.get_text(); |
|
552 | 562 | if (text === source_cell.placeholder) { |
|
553 | 563 | text = ''; |
|
554 | 564 | }; |
|
555 | if (target_cell !== null) { | |
|
556 | // The edit must come before the set_text. | |
|
557 |
|
|
|
558 | target_cell.set_text(text); | |
|
559 | source_element.remove(); | |
|
560 | } | |
|
565 | // The edit must come before the set_text. | |
|
566 | target_cell.edit(); | |
|
567 | target_cell.set_text(text); | |
|
568 | source_element.remove(); | |
|
561 | 569 | this.dirty = true; |
|
562 | 570 | }; |
|
563 | 571 | }; |
@@ -576,18 +584,37 var IPython = (function (IPython) { | |||
|
576 | 584 | if (text === source_cell.placeholder) { |
|
577 | 585 | text = ''; |
|
578 | 586 | }; |
|
579 | if (target_cell !== null) { | |
|
580 | // The edit must come before the set_text. | |
|
581 |
|
|
|
582 | target_cell.set_text(text); | |
|
583 | source_element.remove(); | |
|
584 | } | |
|
587 | // The edit must come before the set_text. | |
|
588 | target_cell.edit(); | |
|
589 | target_cell.set_text(text); | |
|
590 | source_element.remove(); | |
|
585 | 591 | this.dirty = true; |
|
586 | 592 | }; |
|
587 | 593 | }; |
|
588 | 594 | }; |
|
589 | 595 | |
|
590 | 596 | |
|
597 | Notebook.prototype.to_rst = function (index) { | |
|
598 | var i = this.index_or_selected(index); | |
|
599 | if (this.is_valid_cell_index(i)) { | |
|
600 | var source_element = this.get_cell_element(i); | |
|
601 | var source_cell = source_element.data("cell"); | |
|
602 | var target_cell = null; | |
|
603 | if (!(source_cell instanceof IPython.RSTCell)) { | |
|
604 | target_cell = this.insert_cell_below('rst',i); | |
|
605 | var text = source_cell.get_text(); | |
|
606 | if (text === source_cell.placeholder) { | |
|
607 | text = ''; | |
|
608 | }; | |
|
609 | // The edit must come before the set_text. | |
|
610 | target_cell.edit(); | |
|
611 | target_cell.set_text(text); | |
|
612 | source_element.remove(); | |
|
613 | this.dirty = true; | |
|
614 | }; | |
|
615 | }; | |
|
616 | }; | |
|
617 | ||
|
591 | 618 | // Cut/Copy/Paste |
|
592 | 619 | |
|
593 | 620 | Notebook.prototype.enable_paste = function () { |
@@ -241,6 +241,7 var IPython = (function (IPython) { | |||
|
241 | 241 | |
|
242 | 242 | var RSTCell = function (notebook) { |
|
243 | 243 | this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$"; |
|
244 | this.code_mirror_mode = 'rst'; | |
|
244 | 245 | IPython.TextCell.apply(this, arguments); |
|
245 | 246 | this.cell_type = 'rst'; |
|
246 | 247 | }; |
@@ -250,29 +251,38 var IPython = (function (IPython) { | |||
|
250 | 251 | |
|
251 | 252 | |
|
252 | 253 | RSTCell.prototype.render = function () { |
|
253 |
|
|
|
254 |
|
|
|
255 | if (text === "") { text = this.placeholder; } | |
|
256 | var settings = { | |
|
257 | processData : false, | |
|
258 | cache : false, | |
|
259 | type : "POST", | |
|
260 | data : text, | |
|
261 | headers : {'Content-Type': 'application/x-rst'}, | |
|
262 | success : $.proxy(this.handle_render,this) | |
|
263 | }; | |
|
264 | $.ajax("/rstservice/render", settings); | |
|
265 | this.element.find('div.text_cell_input').hide(); | |
|
266 | this.element.find("div.text_cell_render").show(); | |
|
267 | this.set_rendered("Rendering..."); | |
|
254 | this.rendered = true; | |
|
255 | this.edit(); | |
|
256 | }; | |
|
257 | ||
|
258 | ||
|
259 | RSTCell.prototype.select = function () { | |
|
260 | IPython.Cell.prototype.select.apply(this); | |
|
261 | // In some cases (inserting a new cell) we need a refresh before and | |
|
262 | // after the focus. Not sure why this is the case. | |
|
263 | this.code_mirror.refresh(); | |
|
264 | this.code_mirror.focus(); | |
|
265 | this.code_mirror.refresh(); | |
|
266 | }; | |
|
267 | ||
|
268 | ||
|
269 | RSTCell.prototype.at_top = function () { | |
|
270 | var cursor = this.code_mirror.getCursor(); | |
|
271 | if (cursor.line === 0) { | |
|
272 | return true; | |
|
273 | } else { | |
|
274 | return false; | |
|
268 | 275 | } |
|
269 | 276 | }; |
|
270 | 277 | |
|
271 | 278 | |
|
272 |
RSTCell.prototype. |
|
|
273 | this.set_rendered(data); | |
|
274 | this.typeset(); | |
|
275 |
|
|
|
279 | RSTCell.prototype.at_bottom = function () { | |
|
280 | var cursor = this.code_mirror.getCursor(); | |
|
281 | if (cursor.line === (this.code_mirror.lineCount()-1)) { | |
|
282 | return true; | |
|
283 | } else { | |
|
284 | return false; | |
|
285 | } | |
|
276 | 286 | }; |
|
277 | 287 | |
|
278 | 288 |
@@ -119,6 +119,7 | |||
|
119 | 119 | <hr/> |
|
120 | 120 | <li id="to_code"><a href="#">Code Cell</a></li> |
|
121 | 121 | <li id="to_markdown"><a href="#">Markdown Cell</a></li> |
|
122 | <li id="to_rst"><a href="#">RST Cell</a></li> | |
|
122 | 123 | <hr/> |
|
123 | 124 | <li id="toggle_output"><a href="#">Toggle Output</a></li> |
|
124 | 125 | <li id="clear_all_output"><a href="#">Clear All Output</a></li> |
General Comments 0
You need to be logged in to leave comments.
Login now