Skip to content

Commit

Permalink
Remove custom SVG processing in the HTML builder (#12425)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <[email protected]>
  • Loading branch information
tuncbkose and AA-Turner committed Jul 10, 2024
1 parent bf2e230 commit bdd9140
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Bugs fixed
* #11961: Omit anchor references from document title entries in the search index,
removing duplication of search results.
Patch by James Addison.
* #12425: Use Docutils' SVG processing in the HTML builder
and remove Sphinx's custom logic.
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

0 comments on commit bdd9140

Please sign in to comment.