{ "cells": [ { "cell_type": "markdown", "id": "5b6f49a1", "metadata": {}, "source": [ "This workaround is needed to export the notebook to HTML for viewing online. It comes from a comment here:\n", "https://github.com/jupyter/nbconvert/issues/1894#issuecomment-1334355109" ] }, { "cell_type": "code", "execution_count": 1, "id": "9fb1eb57", "metadata": {}, "outputs": [], "source": [ "from nbconvert.exporters import HTMLExporter\n", "from nbconvert.exporters.templateexporter import default_filters\n", "\n", "def convert_to_html(notebook_file, html_file):\n", "\n", " def custom_clean_html(element):\n", " return element.decode() if isinstance(element, bytes) else str(element)\n", "\n", " default_filters[\"clean_html\"] = custom_clean_html\n", "\n", " exportHtml = HTMLExporter()\n", " output, _ = exportHtml.from_filename(notebook_file)\n", " open(html_file, mode=\"w\", encoding=\"utf-8\").write(output)\n", " \n", "convert_to_html(\"PGFPlots.ipynb\", \"PGFPlots.html\")" ] }, { "cell_type": "code", "execution_count": null, "id": "9cb990d4", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }