|
10 | 10 | import json |
11 | 11 | import warnings |
12 | 12 | from collections import OrderedDict |
| 13 | +import urllib.parse |
13 | 14 | from urllib.request import urlopen |
14 | 15 | from uuid import uuid4 |
15 | 16 |
|
@@ -319,15 +320,20 @@ def render(self, **kwargs): |
319 | 320 | return self._template.render(this=self, kwargs=kwargs) |
320 | 321 |
|
321 | 322 | def _repr_html_(self, **kwargs): |
322 | | - """Displays the Figure in a Jupyter notebook.""" |
323 | | - # Base64-encoded HTML is stored in a data-html attribute, which is used to populate |
324 | | - # the iframe. This approach does not encounter the 2MB limit in Chrome for storing |
325 | | - # the HTML in the src attribute with a data URI. The alternative of using a srcdoc |
326 | | - # attribute is not supported in Microsoft Internet Explorer and Edge. |
327 | | - html = base64.b64encode(self.render(**kwargs).encode('utf8')).decode('utf8') |
| 323 | + """Displays the Figure in a Jupyter notebook. |
| 324 | +
|
| 325 | + Percent-encoded HTML is stored in data-html attribute, which is used to populate |
| 326 | + the iframe. This approach does not encounter the 2MB limit in Chrome for storing |
| 327 | + the HTML in the src attribute with a data URI. The alternative of using a srcdoc |
| 328 | + attribute is not supported in Microsoft Internet Explorer and Edge. |
| 329 | +
|
| 330 | + """ |
| 331 | + html = urllib.parse.quote(self.render(**kwargs)) |
328 | 332 | onload = ( |
329 | 333 | 'this.contentDocument.open();' |
330 | | - 'this.contentDocument.write(atob(this.getAttribute(\'data-html\')));' |
| 334 | + 'this.contentDocument.write(' |
| 335 | + ' decodeURIComponent(this.getAttribute(\'data-html\'))' |
| 336 | + ');' |
331 | 337 | 'this.contentDocument.close();' |
332 | 338 | ) |
333 | 339 |
|
|
0 commit comments