Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for broken SVGs in nbconvert #575

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rsmtool/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from os.path import abspath, basename, dirname, join, splitext

from nbconvert.exporters import HTMLExporter
from nbconvert.exporters.templateexporter import default_filters
from traitlets.config import Config

from . import HAS_RSMEXTRA
Expand Down Expand Up @@ -327,6 +328,15 @@ def convert_ipynb_to_html(notebook_file, html_file):
"template_file": join(template_path,
'report.tpl')}})

# newer versions of nbconvert use a "clean_html" filter that
# break SVG rendering; so we override that filter here with
# a custom function that is essentially a noop. For more
# details, please refer to the following issue:
# https://github.com/EducationalTestingService/rsmtool/issues/571
def custom_clean_html(element):
return element.decode() if isinstance(element, bytes) else str(element)
default_filters["clean_html"] = custom_clean_html

exportHtml = HTMLExporter(config=report_config)
output, _ = exportHtml.from_filename(notebook_file)
open(html_file, mode='w', encoding='utf-8').write(output)
Expand Down