Skip to content

Commit

Permalink
Add a toggle to skip the svg encoding of images (#2106)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
gwincr11 and pre-commit-ci[bot] committed Feb 7, 2024
1 parent 392f1e9 commit 87db94d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Enhancements made

- Support configureable width and height of reveal presentations [#2104](https://github.com/jupyter/nbconvert/pull/2104) ([@franzhaas](https://github.com/franzhaas))
- Support configurable width and height of reveal presentations [#2104](https://github.com/jupyter/nbconvert/pull/2104) ([@franzhaas](https://github.com/franzhaas))

### Maintenance and upkeep improvements

Expand Down Expand Up @@ -440,7 +440,7 @@

### Maintenance and upkeep improvements

- Clean up license [#1949](https://github.com/jupyter/nbconvert/pull/1949) ([@dcsaba89](https://github.com/dcsaba89))
- Clean up license [#1949](https://github.com/jupyter/nbconvert/pull/1949) ([@dcsaba89](https://github.com/dcsaba89))
- Add more linting [#1943](https://github.com/jupyter/nbconvert/pull/1943) ([@blink1073](https://github.com/blink1073))

### Contributors to this release
Expand Down Expand Up @@ -564,7 +564,7 @@

### Bugs fixed

- clean_html: allow SVG tags and SVG attributes [#1890](https://github.com/jupyter/nbconvert/pull/1890) ([@akx](https://github.com/akx))
- clean_html: allow SVG tags and SVG attributes [#1890](https://github.com/jupyter/nbconvert/pull/1890) ([@akx](https://github.com/akx))

### Maintenance and upkeep improvements

Expand Down Expand Up @@ -1502,6 +1502,7 @@ raw template
{%- endblock in_prompt -%}
"""


exporter_attr = AttrExporter()
output_attr, _ = exporter_attr.from_notebook_node(nb)
assert "raw template" in output_attr
Expand Down
6 changes: 6 additions & 0 deletions nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def _template_name_default(self):
),
).tag(config=True)

skip_svg_encoding = Bool(
False,
help=("Whether the svg to image data attribute encoding should occur"),
).tag(config=True)

embed_images = Bool(
False, help="Whether or not to embed images as base64 in markdown cells."
).tag(config=True)
Expand Down Expand Up @@ -352,4 +357,5 @@ def resources_include_url(name):
resources["html_manager_semver_range"] = self.html_manager_semver_range
resources["should_sanitize_html"] = self.sanitize_html
resources["language_code"] = self.language_code
resources["should_not_encode_svg"] = self.skip_svg_encoding
return resources
6 changes: 5 additions & 1 deletion share/templates/classic/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ unknown type {{ cell.type }}
{%- if output.svg_filename %}
<img src="{{ output.svg_filename | posix_path | escape_html }}">
{%- else %}
<img src="data:image/svg+xml;base64,{{ output.data['image/svg+xml'] | text_base64 | escape_html }}">
{%- if resources.should_not_encode_svg %}
{{ output.data['image/svg+xml'].encode("utf-8") | clean_html }}
{%- else %}
<img src="data:image/svg+xml;base64,{{ output.data['image/svg+xml'] | text_base64 | escape_html }}">
{%- endif %}
{%- endif %}
</div>
{%- endblock data_svg %}
Expand Down
6 changes: 5 additions & 1 deletion share/templates/lab/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ unknown type {{ cell.type }}
{%- if output.svg_filename %}
<img src="{{ output.svg_filename | posix_path | escape_html }}">
{%- else %}
<img src="data:image/svg+xml;base64,{{ output.data['image/svg+xml'] | text_base64 | escape_html }}">
{%- if resources.should_not_encode_svg %}
{{ output.data['image/svg+xml'].encode("utf-8") | clean_html }}
{%- else %}
<img src="data:image/svg+xml;base64,{{ output.data['image/svg+xml'] | text_base64 | escape_html }}">
{%- endif %}
{%- endif %}
</div>
{%- endblock data_svg %}
Expand Down

0 comments on commit 87db94d

Please sign in to comment.