diff --git a/src/nbsphinx.py b/src/nbsphinx.py index d47f37ee..5c02b118 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -2328,23 +2328,55 @@ def depart_admonition_text(self, node): def depart_gallery_html(self, node): - self.body.append('
\n') + # keep temporary support for old sphinx_gallery versions < 0.11.0 by + # discovering the version at runtime + import importlib.metadata + try: + # avoid hard dependencies to non-standard library packages for this + # temporary fix + from packaging.version import parse + sg_version = importlib.metadata.version('sphinx_gallery') + have_legacy_sphinx_gallery = parse(sg_version) < parse('0.11.0') + except (ModuleNotFoundError, importlib.metadata.PackageNotFoundError): + # keep default behaviour in case errors arise + have_legacy_sphinx_gallery = False + if not have_legacy_sphinx_gallery: + self.body.append('
\n') for title, uri, filename, tooltip in node['entries']: if tooltip: tooltip = ' tooltip="{}"'.format(html.escape(tooltip)) - self.body.append("""\ + self.body.append(("""\ +
+
+ thumbnail +

+ + + {title} + + +

+
+
""" if have_legacy_sphinx_gallery else """\
-

{title}

+

+ + {title} + +

{title}
-""".format( +""").format( uri=html.escape(uri), title=html.escape(title), tooltip=tooltip, filename=html.escape(filename), )) - self.body.append('
\n') + if have_legacy_sphinx_gallery: + self.body.append('
\n') + else: + self.body.append('
\n') def do_nothing(self, node):