From 69d8475b4eb8ec7ab69cb327fb72a96f0e5799e1 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 3 Oct 2005 19:18:04 +0000 Subject: fixed bug with center-alignment of image; added test git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@3920 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/docutils/writers/html4css1.py | 18 ++++++++++++++---- .../functional/expected/standalone_rst_html4css1.html | 6 ++++++ .../test/functional/expected/standalone_rst_latex.tex | 12 ++++++++++++ .../functional/expected/standalone_rst_pseudoxml.txt | 9 +++++++++ docutils/test/functional/input/data/standard.txt | 15 +++++++++++++++ 5 files changed, 56 insertions(+), 4 deletions(-) (limited to 'docutils') diff --git a/docutils/docutils/writers/html4css1.py b/docutils/docutils/writers/html4css1.py index 4394dded9..14d0424da 100644 --- a/docutils/docutils/writers/html4css1.py +++ b/docutils/docutils/writers/html4css1.py @@ -975,9 +975,6 @@ class HTMLTranslator(nodes.NodeVisitor): if style: atts['style'] = ' '.join(style) atts['alt'] = node.get('alt', atts['src']) - if node.has_key('align'): - atts['align'] = self.attval(node['align']) - atts['class'] = 'align-%s' % atts['align'] if (isinstance(node.parent, nodes.TextElement) or (isinstance(node.parent, nodes.reference) and not isinstance(node.parent.parent, nodes.TextElement))): @@ -985,10 +982,23 @@ class HTMLTranslator(nodes.NodeVisitor): suffix = '' else: suffix = '\n' + if node.has_key('align'): + if node['align'] == 'center': + # "align" attribute is set in surrounding "div" element. + self.body.append('
') + self.context.append('
\n') + suffix = '' + else: + # "align" attribute is set in "img" element. + atts['align'] = node['align'] + self.context.append('') + atts['class'] = 'align-%s' % node['align'] + else: + self.context.append('') self.body.append(self.emptytag(node, 'img', suffix, **atts)) def depart_image(self, node): - pass + self.body.append(self.context.pop()) def visit_important(self, node): self.visit_admonition(node, 'important') diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index 0d61313d9..3f6014854 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/test/functional/expected/standalone_rst_html4css1.html @@ -549,6 +549,12 @@ document (a document-wide table o ../../../docs/user/rst/images/title.png

Image with multiple IDs:

../../../docs/user/rst/images/title.png +

A centered image:

+
../../../docs/user/rst/images/biohazard.png
+

A left-aligned image:

+../../../docs/user/rst/images/biohazard.png +

A right-aligned image:

+../../../docs/user/rst/images/biohazard.png

A figure directive:

reStructuredText, the markup syntax diff --git a/docutils/test/functional/expected/standalone_rst_latex.tex b/docutils/test/functional/expected/standalone_rst_latex.tex index aa03b5dc0..4e36fc61f 100644 --- a/docutils/test/functional/expected/standalone_rst_latex.tex +++ b/docutils/test/functional/expected/standalone_rst_latex.tex @@ -869,6 +869,18 @@ Image with multiple IDs: \includegraphics{../../../docs/user/rst/images/title.png} +A centered image: + +{\hfill\includegraphics{../../../docs/user/rst/images/biohazard.png}\hfill} + +A left-aligned image: + +{\includegraphics{../../../docs/user/rst/images/biohazard.png}\hfill} + +A right-aligned image: + +{\hfill\includegraphics{../../../docs/user/rst/images/biohazard.png}} + A figure directive: \begin{figure}[htbp]\begin{center} diff --git a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt index 179760c86..f47750eb5 100644 --- a/docutils/test/functional/expected/standalone_rst_pseudoxml.txt +++ b/docutils/test/functional/expected/standalone_rst_pseudoxml.txt @@ -1128,6 +1128,15 @@ + + A centered image: + + + A left-aligned image: + + + A right-aligned image: + A figure directive:
diff --git a/docutils/test/functional/input/data/standard.txt b/docutils/test/functional/input/data/standard.txt index 85016529f..0ce3020ef 100644 --- a/docutils/test/functional/input/data/standard.txt +++ b/docutils/test/functional/input/data/standard.txt @@ -434,6 +434,21 @@ Image with multiple IDs: .. _image target 3: .. image:: ../../../docs/user/rst/images/title.png +A centered image: + +.. image:: ../../../docs/user/rst/images/biohazard.png + :align: center + +A left-aligned image: + +.. image:: ../../../docs/user/rst/images/biohazard.png + :align: left + +A right-aligned image: + +.. image:: ../../../docs/user/rst/images/biohazard.png + :align: right + A figure directive: .. figure:: ../../../docs/user/rst/images/biohazard.png -- cgit v1.2.1