diff options
5 files changed, 56 insertions, 4 deletions
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('<div align="center" class="align-center">') + self.context.append('</div>\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 <a class="reference" href="#table-of-contents">table o <a class="reference 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> <span id="image-target-2"></span><span id="image-target-1"></span><img alt="../../../docs/user/rst/images/title.png" id="image-target-3" name="image-target-3" src="../../../docs/user/rst/images/title.png" /> +<p>A centered image:</p> +<div align="center" class="align-center"><img alt="../../../docs/user/rst/images/biohazard.png" class="align-center" src="../../../docs/user/rst/images/biohazard.png" /></div> +<p>A left-aligned image:</p> +<img align="left" alt="../../../docs/user/rst/images/biohazard.png" class="align-left" src="../../../docs/user/rst/images/biohazard.png" /> +<p>A right-aligned image:</p> +<img align="right" alt="../../../docs/user/rst/images/biohazard.png" class="align-right" src="../../../docs/user/rst/images/biohazard.png" /> <p>A figure directive:</p> <div align="right" class="figclass1 figclass2 figure"> <img alt="reStructuredText, the markup syntax" class="class1 class2" src="../../../docs/user/rst/images/biohazard.png" style="width: 50px;" /> 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 @@ -1129,6 +1129,15 @@ <target refid="image-target-3"> <image ids="image-target-3 image-target-2 image-target-1" names="image\ target\ 3 image\ target\ 2 image\ target\ 1" uri="../../../docs/user/rst/images/title.png"> <paragraph> + A centered image: + <image align="center" uri="../../../docs/user/rst/images/biohazard.png"> + <paragraph> + A left-aligned image: + <image align="left" uri="../../../docs/user/rst/images/biohazard.png"> + <paragraph> + A right-aligned image: + <image align="right" uri="../../../docs/user/rst/images/biohazard.png"> + <paragraph> A figure directive: <figure align="right" classes="figclass1 figclass2"> <image alt="reStructuredText, the markup syntax" classes="class1 class2" uri="../../../docs/user/rst/images/biohazard.png" width="50"> 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 |
