mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
Restore loading of options_default in text cells
fixes omitted codemirror config due to ignoring options_default. load options_default via config defaults (modifying options_default at runtime has no effect).
This commit is contained in:
parent
0e5047e75d
commit
d52e1e2419
@ -49,10 +49,9 @@ define([
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
this.keyboard_manager = options.keyboard_manager;
|
this.keyboard_manager = options.keyboard_manager;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
var config = utils.mergeopt(Cell, options.config);
|
var config = options.config;
|
||||||
// superclass default overwrite our default
|
// superclass default overwrite our default
|
||||||
|
|
||||||
this.placeholder = config.placeholder || '';
|
|
||||||
this.selected = false;
|
this.selected = false;
|
||||||
this.anchor = false;
|
this.anchor = false;
|
||||||
this.rendered = false;
|
this.rendered = false;
|
||||||
@ -83,19 +82,21 @@ define([
|
|||||||
// load this from metadata later ?
|
// load this from metadata later ?
|
||||||
this.user_highlight = 'auto';
|
this.user_highlight = 'auto';
|
||||||
|
|
||||||
|
// merge my class-specific config data with general cell-level config
|
||||||
var _local_cm_config = {};
|
var class_config_data = {};
|
||||||
if(this.class_config){
|
if (this.class_config) {
|
||||||
_local_cm_config = this.class_config.get_sync('cm_config');
|
class_config_data = this.class_config.get_sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
var local = new configmod.ConfigWithDefaults(options.config,
|
|
||||||
{}, 'Cell');
|
|
||||||
var llcm = local.get_sync('cm_config');
|
|
||||||
|
|
||||||
config.cm_config = utils.mergeopt({}, config.cm_config, utils.mergeopt({}, llcm, _local_cm_config));
|
var cell_config = new configmod.ConfigWithDefaults(options.config,
|
||||||
|
Cell.options_default, 'Cell');
|
||||||
|
var cell_config_data = cell_config.get_sync();
|
||||||
|
|
||||||
|
// this._options is a merge of SomeCell and Cell config data:
|
||||||
|
this._options = utils.mergeopt({}, cell_config_data, class_config_data);
|
||||||
|
this.placeholder = this._options.placeholder || '';
|
||||||
|
|
||||||
this.cell_id = utils.uuid();
|
this.cell_id = utils.uuid();
|
||||||
this._options = config;
|
|
||||||
|
|
||||||
// For JS VM engines optimization, attributes should be all set (even
|
// For JS VM engines optimization, attributes should be all set (even
|
||||||
// to null) in the constructor, and if possible, if different subclass
|
// to null) in the constructor, and if possible, if different subclass
|
||||||
|
@ -96,7 +96,7 @@ define([
|
|||||||
this.tooltip = options.tooltip;
|
this.tooltip = options.tooltip;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
this.class_config = new configmod.ConfigWithDefaults(this.config,
|
this.class_config = new configmod.ConfigWithDefaults(this.config,
|
||||||
CodeCell.config_defaults, 'CodeCell');
|
CodeCell.options_default, 'CodeCell');
|
||||||
|
|
||||||
// create all attributed in constructor function
|
// create all attributed in constructor function
|
||||||
// even if null for V8 VM optimisation
|
// even if null for V8 VM optimisation
|
||||||
@ -141,8 +141,6 @@ define([
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
CodeCell.config_defaults = CodeCell.options_default;
|
|
||||||
|
|
||||||
CodeCell.msg_cells = {};
|
CodeCell.msg_cells = {};
|
||||||
|
|
||||||
CodeCell.prototype = Object.create(Cell.prototype);
|
CodeCell.prototype = Object.create(Cell.prototype);
|
||||||
|
@ -279,9 +279,8 @@ define([
|
|||||||
* notebook: Notebook instance
|
* notebook: Notebook instance
|
||||||
*/
|
*/
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var config = utils.mergeopt(MarkdownCell, {});
|
|
||||||
this.class_config = new configmod.ConfigWithDefaults(options.config,
|
this.class_config = new configmod.ConfigWithDefaults(options.config,
|
||||||
{}, 'MarkdownCell');
|
MarkdownCell.options_default, 'MarkdownCell');
|
||||||
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);
|
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);
|
||||||
|
|
||||||
this.cell_type = 'markdown';
|
this.cell_type = 'markdown';
|
||||||
@ -527,24 +526,19 @@ define([
|
|||||||
* notebook: Notebook instance
|
* notebook: Notebook instance
|
||||||
*/
|
*/
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var config = utils.mergeopt(RawCell, {});
|
|
||||||
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);
|
|
||||||
|
|
||||||
this.class_config = new configmod.ConfigWithDefaults(options.config,
|
this.class_config = new configmod.ConfigWithDefaults(options.config,
|
||||||
RawCell.config_defaults, 'RawCell');
|
RawCell.options_default, 'RawCell');
|
||||||
|
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);
|
||||||
this.cell_type = 'raw';
|
this.cell_type = 'raw';
|
||||||
};
|
};
|
||||||
|
|
||||||
RawCell.options_default = {
|
RawCell.options_default = {
|
||||||
placeholder : "Write raw LaTeX or other formats here, for use with nbconvert. " +
|
|
||||||
"It will not be rendered in the notebook. " +
|
|
||||||
"When passing through nbconvert, a Raw Cell's content is added to the output unmodified."
|
|
||||||
};
|
|
||||||
|
|
||||||
RawCell.config_defaults = {
|
|
||||||
highlight_modes : {
|
highlight_modes : {
|
||||||
'diff' :{'reg':[/^diff/]}
|
'diff' :{'reg':[/^diff/]}
|
||||||
},
|
},
|
||||||
|
placeholder : "Write raw LaTeX or other formats here, for use with nbconvert. " +
|
||||||
|
"It will not be rendered in the notebook. " +
|
||||||
|
"When passing through nbconvert, a Raw Cell's content is added to the output unmodified.",
|
||||||
};
|
};
|
||||||
|
|
||||||
RawCell.prototype = Object.create(TextCell.prototype);
|
RawCell.prototype = Object.create(TextCell.prototype);
|
||||||
|
@ -2,17 +2,26 @@
|
|||||||
|
|
||||||
// Test
|
// Test
|
||||||
casper.notebook_test(function () {
|
casper.notebook_test(function () {
|
||||||
|
function get_cell_cm_mode(index) {
|
||||||
|
return casper.evaluate(function (index) {
|
||||||
|
return Jupyter.notebook.get_cell(index).code_mirror.getMode().name;
|
||||||
|
}, {index: index});
|
||||||
|
}
|
||||||
|
|
||||||
this.then(function () {
|
this.then(function () {
|
||||||
// Cell mode change
|
// Cell mode change
|
||||||
|
var that = this;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
this.select_cell(index);
|
this.select_cell(index);
|
||||||
var a = 'hello\nmulti\nline';
|
var a = 'hello\nmulti\nline';
|
||||||
this.set_cell_text(index, a);
|
this.set_cell_text(index, a);
|
||||||
this.trigger_keydown('esc','r');
|
this.trigger_keydown('esc','r');
|
||||||
this.test.assertEquals(this.get_cell(index).cell_type, 'raw', 'r; cell is raw');
|
this.test.assertEquals(this.get_cell(index).cell_type, 'raw', 'r; cell is raw');
|
||||||
|
this.test.assertEquals(get_cell_cm_mode(index), 'null', 'raw cell codemirror mode is null');
|
||||||
this.trigger_keydown('1');
|
this.trigger_keydown('1');
|
||||||
this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', '1; cell is markdown');
|
this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', '1; cell is markdown');
|
||||||
this.test.assertEquals(this.get_cell_text(index), '# ' + a, '1; markdown heading');
|
this.test.assertEquals(this.get_cell_text(index), '# ' + a, '1; markdown heading');
|
||||||
|
this.test.assertEquals(get_cell_cm_mode(index), 'ipythongfm', 'codemirror cell mode is ipythongfm');
|
||||||
this.trigger_keydown('2');
|
this.trigger_keydown('2');
|
||||||
this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', '2; cell is markdown');
|
this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', '2; cell is markdown');
|
||||||
this.test.assertEquals(this.get_cell_text(index), '## ' + a, '2; markdown heading');
|
this.test.assertEquals(this.get_cell_text(index), '## ' + a, '2; markdown heading');
|
||||||
@ -34,6 +43,7 @@ casper.notebook_test(function () {
|
|||||||
this.trigger_keydown('y');
|
this.trigger_keydown('y');
|
||||||
this.test.assertEquals(this.get_cell(index).cell_type, 'code', 'y; cell is code');
|
this.test.assertEquals(this.get_cell(index).cell_type, 'code', 'y; cell is code');
|
||||||
this.test.assertEquals(this.get_cell_text(index), '###### ' + a, 'y; still has hashes');
|
this.test.assertEquals(this.get_cell_text(index), '###### ' + a, 'y; still has hashes');
|
||||||
|
this.test.assertEquals(get_cell_cm_mode(index), 'ipython', 'code cell mode is ipython');
|
||||||
this.trigger_keydown('1');
|
this.trigger_keydown('1');
|
||||||
this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', '1; cell is markdown');
|
this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', '1; cell is markdown');
|
||||||
this.test.assertEquals(this.get_cell_text(index), '# ' + a, '1; markdown heading');
|
this.test.assertEquals(this.get_cell_text(index), '# ' + a, '1; markdown heading');
|
||||||
|
Loading…
Reference in New Issue
Block a user