##// END OF EJS Templates
add locks to update everywhere by using options to pass this...
add locks to update everywhere by using options to pass this (and check for this)

File last commit:

r14089:a8751bbf
r14570:4e85339b
Show More
textcell.js
560 lines | 17.1 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
Aron Ahmadia
partial refactor, can't quite get environments working
r8565 // Copyright (C) 2008-2012 The IPython Development Team
Brian E. Granger
More review changes....
r4609 //
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
//============================================================================
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 // TextCell
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 //============================================================================
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165
Matthias BUSSONNIER
start to document js
r8709 /**
A module that allow to create different type of Text Cell
Matthias BUSSONNIER
more docs, organize in namespace
r8739 @module IPython
@namespace IPython
Matthias BUSSONNIER
start to document js
r8709 */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var IPython = (function (IPython) {
Matthias BUSSONNIER
patch header-cell and use-strict
r11526 "use strict";
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 // TextCell base class
Bradley M. Froehle
notebook: up/down arrow keys move to begin/end of line at top/bottom of cell...
r8168 var key = IPython.utils.keycodes;
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
Matthias BUSSONNIER
start to document js
r8709 /**
Matthias BUSSONNIER
Document more function....
r8711 * Construct a new TextCell, codemirror mode is by default 'htmlmixed', and cell type is 'text'
* cell start as not redered.
*
Matthias BUSSONNIER
start to document js
r8709 * @class TextCell
Matthias BUSSONNIER
Document more function....
r8711 * @constructor TextCell
MinRK
Markdown in heading cells (take 2)...
r11288 * @extend IPython.Cell
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 * @param {object|undefined} [options]
* @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass)
Matthias BUSSONNIER
start to document js
r8709 */
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 var TextCell = function (options) {
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 // in all TextCell/Cell subclasses
// do not assign most of members here, just pass it down
// in the options dict potentially overwriting what you wish.
// they will be assigned in the base class.
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 // we cannot put this as a class key as it has handle to "this".
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 var cm_overwrite_options = {
Brian E. Granger
Lots of updates and changes....
r14021 onKeyEvent: $.proxy(this.handle_keyevent,this)
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 };
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options});
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
MinRK
give Raw Cells a placeholder...
r13668 this.cell_type = this.cell_type || 'text';
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
MinRK
give Raw Cells a placeholder...
r13668 IPython.Cell.apply(this, [options]);
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.rendered = false;
};
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 TextCell.prototype = new IPython.Cell();
TextCell.options_default = {
cm_config : {
extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},
mode: 'htmlmixed',
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 lineWrapping : true,
}
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 };
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
Matthias BUSSONNIER
Document more function....
r8711 /**
* Create the DOM element of the TextCell
Matthias BUSSONNIER
start to document js
r8709 * @method create_element
* @private
*/
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.create_element = function () {
Matthias BUSSONNIER
create celltoolbar in cell.js and inherit
r9073 IPython.Cell.prototype.create_element.apply(this, arguments);
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776
Matthias BUSSONNIER
include vbox into .cell css definition
r10217 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
Brian E. Granger
Better tabindex support.
r4629 cell.attr('tabindex','2');
Brian Granger
Further cleanup for celltoolbars.
r9144
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776 var prompt = $('<div/>').addClass('prompt input_prompt');
cell.append(prompt);
var inner_cell = $('<div/>').addClass('inner_cell');
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142 this.celltoolbar = new IPython.CellToolbar(this);
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776 inner_cell.append(this.celltoolbar.element);
Brian Granger
Lots of small notebook improvements....
r5946 var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 // The tabindex=-1 makes this div focusable.
Brian Granger
Lots of small notebook improvements....
r5946 var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
Aron Ahmadia
undid unique ids, used jQuery
r8661 addClass('rendered_html').attr('tabindex','-1');
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776 inner_cell.append(input_area).append(render_area);
cell.append(inner_cell);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.element = cell;
};
Matthias BUSSONNIER
Document more function....
r8711 /**
* Bind the DOM evet to cell actions
Matthias BUSSONNIER
start to document js
r8709 * Need to be called after TextCell.create_element
* @private
* @method bind_event
*/
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.bind_events = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Cell.prototype.bind_events.apply(this);
var that = this;
Brian E. Granger
More work on the dual mode UX.
r14015
Brian Granger
Lots of small notebook improvements....
r5946 this.element.dblclick(function () {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 if (that.selected === false) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
};
$([IPython.events]).trigger('edit_mode.Cell', {cell: that});
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
};
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Lots of updates and changes....
r14021 TextCell.prototype.handle_keyevent = function (editor, event) {
Brian E. Granger
Cleaning up console log messages.
r14089 // console.log('CM', this.mode, event.which, event.type)
Brian E. Granger
Lots of updates and changes....
r14021
if (this.mode === 'command') {
return true;
} else if (this.mode === 'edit') {
return this.handle_codemirror_keyevent(editor, event);
}
};
Brian E. Granger
More work on the dual mode UX.
r14015
Matthias BUSSONNIER
Document more function....
r8711 /**
* This method gets called in CodeMirror's onKeyDown/onKeyPress
Matthias BUSSONNIER
start to document js
r8709 * handlers and is used to provide custom key handling.
*
Matthias BUSSONNIER
Document more function....
r8711 * Subclass should override this method to have custom handeling
*
Matthias BUSSONNIER
start to document js
r8709 * @method handle_codemirror_keyevent
Matthias BUSSONNIER
Document more function....
r8711 * @param {CodeMirror} editor - The codemirror instance bound to the cell
Matthias BUSSONNIER
start to document js
r8709 * @param {event} event -
Matthias BUSSONNIER
Document more function....
r8711 * @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise
Matthias BUSSONNIER
start to document js
r8709 */
Brian Granger
Fixing bugs that have shown up since updating CM to 2.2.
r5942 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 var that = this;
Brian E. Granger
Lots of updates and changes....
r14021
if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey || event.altKey)) {
// Always ignore shift-enter in CodeMirror as we handle it.
return true;
} else if (event.which === key.UPARROW && event.type === 'keydown') {
// If we are not at the top, let CM handle the up arrow and
// prevent the global keydown handler from handling it.
if (!that.at_top()) {
event.stop();
return false;
} else {
Brian E. Granger
More work on the dual mode UX.
r14015 return true;
Brian E. Granger
Lots of updates and changes....
r14021 };
} else if (event.which === key.DOWNARROW && event.type === 'keydown') {
// If we are not at the bottom, let CM handle the down arrow and
// prevent the global keydown handler from handling it.
if (!that.at_bottom()) {
event.stop();
return false;
} else {
return true;
};
Brian E. Granger
Special handling for CM's vim keyboard mapping.
r14062 } else if (event.which === key.ESC && event.type === 'keydown') {
if (that.code_mirror.options.keyMap === "vim-insert") {
// vim keyMap is active and in insert mode. In this case we leave vim
// insert mode, but remain in notebook edit mode.
// Let' CM handle this event and prevent global handling.
event.stop();
return false;
} else {
// vim keyMap is not active. Leave notebook edit mode.
// Don't let CM handle the event, defer to global handling.
return true;
}
Brian E. Granger
Lots of updates and changes....
r14021 }
Brian Granger
Fixing bugs that have shown up since updating CM to 2.2.
r5942 return false;
};
Brian E. Granger
Adding new logic to cells.
r14014 // Cell level actions
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.select = function () {
Brian E. Granger
More work on the dual mode UX.
r14015 var cont = IPython.Cell.prototype.select.apply(this);
if (cont) {
Brian E. Granger
Adding new logic to cells.
r14014 if (this.mode === 'edit') {
this.code_mirror.refresh();
}
};
Brian E. Granger
More work on the dual mode UX.
r14015 return cont;
MinRK
trigger textcell render on unselect instead of focusout
r5833 };
Brian E. Granger
Adding new logic to cells.
r14014 TextCell.prototype.unrender = function () {
if (this.read_only) return;
Brian E. Granger
More work on the dual mode UX.
r14015 var cont = IPython.Cell.prototype.unrender.apply(this);
if (cont) {
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 var text_cell = this.element;
Matthias BUSSONNIER
start to document js
r8709 var output = text_cell.find("div.text_cell_render");
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 output.hide();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 text_cell.find('div.text_cell_input').show();
Brian Granger
Work on the base Cell API....
r5943 if (this.get_text() === this.placeholder) {
this.set_text('');
Brian Granger
Lots of small notebook improvements....
r5946 this.refresh();
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 }
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Adding new logic to cells.
r14014 };
Brian E. Granger
More work on the dual mode UX.
r14015 return cont;
};
TextCell.prototype.execute = function () {
this.render();
Brian E. Granger
Adding new logic to cells.
r14014 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Adding new logic to cells.
r14014 TextCell.prototype.edit_mode = function () {
Brian E. Granger
More work on the dual mode UX.
r14015 var cont = IPython.Cell.prototype.edit_mode.apply(this);
if (cont) {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 this.unrender();
Brian E. Granger
Adding new logic to cells.
r14014 this.focus_editor();
};
Brian E. Granger
More work on the dual mode UX.
r14015 return cont;
Brian E. Granger
Adding new logic to cells.
r14014 }
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Matthias BUSSONNIER
start to document js
r8709 /**
* setter: {{#crossLink "TextCell/set_text"}}{{/crossLink}}
* @method get_text
* @retrun {string} CodeMirror current text value
*/
Brian Granger
Work on the base Cell API....
r5943 TextCell.prototype.get_text = function() {
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 return this.code_mirror.getValue();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Matthias BUSSONNIER
start to document js
r8709 /**
* @param {string} text - Codemiror text value
* @see TextCell#get_text
* @method set_text
* */
Brian Granger
Work on the base Cell API....
r5943 TextCell.prototype.set_text = function(text) {
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 this.code_mirror.setValue(text);
this.code_mirror.refresh();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Matthias BUSSONNIER
start to document js
r8709 /**
* setter :{{#crossLink "TextCell/set_rendered"}}{{/crossLink}}
* @method get_rendered
* @return {html} html of rendered element
* */
Brian E. Granger
Fixed text cell rendering bug.
r4513 TextCell.prototype.get_rendered = function() {
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 return this.element.find('div.text_cell_render').html();
};
Matthias BUSSONNIER
start to document js
r8709 /**
* @method set_rendered
*/
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.set_rendered = function(text) {
this.element.find('div.text_cell_render').html(text);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Matthias BUSSONNIER
start to document js
r8709 /**
* @method at_top
Brian E. Granger
More work on the dual mode UX.
r14015 * @return {Boolean}
Matthias BUSSONNIER
start to document js
r8709 */
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.at_top = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (this.rendered) {
return true;
} else {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 var cursor = this.code_mirror.getCursor();
Brian E. Granger
More work on the dual mode UX.
r14015 if (cursor.line === 0 && cursor.ch === 0) {
return true;
} else {
return false;
};
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Matthias BUSSONNIER
start to document js
r8709 /**
* @method at_bottom
Brian E. Granger
More work on the dual mode UX.
r14015 * @return {Boolean}
Matthias BUSSONNIER
start to document js
r8709 * */
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.at_bottom = function () {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (this.rendered) {
return true;
} else {
Brian E. Granger
More work on the dual mode UX.
r14015 var cursor = this.code_mirror.getCursor();
if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
return true;
} else {
return false;
};
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Matthias BUSSONNIER
Document more function....
r8711 /**
* Create Text cell from JSON
Matthias BUSSONNIER
start to document js
r8709 * @param {json} data - JSON serialized text-cell
Matthias BUSSONNIER
Document more function....
r8711 * @method fromJSON
Matthias BUSSONNIER
start to document js
r8709 */
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.fromJSON = function (data) {
MinRK
add empty metadata field on cells/worksheets...
r7523 IPython.Cell.prototype.fromJSON.apply(this, arguments);
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 if (data.cell_type === this.cell_type) {
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 if (data.source !== undefined) {
Brian Granger
Work on the base Cell API....
r5943 this.set_text(data.source);
Paul Ivanov
fix for #1678, undo no longer clears cells...
r7587 // make this value the starting point, so that we can only undo
// to this state, instead of a blank cell
this.code_mirror.clearHistory();
Brian E. Granger
Fixed text cell rendering bug.
r4513 this.set_rendered(data.rendered || '');
this.rendered = false;
this.render();
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 }
}
Brian E. Granger
Fixed text cell rendering bug.
r4513 };
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Matthias BUSSONNIER
Document more function....
r8711 /** Generate JSON from cell
* @return {object} cell data serialised to json
*/
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 TextCell.prototype.toJSON = function () {
MinRK
add empty metadata field on cells/worksheets...
r7523 var data = IPython.Cell.prototype.toJSON.apply(this);
Brian Granger
Work on the base Cell API....
r5943 data.source = this.get_text();
MinRK
give Raw Cells a placeholder...
r13668 if (data.source == this.placeholder) {
data.source = "";
}
Brian E. Granger
Massive work on the notebook document format....
r4484 return data;
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349 };
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
Matthias BUSSONNIER
start to document js
r8709 /**
Matthias BUSSONNIER
Document more function....
r8711 * @class MarkdownCell
* @constructor MarkdownCell
MinRK
Markdown in heading cells (take 2)...
r11288 * @extends IPython.HTMLCell
Matthias BUSSONNIER
start to document js
r8709 */
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 var MarkdownCell = function (options) {
MinRK
give Raw Cells a placeholder...
r13668 options = this.mergeopt(MarkdownCell, options);
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 this.cell_type = 'markdown';
MinRK
give Raw Cells a placeholder...
r13668 TextCell.apply(this, [options]);
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 };
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 MarkdownCell.options_default = {
cm_config: {
MinRK
use highlight.js to highlight markdown code blocks
r10539 mode: 'gfm'
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 },
placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$"
}
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 MarkdownCell.prototype = new TextCell();
Matthias BUSSONNIER
Document more function....
r8711 /**
* @method render
*/
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 MarkdownCell.prototype.render = function () {
Brian E. Granger
More work on the dual mode UX.
r14015 var cont = IPython.TextCell.prototype.render.apply(this);
if (cont) {
Brian Granger
Work on the base Cell API....
r5943 var text = this.get_text();
Jessica B. Hamrick
Parse markdown correctly when mathjax is disabled
r11843 var math = null;
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 if (text === "") { text = this.placeholder; }
Jessica B. Hamrick
Parse markdown correctly when mathjax is disabled
r11843 var text_and_math = IPython.mathjaxutils.remove_math(text);
text = text_and_math[0];
math = text_and_math[1];
MinRK
use marked for markdown
r10536 var html = marked.parser(marked.lexer(text));
Matthias BUSSONNIER
statelessify matjaxutils...
r11524 html = $(IPython.mathjaxutils.replace_math(html, math));
MinRK
open markdown links in new tabs...
r11211 // links in markdown cells should open in new tabs
MinRK
don't set target on internal markdown links...
r11805 html.find("a[href]").not('[href^="#"]').attr("target", "_blank");
Aron Ahmadia
Finalizing fixes to MathJax enhancements...
r8662 try {
this.set_rendered(html);
} catch (e) {
console.log("Error running Javascript in Markdown:");
console.log(e);
this.set_rendered($("<div/>").addClass("js-error").html(
"Error rendering Markdown!<br/>" + e.toString())
);
MinRK
catch js errors when rendering markdown cells
r8052 }
Aron Ahmadia
Finalizing fixes to MathJax enhancements...
r8662 this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
Brian E. Granger
More work on the dual mode UX.
r14015 this.typeset()
};
return cont;
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 };
MinRK
rename plaintext cell -> raw cell
r6248 // RawCell
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
Matthias BUSSONNIER
Document more function....
r8711 /**
* @class RawCell
* @constructor RawCell
MinRK
Markdown in heading cells (take 2)...
r11288 * @extends IPython.TextCell
Matthias BUSSONNIER
start to document js
r8709 */
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 var RawCell = function (options) {
Brian E. Granger
Semi working version of basic dual mode UX....
r14016
options = this.mergeopt(RawCell,options)
MinRK
give Raw Cells a placeholder...
r13668 TextCell.apply(this, [options]);
Brian E. Granger
Semi working version of basic dual mode UX....
r14016 this.cell_type = 'raw';
// RawCell should always hide its rendered div
this.element.find('div.text_cell_render').hide();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 };
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 RawCell.options_default = {
MinRK
tweak raw placeholder
r13769 placeholder : "Write raw LaTeX or other formats here, for use with nbconvert.\n" +
MinRK
give Raw Cells a placeholder...
r13668 "It will not be rendered in the notebook.\n" +
"When passing through nbconvert, a Raw Cell's content is added to the output unmodified."
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 };
MinRK
rename plaintext cell -> raw cell
r6248 RawCell.prototype = new TextCell();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
Brian E. Granger
More work on the dual mode UX.
r14015 /** @method bind_events **/
RawCell.prototype.bind_events = function () {
TextCell.prototype.bind_events.apply(this);
var that = this
this.element.focusout(function() {
that.auto_highlight();
});
};
Matthias BUSSONNIER
Document more function....
r8711 /**
* Trigger autodetection of highlight scheme for current cell
* @method auto_highlight
*/
Matthias BUSSONNIER
autochange highlight with cell magics...
r8202 RawCell.prototype.auto_highlight = function () {
this._auto_highlight(IPython.config.raw_cell_highlight);
};
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
Matthias BUSSONNIER
Document more function....
r8711 /** @method render **/
MinRK
rename plaintext cell -> raw cell
r6248 RawCell.prototype.render = function () {
Brian E. Granger
More work on the dual mode UX.
r14015 // Make sure that this cell type can never be rendered
if (this.rendered) {
this.unrender();
}
MinRK
give Raw Cells a placeholder...
r13668 var text = this.get_text();
if (text === "") { text = this.placeholder; }
this.set_text(text);
Brian Granger
A first go at RST cell support in the notebook.
r6017 };
Matthias BUSSONNIER
add doc to base Cell
r8714 /**
Matthias BUSSONNIER
Document more function....
r8711 * @class HeadingCell
MinRK
Markdown in heading cells (take 2)...
r11288 * @extends IPython.TextCell
Matthias BUSSONNIER
Document more function....
r8711 */
/**
* @constructor HeadingCell
MinRK
Markdown in heading cells (take 2)...
r11288 * @extends IPython.TextCell
Matthias BUSSONNIER
start to document js
r8709 */
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 var HeadingCell = function (options) {
MinRK
give Raw Cells a placeholder...
r13668 options = this.mergeopt(HeadingCell, options);
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165
MinRK
give Raw Cells a placeholder...
r13668 this.level = 1;
this.cell_type = 'heading';
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 TextCell.apply(this, [options]);
Matthias BUSSONNIER
Document more function....
r8711 /**
* heading level of the cell, use getter and setter to access
* @property level
*/
Brian Granger
Adding new HeadingCell.
r6018 };
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 HeadingCell.options_default = {
placeholder: "Type Heading Here"
};
Brian Granger
Adding new HeadingCell.
r6018
HeadingCell.prototype = new TextCell();
Matthias BUSSONNIER
Document more function....
r8711 /** @method fromJSON */
MinRK
include heading level in JSON...
r6156 HeadingCell.prototype.fromJSON = function (data) {
if (data.level != undefined){
this.level = data.level;
}
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 TextCell.prototype.fromJSON.apply(this, arguments);
MinRK
include heading level in JSON...
r6156 };
Matthias BUSSONNIER
Document more function....
r8711 /** @method toJSON */
MinRK
include heading level in JSON...
r6156 HeadingCell.prototype.toJSON = function () {
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 var data = TextCell.prototype.toJSON.apply(this);
MinRK
include heading level in JSON...
r6156 data.level = this.get_level();
return data;
};
MinRK
HeadingCells are not splittable or mergeable...
r12510 /**
* can the cell be split into two cells
* @method is_splittable
**/
HeadingCell.prototype.is_splittable = function () {
return false;
};
/**
* can the cell be merged with other cells
* @method is_mergeable
**/
HeadingCell.prototype.is_mergeable = function () {
return false;
};
MinRK
include heading level in JSON...
r6156
Matthias BUSSONNIER
Document more function....
r8711 /**
* Change heading level of cell, and re-render
* @method set_level
*/
Brian Granger
Finishing first draft of RST and heading cells.
r6019 HeadingCell.prototype.set_level = function (level) {
this.level = level;
if (this.rendered) {
this.rendered = false;
this.render();
};
};
Matthias BUSSONNIER
start to document js
r8709 /** The depth of header cell, based on html (h1 to h6)
Matthias BUSSONNIER
Document more function....
r8711 * @method get_level
Matthias BUSSONNIER
start to document js
r8709 * @return {integer} level - for 1 to 6
*/
Brian Granger
Finishing first draft of RST and heading cells.
r6019 HeadingCell.prototype.get_level = function () {
return this.level;
};
MinRK
Markdown in heading cells (take 2)...
r11288 HeadingCell.prototype.set_rendered = function (html) {
this.element.find("div.text_cell_render").html(html);
Brian Granger
Finishing first draft of RST and heading cells.
r6019 };
Brian Granger
Adding new HeadingCell.
r6018
HeadingCell.prototype.get_rendered = function () {
var r = this.element.find("div.text_cell_render");
return r.children().first().html();
Brian Granger
Finishing first draft of RST and heading cells.
r6019 };
Brian Granger
Adding new HeadingCell.
r6018
HeadingCell.prototype.render = function () {
Brian E. Granger
More work on the dual mode UX.
r14015 var cont = IPython.TextCell.prototype.render.apply(this);
if (cont) {
Brian Granger
Adding new HeadingCell.
r6018 var text = this.get_text();
Jessica B. Hamrick
Parse markdown correctly when mathjax is disabled
r11843 var math = null;
MinRK
merge heading lines...
r11290 // Markdown headings must be a single line
text = text.replace(/\n/g, ' ');
Brian Granger
Adding new HeadingCell.
r6018 if (text === "") { text = this.placeholder; }
MinRK
Markdown in heading cells (take 2)...
r11288 text = Array(this.level + 1).join("#") + " " + text;
Matthias BUSSONNIER
patch header-cell and use-strict
r11526 var text_and_math = IPython.mathjaxutils.remove_math(text);
Jessica B. Hamrick
Parse markdown correctly when mathjax is disabled
r11843 text = text_and_math[0];
math = text_and_math[1];
MinRK
Markdown in heading cells (take 2)...
r11288 var html = marked.parser(marked.lexer(text));
Matthias BUSSONNIER
patch header-cell and use-strict
r11526 var h = $(IPython.mathjaxutils.replace_math(html, math));
MinRK
remove unnecessary heading-anchor...
r11291 // add id and linkback anchor
var hash = h.text().replace(/ /g, '-');
h.attr('id', hash);
h.append(
MinRK
Markdown in heading cells (take 2)...
r11288 $('<a/>')
.addClass('anchor-link')
.attr('href', '#' + hash)
.text('ΒΆ')
);
this.set_rendered(h);
Brian Granger
Adding new HeadingCell.
r6018 this.typeset();
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
Brian E. Granger
More work on the dual mode UX.
r14015
Brian Granger
Finishing first draft of RST and heading cells.
r6019 };
Brian E. Granger
More work on the dual mode UX.
r14015 return cont;
Brian Granger
Adding new HeadingCell.
r6018 };
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 IPython.TextCell = TextCell;
IPython.MarkdownCell = MarkdownCell;
MinRK
rename plaintext cell -> raw cell
r6248 IPython.RawCell = RawCell;
Brian Granger
Finishing first draft of RST and heading cells.
r6019 IPython.HeadingCell = HeadingCell;
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return IPython;
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }(IPython));
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349