|
From: <mi...@us...> - 2021-01-26 23:38:42
|
Revision: 8607
http://sourceforge.net/p/docutils/code/8607
Author: milde
Date: 2021-01-26 23:38:39 +0000 (Tue, 26 Jan 2021)
Log Message:
-----------
Revert "html5 writer: wrap image elements in <p> unless inline or in figure."
This wrapper is not required as we can set the display to "block" with CSS.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/html4css1/__init__.py
trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
trunk/docutils/test/functional/expected/standalone_rst_html5.html
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-01-11 11:07:31 UTC (rev 8606)
+++ trunk/docutils/HISTORY.txt 2021-01-26 23:38:39 UTC (rev 8607)
@@ -104,8 +104,7 @@
Use <ins> and <del> if a matching class value
is found in `inline`, `literal`, or `container` elements.
- - Wrap block-level image elements in <p> (except for figures).
- Move non-essential styling from ``minimal.css`` to ``plain.css``.
+ - Move non-essential styling from ``minimal.css`` to ``plain.css``.
Support numbered figures in ``plain.css``.
- Fix bug #398: properly close link tag to "schema.dcterms".
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2021-01-11 11:07:31 UTC (rev 8606)
+++ trunk/docutils/docutils/writers/_html_base.py 2021-01-26 23:38:39 UTC (rev 8607)
@@ -950,13 +950,13 @@
del atts[att_name]
if style:
atts['style'] = ' '.join(style)
- if isinstance(node.parent, (nodes.figure, nodes.compound)):
+ if (isinstance(node.parent, nodes.TextElement) or
+ (isinstance(node.parent, nodes.reference) and
+ not isinstance(node.parent.parent, nodes.TextElement))):
+ # Inline context or surrounded by <a>...</a>.
+ suffix = ''
+ else:
suffix = '\n'
- elif not isinstance(node.parent, (nodes.TextElement, nodes.reference)):
- self.body.append('<p class="image-wrapper">')
- suffix = '</p>\n'
- else:
- suffix = ''
if 'align' in node:
atts['class'] = 'align-%s' % node['align']
# Embed image file (embedded SVG or data URI):
@@ -1343,15 +1343,12 @@
atts['class'] += ' image-reference'
if not isinstance(node.parent, nodes.TextElement):
assert len(node) == 1 and isinstance(node[0], nodes.image)
- if not isinstance(node.parent, (nodes.figure, nodes.compound)):
- self.body.append('<p class="image-wrapper">')
+ atts['class'] += ' image-reference'
self.body.append(self.starttag(node, 'a', '', **atts))
def depart_reference(self, node):
self.body.append('</a>')
if not isinstance(node.parent, nodes.TextElement):
- if not isinstance(node.parent, (nodes.figure, nodes.compound)):
- self.body.append('</p>')
self.body.append('\n')
self.in_mailto = False
Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py 2021-01-11 11:07:31 UTC (rev 8606)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py 2021-01-26 23:38:39 UTC (rev 8607)
@@ -17,7 +17,6 @@
import os.path
import re
import sys
-
import docutils
from docutils import frontend, nodes, writers, io
from docutils.transforms import writer_aux
@@ -538,13 +537,13 @@
def visit_generated(self, node):
pass
- # Image types to place in an <object> element
+ # Use <object> instead of <img> for some image types:
+
# 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'}
- # do not wrap block-level images in <p></p> (for backwards compatibility)
def visit_image(self, node):
atts = {}
uri = node['uri']
@@ -747,32 +746,6 @@
def depart_paragraph(self, node):
self.body.append(self.context.pop())
- # do not wrap images in paragraphs (for backwards compatibility)
- def visit_reference(self, node):
- atts = {'class': 'reference'}
- if 'refuri' in node:
- atts['href'] = node['refuri']
- if ( self.settings.cloak_email_addresses
- and atts['href'].startswith('mailto:')):
- atts['href'] = self.cloak_mailto(atts['href'])
- self.in_mailto = True
- atts['class'] += ' external'
- else:
- assert 'refid' in node, \
- 'References must have "refuri" or "refid" attribute.'
- atts['href'] = '#' + node['refid']
- atts['class'] += ' internal'
- if not isinstance(node.parent, nodes.TextElement):
- assert len(node) == 1 and isinstance(node[0], nodes.image)
- atts['class'] += ' image-reference'
- self.body.append(self.starttag(node, 'a', '', **atts))
-
- def depart_reference(self, node):
- self.body.append('</a>')
- if not isinstance(node.parent, nodes.TextElement):
- self.body.append('\n')
- self.in_mailto = False
-
# ersatz for first/last pseudo-classes
def visit_sidebar(self, node):
self.body.append(
Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2021-01-11 11:07:31 UTC (rev 8606)
+++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2021-01-26 23:38:39 UTC (rev 8607)
@@ -1378,7 +1378,7 @@
<div class="footer">
<hr class="footer" />
<p>Document footer</p>
-<p><a class="reference external" href="http://validator.w3.org/check?uri=referer"><img alt="Valid XHTML 1.0!" src="http://www.w3.org/Icons/valid-xhtml10" style="width: 88px; height: 31px;" /></a> <a class="reference external" href="http://jigsaw.w3.org/css-validator/check/referer"><img alt="Valid CSS 2.1!" src="http://jigsaw.w3.org/css-validator/images/vcss" style="width: 88px; height: 31px;" /></a></p>
+<p><a class="reference external image-reference" href="http://validator.w3.org/check?uri=referer"><img alt="Valid XHTML 1.0!" src="http://www.w3.org/Icons/valid-xhtml10" style="width: 88px; height: 31px;" /></a> <a class="reference external image-reference" href="http://jigsaw.w3.org/css-validator/check/referer"><img alt="Valid CSS 2.1!" src="http://jigsaw.w3.org/css-validator/images/vcss" style="width: 88px; height: 31px;" /></a></p>
</div>
</body>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2021-01-11 11:07:31 UTC (rev 8606)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2021-01-26 23:38:39 UTC (rev 8607)
@@ -570,18 +570,18 @@
<section id="images-and-figures">
<h4><a class="toc-backref" href="#toc-entry-56"><span class="sectnum">2.14.2</span> Images and Figures</a></h4>
<p>An image directive (also clickable -- a hyperlink reference):</p>
-<p class="image-wrapper"><a class="reference internal image-reference" href="#directives"><img alt="../../../docs/user/rst/images/title.png" class="class1 class2" src="../../../docs/user/rst/images/title.png" /></a></p>
+<a class="reference internal image-reference" href="#directives"><img alt="../../../docs/user/rst/images/title.png" class="class1 class2" src="../../../docs/user/rst/images/title.png" /></a>
<p>Image with multiple IDs:</p>
-<p class="image-wrapper"><span id="image-target-2"></span><span id="image-target-1"></span><img alt="../../../docs/user/rst/images/title.png" id="image-target-3" src="../../../docs/user/rst/images/title.png" /></p>
+<span id="image-target-2"></span><span id="image-target-1"></span><img alt="../../../docs/user/rst/images/title.png" id="image-target-3" src="../../../docs/user/rst/images/title.png" />
<p>A centered image:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.png" class="align-center" src="../../../docs/user/rst/images/biohazard.png" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.png" class="align-center" src="../../../docs/user/rst/images/biohazard.png" />
<p>A left-aligned image:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.png" class="align-left" src="../../../docs/user/rst/images/biohazard.png" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.png" class="align-left" src="../../../docs/user/rst/images/biohazard.png" />
<p>This paragraph might flow around the image.
The specific behavior depends upon the style sheet and
the browser or rendering software used.</p>
<p>A right-aligned image:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.png" class="align-right" src="../../../docs/user/rst/images/biohazard.png" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.png" class="align-right" src="../../../docs/user/rst/images/biohazard.png" />
<p>This paragraph might flow around the image.
The specific behavior depends upon the style sheet and
the browser or rendering software used.</p>
@@ -588,13 +588,13 @@
<p>For inline images see <a class="reference internal" href="#substitution-definitions">Substitution Definitions</a>.</p>
<p>Image size:</p>
<p>An image 2 em wide:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.png" src="../../../docs/user/rst/images/biohazard.png" style="width: 2em;" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.png" src="../../../docs/user/rst/images/biohazard.png" style="width: 2em;" />
<p>An image 2 em wide and 15 pixel high:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.png" src="../../../docs/user/rst/images/biohazard.png" style="width: 2em; height: 15px;" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.png" src="../../../docs/user/rst/images/biohazard.png" style="width: 2em; height: 15px;" />
<p>An image occupying 50% of the line width:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/title.png" src="../../../docs/user/rst/images/title.png" style="width: 50%;" /></p>
+<img alt="../../../docs/user/rst/images/title.png" src="../../../docs/user/rst/images/title.png" style="width: 50%;" />
<p>An image 2 cm high:</p>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.png" src="../../../docs/user/rst/images/biohazard.png" style="height: 2cm;" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.png" src="../../../docs/user/rst/images/biohazard.png" style="height: 2cm;" />
<p>A <em>figure</em> is an image with a caption and/or a legend. With page-based output
media, figures might float to a different position if this helps the page
layout.</p>
@@ -1244,7 +1244,7 @@
<h2><a class="toc-backref" href="#toc-entry-42"><span class="sectnum">3</span> HTML specific</a></h2>
<section id="svg-images">
<h3><a class="toc-backref" href="#toc-entry-43"><span class="sectnum">3.1</span> SVG Images</a></h3>
-<p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.svg" class="align-left" src="../../../docs/user/rst/images/biohazard.svg" style="width: 48px; height: 48px;" /></p>
+<img alt="../../../docs/user/rst/images/biohazard.svg" class="align-left" src="../../../docs/user/rst/images/biohazard.svg" style="width: 48px; height: 48px;" />
<p>Scalable vector graphics (SVG) images are the only standards-compliable way
to include vector graphics in HTML documents. However, they are not
supported by all backends/output formats. (E.g., LaTeX supports the
@@ -1279,30 +1279,30 @@
SVG image is scaled or clipped/padded. Images wrapped in <span class="docutils literal"><img></span> are
always scaled.</p>
<ul>
-<li><p class="image-wrapper"><img alt="../../../docs/user/rst/images/title-scaling.svg" class="align-right" src="../../../docs/user/rst/images/title-scaling.svg" style="width: 50%;" /></p>
+<li><img alt="../../../docs/user/rst/images/title-scaling.svg" class="align-right" src="../../../docs/user/rst/images/title-scaling.svg" style="width: 50%;" />
<p>A scaling image (scales with the browser window), occupying 50% of the line
width. The <span class="docutils literal">viewBox</span> setting in the image file enables auto-scaling also in
<span class="docutils literal"><object></span> tags and embedded SVG (if width and hight are set to 100% in the
SVG <image> tag).</p>
</li>
-<li><p class="image-wrapper"><img alt="../../../docs/user/rst/images/title.svg" class="align-right" src="../../../docs/user/rst/images/title.svg" style="width: 50%; height: 15px;" /></p>
+<li><img alt="../../../docs/user/rst/images/title.svg" class="align-right" src="../../../docs/user/rst/images/title.svg" style="width: 50%; height: 15px;" />
<p>A fixed-size image in a box 50% wide and 15 pixles high. This image is
scaled, if wrapped in an <span class="docutils literal"><img></span> tag but clipped in an <span class="docutils literal"><object></span> tag
or within SVG.</p>
</li>
-<li><p class="image-wrapper"><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.5em;" /></p>
+<li><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.5em;" />
<p>A right aligned, scaling image 50% wide and 1.5 em high. (This SVG image
keeps the aspect ratio.)</p>
</li>
<li><p>An inline 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>
</li>
-<li><p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard-scaling.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-scaling.svg" style="height: 1em;" /></p>
+<li><img alt="../../../docs/user/rst/images/biohazard-scaling.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-scaling.svg" style="height: 1em;" />
<p>A scaling image 1 em high, right aligned:</p>
</li>
<li><p>A scaling image 5 mm x 5 mm, centered, with hyperlink reference:</p>
-<p class="image-wrapper"><a class="reference internal image-reference" href="#svg-images"><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></p>
+<a class="reference internal image-reference" href="#svg-images"><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>
</li>
-<li><p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard.svg" class="align-right" src="../../../docs/user/rst/images/biohazard.svg" style="width: 4cm; height: 2em;" /></p>
+<li><img alt="../../../docs/user/rst/images/biohazard.svg" class="align-right" 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>
</li>
</ul>
@@ -1310,12 +1310,12 @@
konqueror) support the <span class="docutils literal"><img></span> tag but don't display contained bitmap
images in this case.</p>
<ul>
-<li><p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard-bitmap.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-bitmap.svg" style="width: 3em;" /></p>
+<li><img alt="../../../docs/user/rst/images/biohazard-bitmap.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-bitmap.svg" style="width: 3em;" />
<p>A small, fixed-size SVG image with embedded bitmap, The <span class="docutils literal">:width:</span> is
set to 3 em in the rST source. Does not scale if wrapped in <span class="docutils literal"><object></span>
tags.</p>
</li>
-<li><p class="image-wrapper"><img alt="../../../docs/user/rst/images/biohazard-bitmap-scaling.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-bitmap-scaling.svg" style="width: 3em;" /></p>
+<li><img alt="../../../docs/user/rst/images/biohazard-bitmap-scaling.svg" class="align-right" src="../../../docs/user/rst/images/biohazard-bitmap-scaling.svg" style="width: 3em;" />
<p>A scaling SVG image with embedded bitmap, 3 em wide.</p>
</li>
</ul>
@@ -1336,7 +1336,7 @@
concerns.</p>
<p>Images with extension <span class="docutils literal">.swf</span> are placed inside <object> elements.
For complete control over display options use raw HTML.</p>
-<p class="image-wrapper"><object class="align-left" data="../../../docs/user/rst/images/biohazard.swf" style="width: 4cm; height: 2em;" type="application/x-shockwave-flash">[biohazard.swf]</object></p>
+<object class="align-left" data="../../../docs/user/rst/images/biohazard.swf" style="width: 4cm; height: 2em;" type="application/x-shockwave-flash">[biohazard.swf]</object>
<p>An SWF image in a 4 cm x 2 em box, left aligned.</p>
<p>An inline SWF image <object data="../../../docs/user/rst/images/biohazard.swf" style="width: 0.8em; height: 0.8em;" type="application/x-shockwave-flash">inline-swf</object> scaled to 0.8 em x 0.8 em.</p>
</section>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|