diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index d63699c0d..bbb7c57f0 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -151,6 +151,10 @@ class HTMLExporter(TemplateExporter): "*", help="Semver range for Jupyter widgets HTML manager" ).tag(config=True) + postprocess_html = Bool(False, help="Add interactive elements and missing alt text.").tag( + config=True + ) + @default("file_extension") def _file_extension_default(self): return ".html" @@ -265,7 +269,15 @@ def from_notebook_node( # type:ignore[explicit-override, override] self.register_filter("highlight_code", highlight_code) self.register_filter("filter_data_type", filter_data_type) + html, resources = super().from_notebook_node(nb, resources, **kw) + if self.postprocess_html: + html, resources = self.postprocess(html, resources) + + return html, resources + + def postprocess(self, html, resources): + """Use beautifulsoup to make notebooks interactive and replace missing alt text""" soup = BeautifulSoup(html, features="html.parser") # Add image's alternative text missing_alt = 0 diff --git a/share/templates/lab/base.html.j2 b/share/templates/lab/base.html.j2 index cebe84104..d776212af 100644 --- a/share/templates/lab/base.html.j2 +++ b/share/templates/lab/base.html.j2 @@ -2,6 +2,12 @@ {% from 'celltags.j2' import celltags %} {% from 'cell_id_anchor.j2' import cell_id_anchor %} +{%- block body_loop -%} +