Skip to content

Commit

Permalink
Supports isolated iframe (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihiue authored Jun 22, 2021
1 parent aa4c46e commit 4607ed2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'convert_pandoc': filters.convert_pandoc,
'json_dumps': json.dumps,
'strip_trailing_newline': filters.strip_trailing_newline,
'text_base64': filters.text_base64,
}


Expand Down
8 changes: 8 additions & 0 deletions nbconvert/filters/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
import textwrap
import warnings
import base64

from urllib.parse import quote

Expand All @@ -35,6 +36,7 @@
'ascii_only',
'prevent_list_blocks',
'strip_trailing_newline',
'text_base64',
]


Expand Down Expand Up @@ -249,3 +251,9 @@ def strip_trailing_newline(text):
if text.endswith('\n'):
text = text[:-1]
return text

def text_base64(text):
"""
Encode base64 text
"""
return base64.b64encode(text.encode()).decode()
10 changes: 10 additions & 0 deletions share/jupyter/nbconvert/templates/classic/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ unknown type {{ cell.type }}

{% block data_html scoped -%}
<div class="output_html rendered_html output_subarea {{ extra_class }}">
{%- if output.get('metadata', {}).get('text/html', {}).get('isolated') -%}
<iframe
class="isolated-iframe"
style="height:520px; width:100%; margin:0; padding: 0"
frameborder="0"
scrolling="auto"
src="data:text/html;base64,{{output.data['text/html'] | text_base64}}">
</iframe>
{%- else -%}
{{ output.data['text/html'] }}
{%- endif -%}
</div>
{%- endblock data_html %}

Expand Down

0 comments on commit 4607ed2

Please sign in to comment.