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

Differing behaviour in html5 output for an svg image with align specified #7112

Closed
jtanx opened this issue Feb 8, 2020 · 4 comments
Closed
Labels
Milestone

Comments

@jtanx
Copy link

jtanx commented Feb 8, 2020

Describe the bug

When an image is specified, similar to:

.. image:: the-image.svg
   :align: right
   :scale: 200px

This code:

self.body.append('<div align="%s" class="align-%s">' %
(node['align'], node['align']))
self.context.append('</div>\n')

Sticks the svg (for unknown reasons) in a div and somehow also makes it clickable (so adds an internal reference, even though no target has been specified).

The clickable reference is added by this code:

if self.config.html_scaled_image_link and self.html_scaled_image_link:
for node in doctree.traverse(nodes.image):
scale_keys = ('scale', 'width', 'height')
if not any((key in node) for key in scale_keys) or \
isinstance(node.parent, nodes.reference):
# docutils does unfortunately not preserve the
# ``target`` attribute on images, so we need to check
# the parent node here.
continue
uri = node['uri']
reference = nodes.reference('', '', internal=True)
if uri in self.images:
reference['refuri'] = posixpath.join(self.imgpath,
self.images[uri])
else:
reference['refuri'] = uri
node.replace_self(reference)
reference.append(node)

Apparently the clickable thing is a feature(?).

As it's specified in a div, this displayed in block style, which means content does not flow around it, but is displayed below the image. This is different to how alignment works on images.

e.g.:
image

image

To Reproduce

Try rendering an svg to html5

.. image:: the-image.svg
   :align: right
   :scale: 200px

Expected behavior

The svg should behave no different to any other image - it should be styled inline and there should be no reference generated when no target is specified, e.g.:

image
image

Your project
N/A

Screenshots
If applicable, add screenshots to help explain your problem.

Environment info

  • OS: Windows
  • Python version: ] 3.7.2
  • Sphinx version: 2.3.1
  • Sphinx extensions: sphinx.ext.mathjax
  • Extra tools: Firefox

Additional context
N/A

@tk0miya
Copy link
Member

tk0miya commented Feb 8, 2020

Thank you for reporting. I posted #7114 to fix this.

Note: Sphinx does not apply any hyperlinks to SVG images because it can have its own hyperlinks. This is difference between other images formats.

tk0miya added a commit to tk0miya/sphinx that referenced this issue Feb 8, 2020
@jtanx
Copy link
Author

jtanx commented Feb 8, 2020

Awesome, thanks! Would you know the reason why SVGs need to be wrapped in divs, instead of just being treated like other images?

@tk0miya
Copy link
Member

tk0miya commented Feb 9, 2020

Good point. Originally, HTML builder uses <object> tag to embed SVG tag. That is why we use <div> tag for alignment. Now, we use <img> tag for embedding. So <div> tag is no longer needed... It's time for refactoring!

tk0miya added a commit to tk0miya/sphinx that referenced this issue Feb 9, 2020
tk0miya added a commit that referenced this issue Feb 9, 2020
Fix #7112: html: SVG image is not layouted as float even if aligned
@tk0miya
Copy link
Member

tk0miya commented Feb 9, 2020

I updated my PR not to use <div> tag for alignment.
It will be released as 2.4.0 (maybe released in this weekend).
Thanks,

@tk0miya tk0miya closed this as completed Feb 9, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants