|
7 | 7 | """ |
8 | 8 |
|
9 | 9 | import base64 |
| 10 | +from html import escape |
10 | 11 | import json |
11 | 12 | import warnings |
12 | 13 | from collections import OrderedDict |
13 | | -import urllib.parse |
14 | 14 | from urllib.request import urlopen |
15 | 15 | from uuid import uuid4 |
16 | 16 |
|
@@ -320,43 +320,26 @@ def render(self, **kwargs): |
320 | 320 | return self._template.render(this=self, kwargs=kwargs) |
321 | 321 |
|
322 | 322 | def _repr_html_(self, **kwargs): |
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)) |
332 | | - onload = ( |
333 | | - 'this.contentDocument.open();' |
334 | | - 'this.contentDocument.write(' |
335 | | - ' decodeURIComponent(this.getAttribute(\'data-html\'))' |
336 | | - ');' |
337 | | - 'this.contentDocument.close();' |
338 | | - ) |
339 | | - |
| 323 | + """Displays the Figure in a Jupyter notebook.""" |
| 324 | + html = escape(self.render(**kwargs)) |
340 | 325 | if self.height is None: |
341 | 326 | iframe = ( |
342 | 327 | '<div style="width:{width};">' |
343 | 328 | '<div style="position:relative;width:100%;height:0;padding-bottom:{ratio};">' # noqa |
344 | 329 | '<span style="color:#565656">Make this Notebook Trusted to load map: File -> Trust Notebook</span>' # noqa |
345 | | - '<iframe src="about:blank" style="position:absolute;width:100%;height:100%;left:0;top:0;' # noqa |
| 330 | + '<iframe srcdoc="{html}" style="position:absolute;width:100%;height:100%;left:0;top:0;' # noqa |
346 | 331 | 'border:none !important;" ' |
347 | | - 'data-html={html} onload="{onload}" ' |
348 | 332 | 'allowfullscreen webkitallowfullscreen mozallowfullscreen>' |
349 | 333 | '</iframe>' |
350 | 334 | '</div></div>' |
351 | | - ).format(html=html, onload=onload, width=self.width, ratio=self.ratio) |
| 335 | + ).format(html=html, width=self.width, ratio=self.ratio) |
352 | 336 | else: |
353 | 337 | iframe = ( |
354 | | - '<iframe src="about:blank" width="{width}" height="{height}"' |
| 338 | + '<iframe srcdoc="{html}" width="{width}" height="{height}"' |
355 | 339 | 'style="border:none !important;" ' |
356 | | - 'data-html={html} onload="{onload}" ' |
357 | 340 | '"allowfullscreen" "webkitallowfullscreen" "mozallowfullscreen">' |
358 | 341 | '</iframe>' |
359 | | - ).format(html=html, onload=onload, width=self.width, height=self.height) |
| 342 | + ).format(html=html, width=self.width, height=self.height) |
360 | 343 | return iframe |
361 | 344 |
|
362 | 345 | def add_subplot(self, x, y, n, margin=0.05): |
|
0 commit comments