diff --git a/CHANGES.rst b/CHANGES.rst index 36b1e15b7ff..f01226e029a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ------- diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 1ebea36058a..41b59c3a2cc 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -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 diff --git a/tests/roots/test-root/images.txt b/tests/roots/test-root/images.txt index 5a096dc5b4d..a07429a4501 100644 --- a/tests/roots/test-root/images.txt +++ b/tests/roots/test-root/images.txt @@ -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 diff --git a/tests/test_builders/test_build_html_5_output.py b/tests/test_builders/test_build_html_5_output.py index 1beb3350de4..49ad633a46b 100644 --- a/tests/test_builders/test_build_html_5_output.py +++ b/tests/test_builders/test_build_html_5_output.py @@ -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']", ''),