Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conditional to support sphinx gallery pre and post v0.11 #2

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2328,23 +2328,55 @@ def depart_admonition_text(self, node):


def depart_gallery_html(self, node):
self.body.append('<div class="sphx-glr-thumbnails">\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('<div class="sphx-glr-thumbnails">\n')
for title, uri, filename, tooltip in node['entries']:
if tooltip:
tooltip = ' tooltip="{}"'.format(html.escape(tooltip))
self.body.append("""\
self.body.append(("""\
<div class="sphx-glr-thumbcontainer"{tooltip}>
<div class="figure align-center">
<img alt="thumbnail" src="{filename}" />
<p class="caption">
<span class="caption-text">
<a class="reference internal" href="{uri}">
<span class="std std-ref">{title}</span>
</a>
</span>
</p>
</div>
</div>""" if have_legacy_sphinx_gallery else """\
<div class="sphx-glr-thumbcontainer"{tooltip}>
<img alt="" src="{filename}" />
<p><a class="reference internal" href="{uri}"><span class="std std-ref">{title}</span></a></p>
<p>
<a class="reference internal" href="{uri}">
<span class="std std-ref">{title}</span>
</a>
</p>
<div class="sphx-glr-thumbnail-title">{title}</div>
</div>
""".format(
""").format(
uri=html.escape(uri),
title=html.escape(title),
tooltip=tooltip,
filename=html.escape(filename),
))
self.body.append('</div>\n')
if have_legacy_sphinx_gallery:
self.body.append('<div class="sphx-glr-clear"></div>\n')
else:
self.body.append('</div>\n')


def do_nothing(self, node):
Expand Down