This workaround is needed to export the notebook to HTML for viewing online. It comes from a comment here: https://github.com/jupyter/nbconvert/issues/1894#issuecomment-1334355109
from nbconvert.exporters import HTMLExporter
from nbconvert.exporters.templateexporter import default_filters
def convert_to_html(notebook_file, html_file):
def custom_clean_html(element):
return element.decode() if isinstance(element, bytes) else str(element)
default_filters["clean_html"] = custom_clean_html
exportHtml = HTMLExporter()
output, _ = exportHtml.from_filename(notebook_file)
open(html_file, mode="w", encoding="utf-8").write(output)
convert_to_html("PGFPlots.ipynb", "PGFPlots.html")