From 47e4e1e2c4a7d1409f7146ae901a00f050bc406a Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Mon, 23 Jan 2012 18:58:50 -0800 Subject: [PATCH 1/7] A first go at RST cell support in the notebook. --- .../html/notebook/static/js/menubar.js | 3 + .../html/notebook/static/js/notebook.js | 71 +++++++++++++------ .../html/notebook/static/js/textcell.js | 48 ++++++++----- .../html/notebook/templates/notebook.html | 1 + 4 files changed, 82 insertions(+), 41 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index 5ddf5f09a..cdeb1c504 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -129,6 +129,9 @@ var IPython = (function (IPython) { this.element.find('#to_markdown').click(function () { IPython.notebook.to_markdown(); }); + this.element.find('#to_rst').click(function () { + IPython.notebook.to_rst(); + }); this.element.find('#toggle_output').click(function () { IPython.notebook.toggle_output(); }); diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index c69a75817..9e0137da6 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -135,6 +135,11 @@ var IPython = (function (IPython) { that.to_markdown(); that.control_key_active = false; return false; + } else if (event.which === 82 && that.control_key_active) { + // To RST = r + that.to_rst(); + that.control_key_active = false; + return false; } else if (event.which === 84 && that.control_key_active) { // Toggle output = t that.toggle_output(); @@ -467,15 +472,17 @@ var IPython = (function (IPython) { // type = ('code','html','markdown') // index = cell index or undefined to insert below selected index = this.index_or_selected(index); + var cell = null; if (this.ncells() === 0 || this.is_valid_cell_index(index)) { - var cell = null; if (type === 'code') { - var cell = new IPython.CodeCell(this); + cell = new IPython.CodeCell(this); cell.set_input_prompt(); } else if (type === 'markdown') { - var cell = new IPython.MarkdownCell(this); + cell = new IPython.MarkdownCell(this); } else if (type === 'html') { - var cell = new IPython.HTMLCell(this); + cell = new IPython.HTMLCell(this); + } else if (type === 'rst') { + cell = new IPython.RSTCell(this); }; if (cell !== null) { if (this.ncells() === 0) { @@ -489,6 +496,7 @@ var IPython = (function (IPython) { return cell; }; }; + return cell; }; @@ -496,15 +504,17 @@ var IPython = (function (IPython) { // type = ('code','html','markdown') // index = cell index or undefined to insert above selected index = this.index_or_selected(index); + var cell = null; if (this.ncells() === 0 || this.is_valid_cell_index(index)) { - var cell = null; if (type === 'code') { - var cell = new IPython.CodeCell(this); + cell = new IPython.CodeCell(this); cell.set_input_prompt(); } else if (type === 'markdown') { - var cell = new IPython.MarkdownCell(this); + cell = new IPython.MarkdownCell(this); } else if (type === 'html') { - var cell = new IPython.HTMLCell(this); + cell = new IPython.HTMLCell(this); + } else if (type === 'rst') { + cell = new IPython.RSTCell(this); }; if (cell !== null) { if (this.ncells() === 0) { @@ -518,6 +528,7 @@ var IPython = (function (IPython) { return cell; }; }; + return cell; }; @@ -534,8 +545,8 @@ var IPython = (function (IPython) { } target_cell.set_text(text); source_element.remove(); + this.dirty = true; }; - this.dirty = true; }; }; @@ -545,19 +556,16 @@ var IPython = (function (IPython) { if (this.is_valid_cell_index(i)) { var source_element = this.get_cell_element(i); var source_cell = source_element.data("cell"); - var target_cell = null; if (!(source_cell instanceof IPython.MarkdownCell)) { target_cell = this.insert_cell_below('markdown',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { text = ''; }; - if (target_cell !== null) { - // The edit must come before the set_text. - target_cell.edit(); - target_cell.set_text(text); - source_element.remove(); - } + // The edit must come before the set_text. + target_cell.edit(); + target_cell.set_text(text); + source_element.remove(); this.dirty = true; }; }; @@ -576,18 +584,37 @@ var IPython = (function (IPython) { if (text === source_cell.placeholder) { text = ''; }; - if (target_cell !== null) { - // The edit must come before the set_text. - target_cell.edit(); - target_cell.set_text(text); - source_element.remove(); - } + // The edit must come before the set_text. + target_cell.edit(); + target_cell.set_text(text); + source_element.remove(); this.dirty = true; }; }; }; + Notebook.prototype.to_rst = function (index) { + var i = this.index_or_selected(index); + if (this.is_valid_cell_index(i)) { + var source_element = this.get_cell_element(i); + var source_cell = source_element.data("cell"); + var target_cell = null; + if (!(source_cell instanceof IPython.RSTCell)) { + target_cell = this.insert_cell_below('rst',i); + var text = source_cell.get_text(); + if (text === source_cell.placeholder) { + text = ''; + }; + // The edit must come before the set_text. + target_cell.edit(); + target_cell.set_text(text); + source_element.remove(); + this.dirty = true; + }; + }; + }; + // Cut/Copy/Paste Notebook.prototype.enable_paste = function () { diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index aacfddf05..19c97448b 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -241,6 +241,7 @@ var IPython = (function (IPython) { var RSTCell = function (notebook) { this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$"; + this.code_mirror_mode = 'rst'; IPython.TextCell.apply(this, arguments); this.cell_type = 'rst'; }; @@ -250,29 +251,38 @@ var IPython = (function (IPython) { RSTCell.prototype.render = function () { - if (this.rendered === false) { - var text = this.get_text(); - if (text === "") { text = this.placeholder; } - var settings = { - processData : false, - cache : false, - type : "POST", - data : text, - headers : {'Content-Type': 'application/x-rst'}, - success : $.proxy(this.handle_render,this) - }; - $.ajax("/rstservice/render", settings); - this.element.find('div.text_cell_input').hide(); - this.element.find("div.text_cell_render").show(); - this.set_rendered("Rendering..."); + this.rendered = true; + this.edit(); + }; + + + RSTCell.prototype.select = function () { + IPython.Cell.prototype.select.apply(this); + // In some cases (inserting a new cell) we need a refresh before and + // after the focus. Not sure why this is the case. + this.code_mirror.refresh(); + this.code_mirror.focus(); + this.code_mirror.refresh(); + }; + + + RSTCell.prototype.at_top = function () { + var cursor = this.code_mirror.getCursor(); + if (cursor.line === 0) { + return true; + } else { + return false; } }; - RSTCell.prototype.handle_render = function (data, status, xhr) { - this.set_rendered(data); - this.typeset(); - this.rendered = true; + RSTCell.prototype.at_bottom = function () { + var cursor = this.code_mirror.getCursor(); + if (cursor.line === (this.code_mirror.lineCount()-1)) { + return true; + } else { + return false; + } }; diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 7e547f103..ab215f054 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -119,6 +119,7 @@
  • Code Cell
  • Markdown Cell
  • +
  • RST Cell

  • Toggle Output
  • Clear All Output
  • From f65adcf33e98520308e303ceee7fa5650f5475f1 Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Thu, 26 Jan 2012 16:17:18 -0800 Subject: [PATCH 2/7] Adding new HeadingCell. --- .../html/notebook/static/js/textcell.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 19c97448b..570be4e3a 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -286,6 +286,44 @@ var IPython = (function (IPython) { }; + // HTMLCell + + var HeadingCell = function (notebook) { + this.placeholder = "Type Heading Here"; + IPython.TextCell.apply(this, arguments); + this.cell_type = 'heading'; + this.level = 1; + }; + + + HeadingCell.prototype = new TextCell(); + + + HeadingCell.prototype.set_rendered = function (text) { + var r = this.element.find("div.text_cell_render"); + r.empty(); + r.append($('

    ').html(text)); + } + + + HeadingCell.prototype.get_rendered = function () { + var r = this.element.find("div.text_cell_render"); + return r.children().first().html(); + } + + + HeadingCell.prototype.render = function () { + if (this.rendered === false) { + var text = this.get_text(); + if (text === "") { text = this.placeholder; } + this.set_rendered(text); + this.typeset(); + this.element.find('div.text_cell_input').hide(); + this.element.find("div.text_cell_render").show(); + this.rendered = true; + } + }; + IPython.TextCell = TextCell; IPython.HTMLCell = HTMLCell; IPython.MarkdownCell = MarkdownCell; From fd3d5edb66c2f750e893fed7a4beeaa8dcfcb3c6 Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Thu, 26 Jan 2012 17:07:00 -0800 Subject: [PATCH 3/7] Finishing first draft of RST and heading cells. --- .../html/notebook/static/js/menubar.js | 18 ++++++ .../html/notebook/static/js/notebook.js | 61 +++++++++++++++++++ .../html/notebook/static/js/textcell.js | 23 +++++-- .../html/notebook/templates/notebook.html | 12 +++- 4 files changed, 107 insertions(+), 7 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index cdeb1c504..ae5893d08 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -132,6 +132,24 @@ var IPython = (function (IPython) { this.element.find('#to_rst').click(function () { IPython.notebook.to_rst(); }); + this.element.find('#to_heading1').click(function () { + IPython.notebook.to_heading(undefined, 1); + }); + this.element.find('#to_heading2').click(function () { + IPython.notebook.to_heading(undefined, 2); + }); + this.element.find('#to_heading3').click(function () { + IPython.notebook.to_heading(undefined, 3); + }); + this.element.find('#to_heading4').click(function () { + IPython.notebook.to_heading(undefined, 4); + }); + this.element.find('#to_heading5').click(function () { + IPython.notebook.to_heading(undefined, 5); + }); + this.element.find('#to_heading6').click(function () { + IPython.notebook.to_heading(undefined, 6); + }); this.element.find('#toggle_output').click(function () { IPython.notebook.toggle_output(); }); diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 9e0137da6..60277a5bf 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -140,6 +140,36 @@ var IPython = (function (IPython) { that.to_rst(); that.control_key_active = false; return false; + } else if (event.which === 49 && that.control_key_active) { + // To Heading 1 = 1 + that.to_heading(undefined, 1); + that.control_key_active = false; + return false; + } else if (event.which === 50 && that.control_key_active) { + // To Heading 2 = 2 + that.to_heading(undefined, 2); + that.control_key_active = false; + return false; + } else if (event.which === 51 && that.control_key_active) { + // To Heading 3 = 3 + that.to_heading(undefined, 3); + that.control_key_active = false; + return false; + } else if (event.which === 52 && that.control_key_active) { + // To Heading 4 = 4 + that.to_heading(undefined, 4); + that.control_key_active = false; + return false; + } else if (event.which === 53 && that.control_key_active) { + // To Heading 5 = 5 + that.to_heading(undefined, 5); + that.control_key_active = false; + return false; + } else if (event.which === 54 && that.control_key_active) { + // To Heading 6 = 6 + that.to_heading(undefined, 6); + that.control_key_active = false; + return false; } else if (event.which === 84 && that.control_key_active) { // Toggle output = t that.toggle_output(); @@ -483,6 +513,8 @@ var IPython = (function (IPython) { cell = new IPython.HTMLCell(this); } else if (type === 'rst') { cell = new IPython.RSTCell(this); + } else if (type === 'heading') { + cell = new IPython.HeadingCell(this); }; if (cell !== null) { if (this.ncells() === 0) { @@ -515,6 +547,8 @@ var IPython = (function (IPython) { cell = new IPython.HTMLCell(this); } else if (type === 'rst') { cell = new IPython.RSTCell(this); + } else if (type === 'heading') { + cell = new IPython.HeadingCell(this); }; if (cell !== null) { if (this.ncells() === 0) { @@ -615,6 +649,33 @@ var IPython = (function (IPython) { }; }; + + Notebook.prototype.to_heading = function (index, level) { + level = level || 1; + var i = this.index_or_selected(index); + if (this.is_valid_cell_index(i)) { + var source_element = this.get_cell_element(i); + var source_cell = source_element.data("cell"); + var target_cell = null; + if (source_cell instanceof IPython.HeadingCell) { + source_cell.set_level(level); + } else { + target_cell = this.insert_cell_below('heading',i); + var text = source_cell.get_text(); + if (text === source_cell.placeholder) { + text = ''; + }; + // The edit must come before the set_text. + target_cell.set_level(level); + target_cell.edit(); + target_cell.set_text(text); + source_element.remove(); + this.dirty = true; + }; + }; + }; + + // Cut/Copy/Paste Notebook.prototype.enable_paste = function () { diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 570be4e3a..984328f20 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -299,17 +299,31 @@ var IPython = (function (IPython) { HeadingCell.prototype = new TextCell(); + HeadingCell.prototype.set_level = function (level) { + this.level = level; + if (this.rendered) { + this.rendered = false; + this.render(); + }; + }; + + + HeadingCell.prototype.get_level = function () { + return this.level; + }; + + HeadingCell.prototype.set_rendered = function (text) { var r = this.element.find("div.text_cell_render"); r.empty(); - r.append($('

    ').html(text)); - } + r.append($('').html(text)); + }; HeadingCell.prototype.get_rendered = function () { var r = this.element.find("div.text_cell_render"); return r.children().first().html(); - } + }; HeadingCell.prototype.render = function () { @@ -321,13 +335,14 @@ var IPython = (function (IPython) { this.element.find('div.text_cell_input').hide(); this.element.find("div.text_cell_render").show(); this.rendered = true; - } + }; }; IPython.TextCell = TextCell; IPython.HTMLCell = HTMLCell; IPython.MarkdownCell = MarkdownCell; IPython.RSTCell = RSTCell; + IPython.HeadingCell = HeadingCell; return IPython; diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index ab215f054..b9e25eedc 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -117,9 +117,15 @@
  • Run in Place
  • Run All

  • -
  • Code Cell
  • -
  • Markdown Cell
  • -
  • RST Cell
  • +
  • Code
  • +
  • Markdown
  • +
  • RST
  • +
  • Heading 1
  • +
  • Heading 2
  • +
  • Heading 3
  • +
  • Heading 4
  • +
  • Heading 5
  • +
  • Heading 6

  • Toggle Output
  • Clear All Output
  • From 2f88004a05a77c4919e4d8c81924c7380f25d99c Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Mon, 30 Jan 2012 11:45:14 -0800 Subject: [PATCH 4/7] Updating JS part of plaintext cell handling. --- .../html/notebook/static/js/menubar.js | 4 ++-- .../html/notebook/static/js/notebook.js | 24 +++++++++---------- .../html/notebook/static/js/quickhelp.js | 3 ++- .../html/notebook/static/js/textcell.js | 20 ++++++++-------- .../html/notebook/templates/notebook.html | 2 +- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index ae5893d08..b513ecd68 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -129,8 +129,8 @@ var IPython = (function (IPython) { this.element.find('#to_markdown').click(function () { IPython.notebook.to_markdown(); }); - this.element.find('#to_rst').click(function () { - IPython.notebook.to_rst(); + this.element.find('#to_plaintext').click(function () { + IPython.notebook.to_plaintext(); }); this.element.find('#to_heading1').click(function () { IPython.notebook.to_heading(undefined, 1); diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 60277a5bf..ec4a74ee8 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -135,9 +135,9 @@ var IPython = (function (IPython) { that.to_markdown(); that.control_key_active = false; return false; - } else if (event.which === 82 && that.control_key_active) { - // To RST = r - that.to_rst(); + } else if (event.which === 84 && that.control_key_active) { + // To Plaintext = r + that.to_plaintext(); that.control_key_active = false; return false; } else if (event.which === 49 && that.control_key_active) { @@ -170,8 +170,8 @@ var IPython = (function (IPython) { that.to_heading(undefined, 6); that.control_key_active = false; return false; - } else if (event.which === 84 && that.control_key_active) { - // Toggle output = t + } else if (event.which === 79 && that.control_key_active) { + // Toggle output = o that.toggle_output(); that.control_key_active = false; return false; @@ -511,8 +511,8 @@ var IPython = (function (IPython) { cell = new IPython.MarkdownCell(this); } else if (type === 'html') { cell = new IPython.HTMLCell(this); - } else if (type === 'rst') { - cell = new IPython.RSTCell(this); + } else if (type === 'plaintext') { + cell = new IPython.PlaintextCell(this); } else if (type === 'heading') { cell = new IPython.HeadingCell(this); }; @@ -545,8 +545,8 @@ var IPython = (function (IPython) { cell = new IPython.MarkdownCell(this); } else if (type === 'html') { cell = new IPython.HTMLCell(this); - } else if (type === 'rst') { - cell = new IPython.RSTCell(this); + } else if (type === 'plaintext') { + cell = new IPython.PlaintextCell(this); } else if (type === 'heading') { cell = new IPython.HeadingCell(this); }; @@ -628,14 +628,14 @@ var IPython = (function (IPython) { }; - Notebook.prototype.to_rst = function (index) { + Notebook.prototype.to_plaintext = function (index) { var i = this.index_or_selected(index); if (this.is_valid_cell_index(i)) { var source_element = this.get_cell_element(i); var source_cell = source_element.data("cell"); var target_cell = null; - if (!(source_cell instanceof IPython.RSTCell)) { - target_cell = this.insert_cell_below('rst',i); + if (!(source_cell instanceof IPython.PlaintextCell)) { + target_cell = this.insert_cell_below('plaintext',i); var text = source_cell.get_text(); if (text === source_cell.placeholder) { text = ''; diff --git a/IPython/frontend/html/notebook/static/js/quickhelp.js b/IPython/frontend/html/notebook/static/js/quickhelp.js index 8e2954158..585e6210b 100644 --- a/IPython/frontend/html/notebook/static/js/quickhelp.js +++ b/IPython/frontend/html/notebook/static/js/quickhelp.js @@ -34,13 +34,14 @@ var IPython = (function (IPython) { {key: 'Ctrl-m d', help: 'delete cell'}, {key: 'Ctrl-m a', help: 'insert cell above'}, {key: 'Ctrl-m b', help: 'insert cell below'}, - {key: 'Ctrl-m t', help: 'toggle output'}, + {key: 'Ctrl-m o', help: 'toggle output'}, {key: 'Ctrl-m l', help: 'toggle line numbers'}, {key: 'Ctrl-m s', help: 'save notebook'}, {key: 'Ctrl-m j', help: 'move cell down'}, {key: 'Ctrl-m k', help: 'move cell up'}, {key: 'Ctrl-m y', help: 'code cell'}, {key: 'Ctrl-m m', help: 'markdown cell'}, + {key: 'Ctrl-m t', help: 'plaintext cell'}, {key: 'Ctrl-m p', help: 'select previous'}, {key: 'Ctrl-m n', help: 'select next'}, {key: 'Ctrl-m i', help: 'interrupt kernel'}, diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 984328f20..6e58523e9 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -237,26 +237,26 @@ var IPython = (function (IPython) { }; - // RSTCell + // PlaintextCell - var RSTCell = function (notebook) { - this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$"; + var PlaintextCell = function (notebook) { + this.placeholder = "Type plain text and LaTeX: $\\alpha^2$"; this.code_mirror_mode = 'rst'; IPython.TextCell.apply(this, arguments); - this.cell_type = 'rst'; + this.cell_type = 'plaintext'; }; - RSTCell.prototype = new TextCell(); + PlaintextCell.prototype = new TextCell(); - RSTCell.prototype.render = function () { + PlaintextCell.prototype.render = function () { this.rendered = true; this.edit(); }; - RSTCell.prototype.select = function () { + PlaintextCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); // In some cases (inserting a new cell) we need a refresh before and // after the focus. Not sure why this is the case. @@ -266,7 +266,7 @@ var IPython = (function (IPython) { }; - RSTCell.prototype.at_top = function () { + PlaintextCell.prototype.at_top = function () { var cursor = this.code_mirror.getCursor(); if (cursor.line === 0) { return true; @@ -276,7 +276,7 @@ var IPython = (function (IPython) { }; - RSTCell.prototype.at_bottom = function () { + PlaintextCell.prototype.at_bottom = function () { var cursor = this.code_mirror.getCursor(); if (cursor.line === (this.code_mirror.lineCount()-1)) { return true; @@ -341,7 +341,7 @@ var IPython = (function (IPython) { IPython.TextCell = TextCell; IPython.HTMLCell = HTMLCell; IPython.MarkdownCell = MarkdownCell; - IPython.RSTCell = RSTCell; + IPython.PlaintextCell = PlaintextCell; IPython.HeadingCell = HeadingCell; diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index b9e25eedc..15e0a53be 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -119,7 +119,7 @@
  • Code
  • Markdown
  • -
  • RST
  • +
  • Plaintext
  • Heading 1
  • Heading 2
  • Heading 3
  • From a00fc0165b13a7e560bb7d42594bb43242750805 Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Mon, 30 Jan 2012 12:08:36 -0800 Subject: [PATCH 5/7] Heading/plaintext cells now wired up to toolbar UI. --- .../frontend/html/notebook/static/js/notebook.js | 9 +++++++-- .../frontend/html/notebook/static/js/toolbar.js | 14 ++++++++++++++ .../frontend/html/notebook/templates/notebook.html | 7 +++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index ec4a74ee8..5f68ffaf7 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -136,7 +136,7 @@ var IPython = (function (IPython) { that.control_key_active = false; return false; } else if (event.which === 84 && that.control_key_active) { - // To Plaintext = r + // To Plaintext = t that.to_plaintext(); that.control_key_active = false; return false; @@ -401,7 +401,11 @@ var IPython = (function (IPython) { }; var cell = this.get_cell(index) cell.select(); - IPython.toolbar.set_cell_type(cell.cell_type); + if (cell.cell_type === 'heading') { + IPython.toolbar.set_cell_type(cell.cell_type+cell.level); + } else { + IPython.toolbar.set_cell_type(cell.cell_type) + } }; return this; }; @@ -672,6 +676,7 @@ var IPython = (function (IPython) { source_element.remove(); this.dirty = true; }; + IPython.toolbar.set_cell_type("heading"+level); }; }; diff --git a/IPython/frontend/html/notebook/static/js/toolbar.js b/IPython/frontend/html/notebook/static/js/toolbar.js index 501f00a03..df0de2510 100644 --- a/IPython/frontend/html/notebook/static/js/toolbar.js +++ b/IPython/frontend/html/notebook/static/js/toolbar.js @@ -108,6 +108,20 @@ var IPython = (function (IPython) { IPython.notebook.to_code(); } else if (cell_type === 'markdown') { IPython.notebook.to_markdown(); + } else if (cell_type === 'plaintext') { + IPython.notebook.to_plaintext(); + } else if (cell_type === 'heading1') { + IPython.notebook.to_heading(undefined, 1); + } else if (cell_type === 'heading2') { + IPython.notebook.to_heading(undefined, 2); + } else if (cell_type === 'heading3') { + IPython.notebook.to_heading(undefined, 3); + } else if (cell_type === 'heading4') { + IPython.notebook.to_heading(undefined, 4); + } else if (cell_type === 'heading5') { + IPython.notebook.to_heading(undefined, 5); + } else if (cell_type === 'heading6') { + IPython.notebook.to_heading(undefined, 6); }; }); diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 15e0a53be..242a5d0b8 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -180,6 +180,13 @@ From bdd17da81dbb81c0b6972819f75d54282a5b3d51 Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Mon, 30 Jan 2012 14:20:54 -0800 Subject: [PATCH 6/7] Fixing minor bugs in nbformat and saving. * json separator is not ',' to avoid adding extra space at EOL. * vs used throughout nbformat.current. * Cell collapse is properly loaded from notebook. --- IPython/frontend/html/notebook/static/js/codecell.js | 2 ++ IPython/frontend/html/notebook/static/js/notebook.js | 2 +- IPython/frontend/html/notebook/static/js/quickhelp.js | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 71d0670ba..e02a61826 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -824,6 +824,8 @@ var IPython = (function (IPython) { if (data.collapsed !== undefined) { if (data.collapsed) { this.collapse(); + } else { + this.expand(); }; }; }; diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 5f68ffaf7..df20219cc 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -1191,7 +1191,7 @@ var IPython = (function (IPython) { // We may want to move the name/id/nbformat logic inside toJSON? var data = this.toJSON(); data.metadata.name = nbname; - data.nbformat = 2; + data.nbformat = 3; // We do the call with settings so we can set cache to false. var settings = { processData : false, diff --git a/IPython/frontend/html/notebook/static/js/quickhelp.js b/IPython/frontend/html/notebook/static/js/quickhelp.js index 585e6210b..4edd117f9 100644 --- a/IPython/frontend/html/notebook/static/js/quickhelp.js +++ b/IPython/frontend/html/notebook/static/js/quickhelp.js @@ -42,6 +42,7 @@ var IPython = (function (IPython) { {key: 'Ctrl-m y', help: 'code cell'}, {key: 'Ctrl-m m', help: 'markdown cell'}, {key: 'Ctrl-m t', help: 'plaintext cell'}, + {key: 'Ctrl-m 1-6', help: 'heading 1-6 cell'}, {key: 'Ctrl-m p', help: 'select previous'}, {key: 'Ctrl-m n', help: 'select next'}, {key: 'Ctrl-m i', help: 'interrupt kernel'}, From d7efc0557240dd29a1142fd0e15865d40d6dfac1 Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Mon, 30 Jan 2012 14:54:26 -0800 Subject: [PATCH 7/7] Removing extra refresh in PlaintextCell. --- IPython/frontend/html/notebook/static/js/textcell.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 6e58523e9..1c98deada 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -258,11 +258,8 @@ var IPython = (function (IPython) { PlaintextCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); - // In some cases (inserting a new cell) we need a refresh before and - // after the focus. Not sure why this is the case. this.code_mirror.refresh(); this.code_mirror.focus(); - this.code_mirror.refresh(); };