From 666f2ad1405f9d915df699731a5c59c1736aa266 Mon Sep 17 00:00:00 2001 From: jbannister Date: Wed, 31 Jan 2024 17:42:37 +0000 Subject: [PATCH] #165: Fix the word "None" appearing at the top of each nbconvert report when nbconvert>7.0.0. --- CHANGELOG.md | 4 + .../nbtemplates/notebooker_html_output.tpl | 6 +- .../notebooker_html_output_deprecated.tpl | 100 ++++++++++++++++++ notebooker/utils/conversion.py | 9 +- 4 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 notebooker/nbtemplates/notebooker_html_output_deprecated.tpl diff --git a/CHANGELOG.md b/CHANGELOG.md index ce98805..a29e945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +0.6.2 (2024-xx-xx) +------------------ +* Bugfix: None will stop appearing at the top of reports with nbconvert>7.0.0 + 0.6.1 (2023-09-13) ------------------ * Feature: GridFS document storage in Mongo-backed instances is now sharded if the mongo server supports it. diff --git a/notebooker/nbtemplates/notebooker_html_output.tpl b/notebooker/nbtemplates/notebooker_html_output.tpl index c22a5d0..7b39af4 100644 --- a/notebooker/nbtemplates/notebooker_html_output.tpl +++ b/notebooker/nbtemplates/notebooker_html_output.tpl @@ -1,4 +1,4 @@ -{% extends 'full.tpl'%} +{% extends 'index.html.j2' %} {% block html_head %} {{ super() }} + + + + +{%- endblock html_head -%} + +{% block stream %} + {%- if resources.global_content_filter.include_output_prompt -%} + {{ super() }} + {%- endif -%} +{%- endblock stream %} diff --git a/notebooker/utils/conversion.py b/notebooker/utils/conversion.py index 522d16e..989df4c 100644 --- a/notebooker/utils/conversion.py +++ b/notebooker/utils/conversion.py @@ -4,10 +4,12 @@ import git import jupytext +import nbconvert import nbformat import pkg_resources from nbconvert import HTMLExporter, PDFExporter, SlidesExporter from nbconvert.exporters.exporter import ResourcesDict +from packaging import version from traitlets.config import Config from notebooker.constants import TEMPLATE_DIR_SEPARATOR, kernel_spec @@ -32,9 +34,14 @@ def ipython_to_html( html, resources = exporter.from_notebook_node(nb) else: c.HTMLExporter.preprocessors = ["nbconvert.preprocessors.ExtractOutputPreprocessor"] + if version.parse(nbconvert.__version__) >= version.parse("7.0.0"): + template_filename = "notebooker_html_output.tpl" + else: + template_filename = "notebooker_html_output_deprecated.tpl" c.HTMLExporter.template_file = pkg_resources.resource_filename( - __name__, "../nbtemplates/notebooker_html_output.tpl" + __name__, f"../nbtemplates/{template_filename}" ) + c.HTMLExporter.exclude_input = hide_code c.HTMLExporter.exclude_input_prompt = hide_code c.HTMLExporter.exclude_output_prompt = hide_code