From 4a4625e40c63c196ca419154d6947347abad968e Mon Sep 17 00:00:00 2001
From: milde
Date: Mon, 23 Feb 2015 21:40:49 +0000
Subject: [PATCH] Wrap SVG images in tags not .
Addresses bug [ 247 ], but rendering problems remain
(see test output test/functional/expected/standalone_rst_xhtml11.xhtml),
so we might need a config setting.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7799 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
---
docutils/HISTORY.txt | 6 ++++-
docutils/docutils/writers/html4css1/__init__.py | 21 +++++++++--------
docutils/docutils/writers/xhtml11/__init__.py | 7 +++++-
.../expected/standalone_rst_html4css1.html | 3 +++
.../expected/standalone_rst_xhtml11.xhtml | 27 +++++++++-------------
docutils/test/functional/input/data/svg_images.txt | 6 +++++
6 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt
index 879cd6455..226566827 100644
--- a/docutils/HISTORY.txt
+++ b/docutils/HISTORY.txt
@@ -42,9 +42,13 @@ Changes Since 0.12
* docutils/writers/xhtml11/
- New HTML writer generating `XHTML1.1`_ styled with CSS2.
-
Moved to the docutils core from sandbox/html4strict.
+ - Wrap SVG images in tags not .
+ Addresses bug [ 247 ], but rendering problems remain
+ (see test/functional/expected/standalone_rst_xhtml11.xhtml),
+ so we might need a config setting.
+
.. _XHTML1.1: http://www.w3.org/TR/xhtml11/
* docutils/writers/latex2e/__init__.py
diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py
index 6cc10cab4..974480cab 100644
--- a/docutils/docutils/writers/html4css1/__init__.py
+++ b/docutils/docutils/writers/html4css1/__init__.py
@@ -903,7 +903,7 @@ class HTMLTranslator(nodes.NodeVisitor):
and len(node.astext()) > self.settings.field_name_limit):
atts['colspan'] = 2
self.context.append('\n'
- + self.starttag(node.parent, 'tr', '',
+ + self.starttag(node.parent, 'tr', '',
CLASS='field')
+ ' ')
else:
@@ -1013,16 +1013,19 @@ class HTMLTranslator(nodes.NodeVisitor):
self.header.extend(header)
del self.body[start:]
+ # Image types to place in an element
+ # SVG not supported by IE up to version 8
+ # (html4css1 strives for IE6 compatibility)
+ object_image_types = {'.svg': 'image/svg+xml',
+ '.swf': 'application/x-shockwave-flash'}
+
def visit_image(self, node):
atts = {}
uri = node['uri']
- # place SVG and SWF images in an element
- types = {'.svg': 'image/svg+xml',
- '.swf': 'application/x-shockwave-flash'}
ext = os.path.splitext(uri)[1].lower()
- if ext in ('.svg', '.swf'):
+ if ext in self.object_image_types: # ('.svg', '.swf'):
atts['data'] = uri
- atts['type'] = types[ext]
+ atts['type'] = self.object_image_types[ext]
else:
atts['src'] = uri
atts['alt'] = node.get('alt', uri)
@@ -1074,8 +1077,7 @@ class HTMLTranslator(nodes.NodeVisitor):
suffix = '\n'
if 'align' in node:
atts['class'] = 'align-%s' % node['align']
- self.context.append('')
- if ext in ('.svg', '.swf'): # place in an object element,
+ if ext in self.object_image_types: # ('.svg', '.swf')
# do NOT use an empty tag: incorrect rendering in browsers
self.body.append(self.starttag(node, 'object', suffix, **atts) +
node.get('alt', uri) + ' ' + suffix)
@@ -1083,7 +1085,8 @@ class HTMLTranslator(nodes.NodeVisitor):
self.body.append(self.emptytag(node, 'img', suffix, **atts))
def depart_image(self, node):
- self.body.append(self.context.pop())
+ # self.body.append(self.context.pop())
+ pass
def visit_inline(self, node):
self.body.append(self.starttag(node, 'span', ''))
diff --git a/docutils/docutils/writers/xhtml11/__init__.py b/docutils/docutils/writers/xhtml11/__init__.py
index 259e726ac..8b2f7d48a 100644
--- a/docutils/docutils/writers/xhtml11/__init__.py
+++ b/docutils/docutils/writers/xhtml11/__init__.py
@@ -41,7 +41,7 @@ class Writer(html4css1.Writer):
"""Formats this writer supports."""
default_stylesheets = ['html4css1.css', 'xhtml11.css']
- default_stylesheet_dirs = ['.',
+ default_stylesheet_dirs = ['.',
os.path.abspath(os.path.dirname(__file__)),
os.path.abspath(os.path.join(
os.path.dirname(os.path.dirname(__file__)), 'html4css1'))
@@ -313,6 +313,11 @@ class HTMLTranslator(html4css1.HTMLTranslator):
# def depart_generated(self, node):
# pass
+ # Image types to place in an element
+ # SVG as supported since IE version 9
+ # (but rendering problems remain (see standalonge_rst2xhtml11.xhtml test output)
+ object_image_types = {'.swf': 'application/x-shockwave-flash'}
+
# Do not mark the first child with 'class="first"'
def visit_list_item(self, node):
self.body.append(self.starttag(node, 'li', ''))
diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html
index 5c4ce6329..3b2c2b4ab 100644
--- a/docutils/test/functional/expected/standalone_rst_html4css1.html
+++ b/docutils/test/functional/expected/standalone_rst_html4css1.html
@@ -1119,6 +1119,9 @@ right aligned (this SVG image keeps the aspect ratio):
reStructuredText, the markup syntax
SVG image in a figure.
+
+../../../docs/user/rst/images/biohazard-bitmap.svg
+An SVG image with embedded bitmap. Should be 3 em wide, right aligned.
diff --git a/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml b/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml
index 88d1984e7..90064e0f6 100644
--- a/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml
+++ b/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml
@@ -1077,39 +1077,34 @@ crunchy, now would it?
-
-../../../docs/user/rst/images/biohazard.svg
+
Scalable vector graphics (SVG) images are not supported by all backends.
Rendering depends partially on the backend, especially if the size is
not explicitely given.
-
-../../../docs/user/rst/images/title-scaling.svg
+
A scaling image occupying 50% of the line width (scales with the
browser window).
Whether an SVG image is scaled or clipped/padded cannot be set in the
containing HTML. It depends on the viewport declaration inside its
root <svg> element.
-
An inline SVG image inline-svg scaled to a height of 0.8 em.
-
-../../../docs/user/rst/images/title-scaling.svg
+
An inline SVG image scaled to a height of 0.8 em.
+
A scaling image occupying 50% of the line width and 1.2 em high,
right aligned (this SVG image keeps the aspect ratio):
-
-../../../docs/user/rst/images/biohazard-scaling.svg
+
A scaling image 1 em high, left aligned.
A scaling image 5 mm x 5 mm, centered, with hyperlink reference:
-
../../../docs/user/rst/images/biohazard-scaling.svg
-
-../../../docs/user/rst/images/biohazard.svg
+
+
A fixed-size image in a 4 cm x 2 em box.
-
-../../../docs/user/rst/images/title.svg
+
A fixed-size image in a box 50% the line width and 15 pixle high.
+
+
An SVG image with embedded bitmap. Should be 3 em wide, right aligned.
diff --git a/docutils/test/functional/input/data/svg_images.txt b/docutils/test/functional/input/data/svg_images.txt
index 300575232..856dd1ff2 100644
--- a/docutils/test/functional/input/data/svg_images.txt
+++ b/docutils/test/functional/input/data/svg_images.txt
@@ -67,3 +67,9 @@ A fixed-size image in a box 50% the line width and 15 pixle high.
:height: 28 px
SVG image in a figure.
+
+.. image:: ../../../docs/user/rst/images/biohazard-bitmap.svg
+ :width: 3em
+ :align: right
+
+An SVG image with embedded bitmap. Should be 3 em wide, right aligned.
--
2.11.4.GIT