diff --git a/CHANGES b/CHANGES index b91848413..510738b4a 100644 --- a/CHANGES +++ b/CHANGES @@ -61,6 +61,9 @@ New features added - Scaled images now get a link to the unscaled version. + - SVG images are now supported in HTML (via ```` and + ```` tags). + - Added a ``toctree`` callable to the templates, and the ability to include external links in toctrees. The 'collapse' keyword argument indicates whether or not to only display subitems of diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 44a7c8792..0859bae66 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -283,6 +283,26 @@ class HTMLTranslator(BaseTranslator): node['uri'] = posixpath.join(self.builder.imgpath, self.builder.images[olduri]) + if node['uri'].lower().endswith('svg') or \ + node['uri'].lower().endswith('svgz'): + atts = {'data': node['uri'], 'type': 'image/svg+xml'} + if 'width' in node: + atts['width'] = node['width'] + if 'height' in node: + atts['height'] = node['height'] + if 'align' in node: + self.body.append('' % + (node['align'], node['align'])) + self.context.append('\n') + else: + self.context.append('') + embatts = atts.copy() + embatts['src'] = embatts.pop('data') + self.body.append(self.starttag(node, 'object', '', **atts)) + self.body.append(self.emptytag(node, 'embed', '', **embatts)) + self.body.append('\n') + return + if node.has_key('scale'): if Image and not (node.has_key('width') and node.has_key('height')): diff --git a/tests/root/images.txt b/tests/root/images.txt index be868dfea..bd64d573a 100644 --- a/tests/root/images.txt +++ b/tests/root/images.txt @@ -23,3 +23,6 @@ Sphinx image handling .. an image with subdir and unspecified extension .. image:: subdir/simg.* + +.. an SVG image (for HTML at least) +.. image:: svgimg.* diff --git a/tests/root/svgimg.pdf b/tests/root/svgimg.pdf new file mode 100644 index 000000000..cacbd855d Binary files /dev/null and b/tests/root/svgimg.pdf differ diff --git a/tests/root/svgimg.svg b/tests/root/svgimg.svg new file mode 100644 index 000000000..10e035b6d --- /dev/null +++ b/tests/root/svgimg.svg @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + Part of the Flat Icon Collection (Thu Aug 26 14:31:40 2004) + + + + + + + + + + + + + + Danny Allen + + + + + Danny Allen + + + + image/svg+xml + + + + + en + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/tests/test_build.py b/tests/test_build.py index a8934b827..326a4bd67 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -59,6 +59,8 @@ HTML_XPATH = { ".//img[@src='_images/img.png']": '', ".//img[@src='_images/img1.png']": '', ".//img[@src='_images/simg.png']": '', + ".//object[@data='_images/svgimg.svg']": '', + ".//embed[@src='_images/svgimg.svg']": '', }, 'subdir/images.html': { ".//img[@src='../_images/img1.png']": '', diff --git a/tests/test_env.py b/tests/test_env.py index 32d87ebf3..5d27bcfd0 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -56,21 +56,21 @@ def test_images(): htmlbuilder.post_process_images(tree) assert "no matching candidate for image URI u'foo.*'" in \ app._warning.content[-1] - assert set(htmlbuilder.images.keys()) == set(['subdir/img.png', 'img.png', - 'subdir/simg.png']) - assert set(htmlbuilder.images.values()) == set(['img.png', 'img1.png', - 'simg.png']) + assert set(htmlbuilder.images.keys()) == \ + set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg']) + assert set(htmlbuilder.images.values()) == \ + set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg']) app._warning.reset() latexbuilder = LaTeXBuilder(app, env) latexbuilder.post_process_images(tree) assert "no matching candidate for image URI u'foo.*'" in \ app._warning.content[-1] - assert set(latexbuilder.images.keys()) == set(['subdir/img.png', - 'subdir/simg.png', - 'img.png', 'img.pdf']) - assert set(latexbuilder.images.values()) == set(['img.pdf', 'img.png', - 'img1.png', 'simg.png']) + assert set(latexbuilder.images.keys()) == \ + set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', + 'svgimg.pdf']) + assert set(latexbuilder.images.values()) == \ + set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf']) def test_second_update(): # delete, add and "edit" (change saved mtime) some files and update again