|
From: <mi...@us...> - 2015-02-23 21:40:50
|
Revision: 7799
http://sourceforge.net/p/docutils/code/7799
Author: milde
Date: 2015-02-23 21:40:49 +0000 (Mon, 23 Feb 2015)
Log Message:
-----------
Wrap SVG images in <img> tags not <object>.
Addresses bug [ 247 ], but rendering problems remain
(see test output test/functional/expected/standalone_rst_xhtml11.xhtml),
so we might need a config setting.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/html4css1/__init__.py
trunk/docutils/docutils/writers/xhtml11/__init__.py
trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
trunk/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml
trunk/docutils/test/functional/input/data/svg_images.txt
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2015-02-21 16:59:18 UTC (rev 7798)
+++ trunk/docutils/HISTORY.txt 2015-02-23 21:40:49 UTC (rev 7799)
@@ -42,9 +42,13 @@
* docutils/writers/xhtml11/
- New HTML writer generating `XHTML1.1`_ styled with CSS2.
-
Moved to the docutils core from sandbox/html4strict.
+ - Wrap SVG images in <img> tags not <object>.
+ 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
Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py 2015-02-21 16:59:18 UTC (rev 7798)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py 2015-02-23 21:40:49 UTC (rev 7799)
@@ -903,7 +903,7 @@
and len(node.astext()) > self.settings.field_name_limit):
atts['colspan'] = 2
self.context.append('</tr>\n'
- + self.starttag(node.parent, 'tr', '',
+ + self.starttag(node.parent, 'tr', '',
CLASS='field')
+ '<td> </td>')
else:
@@ -1013,16 +1013,19 @@
self.header.extend(header)
del self.body[start:]
+ # Image types to place in an <object> 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 <object> 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 @@
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) + '</object>' + suffix)
@@ -1083,7 +1085,8 @@
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', ''))
Modified: trunk/docutils/docutils/writers/xhtml11/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/xhtml11/__init__.py 2015-02-21 16:59:18 UTC (rev 7798)
+++ trunk/docutils/docutils/writers/xhtml11/__init__.py 2015-02-23 21:40:49 UTC (rev 7799)
@@ -41,7 +41,7 @@
"""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 @@
# def depart_generated(self, node):
# pass
+ # Image types to place in an <object> element
+ # SVG as <img> 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', ''))
Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2015-02-21 16:59:18 UTC (rev 7798)
+++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2015-02-23 21:40:49 UTC (rev 7799)
@@ -1119,6 +1119,9 @@
reStructuredText, the markup syntax</object>
<p class="caption">SVG image in a figure.</p>
</div>
+<object class="align-right" data="../../../docs/user/rst/images/biohazard-bitmap.svg" style="width: 3em;" type="image/svg+xml">
+../../../docs/user/rst/images/biohazard-bitmap.svg</object>
+<p>An SVG image with embedded bitmap. Should be 3 em wide, right aligned.</p>
</div>
<div class="section" id="swf-images">
<h2><a class="toc-backref" href="#id75">2.25 SWF Images</a></h2>
Modified: trunk/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml 2015-02-21 16:59:18 UTC (rev 7798)
+++ trunk/docutils/test/functional/expected/standalone_rst_xhtml11.xhtml 2015-02-23 21:40:49 UTC (rev 7799)
@@ -1077,39 +1077,34 @@
</div>
<div class="section" id="svg-images">
<h2><a class="toc-backref" href="#id78"><span class="sectnum">2.24</span> SVG Images</a></h2>
-<object data="../../../docs/user/rst/images/biohazard.svg" style="width: 48px; height: 48px;" type="image/svg+xml">
-../../../docs/user/rst/images/biohazard.svg</object>
+<img alt="../../../docs/user/rst/images/biohazard.svg" src="../../../docs/user/rst/images/biohazard.svg" style="width: 48px; height: 48px;" />
<p>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.</p>
-<object class="align-left" data="../../../docs/user/rst/images/title-scaling.svg" style="width: 50%;" type="image/svg+xml">
-../../../docs/user/rst/images/title-scaling.svg</object>
+<img alt="../../../docs/user/rst/images/title-scaling.svg" class="align-left" src="../../../docs/user/rst/images/title-scaling.svg" style="width: 50%;" />
<p>A scaling image occupying 50% of the line width (scales with the
browser window).</p>
<p>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.</p>
-<p>An inline SVG image <object data="../../../docs/user/rst/images/biohazard-scaling.svg" style="height: 0.8em;" type="image/svg+xml">inline-svg</object> scaled to a height of 0.8 em.</p>
-<object class="align-right" data="../../../docs/user/rst/images/title-scaling.svg" style="width: 50%; height: 1.2em;" type="image/svg+xml">
-../../../docs/user/rst/images/title-scaling.svg</object>
+<p>An inline SVG image <img alt="inline-svg" src="../../../docs/user/rst/images/biohazard-scaling.svg" style="height: 0.8em;" /> scaled to a height of 0.8 em.</p>
+<img alt="../../../docs/user/rst/images/title-scaling.svg" class="align-right" src="../../../docs/user/rst/images/title-scaling.svg" style="width: 50%; height: 1.2em;" />
<p>A scaling image occupying 50% of the line width and 1.2 em high,
right aligned (this SVG image keeps the aspect ratio):</p>
-<object class="align-left" data="../../../docs/user/rst/images/biohazard-scaling.svg" style="height: 1em;" type="image/svg+xml">
-../../../docs/user/rst/images/biohazard-scaling.svg</object>
+<img alt="../../../docs/user/rst/images/biohazard-scaling.svg" class="align-left" src="../../../docs/user/rst/images/biohazard-scaling.svg" style="height: 1em;" />
<p>A scaling image 1 em high, left aligned.</p>
<p>A scaling image 5 mm x 5 mm, centered, with hyperlink reference:</p>
-<a class="reference internal image-reference" href="#directives"><object class="align-center" data="../../../docs/user/rst/images/biohazard-scaling.svg" style="width: 5mm; height: 5mm;" type="image/svg+xml">../../../docs/user/rst/images/biohazard-scaling.svg</object></a>
-<object class="align-left" data="../../../docs/user/rst/images/biohazard.svg" style="width: 4cm; height: 2em;" type="image/svg+xml">
-../../../docs/user/rst/images/biohazard.svg</object>
+<a class="reference internal image-reference" href="#directives"><img alt="../../../docs/user/rst/images/biohazard-scaling.svg" class="align-center" src="../../../docs/user/rst/images/biohazard-scaling.svg" style="width: 5mm; height: 5mm;" /></a>
+<img alt="../../../docs/user/rst/images/biohazard.svg" class="align-left" src="../../../docs/user/rst/images/biohazard.svg" style="width: 4cm; height: 2em;" />
<p>A fixed-size image in a 4 cm x 2 em box.</p>
-<object class="align-left" data="../../../docs/user/rst/images/title.svg" style="width: 50%; height: 15px;" type="image/svg+xml">
-../../../docs/user/rst/images/title.svg</object>
+<img alt="../../../docs/user/rst/images/title.svg" class="align-left" src="../../../docs/user/rst/images/title.svg" style="width: 50%; height: 15px;" />
<p>A fixed-size image in a box 50% the line width and 15 pixle high.</p>
<div class="figure">
-<object data="../../../docs/user/rst/images/title.svg" style="width: 290px; height: 28px;" type="image/svg+xml">
-reStructuredText, the markup syntax</object>
+<img alt="reStructuredText, the markup syntax" src="../../../docs/user/rst/images/title.svg" style="width: 290px; height: 28px;" />
<p class="caption">SVG image in a figure.</p>
</div>
+<img alt="../../../docs/user/rst/images/biohazard-bitmap.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-bitmap.svg" style="width: 3em;" />
+<p>An SVG image with embedded bitmap. Should be 3 em wide, right aligned.</p>
</div>
<div class="section" id="swf-images">
<h2><a class="toc-backref" href="#id79"><span class="sectnum">2.25</span> SWF Images</a></h2>
Modified: trunk/docutils/test/functional/input/data/svg_images.txt
===================================================================
--- trunk/docutils/test/functional/input/data/svg_images.txt 2015-02-21 16:59:18 UTC (rev 7798)
+++ trunk/docutils/test/functional/input/data/svg_images.txt 2015-02-23 21:40:49 UTC (rev 7799)
@@ -67,3 +67,9 @@
: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.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|