From 39bd53aeb46e4f17c58bece3a9352a2f5ba9d57c 2018-04-27 16:22:11 From: Thomas Kluyver Date: 2018-04-27 16:22:11 Subject: [PATCH] Display objects should emit metadata when it exists --- diff --git a/IPython/core/display.py b/IPython/core/display.py index 1b98dbb..fa64d9c 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -667,7 +667,7 @@ class Pretty(TextDisplayObject): class HTML(TextDisplayObject): def _repr_html_(self): - return self.data + return self._data_and_metadata() def __html__(self): """ @@ -681,20 +681,23 @@ class HTML(TextDisplayObject): class Markdown(TextDisplayObject): def _repr_markdown_(self): - return self.data + return self._data_and_metadata() class Math(TextDisplayObject): def _repr_latex_(self): - s = self.data.strip('$') - return "$$%s$$" % s + s = "$$%s$$" % self.data.strip('$') + if self.metadata: + return s, deepcopy(self.metadata) + else: + return s class Latex(TextDisplayObject): def _repr_latex_(self): - return self.data + return self._data_and_metadata() class SVG(DisplayObject): diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py index f222871..5a1b5be 100644 --- a/IPython/core/tests/test_display.py +++ b/IPython/core/tests/test_display.py @@ -275,6 +275,10 @@ def test_video_embedding(): html = v._repr_html_() nt.assert_in('src="data:video/xyz;base64,YWJj"',html) +def test_html_metadata(): + s = "

Test

" + h = display.HTML(s, metadata={"isolated": True}) + nt.assert_equal(h._repr_html_(), (s, {"isolated": True})) def test_display_id(): ip = get_ipython()