Show More
@@ -14,6 +14,7 define([ | |||
|
14 | 14 | 'jquery', |
|
15 | 15 | 'base/js/utils', |
|
16 | 16 | 'base/js/keyboard', |
|
17 | 'services/config', | |
|
17 | 18 | 'notebook/js/cell', |
|
18 | 19 | 'notebook/js/outputarea', |
|
19 | 20 | 'notebook/js/completer', |
@@ -21,7 +22,19 define([ | |||
|
21 | 22 | 'codemirror/lib/codemirror', |
|
22 | 23 | 'codemirror/mode/python/python', |
|
23 | 24 | 'notebook/js/codemirror-ipython' |
|
24 | ], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) { | |
|
25 | ], function(IPython, | |
|
26 | $, | |
|
27 | utils, | |
|
28 | keyboard, | |
|
29 | configmod, | |
|
30 | cell, | |
|
31 | outputarea, | |
|
32 | completer, | |
|
33 | celltoolbar, | |
|
34 | CodeMirror, | |
|
35 | cmpython, | |
|
36 | cmip | |
|
37 | ) { | |
|
25 | 38 | "use strict"; |
|
26 | 39 | |
|
27 | 40 | var Cell = cell.Cell; |
@@ -76,6 +89,8 define([ | |||
|
76 | 89 | this.events = options.events; |
|
77 | 90 | this.tooltip = options.tooltip; |
|
78 | 91 | this.config = options.config; |
|
92 | this.class_config = new configmod.ConfigWithDefaults(this.config, | |
|
93 | CodeCell.config_defaults, 'CodeCell'); | |
|
79 | 94 | |
|
80 | 95 | // create all attributed in constructor function |
|
81 | 96 | // even if null for V8 VM optimisation |
@@ -103,9 +118,8 define([ | |||
|
103 | 118 | this.completer = null; |
|
104 | 119 | this.widget_views = []; |
|
105 | 120 | |
|
106 | var config = utils.mergeopt(CodeCell, this.config); | |
|
107 | 121 | Cell.apply(this,[{ |
|
108 | config: config, | |
|
122 | config: $.extend({}, CodeCell.options_default), | |
|
109 | 123 | keyboard_manager: options.keyboard_manager, |
|
110 | 124 | events: this.events}]); |
|
111 | 125 | |
@@ -131,6 +145,18 define([ | |||
|
131 | 145 | } |
|
132 | 146 | }; |
|
133 | 147 | |
|
148 | CodeCell.config_defaults = { | |
|
149 | cell_magic_highlight : { | |
|
150 | 'magic_javascript' :{'reg':[/^%%javascript/]}, | |
|
151 | 'magic_perl' :{'reg':[/^%%perl/]}, | |
|
152 | 'magic_ruby' :{'reg':[/^%%ruby/]}, | |
|
153 | 'magic_python' :{'reg':[/^%%python3?/]}, | |
|
154 | 'magic_shell' :{'reg':[/^%%bash/]}, | |
|
155 | 'magic_r' :{'reg':[/^%%R/]}, | |
|
156 | 'magic_text/x-cython' :{'reg':[/^%%cython/]}, | |
|
157 | }, | |
|
158 | }; | |
|
159 | ||
|
134 | 160 | CodeCell.msg_cells = {}; |
|
135 | 161 | |
|
136 | 162 | CodeCell.prototype = Object.create(Cell.prototype); |
@@ -156,7 +182,7 define([ | |||
|
156 | 182 | * @method auto_highlight |
|
157 | 183 | */ |
|
158 | 184 | CodeCell.prototype.auto_highlight = function () { |
|
159 | this._auto_highlight(this.config.cell_magic_highlight); | |
|
185 | this._auto_highlight(this.class_config.get_sync('cell_magic_highlight')); | |
|
160 | 186 | }; |
|
161 | 187 | |
|
162 | 188 | /** @method create_element */ |
@@ -19,7 +19,6 require([ | |||
|
19 | 19 | 'notebook/js/savewidget', |
|
20 | 20 | 'notebook/js/actions', |
|
21 | 21 | 'notebook/js/keyboardmanager', |
|
22 | 'notebook/js/config', | |
|
23 | 22 | 'notebook/js/kernelselector', |
|
24 | 23 | 'codemirror/lib/codemirror', |
|
25 | 24 | 'notebook/js/about', |
@@ -43,7 +42,6 require([ | |||
|
43 | 42 | savewidget, |
|
44 | 43 | actions, |
|
45 | 44 | keyboardmanager, |
|
46 | config, | |
|
47 | 45 | kernelselector, |
|
48 | 46 | CodeMirror, |
|
49 | 47 | about, |
@@ -62,7 +60,6 require([ | |||
|
62 | 60 | notebook_name : utils.get_body_data('notebookName') |
|
63 | 61 | }; |
|
64 | 62 | |
|
65 | var user_config = $.extend({}, config.default_config); | |
|
66 | 63 | var page = new page.Page(); |
|
67 | 64 | var pager = new pager.Pager('div#pager', { |
|
68 | 65 | events: events}); |
@@ -84,7 +81,7 require([ | |||
|
84 | 81 | keyboard_manager: keyboard_manager, |
|
85 | 82 | save_widget: save_widget, |
|
86 | 83 | contents: contents, |
|
87 |
config: |
|
|
84 | config: config_section}, | |
|
88 | 85 | common_options)); |
|
89 | 86 | var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); |
|
90 | 87 | var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { |
@@ -150,7 +147,6 require([ | |||
|
150 | 147 | IPython.notification_area = notification_area; |
|
151 | 148 | IPython.keyboard_manager = keyboard_manager; |
|
152 | 149 | IPython.save_widget = save_widget; |
|
153 | IPython.config = user_config; | |
|
154 | 150 | IPython.tooltip = notebook.tooltip; |
|
155 | 151 | |
|
156 | 152 | events.trigger('app_initialized.NotebookApp'); |
@@ -12,6 +12,7 define([ | |||
|
12 | 12 | 'notebook/js/cell', |
|
13 | 13 | 'notebook/js/textcell', |
|
14 | 14 | 'notebook/js/codecell', |
|
15 | 'services/config', | |
|
15 | 16 | 'services/sessions/session', |
|
16 | 17 | 'notebook/js/celltoolbar', |
|
17 | 18 | 'components/marked/lib/marked', |
@@ -32,6 +33,7 define([ | |||
|
32 | 33 | cellmod, |
|
33 | 34 | textcell, |
|
34 | 35 | codecell, |
|
36 | configmod, | |
|
35 | 37 | session, |
|
36 | 38 | celltoolbar, |
|
37 | 39 | marked, |
@@ -63,7 +65,9 define([ | |||
|
63 | 65 | * @param {string} options.notebook_name |
|
64 | 66 | */ |
|
65 | 67 | var Notebook = function (selector, options) { |
|
66 |
this.config = |
|
|
68 | this.config = options.config; | |
|
69 | this.class_config = new configmod.ConfigWithDefaults(this.config, | |
|
70 | Notebook.options_default, 'Notebook'); | |
|
67 | 71 | this.base_url = options.base_url; |
|
68 | 72 | this.notebook_path = options.notebook_path; |
|
69 | 73 | this.notebook_name = options.notebook_name; |
@@ -74,7 +78,6 define([ | |||
|
74 | 78 | this.tooltip = new tooltip.Tooltip(this.events); |
|
75 | 79 | this.ws_url = options.ws_url; |
|
76 | 80 | this._session_starting = false; |
|
77 | this.default_cell_type = this.config.default_cell_type || 'code'; | |
|
78 | 81 | |
|
79 | 82 | // Create default scroll manager. |
|
80 | 83 | this.scroll_manager = new scrollmanager.ScrollManager(this); |
@@ -861,7 +864,7 define([ | |||
|
861 | 864 | index = Math.min(index, ncells); |
|
862 | 865 | index = Math.max(index, 0); |
|
863 | 866 | var cell = null; |
|
864 | type = type || this.default_cell_type; | |
|
867 | type = type || this.class_config.get_sync('default_cell_type'); | |
|
865 | 868 | if (type === 'above') { |
|
866 | 869 | if (index > 0) { |
|
867 | 870 | type = this.get_cell(index-1).cell_type; |
@@ -7,13 +7,26 define([ | |||
|
7 | 7 | 'jquery', |
|
8 | 8 | 'notebook/js/cell', |
|
9 | 9 | 'base/js/security', |
|
10 | 'services/config', | |
|
10 | 11 | 'notebook/js/mathjaxutils', |
|
11 | 12 | 'notebook/js/celltoolbar', |
|
12 | 13 | 'components/marked/lib/marked', |
|
13 | 14 | 'codemirror/lib/codemirror', |
|
14 | 15 | 'codemirror/mode/gfm/gfm', |
|
15 | 16 | 'notebook/js/codemirror-ipythongfm' |
|
16 | ], function(IPython,utils , $, cell, security, mathjaxutils, celltoolbar, marked, CodeMirror, gfm, ipgfm) { | |
|
17 | ], function(IPython, | |
|
18 | utils, | |
|
19 | $, | |
|
20 | cell, | |
|
21 | security, | |
|
22 | configmod, | |
|
23 | mathjaxutils, | |
|
24 | celltoolbar, | |
|
25 | marked, | |
|
26 | CodeMirror, | |
|
27 | gfm, | |
|
28 | ipgfm | |
|
29 | ) { | |
|
17 | 30 | "use strict"; |
|
18 | 31 | var Cell = cell.Cell; |
|
19 | 32 | |
@@ -204,14 +217,16 define([ | |||
|
204 | 217 | * options: dictionary |
|
205 | 218 | * Dictionary of keyword arguments. |
|
206 | 219 | * events: $(Events) instance |
|
207 |
* config: |
|
|
220 | * config: ConfigSection instance | |
|
208 | 221 | * keyboard_manager: KeyboardManager instance |
|
209 | 222 | * notebook: Notebook instance |
|
210 | 223 | */ |
|
211 | 224 | options = options || {}; |
|
212 |
var config = utils.mergeopt(MarkdownCell, |
|
|
225 | var config = utils.mergeopt(MarkdownCell, {}); | |
|
213 | 226 | TextCell.apply(this, [$.extend({}, options, {config: config})]); |
|
214 | 227 | |
|
228 | this.class_config = new configmod.ConfigWithDefaults(options.config, | |
|
229 | {}, 'MarkdownCell'); | |
|
215 | 230 | this.cell_type = 'markdown'; |
|
216 | 231 | }; |
|
217 | 232 | |
@@ -287,14 +302,16 define([ | |||
|
287 | 302 | * options: dictionary |
|
288 | 303 | * Dictionary of keyword arguments. |
|
289 | 304 | * events: $(Events) instance |
|
290 |
* config: |
|
|
305 | * config: ConfigSection instance | |
|
291 | 306 | * keyboard_manager: KeyboardManager instance |
|
292 | 307 | * notebook: Notebook instance |
|
293 | 308 | */ |
|
294 | 309 | options = options || {}; |
|
295 |
var config = utils.mergeopt(RawCell, |
|
|
310 | var config = utils.mergeopt(RawCell, {}); | |
|
296 | 311 | TextCell.apply(this, [$.extend({}, options, {config: config})]); |
|
297 | 312 | |
|
313 | this.class_config = new configmod.ConfigWithDefaults(options.config, | |
|
314 | RawCell.config_defaults, 'RawCell'); | |
|
298 | 315 | this.cell_type = 'raw'; |
|
299 | 316 | }; |
|
300 | 317 | |
@@ -303,6 +320,12 define([ | |||
|
303 | 320 | "It will not be rendered in the notebook. " + |
|
304 | 321 | "When passing through nbconvert, a Raw Cell's content is added to the output unmodified." |
|
305 | 322 | }; |
|
323 | ||
|
324 | RawCell.config_defaults = { | |
|
325 | highlight_modes : { | |
|
326 | 'diff' :{'reg':[/^diff/]} | |
|
327 | }, | |
|
328 | }; | |
|
306 | 329 | |
|
307 | 330 | RawCell.prototype = Object.create(TextCell.prototype); |
|
308 | 331 | |
@@ -323,7 +346,7 define([ | |||
|
323 | 346 | * @method auto_highlight |
|
324 | 347 | */ |
|
325 | 348 | RawCell.prototype.auto_highlight = function () { |
|
326 |
this._auto_highlight(this.config. |
|
|
349 | this._auto_highlight(this.class_config.get_sync('highlight_modes')); | |
|
327 | 350 | }; |
|
328 | 351 | |
|
329 | 352 | /** @method render **/ |
@@ -63,6 +63,42 function($, utils) { | |||
|
63 | 63 | }); |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | return {ConfigSection: ConfigSection}; | |
|
66 | ||
|
67 | var ConfigWithDefaults = function(section, defaults, classname) { | |
|
68 | this.section = section; | |
|
69 | this.defaults = defaults; | |
|
70 | this.classname = classname; | |
|
71 | }; | |
|
72 | ||
|
73 | ConfigWithDefaults.prototype._class_data = function() { | |
|
74 | if (this.classname) { | |
|
75 | return this.section.data[this.classname] || {}; | |
|
76 | } else { | |
|
77 | return this.section.data | |
|
78 | } | |
|
79 | }; | |
|
80 | ||
|
81 | /** | |
|
82 | * Wait for config to have loaded, then get a value or the default. | |
|
83 | * Returns a promise. | |
|
84 | */ | |
|
85 | ConfigWithDefaults.prototype.get = function(key) { | |
|
86 | var that = this; | |
|
87 | return this.section.loaded.then(function() { | |
|
88 | return this._class_data()[key] || this.defaults[key] | |
|
89 | }); | |
|
90 | }; | |
|
91 | ||
|
92 | /** | |
|
93 | * Return a config value. If config is not yet loaded, return the default | |
|
94 | * instead of waiting for it to load. | |
|
95 | */ | |
|
96 | ConfigWithDefaults.prototype.get_sync = function(key) { | |
|
97 | return this._class_data()[key] || this.defaults[key]; | |
|
98 | }; | |
|
99 | ||
|
100 | return {ConfigSection: ConfigSection, | |
|
101 | ConfigWithDefaults: ConfigWithDefaults, | |
|
102 | }; | |
|
67 | 103 | |
|
68 | 104 | }); |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now