-
Notifications
You must be signed in to change notification settings - Fork 200
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
ENH: Add support for capturing svg, png, and jpeg and _repr_mimebundle_ #1138
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ absl-py | |
graphviz | ||
packaging | ||
jupyterlite-sphinx | ||
sphinxcontrib-svg2pdfconverter[CairoSVG] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -353,7 +353,8 @@ def save_figures(block, block_vars, gallery_conf): | |||||
return all_rst | ||||||
|
||||||
|
||||||
def figure_rst(figure_list, sources_dir, fig_titles='', srcsetpaths=None): | ||||||
def figure_rst(figure_list, sources_dir, fig_titles='', srcsetpaths=None, | ||||||
svg_image=False): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well add these because it's easy
Suggested change
|
||||||
"""Generate reST for a list of image filenames. | ||||||
|
||||||
Depending on whether we have one or more figures, we use a | ||||||
|
@@ -376,6 +377,10 @@ def figure_rst(figure_list, sources_dir, fig_titles='', srcsetpaths=None): | |||||
{0: /images/image.png, 2.0: /images/image_2_00x.png} | ||||||
where the key is the multiplication factor and the contents | ||||||
the path to the image created above. | ||||||
svg_image : bool | ||||||
Whether to use the standard ``sg_image`` wrapper (False, default) or a | ||||||
special version of the ``sg_image`` for SVG images to enable later | ||||||
conversions. | ||||||
|
||||||
Returns | ||||||
------- | ||||||
|
@@ -416,8 +421,10 @@ def figure_rst(figure_list, sources_dir, fig_titles='', srcsetpaths=None): | |||||
figure_name = figure_paths[0] | ||||||
hinames = srcsetpaths[0] | ||||||
srcset = _get_srcset_st(sources_dir, hinames) | ||||||
images_rst = SG_IMAGE % (figure_name, alt, srcset) | ||||||
|
||||||
if svg_image: | ||||||
images_rst = SVG_IMAGE % (figure_name, alt) | ||||||
else: | ||||||
images_rst = SG_IMAGE % (figure_name, alt, srcset) | ||||||
elif len(figure_paths) > 1: | ||||||
images_rst = HLIST_HEADER | ||||||
for nn, figure_name in enumerate(figure_paths): | ||||||
|
@@ -492,6 +499,13 @@ def _single_line_sanitize(s): | |||||
:class: sphx-glr-single-img | ||||||
""" | ||||||
|
||||||
# Used for SVGs | ||||||
SVG_IMAGE = """ | ||||||
.. image:: /%s | ||||||
:alt: %s | ||||||
:class: sphx-glr-single-img | ||||||
""" | ||||||
Comment on lines
+502
to
+507
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DRY / this appears to be a duplicate of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except for that initial space. Since it said it was kept for backwards compatibility I wasn't sure if the space should still be there to not break anything. But maybe the space is always an issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think the space is a bug and can safely be removed |
||||||
|
||||||
# keep around for back-compat: | ||||||
SINGLE_IMAGE = """ | ||||||
.. image:: /%s | ||||||
oscargus marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
hasattr
is unnecessary, thetry
below would catch theAttributeError
below anyway. Might as well remove itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are correct. I think the idea was to try to catch a slightly more narrow class of exceptions, where
AttributeError
wasn't one of them, but never managed to figure out what a suitable subset might be.