Remove custom SVG processing in the HTML builder (#12425)

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
tuncbkose
2024-07-10 21:31:01 +03:00
committed by GitHub
parent bf2e2301e9
commit bdd9140842
4 changed files with 14 additions and 18 deletions

View File

@@ -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
-------

View File

@@ -696,24 +696,6 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
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

View File

@@ -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

View File

@@ -25,6 +25,9 @@ def tail_check(check):
('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']", ''),