##// END OF EJS Templates
Merge pull request #1490 from minrk/raw...
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*.

File last commit:

r6059:de286793
r6480:a0e0f391 merge
Show More
cell.js
160 lines | 4.2 KiB | application/javascript | JavascriptLexer
//----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// Cell
//============================================================================
var IPython = (function (IPython) {
var utils = IPython.utils;
var Cell = function (notebook) {
this.placeholder = this.placeholder || '';
this.notebook = notebook;
this.read_only = false;
if (notebook){
this.read_only = notebook.read_only;
}
this.selected = false;
this.element = null;
this.create_element();
if (this.element !== null) {
this.element.data("cell", this);
this.bind_events();
}
this.cell_id = utils.uuid();
};
// Subclasses must implement create_element.
Cell.prototype.create_element = function () {};
Cell.prototype.bind_events = function () {
var that = this;
var nb = that.notebook;
that.element.click(function (event) {
if (that.selected === false) {
nb.select(nb.find_cell_index(that));
}
});
that.element.focusin(function (event) {
if (that.selected === false) {
nb.select(nb.find_cell_index(that));
}
});
};
// typeset with MathJax if MathJax is available
Cell.prototype.typeset = function () {
if (window.MathJax){
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
};
Cell.prototype.select = function () {
this.element.addClass('ui-widget-content ui-corner-all');
this.selected = true;
};
Cell.prototype.unselect = function () {
this.element.removeClass('ui-widget-content ui-corner-all');
this.selected = false;
};
Cell.prototype.get_text = function () {
};
Cell.prototype.set_text = function (text) {
};
Cell.prototype.refresh = function () {
this.code_mirror.refresh();
};
Cell.prototype.edit = function () {
};
Cell.prototype.render = function () {
};
Cell.prototype.toJSON = function () {
};
Cell.prototype.fromJSON = function (data) {
};
Cell.prototype.is_splittable = function () {
return true;
};
Cell.prototype.get_pre_cursor = function () {
var cursor = this.code_mirror.getCursor();
var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
text = text.replace(/^\n+/, '').replace(/\n+$/, '');
return text;
}
Cell.prototype.get_post_cursor = function () {
var cursor = this.code_mirror.getCursor();
var last_line_num = this.code_mirror.lineCount()-1;
var last_line_len = this.code_mirror.getLine(last_line_num).length;
var end = {line:last_line_num, ch:last_line_len}
var text = this.code_mirror.getRange(cursor, end);
text = text.replace(/^\n+/, '').replace(/\n+$/, '');
return text;
};
Cell.prototype.grow = function(element) {
// Grow the cell by hand. This is used upon reloading from JSON, when the
// autogrow handler is not called.
var dom = element.get(0);
var lines_count = 0;
// modified split rule from
// http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
var lines = dom.value.split(/\r|\r\n|\n/);
lines_count = lines.length;
if (lines_count >= 1) {
dom.rows = lines_count;
} else {
dom.rows = 1;
}
};
Cell.prototype.toggle_line_numbers = function () {
if (this.code_mirror.getOption('lineNumbers') == false) {
this.code_mirror.setOption('lineNumbers', true);
} else {
this.code_mirror.setOption('lineNumbers', false);
}
this.code_mirror.refresh();
};
IPython.Cell = Cell;
return IPython;
}(IPython));