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

HTML: remove early return in SVG processing #12425

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Bugs fixed
* #11961: Omit anchor references from document title entries in the search index,
removing duplication of search results.
Patch by James Addison.
* #12425: Remove early return in SVG processing for HTML.
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
Patch by Tunç Başar Köse.

Testing
-------
Expand Down
18 changes: 0 additions & 18 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,24 +696,6 @@ def visit_image(self, node: Element) -> None:
if 'height' not in node:
node['height'] = str(size[1])

uri = node['uri']
if uri.lower().endswith(('svg', 'svgz')):
atts = {'src': uri}
if 'width' in node:
atts['width'] = node['width']
if 'height' in node:
atts['height'] = node['height']
if 'scale' in node:
if 'width' in atts:
atts['width'] = multiply_length(atts['width'], node['scale'])
if 'height' in atts:
atts['height'] = multiply_length(atts['height'], node['scale'])
atts['alt'] = node.get('alt', uri)
if 'align' in node:
atts['class'] = 'align-%s' % node['align']
self.body.append(self.emptytag(node, 'img', '', **atts))
return

super().visit_image(node)

# overwritten
Expand Down
8 changes: 8 additions & 0 deletions tests/roots/test-root/images.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ Sphinx image handling
.. an SVG image (for HTML at least)
.. image:: svgimg.*

.. an SVG image using width with units
.. image:: svgimg.*
:width: 2cm

.. an SVG image using height with units
.. image:: svgimg.*
:height: 2cm

.. an image with more than 1 dot in its file name
.. image:: img.foo.png
3 changes: 3 additions & 0 deletions tests/test_builders/test_build_html_5_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def checker(nodes):
('images.html', ".//img[@src='_images/simg.png']", ''),
('images.html', ".//img[@src='_images/svgimg.svg']", ''),
('images.html', ".//a[@href='_sources/images.txt']", ''),
# Check svg options
('images.html', ".//img[@src='_images/svgimg.svg'][@style='width: 2cm;']", ''),
('images.html', ".//img[@src='_images/svgimg.svg'][@style='height: 2cm;']", ''),
('subdir/images.html', ".//img[@src='../_images/img1.png']", ''),
('subdir/images.html', ".//img[@src='../_images/rimg.png']", ''),
Expand Down
Loading