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:
What issues does that cause?

> What issues does that cause?

Mostly people having issues getting the html right (width, height), url escaping, and remove the frameborder. The exact reason why we have an IFrame object. 

could you say a bit more on the issue? maybe produce an example of when this comes up?
The suggestion is to warn when someone is doing this:

```python
from IPython.display import HTML
HTML('<iframe src="..."></iframe>')
```

Instead of this:

```python
from IPython.display import IFrame
IFrame('...')
```

I'm still not convinced that it's worth it, though. A warning is going to be annoying if you do need to put an iframe in HTML, or if the display object is being made by code someone else wrote which you don't want to go and change.
Hey! I would like to help with this issue.
This looks like a good first issue. I'll work on this for hacktoberfest.
@meeseeksdev[bot] tag hacktoberfest
Aww Carreau, I was not able to apply the following label(s): `hacktoberfest`. Either because they are not existing labels on this repository or because you do not have the permission to apply these.I tried my best to guess by looking at the casing, but was unable to find matching labels.
Hummm

@meeseeksdev[bot] tag Hacktoberfest
Aww Carreau, I was not able to apply the following label(s): `Hacktoberfest`. Either because they are not existing labels on this repository or because you do not have the permission to apply these.I tried my best to guess by looking at the casing, but was unable to find matching labels.
Reopening as there is some extra possible improvements. See https://github.com/ipython/ipython/pull/11350#discussion_r222363869
Hello! If nobody is working on this, can I pick it up?
@ProximaDas There's a small change I need to push to close this, otherwise, the task is done.

Resolving patch:
diff --git a/IPython/core/display.py b/IPython/core/display.py
--- a/IPython/core/display.py
+++ b/IPython/core/display.py
@@ -667,7 +667,19 @@ 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:
+        def warn():
+            if not data:
+                return False
+
+            #
+            # Avoid calling lower() on the entire data, because it could be a
+            # long string and we're only interested in its beginning and end.
+            #
+            prefix = data[:10].lower()
+            suffix = data[-10:].lower()
+            return prefix.startswith("<iframe ") and suffix.endswith("</iframe>")
+
+        if warn():
             warnings.warn("Consider using IPython.display.IFrame instead")
         super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata)
 


Test patch:
diff --git a/IPython/core/tests/test_display.py b/IPython/core/tests/test_display.py
--- a/IPython/core/tests/test_display.py
+++ b/IPython/core/tests/test_display.py
@@ -197,12 +197,22 @@ def test_displayobject_repr():
 
 @mock.patch('warnings.warn')
 def test_encourage_iframe_over_html(m_warn):
+    display.HTML()
+    m_warn.assert_not_called()
+
     display.HTML('<br />')
     m_warn.assert_not_called()
 
+    display.HTML('<html><p>Lots of content here</p><iframe src="http://a.com"></iframe>')
+    m_warn.assert_not_called()
+
     display.HTML('<iframe src="http://a.com"></iframe>')
     m_warn.assert_called_with('Consider using IPython.display.IFrame instead')
 
+    m_warn.reset_mock()
+    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))