##// END OF EJS Templates
Merge branch 'master' of github.com:ipython/ipython
Brian E. Granger -
r15897:d3631749 merge
parent child Browse files
Show More
@@ -44,17 +44,17 b' IPython.keyboard = (function (IPython) {'
44 44 // These apply to Firefox and Opera
45 45 var _mozilla_keycodes = {
46 46 '; :': 59, '= +': 61, '- _': 173, 'meta': 224
47 }
47 };
48 48
49 49 // This apply to Webkit and IE
50 50 var _ie_keycodes = {
51 '; :': 186, '= +': 187, '- _': 189,
52 }
51 '; :': 186, '= +': 187, '- _': 189
52 };
53 53
54 54 var browser = IPython.utils.browser[0];
55 55 var platform = IPython.utils.platform;
56 56
57 if (browser === 'Firefox' || browser === 'Opera') {
57 if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') {
58 58 $.extend(_keycodes, _mozilla_keycodes);
59 59 } else if (browser === 'Safari' || browser === 'Chrome' || browser === 'MSIE') {
60 60 $.extend(_keycodes, _ie_keycodes);
@@ -65,45 +65,47 b' IPython.keyboard = (function (IPython) {'
65 65 for (var name in _keycodes) {
66 66 var names = name.split(' ');
67 67 if (names.length === 1) {
68 var n = names[0]
69 keycodes[n] = _keycodes[n]
70 inv_keycodes[_keycodes[n]] = n
68 var n = names[0];
69 keycodes[n] = _keycodes[n];
70 inv_keycodes[_keycodes[n]] = n;
71 71 } else {
72 72 var primary = names[0];
73 73 var secondary = names[1];
74 keycodes[primary] = _keycodes[name]
75 keycodes[secondary] = _keycodes[name]
76 inv_keycodes[_keycodes[name]] = primary
74 keycodes[primary] = _keycodes[name];
75 keycodes[secondary] = _keycodes[name];
76 inv_keycodes[_keycodes[name]] = primary;
77 77 }
78 78 }
79 79
80 80 var normalize_key = function (key) {
81 81 return inv_keycodes[keycodes[key]];
82 }
82 };
83 83
84 84 var normalize_shortcut = function (shortcut) {
85 85 // Put a shortcut into normalized form:
86 86 // 1. Make lowercase
87 87 // 2. Replace cmd by meta
88 // 3. Sort '+' separated modifiers into the order alt+ctrl+meta+shift
88 // 3. Sort '-' separated modifiers into the order alt-ctrl-meta-shift
89 89 // 4. Normalize keys
90 90 shortcut = shortcut.toLowerCase().replace('cmd', 'meta');
91 var values = shortcut.split("+");
91 shortcut = shortcut.replace(/-$/, '_'); // catch shortcuts using '-' key
92 var values = shortcut.split("-");
92 93 if (values.length === 1) {
93 return normalize_key(values[0])
94 return normalize_key(values[0]);
94 95 } else {
95 96 var modifiers = values.slice(0,-1);
96 97 var key = normalize_key(values[values.length-1]);
97 98 modifiers.sort();
98 return modifiers.join('+') + '+' + key;
99 return modifiers.join('-') + '-' + key;
99 100 }
100 }
101 };
101 102
102 103 var shortcut_to_event = function (shortcut, type) {
103 // Convert a shortcut (shift+r) to a jQuery Event object
104 // Convert a shortcut (shift-r) to a jQuery Event object
104 105 type = type || 'keydown';
105 106 shortcut = normalize_shortcut(shortcut);
106 var values = shortcut.split("+");
107 shortcut = shortcut.replace(/-$/, '_'); // catch shortcuts using '-' key
108 var values = shortcut.split("-");
107 109 var modifiers = values.slice(0,-1);
108 110 var key = values[values.length-1];
109 111 var opts = {which: keycodes[key]};
@@ -112,19 +114,19 b' IPython.keyboard = (function (IPython) {'
112 114 if (modifiers.indexOf('meta') !== -1) {opts.metaKey = true;}
113 115 if (modifiers.indexOf('shift') !== -1) {opts.shiftKey = true;}
114 116 return $.Event(type, opts);
115 }
117 };
116 118
117 119 var event_to_shortcut = function (event) {
118 // Convert a jQuery Event object to a shortcut (shift+r)
120 // Convert a jQuery Event object to a shortcut (shift-r)
119 121 var shortcut = '';
120 var key = inv_keycodes[event.which]
121 if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
122 if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
123 if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
124 if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
122 var key = inv_keycodes[event.which];
123 if (event.altKey && key !== 'alt') {shortcut += 'alt-';}
124 if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl-';}
125 if (event.metaKey && key !== 'meta') {shortcut += 'meta-';}
126 if (event.shiftKey && key !== 'shift') {shortcut += 'shift-';}
125 127 shortcut += key;
126 return shortcut
127 }
128 return shortcut;
129 };
128 130
129 131 var trigger_keydown = function (shortcut, element) {
130 132 // Trigger shortcut keydown on an element
@@ -132,17 +134,17 b' IPython.keyboard = (function (IPython) {'
132 134 element = $(element);
133 135 var event = shortcut_to_event(shortcut, 'keydown');
134 136 element.trigger(event);
135 }
137 };
136 138
137 139
138 140 // Shortcut manager class
139 141
140 142 var ShortcutManager = function (delay) {
141 this._shortcuts = {}
142 this._counts = {}
143 this._timers = {}
143 this._shortcuts = {};
144 this._counts = {};
145 this._timers = {};
144 146 this.delay = delay || 800; // delay in milliseconds
145 }
147 };
146 148
147 149 ShortcutManager.prototype.help = function () {
148 150 var help = [];
@@ -168,15 +170,15 b' IPython.keyboard = (function (IPython) {'
168 170 return 0;
169 171 });
170 172 return help;
171 }
173 };
172 174
173 175 ShortcutManager.prototype.clear_shortcuts = function () {
174 176 this._shortcuts = {};
175 }
177 };
176 178
177 ShortcutManager.prototype.add_shortcut = function (shortcut, data) {
179 ShortcutManager.prototype.add_shortcut = function (shortcut, data, suppress_help_update) {
178 180 if (typeof(data) === 'function') {
179 data = {help: '', help_index: '', handler: data}
181 data = {help: '', help_index: '', handler: data};
180 182 }
181 183 data.help_index = data.help_index || '';
182 184 data.help = data.help || '';
@@ -187,19 +189,29 b' IPython.keyboard = (function (IPython) {'
187 189 shortcut = normalize_shortcut(shortcut);
188 190 this._counts[shortcut] = 0;
189 191 this._shortcuts[shortcut] = data;
190 }
192 if (!suppress_help_update) {
193 // update the keyboard shortcuts notebook help
194 $([IPython.events]).trigger('rebuild.QuickHelp');
195 }
196 };
191 197
192 198 ShortcutManager.prototype.add_shortcuts = function (data) {
193 199 for (var shortcut in data) {
194 this.add_shortcut(shortcut, data[shortcut]);
200 this.add_shortcut(shortcut, data[shortcut], true);
195 201 }
196 }
202 // update the keyboard shortcuts notebook help
203 $([IPython.events]).trigger('rebuild.QuickHelp');
204 };
197 205
198 ShortcutManager.prototype.remove_shortcut = function (shortcut) {
206 ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
199 207 shortcut = normalize_shortcut(shortcut);
200 208 delete this._counts[shortcut];
201 209 delete this._shortcuts[shortcut];
202 }
210 if (!suppress_help_update) {
211 // update the keyboard shortcuts notebook help
212 $([IPython.events]).trigger('rebuild.QuickHelp');
213 }
214 };
203 215
204 216 ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
205 217 var that = this;
@@ -219,7 +231,7 b' IPython.keyboard = (function (IPython) {'
219 231 t[shortcut] = timer;
220 232 }
221 233 return false;
222 }
234 };
223 235
224 236 ShortcutManager.prototype.call_handler = function (event) {
225 237 var shortcut = event_to_shortcut(event);
@@ -235,7 +247,7 b' IPython.keyboard = (function (IPython) {'
235 247 }
236 248 }
237 249 return true;
238 }
250 };
239 251
240 252 ShortcutManager.prototype.handles = function (event) {
241 253 var shortcut = event_to_shortcut(event);
@@ -252,6 +264,6 b' IPython.keyboard = (function (IPython) {'
252 264 shortcut_to_event : shortcut_to_event,
253 265 event_to_shortcut : event_to_shortcut,
254 266 trigger_keydown : trigger_keydown
255 }
267 };
256 268
257 269 }(IPython));
@@ -5,5 +5,9 b''
5 5 @monoFontFamily: monospace; // to allow user to customize their fonts
6 6 @navbarHeight: 36px;
7 7
8 code {
9 color: @black; // default code color in bootstrap is #d14 (crimson / amaranth)
10 }
11
8 12 // Our own global variables for all pages go here
9 13
@@ -26,7 +26,7 b' var IPython = (function (IPython) {'
26 26 return true;
27 27 }
28 28 },
29 'shift+enter' : {
29 'shift-enter' : {
30 30 help : 'run cell, select below',
31 31 help_index : 'ba',
32 32 handler : function (event) {
@@ -34,7 +34,7 b' var IPython = (function (IPython) {'
34 34 return false;
35 35 }
36 36 },
37 'ctrl+enter' : {
37 'ctrl-enter' : {
38 38 help : 'run cell',
39 39 help_index : 'bb',
40 40 handler : function (event) {
@@ -42,7 +42,7 b' var IPython = (function (IPython) {'
42 42 return false;
43 43 }
44 44 },
45 'alt+enter' : {
45 'alt-enter' : {
46 46 help : 'run cell, insert below',
47 47 help_index : 'bc',
48 48 handler : function (event) {
@@ -53,7 +53,7 b' var IPython = (function (IPython) {'
53 53 };
54 54
55 55 if (platform === 'MacOS') {
56 default_common_shortcuts['cmd+s'] =
56 default_common_shortcuts['cmd-s'] =
57 57 {
58 58 help : 'save notebook',
59 59 help_index : 'fb',
@@ -64,7 +64,7 b' var IPython = (function (IPython) {'
64 64 }
65 65 };
66 66 } else {
67 default_common_shortcuts['ctrl+s'] =
67 default_common_shortcuts['ctrl-s'] =
68 68 {
69 69 help : 'save notebook',
70 70 help_index : 'fb',
@@ -87,7 +87,7 b' var IPython = (function (IPython) {'
87 87 return false;
88 88 }
89 89 },
90 'ctrl+m' : {
90 'ctrl-m' : {
91 91 help : 'command mode',
92 92 help_index : 'ab',
93 93 handler : function (event) {
@@ -141,7 +141,7 b' var IPython = (function (IPython) {'
141 141 }
142 142 }
143 143 },
144 'alt+-' : {
144 'alt--' : {
145 145 help : 'split cell',
146 146 help_index : 'ea',
147 147 handler : function (event) {
@@ -149,7 +149,7 b' var IPython = (function (IPython) {'
149 149 return false;
150 150 }
151 151 },
152 'alt+subtract' : {
152 'alt-subtract' : {
153 153 help : '',
154 154 help_index : 'eb',
155 155 handler : function (event) {
@@ -161,40 +161,40 b' var IPython = (function (IPython) {'
161 161 help : 'indent or complete',
162 162 help_index : 'ec',
163 163 },
164 'shift+tab' : {
164 'shift-tab' : {
165 165 help : 'tooltip',
166 166 help_index : 'ed',
167 167 },
168 168 };
169 169
170 170 if (platform === 'MacOS') {
171 default_edit_shortcuts['cmd+/'] =
171 default_edit_shortcuts['cmd-/'] =
172 172 {
173 173 help : 'toggle comment',
174 174 help_index : 'ee'
175 175 };
176 default_edit_shortcuts['cmd+]'] =
176 default_edit_shortcuts['cmd-]'] =
177 177 {
178 178 help : 'indent',
179 179 help_index : 'ef'
180 180 };
181 default_edit_shortcuts['cmd+['] =
181 default_edit_shortcuts['cmd-['] =
182 182 {
183 183 help : 'dedent',
184 184 help_index : 'eg'
185 185 };
186 186 } else {
187 default_edit_shortcuts['ctrl+/'] =
187 default_edit_shortcuts['ctrl-/'] =
188 188 {
189 189 help : 'toggle comment',
190 190 help_index : 'ee'
191 191 };
192 default_edit_shortcuts['ctrl+]'] =
192 default_edit_shortcuts['ctrl-]'] =
193 193 {
194 194 help : 'indent',
195 195 help_index : 'ef'
196 196 };
197 default_edit_shortcuts['ctrl+['] =
197 default_edit_shortcuts['ctrl-['] =
198 198 {
199 199 help : 'dedent',
200 200 help_index : 'eg'
@@ -276,7 +276,7 b' var IPython = (function (IPython) {'
276 276 return false;
277 277 }
278 278 },
279 'shift+v' : {
279 'shift-v' : {
280 280 help : 'paste cell above',
281 281 help_index : 'eg',
282 282 handler : function (event) {
@@ -401,7 +401,7 b' var IPython = (function (IPython) {'
401 401 return false;
402 402 }
403 403 },
404 'shift+o' : {
404 'shift-o' : {
405 405 help : 'toggle output scrolling',
406 406 help_index : 'gc',
407 407 handler : function (event) {
@@ -417,7 +417,7 b' var IPython = (function (IPython) {'
417 417 return false;
418 418 }
419 419 },
420 'ctrl+j' : {
420 'ctrl-j' : {
421 421 help : 'move cell down',
422 422 help_index : 'eb',
423 423 handler : function (event) {
@@ -425,7 +425,7 b' var IPython = (function (IPython) {'
425 425 return false;
426 426 }
427 427 },
428 'ctrl+k' : {
428 'ctrl-k' : {
429 429 help : 'move cell up',
430 430 help_index : 'ea',
431 431 handler : function (event) {
@@ -475,7 +475,7 b' var IPython = (function (IPython) {'
475 475 return false;
476 476 }
477 477 },
478 'shift+m' : {
478 'shift-m' : {
479 479 help : 'merge cell below',
480 480 help_index : 'ek',
481 481 handler : function (event) {
@@ -18,6 +18,11 b' var IPython = (function (IPython) {'
18 18 QuickHelp.prototype.show_keyboard_shortcuts = function () {
19 19 // toggles display of keyboard shortcut dialog
20 20 var that = this;
21 if ( this.force_rebuild ) {
22 this.shortcut_dialog.remove();
23 delete(this.shortcut_dialog);
24 this.force_rebuild = false;
25 }
21 26 if ( this.shortcut_dialog ){
22 27 // if dialog is already shown, close it
23 28 $(this.shortcut_dialog).modal("toggle");
@@ -38,7 +43,7 b' var IPython = (function (IPython) {'
38 43 'allows you to type code/text into a cell and is indicated by a green cell '+
39 44 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
40 45 'and is indicated by a grey cell border.'
41 )
46 );
42 47 element.append(doc);
43 48
44 49 // Command mode
@@ -57,73 +62,63 b' var IPython = (function (IPython) {'
57 62 Close : {}
58 63 }
59 64 });
65
66 $([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
60 67 };
61 68
62 69 QuickHelp.prototype.build_command_help = function () {
63 70 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
64 var help, shortcut;
65 var i, half, n;
71 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
72 };
66 73
67 // Command mode
68 var cmd_div = $('<div/>').append($('<h4>Command Mode (press <code>esc</code> to enable)</h4>'));
69 var cmd_sub_div = $('<div/>').addClass('hbox');
70 var cmd_col1 = $('<div/>').addClass('box-flex0');
71 var cmd_col2 = $('<div/>').addClass('box-flex0');
72 n = command_shortcuts.length;
73 half = ~~(n/2); // Truncate :)
74 for (i=0; i<half; i++) {
75 help = command_shortcuts[i]['help'];
76 shortcut = command_shortcuts[i]['shortcut'];
77 cmd_col1.append($('<div>').addClass('quickhelp').
78 append($('<span/>').addClass('shortcut_key').text(shortcut)).
79 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
80 );
81 };
82 for (i=half; i<n; i++) {
83 help = command_shortcuts[i]['help'];
84 shortcut = command_shortcuts[i]['shortcut'];
85 cmd_col2.append($('<div>').addClass('quickhelp').
86 append($('<span/>').addClass('shortcut_key').text(shortcut)).
87 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
88 );
89 };
90 cmd_sub_div.append(cmd_col1).append(cmd_col2);
91 cmd_div.append(cmd_sub_div);
92 return cmd_div;
93 }
74 var special_case = { pageup: "PageUp", pagedown: "Page Down", 'minus': '-' };
75 var prettify = function (s) {
76 s = s.replace(/-$/, 'minus'); // catch shortcuts using '-' key
77 var keys = s.split('-');
78 var k, i;
79 for (i in keys) {
80 k = keys[i];
81 if ( k.length == 1 ) {
82 keys[i] = "<code><strong>" + k + "</strong></code>";
83 continue; // leave individual keys lower-cased
84 }
85 keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) );
86 keys[i] = "<code><strong>" + keys[i] + "</strong></code>";
87 }
88 return keys.join('-');
89
90
91 };
94 92
95 93 QuickHelp.prototype.build_edit_help = function () {
96 94 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
97 var help, shortcut;
98 var i, half, n;
99
100 95 // Edit mode
101 var edit_div = $('<div/>').append($('<h4>Edit Mode (press <code>enter</code> to enable)</h4>'));
102 var edit_sub_div = $('<div/>').addClass('hbox');
103 var edit_col1 = $('<div/>').addClass('box-flex0');
104 var edit_col2 = $('<div/>').addClass('box-flex0');
105 n = edit_shortcuts.length;
96 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', edit_shortcuts);
97 };
98
99 var build_one = function (s) {
100 var help = s.help;
101 var shortcut = prettify(s.shortcut);
102 return $('<div>').addClass('quickhelp').
103 append($('<span/>').addClass('shortcut_key').append($(shortcut))).
104 append($('<span/>').addClass('shortcut_descr').text(' : ' + help));
105
106 };
107
108 var build_div = function (title, shortcuts) {
109 var i, half, n;
110 var div = $('<div/>').append($(title));
111 var sub_div = $('<div/>').addClass('hbox');
112 var col1 = $('<div/>').addClass('box-flex0');
113 var col2 = $('<div/>').addClass('box-flex0');
114 n = shortcuts.length;
106 115 half = ~~(n/2); // Truncate :)
107 for (i=0; i<half; i++) {
108 help = edit_shortcuts[i]['help'];
109 shortcut = edit_shortcuts[i]['shortcut'];
110 edit_col1.append($('<div>').addClass('quickhelp').
111 append($('<span/>').addClass('shortcut_key').text(shortcut)).
112 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
113 );
114 };
115 for (i=half; i<n; i++) {
116 help = edit_shortcuts[i]['help'];
117 shortcut = edit_shortcuts[i]['shortcut'];
118 edit_col2.append($('<div>').addClass('quickhelp').
119 append($('<span/>').addClass('shortcut_key').text(shortcut)).
120 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
121 );
122 };
123 edit_sub_div.append(edit_col1).append(edit_col2);
124 edit_div.append(edit_sub_div);
125 return edit_div;
126 }
116 for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); }
117 for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); }
118 sub_div.append(col1).append(col2);
119 div.append(sub_div);
120 return div;
121 };
127 122
128 123 // Set module variables
129 124 IPython.QuickHelp = QuickHelp;
@@ -56,7 +56,7 b' var tour_steps = ['
56 56 title: "Edit Mode",
57 57 placement: 'bottom',
58 58 onShow: function(tour) { edit_mode(); },
59 content: "Pressing <code>enter</code> or clicking in the input text area of the cell switches to Edit Mode."
59 content: "Pressing <code>Enter</code> or clicking in the input text area of the cell switches to Edit Mode."
60 60 }, {
61 61 element: '.selected',
62 62 title: "Edit Mode",
@@ -68,7 +68,7 b' var tour_steps = ['
68 68 title: "Back to Command Mode",
69 69 placement: 'bottom',
70 70 onShow: function(tour) { IPython.notebook.command_mode(); },
71 content: "Pressing <code>esc</code> or clicking outside of the input text area takes you back to Command Mode."
71 content: "Pressing <code>Esc</code> or clicking outside of the input text area takes you back to Command Mode."
72 72 }, {
73 73 element: '#keyboard_shortcuts',
74 74 title: "Keyboard Shortcuts",
@@ -1,6 +1,6 b''
1 1 .shortcut_key {
2 2 display: inline-block;
3 width: 15ex;
3 width: 16ex;
4 4 text-align: right;
5 5 font-family: @monoFontFamily;
6 6 }
@@ -2,6 +2,7 b''
2 2 .clearfix:after{clear:both}
3 3 .hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}
4 4 .input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
5 code{color:#000}
5 6 .border-box-sizing{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}
6 7 .corner-all{border-radius:4px}
7 8 .hbox{display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;display:flex;flex-direction:row;align-items:stretch}
@@ -1265,6 +1265,7 b' a .icon-rotate-90:before,a .icon-rotate-180:before,a .icon-rotate-270:before,a .'
1265 1265 .icon-vk:before{content:"\f189"}
1266 1266 .icon-weibo:before{content:"\f18a"}
1267 1267 .icon-renren:before{content:"\f18b"}
1268 code{color:#000}
1268 1269 .border-box-sizing{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}
1269 1270 .corner-all{border-radius:4px}
1270 1271 .hbox{display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;display:flex;flex-direction:row;align-items:stretch}
@@ -1515,7 +1516,7 b' ul#help_menu li a{overflow:hidden;padding-right:2.2em}ul#help_menu li a i{margin'
1515 1516 div#pager_splitter{height:8px}
1516 1517 #pager-container{position:relative;padding:15px 0}
1517 1518 div#pager{font-size:14px;line-height:20px;overflow:auto;display:none}div#pager pre{font-size:13px;line-height:1.21429em;color:#000;background-color:#f7f7f7;padding:.4em}
1518 .shortcut_key{display:inline-block;width:15ex;text-align:right;font-family:monospace}
1519 .shortcut_key{display:inline-block;width:16ex;text-align:right;font-family:monospace}
1519 1520 .shortcut_descr{display:inline-block}
1520 1521 span#save_widget{padding:0 5px;margin-top:12px}
1521 1522 span#checkpoint_status,span#autosave_status{font-size:small}
@@ -1,13 +1,13 b''
1 1
2 2
3 3 var normalized_shortcuts = [
4 'ctrl+shift+m',
5 'alt+meta+p',
4 'ctrl-shift-m',
5 'alt-meta-p',
6 6 ];
7 7
8 8 var to_normalize = [
9 ['shift+%', 'shift+5'],
10 ['ShiFT+MeTa+CtRl+AlT+m', 'alt+ctrl+meta+shift+m'],
9 ['shift-%', 'shift-5'],
10 ['ShiFT-MeTa-CtRl-AlT-m', 'alt-ctrl-meta-shift-m'],
11 11 ];
12 12
13 13 var unshifted = "` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \\ a s d f g h j k l ; ' z x c v b n m , . /";
@@ -33,7 +33,7 b' casper.notebook_test(function () {'
33 33 }, item);
34 34 this.test.assertEquals(result, item[1], 'Normalize shortcut: '+item[0]);
35 35 });
36 })
36 });
37 37
38 38 this.then(function () {
39 39 this.each(normalized_shortcuts, function (self, item) {
@@ -46,4 +46,4 b' casper.notebook_test(function () {'
46 46 });
47 47 });
48 48
49 }); No newline at end of file
49 });
@@ -22,7 +22,7 b' casper.notebook_test(function () {'
22 22 var cell = IPython.notebook.get_cell(0);
23 23 cell.set_text('a=11; print(a)');
24 24 cell.clear_output();
25 IPython.keyboard.trigger_keydown('shift+enter');
25 IPython.keyboard.trigger_keydown('shift-enter');
26 26 });
27 27
28 28 this.wait_for_output(0);
@@ -41,7 +41,7 b' casper.notebook_test(function () {'
41 41 var cell = IPython.notebook.get_cell(0);
42 42 cell.set_text('a=12; print(a)');
43 43 cell.clear_output();
44 IPython.keyboard.trigger_keydown('ctrl+enter');
44 IPython.keyboard.trigger_keydown('ctrl-enter');
45 45 });
46 46
47 47 this.wait_for_output(0);
@@ -103,7 +103,7 b" def markdown2html_marked(source, encoding='utf-8'):"
103 103 return out.rstrip('\n')
104 104
105 105 def markdown2rst(source):
106 """Convert a markdown string to LaTeX via pandoc.
106 """Convert a markdown string to ReST via pandoc.
107 107
108 108 This function will raise an error if pandoc is not installed.
109 109 Any error messages generated by pandoc are printed to stderr.
@@ -11,9 +11,13 b' addition to the coalesce_streams pre-proccessor.'
11 11 #-----------------------------------------------------------------------------
12 12
13 13 #-----------------------------------------------------------------------------
14 # Functions
14 # Imports
15 15 #-----------------------------------------------------------------------------
16 import re
16 17
18 #-----------------------------------------------------------------------------
19 # Functions
20 #-----------------------------------------------------------------------------
17 21 def cell_preprocessor(function):
18 22 """
19 23 Wrap a function to be executed on all cells of a notebook
@@ -67,6 +71,10 b' def coalesce_streams(cell, resources, index):'
67 71 last.stream == output.stream
68 72 ):
69 73 last.text += output.text
74
75 # Respect \r characters.
76 cr_pat = re.compile(r'.*\r(?=[^\n])')
77 last.text = cr_pat.sub('', last.text)
70 78 else:
71 79 new_outputs.append(output)
72 80 last = output
@@ -13,7 +13,6 b' Module with tests for the coalescestreams preprocessor'
13 13 #-----------------------------------------------------------------------------
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16
17 16 from IPython.nbformat import current as nbformat
18 17
19 18 from .base import PreprocessorTestsBase
@@ -23,7 +22,6 b' from ..coalescestreams import coalesce_streams'
23 22 #-----------------------------------------------------------------------------
24 23 # Class
25 24 #-----------------------------------------------------------------------------
26
27 25 class TestCoalesceStreams(PreprocessorTestsBase):
28 26 """Contains test functions for coalescestreams.py"""
29 27
@@ -38,10 +36,8 b' class TestCoalesceStreams(PreprocessorTestsBase):'
38 36 self.assertEqual(outputs[2].text, "cd")
39 37 self.assertEqual(outputs[3].text, "ef")
40 38
41
42 39 def test_coalesce_sequenced_streams(self):
43 40 """Can the coalesce streams preprocessor merge a sequence of streams?"""
44
45 41 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="0"),
46 42 nbformat.new_output(output_type="stream", stream="stdout", output_text="1"),
47 43 nbformat.new_output(output_type="stream", stream="stdout", output_text="2"),
@@ -58,3 +54,20 b' class TestCoalesceStreams(PreprocessorTestsBase):'
58 54 nb, res = coalesce_streams(nb, res)
59 55 outputs = nb.worksheets[0].cells[0].outputs
60 56 self.assertEqual(outputs[0].text, u'01234567')
57
58 def test_coalesce_replace_streams(self):
59 """Are \\r characters handled?"""
60 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="z"),
61 nbformat.new_output(output_type="stream", stream="stdout", output_text="\ra"),
62 nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz\rb"),
63 nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz"),
64 nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc\n"),
65 nbformat.new_output(output_type="stream", stream="stdout", output_text="z\rz\rd")]
66 cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
67 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
68
69 nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
70 res = self.build_resources()
71 nb, res = coalesce_streams(nb, res)
72 outputs = nb.worksheets[0].cells[0].outputs
73 self.assertEqual(outputs[0].text, u'a\nb\nc\nd')
@@ -38,15 +38,15 b''
38 38 {% endblock stream %}
39 39
40 40 {% block data_svg %}
41 .. image:: {{ output.svg_filename }}
41 .. image:: {{ output.svg_filename|urlencode }}
42 42 {% endblock data_svg %}
43 43
44 44 {% block data_png %}
45 .. image:: {{ output.png_filename }}
45 .. image:: {{ output.png_filename|urlencode }}
46 46 {% endblock data_png %}
47 47
48 48 {% block data_jpg %}
49 .. image:: {{ output.jpeg_filename }}
49 .. image:: {{ output.jpeg_filename|urlencode }}
50 50 {% endblock data_jpg %}
51 51
52 52 {% block data_latex %}
General Comments 0
You need to be logged in to leave comments. Login now