diff --git a/IPython/html/static/base/js/keyboard.js b/IPython/html/static/base/js/keyboard.js index 96edd73..4fa77d5 100644 --- a/IPython/html/static/base/js/keyboard.js +++ b/IPython/html/static/base/js/keyboard.js @@ -44,17 +44,17 @@ IPython.keyboard = (function (IPython) { // These apply to Firefox and Opera var _mozilla_keycodes = { '; :': 59, '= +': 61, '- _': 173, 'meta': 224 - } + }; // This apply to Webkit and IE var _ie_keycodes = { - '; :': 186, '= +': 187, '- _': 189, - } + '; :': 186, '= +': 187, '- _': 189 + }; var browser = IPython.utils.browser[0]; var platform = IPython.utils.platform; - if (browser === 'Firefox' || browser === 'Opera') { + if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') { $.extend(_keycodes, _mozilla_keycodes); } else if (browser === 'Safari' || browser === 'Chrome' || browser === 'MSIE') { $.extend(_keycodes, _ie_keycodes); @@ -65,45 +65,47 @@ IPython.keyboard = (function (IPython) { for (var name in _keycodes) { var names = name.split(' '); if (names.length === 1) { - var n = names[0] - keycodes[n] = _keycodes[n] - inv_keycodes[_keycodes[n]] = n + var n = names[0]; + keycodes[n] = _keycodes[n]; + inv_keycodes[_keycodes[n]] = n; } else { var primary = names[0]; var secondary = names[1]; - keycodes[primary] = _keycodes[name] - keycodes[secondary] = _keycodes[name] - inv_keycodes[_keycodes[name]] = primary + keycodes[primary] = _keycodes[name]; + keycodes[secondary] = _keycodes[name]; + inv_keycodes[_keycodes[name]] = primary; } } var normalize_key = function (key) { return inv_keycodes[keycodes[key]]; - } + }; var normalize_shortcut = function (shortcut) { // Put a shortcut into normalized form: // 1. Make lowercase // 2. Replace cmd by meta - // 3. Sort '+' separated modifiers into the order alt+ctrl+meta+shift + // 3. Sort '-' separated modifiers into the order alt-ctrl-meta-shift // 4. Normalize keys shortcut = shortcut.toLowerCase().replace('cmd', 'meta'); - var values = shortcut.split("+"); + shortcut = shortcut.replace(/-$/, '_'); // catch shortcuts using '-' key + var values = shortcut.split("-"); if (values.length === 1) { - return normalize_key(values[0]) + return normalize_key(values[0]); } else { var modifiers = values.slice(0,-1); var key = normalize_key(values[values.length-1]); modifiers.sort(); - return modifiers.join('+') + '+' + key; + return modifiers.join('-') + '-' + key; } - } + }; var shortcut_to_event = function (shortcut, type) { - // Convert a shortcut (shift+r) to a jQuery Event object + // Convert a shortcut (shift-r) to a jQuery Event object type = type || 'keydown'; shortcut = normalize_shortcut(shortcut); - var values = shortcut.split("+"); + shortcut = shortcut.replace(/-$/, '_'); // catch shortcuts using '-' key + var values = shortcut.split("-"); var modifiers = values.slice(0,-1); var key = values[values.length-1]; var opts = {which: keycodes[key]}; @@ -112,19 +114,19 @@ IPython.keyboard = (function (IPython) { if (modifiers.indexOf('meta') !== -1) {opts.metaKey = true;} if (modifiers.indexOf('shift') !== -1) {opts.shiftKey = true;} return $.Event(type, opts); - } + }; var event_to_shortcut = function (event) { - // Convert a jQuery Event object to a shortcut (shift+r) + // Convert a jQuery Event object to a shortcut (shift-r) var shortcut = ''; - var key = inv_keycodes[event.which] - if (event.altKey && key !== 'alt') {shortcut += 'alt+';} - if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';} - if (event.metaKey && key !== 'meta') {shortcut += 'meta+';} - if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';} + var key = inv_keycodes[event.which]; + if (event.altKey && key !== 'alt') {shortcut += 'alt-';} + if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl-';} + if (event.metaKey && key !== 'meta') {shortcut += 'meta-';} + if (event.shiftKey && key !== 'shift') {shortcut += 'shift-';} shortcut += key; - return shortcut - } + return shortcut; + }; var trigger_keydown = function (shortcut, element) { // Trigger shortcut keydown on an element @@ -132,17 +134,17 @@ IPython.keyboard = (function (IPython) { element = $(element); var event = shortcut_to_event(shortcut, 'keydown'); element.trigger(event); - } + }; // Shortcut manager class var ShortcutManager = function (delay) { - this._shortcuts = {} - this._counts = {} - this._timers = {} + this._shortcuts = {}; + this._counts = {}; + this._timers = {}; this.delay = delay || 800; // delay in milliseconds - } + }; ShortcutManager.prototype.help = function () { var help = []; @@ -168,15 +170,15 @@ IPython.keyboard = (function (IPython) { return 0; }); return help; - } + }; ShortcutManager.prototype.clear_shortcuts = function () { this._shortcuts = {}; - } + }; - ShortcutManager.prototype.add_shortcut = function (shortcut, data) { + ShortcutManager.prototype.add_shortcut = function (shortcut, data, suppress_help_update) { if (typeof(data) === 'function') { - data = {help: '', help_index: '', handler: data} + data = {help: '', help_index: '', handler: data}; } data.help_index = data.help_index || ''; data.help = data.help || ''; @@ -187,19 +189,29 @@ IPython.keyboard = (function (IPython) { shortcut = normalize_shortcut(shortcut); this._counts[shortcut] = 0; this._shortcuts[shortcut] = data; - } + if (!suppress_help_update) { + // update the keyboard shortcuts notebook help + $([IPython.events]).trigger('rebuild.QuickHelp'); + } + }; ShortcutManager.prototype.add_shortcuts = function (data) { for (var shortcut in data) { - this.add_shortcut(shortcut, data[shortcut]); + this.add_shortcut(shortcut, data[shortcut], true); } - } + // update the keyboard shortcuts notebook help + $([IPython.events]).trigger('rebuild.QuickHelp'); + }; - ShortcutManager.prototype.remove_shortcut = function (shortcut) { + ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) { shortcut = normalize_shortcut(shortcut); delete this._counts[shortcut]; delete this._shortcuts[shortcut]; - } + if (!suppress_help_update) { + // update the keyboard shortcuts notebook help + $([IPython.events]).trigger('rebuild.QuickHelp'); + } + }; ShortcutManager.prototype.count_handler = function (shortcut, event, data) { var that = this; @@ -219,7 +231,7 @@ IPython.keyboard = (function (IPython) { t[shortcut] = timer; } return false; - } + }; ShortcutManager.prototype.call_handler = function (event) { var shortcut = event_to_shortcut(event); @@ -235,7 +247,7 @@ IPython.keyboard = (function (IPython) { } } return true; - } + }; ShortcutManager.prototype.handles = function (event) { var shortcut = event_to_shortcut(event); @@ -252,6 +264,6 @@ IPython.keyboard = (function (IPython) { shortcut_to_event : shortcut_to_event, event_to_shortcut : event_to_shortcut, trigger_keydown : trigger_keydown - } + }; }(IPython)); diff --git a/IPython/html/static/base/less/variables.less b/IPython/html/static/base/less/variables.less index 42d9f61..ac93c19 100644 --- a/IPython/html/static/base/less/variables.less +++ b/IPython/html/static/base/less/variables.less @@ -5,5 +5,9 @@ @monoFontFamily: monospace; // to allow user to customize their fonts @navbarHeight: 36px; +code { + color: @black; // default code color in bootstrap is #d14 (crimson / amaranth) +} + // Our own global variables for all pages go here diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index fed12f6..5479609 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -26,7 +26,7 @@ var IPython = (function (IPython) { return true; } }, - 'shift+enter' : { + 'shift-enter' : { help : 'run cell, select below', help_index : 'ba', handler : function (event) { @@ -34,7 +34,7 @@ var IPython = (function (IPython) { return false; } }, - 'ctrl+enter' : { + 'ctrl-enter' : { help : 'run cell', help_index : 'bb', handler : function (event) { @@ -42,7 +42,7 @@ var IPython = (function (IPython) { return false; } }, - 'alt+enter' : { + 'alt-enter' : { help : 'run cell, insert below', help_index : 'bc', handler : function (event) { @@ -53,7 +53,7 @@ var IPython = (function (IPython) { }; if (platform === 'MacOS') { - default_common_shortcuts['cmd+s'] = + default_common_shortcuts['cmd-s'] = { help : 'save notebook', help_index : 'fb', @@ -64,7 +64,7 @@ var IPython = (function (IPython) { } }; } else { - default_common_shortcuts['ctrl+s'] = + default_common_shortcuts['ctrl-s'] = { help : 'save notebook', help_index : 'fb', @@ -87,7 +87,7 @@ var IPython = (function (IPython) { return false; } }, - 'ctrl+m' : { + 'ctrl-m' : { help : 'command mode', help_index : 'ab', handler : function (event) { @@ -141,7 +141,7 @@ var IPython = (function (IPython) { } } }, - 'alt+-' : { + 'alt--' : { help : 'split cell', help_index : 'ea', handler : function (event) { @@ -149,7 +149,7 @@ var IPython = (function (IPython) { return false; } }, - 'alt+subtract' : { + 'alt-subtract' : { help : '', help_index : 'eb', handler : function (event) { @@ -161,40 +161,40 @@ var IPython = (function (IPython) { help : 'indent or complete', help_index : 'ec', }, - 'shift+tab' : { + 'shift-tab' : { help : 'tooltip', help_index : 'ed', }, }; if (platform === 'MacOS') { - default_edit_shortcuts['cmd+/'] = + default_edit_shortcuts['cmd-/'] = { help : 'toggle comment', help_index : 'ee' }; - default_edit_shortcuts['cmd+]'] = + default_edit_shortcuts['cmd-]'] = { help : 'indent', help_index : 'ef' }; - default_edit_shortcuts['cmd+['] = + default_edit_shortcuts['cmd-['] = { help : 'dedent', help_index : 'eg' }; } else { - default_edit_shortcuts['ctrl+/'] = + default_edit_shortcuts['ctrl-/'] = { help : 'toggle comment', help_index : 'ee' }; - default_edit_shortcuts['ctrl+]'] = + default_edit_shortcuts['ctrl-]'] = { help : 'indent', help_index : 'ef' }; - default_edit_shortcuts['ctrl+['] = + default_edit_shortcuts['ctrl-['] = { help : 'dedent', help_index : 'eg' @@ -276,7 +276,7 @@ var IPython = (function (IPython) { return false; } }, - 'shift+v' : { + 'shift-v' : { help : 'paste cell above', help_index : 'eg', handler : function (event) { @@ -401,7 +401,7 @@ var IPython = (function (IPython) { return false; } }, - 'shift+o' : { + 'shift-o' : { help : 'toggle output scrolling', help_index : 'gc', handler : function (event) { @@ -417,7 +417,7 @@ var IPython = (function (IPython) { return false; } }, - 'ctrl+j' : { + 'ctrl-j' : { help : 'move cell down', help_index : 'eb', handler : function (event) { @@ -425,7 +425,7 @@ var IPython = (function (IPython) { return false; } }, - 'ctrl+k' : { + 'ctrl-k' : { help : 'move cell up', help_index : 'ea', handler : function (event) { @@ -475,7 +475,7 @@ var IPython = (function (IPython) { return false; } }, - 'shift+m' : { + 'shift-m' : { help : 'merge cell below', help_index : 'ek', handler : function (event) { diff --git a/IPython/html/static/notebook/js/quickhelp.js b/IPython/html/static/notebook/js/quickhelp.js index 29cb3de..84f825f 100644 --- a/IPython/html/static/notebook/js/quickhelp.js +++ b/IPython/html/static/notebook/js/quickhelp.js @@ -18,6 +18,11 @@ var IPython = (function (IPython) { QuickHelp.prototype.show_keyboard_shortcuts = function () { // toggles display of keyboard shortcut dialog var that = this; + if ( this.force_rebuild ) { + this.shortcut_dialog.remove(); + delete(this.shortcut_dialog); + this.force_rebuild = false; + } if ( this.shortcut_dialog ){ // if dialog is already shown, close it $(this.shortcut_dialog).modal("toggle"); @@ -38,7 +43,7 @@ var IPython = (function (IPython) { 'allows you to type code/text into a cell and is indicated by a green cell '+ 'border. Command mode binds the keyboard to notebook level actions '+ 'and is indicated by a grey cell border.' - ) + ); element.append(doc); // Command mode @@ -57,73 +62,63 @@ var IPython = (function (IPython) { Close : {} } }); + + $([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;}); }; QuickHelp.prototype.build_command_help = function () { var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); - var help, shortcut; - var i, half, n; + return build_div('
Esc
to enable)esc
to enable)" + k + "
";
+ continue; // leave individual keys lower-cased
+ }
+ keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) );
+ keys[i] = "" + keys[i] + "
";
+ }
+ return keys.join('-');
+
+
+ };
QuickHelp.prototype.build_edit_help = function () {
var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
- var help, shortcut;
- var i, half, n;
-
// Edit mode
- var edit_div = $('').append($('enter
to enable)Enter
to enable)Enter
or clicking in the input text area of the cell switches to Edit Mode."
}, {
element: '.selected',
title: "Edit Mode",
@@ -68,7 +68,7 @@ var tour_steps = [
title: "Back to Command Mode",
placement: 'bottom',
onShow: function(tour) { IPython.notebook.command_mode(); },
- content: "Pressing esc
or clicking outside of the input text area takes you back to Command Mode."
+ content: "Pressing Esc
or clicking outside of the input text area takes you back to Command Mode."
}, {
element: '#keyboard_shortcuts',
title: "Keyboard Shortcuts",
diff --git a/IPython/html/static/notebook/less/quickhelp.less b/IPython/html/static/notebook/less/quickhelp.less
index fbd8c21..f57c38e 100644
--- a/IPython/html/static/notebook/less/quickhelp.less
+++ b/IPython/html/static/notebook/less/quickhelp.less
@@ -1,6 +1,6 @@
.shortcut_key {
display: inline-block;
- width: 15ex;
+ width: 16ex;
text-align: right;
font-family: @monoFontFamily;
}
diff --git a/IPython/html/static/style/ipython.min.css b/IPython/html/static/style/ipython.min.css
index b176472..1029e0c 100644
--- a/IPython/html/static/style/ipython.min.css
+++ b/IPython/html/static/style/ipython.min.css
@@ -2,6 +2,7 @@
.clearfix:after{clear:both}
.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}
.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
+code{color:#000}
.border-box-sizing{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}
.corner-all{border-radius:4px}
.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}
diff --git a/IPython/html/static/style/style.min.css b/IPython/html/static/style/style.min.css
index 2b4bd18..33cbbc8 100644
--- a/IPython/html/static/style/style.min.css
+++ b/IPython/html/static/style/style.min.css
@@ -1265,6 +1265,7 @@ a .icon-rotate-90:before,a .icon-rotate-180:before,a .icon-rotate-270:before,a .
.icon-vk:before{content:"\f189"}
.icon-weibo:before{content:"\f18a"}
.icon-renren:before{content:"\f18b"}
+code{color:#000}
.border-box-sizing{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}
.corner-all{border-radius:4px}
.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 @@ ul#help_menu li a{overflow:hidden;padding-right:2.2em}ul#help_menu li a i{margin
div#pager_splitter{height:8px}
#pager-container{position:relative;padding:15px 0}
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}
-.shortcut_key{display:inline-block;width:15ex;text-align:right;font-family:monospace}
+.shortcut_key{display:inline-block;width:16ex;text-align:right;font-family:monospace}
.shortcut_descr{display:inline-block}
span#save_widget{padding:0 5px;margin-top:12px}
span#checkpoint_status,span#autosave_status{font-size:small}
diff --git a/IPython/html/tests/base/keyboard.js b/IPython/html/tests/base/keyboard.js
index 1fc1edc..d74113f 100644
--- a/IPython/html/tests/base/keyboard.js
+++ b/IPython/html/tests/base/keyboard.js
@@ -1,13 +1,13 @@
var normalized_shortcuts = [
- 'ctrl+shift+m',
- 'alt+meta+p',
+ 'ctrl-shift-m',
+ 'alt-meta-p',
];
var to_normalize = [
- ['shift+%', 'shift+5'],
- ['ShiFT+MeTa+CtRl+AlT+m', 'alt+ctrl+meta+shift+m'],
+ ['shift-%', 'shift-5'],
+ ['ShiFT-MeTa-CtRl-AlT-m', 'alt-ctrl-meta-shift-m'],
];
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 @@ casper.notebook_test(function () {
}, item);
this.test.assertEquals(result, item[1], 'Normalize shortcut: '+item[0]);
});
- })
+ });
this.then(function () {
this.each(normalized_shortcuts, function (self, item) {
@@ -46,4 +46,4 @@ casper.notebook_test(function () {
});
});
-});
\ No newline at end of file
+});
diff --git a/IPython/html/tests/notebook/execute_code.js b/IPython/html/tests/notebook/execute_code.js
index fc399e4..1af684f 100644
--- a/IPython/html/tests/notebook/execute_code.js
+++ b/IPython/html/tests/notebook/execute_code.js
@@ -22,7 +22,7 @@ casper.notebook_test(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=11; print(a)');
cell.clear_output();
- IPython.keyboard.trigger_keydown('shift+enter');
+ IPython.keyboard.trigger_keydown('shift-enter');
});
this.wait_for_output(0);
@@ -41,7 +41,7 @@ casper.notebook_test(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=12; print(a)');
cell.clear_output();
- IPython.keyboard.trigger_keydown('ctrl+enter');
+ IPython.keyboard.trigger_keydown('ctrl-enter');
});
this.wait_for_output(0);
diff --git a/IPython/nbconvert/filters/markdown.py b/IPython/nbconvert/filters/markdown.py
index e550565..0d6f679 100755
--- a/IPython/nbconvert/filters/markdown.py
+++ b/IPython/nbconvert/filters/markdown.py
@@ -103,7 +103,7 @@ def markdown2html_marked(source, encoding='utf-8'):
return out.rstrip('\n')
def markdown2rst(source):
- """Convert a markdown string to LaTeX via pandoc.
+ """Convert a markdown string to ReST via pandoc.
This function will raise an error if pandoc is not installed.
Any error messages generated by pandoc are printed to stderr.
diff --git a/IPython/nbconvert/preprocessors/coalescestreams.py b/IPython/nbconvert/preprocessors/coalescestreams.py
index 3fa4379..37fddd1 100644
--- a/IPython/nbconvert/preprocessors/coalescestreams.py
+++ b/IPython/nbconvert/preprocessors/coalescestreams.py
@@ -11,9 +11,13 @@ addition to the coalesce_streams pre-proccessor.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
-# Functions
+# Imports
#-----------------------------------------------------------------------------
+import re
+#-----------------------------------------------------------------------------
+# Functions
+#-----------------------------------------------------------------------------
def cell_preprocessor(function):
"""
Wrap a function to be executed on all cells of a notebook
@@ -67,6 +71,10 @@ def coalesce_streams(cell, resources, index):
last.stream == output.stream
):
last.text += output.text
+
+ # Respect \r characters.
+ cr_pat = re.compile(r'.*\r(?=[^\n])')
+ last.text = cr_pat.sub('', last.text)
else:
new_outputs.append(output)
last = output
diff --git a/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py b/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py
index fd9c14f..1df7e0e 100644
--- a/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py
+++ b/IPython/nbconvert/preprocessors/tests/test_coalescestreams.py
@@ -13,7 +13,6 @@ Module with tests for the coalescestreams preprocessor
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
-
from IPython.nbformat import current as nbformat
from .base import PreprocessorTestsBase
@@ -23,7 +22,6 @@ from ..coalescestreams import coalesce_streams
#-----------------------------------------------------------------------------
# Class
#-----------------------------------------------------------------------------
-
class TestCoalesceStreams(PreprocessorTestsBase):
"""Contains test functions for coalescestreams.py"""
@@ -38,10 +36,8 @@ class TestCoalesceStreams(PreprocessorTestsBase):
self.assertEqual(outputs[2].text, "cd")
self.assertEqual(outputs[3].text, "ef")
-
def test_coalesce_sequenced_streams(self):
"""Can the coalesce streams preprocessor merge a sequence of streams?"""
-
outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="0"),
nbformat.new_output(output_type="stream", stream="stdout", output_text="1"),
nbformat.new_output(output_type="stream", stream="stdout", output_text="2"),
@@ -58,3 +54,20 @@ class TestCoalesceStreams(PreprocessorTestsBase):
nb, res = coalesce_streams(nb, res)
outputs = nb.worksheets[0].cells[0].outputs
self.assertEqual(outputs[0].text, u'01234567')
+
+ def test_coalesce_replace_streams(self):
+ """Are \\r characters handled?"""
+ outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="z"),
+ nbformat.new_output(output_type="stream", stream="stdout", output_text="\ra"),
+ nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz\rb"),
+ nbformat.new_output(output_type="stream", stream="stdout", output_text="\nz"),
+ nbformat.new_output(output_type="stream", stream="stdout", output_text="\rc\n"),
+ nbformat.new_output(output_type="stream", stream="stdout", output_text="z\rz\rd")]
+ cells=[nbformat.new_code_cell(input="# None", prompt_number=1,outputs=outputs)]
+ worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
+
+ nb = nbformat.new_notebook(name="notebook1", worksheets=worksheets)
+ res = self.build_resources()
+ nb, res = coalesce_streams(nb, res)
+ outputs = nb.worksheets[0].cells[0].outputs
+ self.assertEqual(outputs[0].text, u'a\nb\nc\nd')
diff --git a/IPython/nbconvert/templates/rst.tpl b/IPython/nbconvert/templates/rst.tpl
index 7f25aca..fdabe2a 100644
--- a/IPython/nbconvert/templates/rst.tpl
+++ b/IPython/nbconvert/templates/rst.tpl
@@ -38,15 +38,15 @@
{% endblock stream %}
{% block data_svg %}
-.. image:: {{ output.svg_filename }}
+.. image:: {{ output.svg_filename|urlencode }}
{% endblock data_svg %}
{% block data_png %}
-.. image:: {{ output.png_filename }}
+.. image:: {{ output.png_filename|urlencode }}
{% endblock data_png %}
{% block data_jpg %}
-.. image:: {{ output.jpeg_filename }}
+.. image:: {{ output.jpeg_filename|urlencode }}
{% endblock data_jpg %}
{% block data_latex %}