Repository: ipython/ipython

Issue:
HTML vs Iframe
I was again the witness of people miss-using HTML to display IFrames, and having issues. 

Could we detect in  HTML the usage of `<iframe>....</iframe>` and warn user that there is an iframe object ? 


Discussion:

Patch:
diff --git a/IPython/core/display.py b/IPython/core/display.py
index ca5c3aa5b..4a2e28179 100644
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -666,6 +666,11 @@ def _repr_pretty_(self, pp, cycle):
 
 class HTML(TextDisplayObject):
 
+    def __init__(self, data=None, url=None, filename=None, metadata=None):
+        if data and "<iframe " in data and "</iframe>" in data:
+            warnings.warn("Consider using IPython.display.IFrame instead")
+        super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata)
+
     def _repr_html_(self):
         return self._data_and_metadata()
 


Test patch:
diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py
index 3851d6757..7c1f978b4 100644
--- a/IPython/core/tests/test_display.py
+++ b/IPython/core/tests/test_display.py
@@ -195,6 +195,14 @@ def test_displayobject_repr():
     j._show_mem_addr = False
     nt.assert_equal(repr(j), '<IPython.core.display.Javascript object>')
 
+@mock.patch('warnings.warn')
+def test_encourage_iframe_over_html(m_warn):
+    display.HTML('<br />')
+    m_warn.assert_not_called()
+
+    display.HTML('<iframe src="http://a.com"></iframe>')
+    m_warn.assert_called_with('Consider using IPython.display.IFrame instead')
+
 def test_progress():
     p = display.ProgressBar(10)
     nt.assert_in('0/10',repr(p))