Merge pull request #1490 from minrk/raw

rename plaintext cell -> raw cell

Raw cells should be *untransformed* when writing various output formats, as the point of them is to let users pass through IPython to their rendered document format (rst, latex, etc.).  This is different from what is the logical meaning of 'plaintext', which would suggest that the contents should be preserved as unformatted plaintext (e.g. in a `<pre>` tag, or literal block).

In the UI, these cells will be displayed as 'Raw Text'.

WARNING: any existing v3 notebooks which use plaintext cells, when read in by versions after this merge, will silently rename those cells to 'raw'.  But if such a notebook is uploaded into a pre-merge IPython, cells labeled as 'raw' will simply *not be displayed*.
This commit is contained in:
Fernando Perez 2012-04-14 17:46:25 -07:00
commit 0344f92a62
6 changed files with 31 additions and 25 deletions

View File

@ -130,8 +130,8 @@ var IPython = (function (IPython) {
this.element.find('#to_markdown').click(function () {
IPython.notebook.to_markdown();
});
this.element.find('#to_plaintext').click(function () {
IPython.notebook.to_plaintext();
this.element.find('#to_raw').click(function () {
IPython.notebook.to_raw();
});
this.element.find('#to_heading1').click(function () {
IPython.notebook.to_heading(undefined, 1);

View File

@ -140,8 +140,8 @@ var IPython = (function (IPython) {
that.control_key_active = false;
return false;
} else if (event.which === 84 && that.control_key_active) {
// To Plaintext = t
that.to_plaintext();
// To Raw = t
that.to_raw();
that.control_key_active = false;
return false;
} else if (event.which === 49 && that.control_key_active) {
@ -523,8 +523,8 @@ var IPython = (function (IPython) {
cell = new IPython.MarkdownCell(this);
} else if (type === 'html') {
cell = new IPython.HTMLCell(this);
} else if (type === 'plaintext') {
cell = new IPython.PlaintextCell(this);
} else if (type === 'raw') {
cell = new IPython.RawCell(this);
} else if (type === 'heading') {
cell = new IPython.HeadingCell(this);
};
@ -557,8 +557,8 @@ var IPython = (function (IPython) {
cell = new IPython.MarkdownCell(this);
} else if (type === 'html') {
cell = new IPython.HTMLCell(this);
} else if (type === 'plaintext') {
cell = new IPython.PlaintextCell(this);
} else if (type === 'raw') {
cell = new IPython.RawCell(this);
} else if (type === 'heading') {
cell = new IPython.HeadingCell(this);
};
@ -640,14 +640,14 @@ var IPython = (function (IPython) {
};
Notebook.prototype.to_plaintext = function (index) {
Notebook.prototype.to_raw = 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.PlaintextCell)) {
target_cell = this.insert_cell_below('plaintext',i);
if (!(source_cell instanceof IPython.RawCell)) {
target_cell = this.insert_cell_below('raw',i);
var text = source_cell.get_text();
if (text === source_cell.placeholder) {
text = '';
@ -1197,6 +1197,12 @@ var IPython = (function (IPython) {
var new_cell = null;
for (i=0; i<ncells; i++) {
cell_data = new_cells[i];
// VERSIONHACK: plaintext -> raw
// handle never-released plaintext name for raw cells
if (cell_data.cell_type === 'plaintext'){
cell_data.cell_type = 'raw';
}
new_cell = this.insert_cell_below(cell_data.cell_type);
new_cell.fromJSON(cell_data);
};

View File

@ -41,7 +41,7 @@ var IPython = (function (IPython) {
{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 t', help: 'raw 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'},

View File

@ -237,33 +237,33 @@ var IPython = (function (IPython) {
};
// PlaintextCell
// RawCell
var PlaintextCell = function (notebook) {
var RawCell = function (notebook) {
this.placeholder = "Type plain text and LaTeX: $\\alpha^2$";
this.code_mirror_mode = 'rst';
IPython.TextCell.apply(this, arguments);
this.cell_type = 'plaintext';
this.cell_type = 'raw';
};
PlaintextCell.prototype = new TextCell();
RawCell.prototype = new TextCell();
PlaintextCell.prototype.render = function () {
RawCell.prototype.render = function () {
this.rendered = true;
this.edit();
};
PlaintextCell.prototype.select = function () {
RawCell.prototype.select = function () {
IPython.Cell.prototype.select.apply(this);
this.code_mirror.refresh();
this.code_mirror.focus();
};
PlaintextCell.prototype.at_top = function () {
RawCell.prototype.at_top = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === 0) {
return true;
@ -273,7 +273,7 @@ var IPython = (function (IPython) {
};
PlaintextCell.prototype.at_bottom = function () {
RawCell.prototype.at_bottom = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === (this.code_mirror.lineCount()-1)) {
return true;
@ -353,7 +353,7 @@ var IPython = (function (IPython) {
IPython.TextCell = TextCell;
IPython.HTMLCell = HTMLCell;
IPython.MarkdownCell = MarkdownCell;
IPython.PlaintextCell = PlaintextCell;
IPython.RawCell = RawCell;
IPython.HeadingCell = HeadingCell;

View File

@ -113,8 +113,8 @@ 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 === 'raw') {
IPython.notebook.to_raw();
} else if (cell_type === 'heading1') {
IPython.notebook.to_heading(undefined, 1);
} else if (cell_type === 'heading2') {

View File

@ -107,7 +107,7 @@ data-notebook-id={{notebook_id}}
<hr/>
<li id="to_code"><a href="#">Code</a></li>
<li id="to_markdown"><a href="#">Markdown </a></li>
<li id="to_plaintext"><a href="#">Plaintext</a></li>
<li id="to_raw"><a href="#">Raw Text</a></li>
<li id="to_heading1"><a href="#">Heading 1</a></li>
<li id="to_heading2"><a href="#">Heading 2</a></li>
<li id="to_heading3"><a href="#">Heading 3</a></li>
@ -171,7 +171,7 @@ data-notebook-id={{notebook_id}}
<select id="cell_type">
<option value="code">Code</option>
<option value="markdown">Markdown</option>
<option value="plaintext">Plaintext</option>
<option value="raw">Raw Text</option>
<option value="heading1">Heading 1</option>
<option value="heading2">Heading 2</option>
<option value="heading3">Heading 3</option>