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
4 changes: 2 additions & 2 deletions branca/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ def _repr_html_(self, **kwargs) -> str:
).format(html=html, width=self.width, ratio=self.ratio)
else:
iframe = (
'<iframe srcdoc="{html}" width="{width}" height="{height}"'
'<iframe srcdoc="{html}" width="{width}" height="{height}" '
'style="border:none !important;" '
'"allowfullscreen" "webkitallowfullscreen" "mozallowfullscreen">'
"allowfullscreen webkitallowfullscreen mozallowfullscreen>"
"</iframe>"
).format(html=html, width=self.width, height=self.height)
return iframe
Expand Down
44 changes: 44 additions & 0 deletions tests/test_element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Tests for branca.element
------------------------
"""

from html.parser import HTMLParser

import branca.element as elem


class _IframeAttrs(HTMLParser):
"""Collect the attributes of every <iframe> start tag."""

def __init__(self):
super().__init__()
self.iframes = []

def handle_starttag(self, tag, attrs):
if tag == "iframe":
self.iframes.append(dict(attrs))


def _iframe_attrs(html):
parser = _IframeAttrs()
parser.feed(html)
assert len(parser.iframes) == 1
return parser.iframes[0]


def test_figure_repr_html_fullscreen_attrs_without_height():
attrs = _iframe_attrs(elem.Figure()._repr_html_())
for name in ("allowfullscreen", "webkitallowfullscreen", "mozallowfullscreen"):
assert name in attrs


def test_figure_repr_html_fullscreen_attrs_with_height():
# The height branch used to quote the boolean attributes, producing
# <iframe ... "allowfullscreen" ...>, so the attribute names came out
# wrapped in literal quotes and the browser ignored them.
attrs = _iframe_attrs(elem.Figure(height="400px")._repr_html_())
for name in ("allowfullscreen", "webkitallowfullscreen", "mozallowfullscreen"):
assert name in attrs, f"{name!r} missing; got {sorted(attrs)}"
assert attrs["height"] == "400px"
assert attrs["width"] == "100%"