diff --git a/.travis.yml b/.travis.yml index 2326c65..dc2d5a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,10 @@ env: - MOZ_HEADLESS=1 addons: + apt: + packages: + # Without libgtk (as of 2019-11-6), firefox cannot run properly + - libgtk-3-0 firefox: latest env: diff --git a/branca/element.py b/branca/element.py index 12f39d3..7f9ccb9 100644 --- a/branca/element.py +++ b/branca/element.py @@ -322,30 +322,36 @@ def render(self, **kwargs): return self._template.render(this=self, kwargs=kwargs) def _repr_html_(self, **kwargs): - """Displays the Figure in a Jupyter notebook. - - """ - html = self.render(**kwargs) - html = "data:text/html;charset=utf-8;base64," + base64.b64encode(html.encode('utf8')).decode('utf8') # noqa + """Displays the Figure in a Jupyter notebook.""" + # Base64-encoded HTML is stored in a data-html attribute, which is used to populate + # the iframe. This approach does not encounter the 2MB limit in Chrome for storing + # the HTML in the src attribute with a data URI. The alternative of using a srcdoc + # attribute is not supported in Microsoft Internet Explorer and Edge. + html = base64.b64encode(self.render(**kwargs).encode('utf8')).decode('utf8') + onload = ( + 'this.contentDocument.open();' + 'this.contentDocument.write(atob(this.getAttribute(\'data-html\')));' + 'this.contentDocument.close();' + ) if self.height is None: iframe = ( '