| 699 | |
| 700 | |
| 701 | class HTML(TextDisplayObject): |
| 702 | |
| 703 | def __init__(self, data=None, url=None, filename=None, metadata=None): |
| 704 | def warn(): |
| 705 | if not data: |
| 706 | return False |
| 707 | |
| 708 | # |
| 709 | # Avoid calling lower() on the entire data, because it could be a |
| 710 | # long string and we're only interested in its beginning and end. |
| 711 | # |
| 712 | prefix = data[:10].lower() |
| 713 | suffix = data[-10:].lower() |
| 714 | return prefix.startswith("<iframe ") and suffix.endswith("</iframe>") |
| 715 | |
| 716 | if warn(): |
| 717 | warnings.warn("Consider using IPython.display.IFrame instead") |
| 718 | super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata) |
| 719 | |
| 720 | def _repr_html_(self): |
| 721 | return self._data_and_metadata() |
| 722 | |
| 723 | def __html__(self): |
| 724 | """ |
| 725 | This method exists to inform other HTML-using modules (e.g. Markupsafe, |
| 726 | htmltag, etc) that this object is HTML and does not need things like |
| 727 | special characters (<>&) escaped. |
| 728 | """ |
| 729 | return self._repr_html_() |
| 730 | |
| 731 | |
| 732 | class Markdown(TextDisplayObject): |