Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion IPython/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,9 @@ def _repr_html_(self):
klass = ' class="unconfined"'
if self.alt:
alt = ' alt="%s"' % html.escape(self.alt)
url = self.url if self.url is not None else self.filename
return '<img src="{url}"{width}{height}{klass}{alt}/>'.format(
url=html.escape(self.url or ""),
url=html.escape(url or ""),
width=width,
height=height,
klass=klass,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_display_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def test_image_size():
assert '<img src="%s" class="unconfined"/>' % (thisurl) == img._repr_html_()


def test_image_local_file_url_without_embedding():
"""A local image requested without embedding keeps its file URL."""
filename = os.path.join(os.path.dirname(__file__), "2x2.png")
img = display.Image(filename=filename, embed=False)
assert f'<img src="{filename}"/>' == img._repr_html_()


def test_image_mimes():
fmt = get_ipython().display_formatter.format
for name, format in ImageFormat.__members__.items():
Expand Down
Loading