Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support figure / image alignment #11

Merged
merged 1 commit into from
Aug 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions creole/rest2html/clean_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@ def visit_docinfo(self, node):
def depart_docinfo(self, node):
self.body.append('</table>\n')

#__________________________________________________________________________
# Clean image:

depart_figure = _do_nothing

def visit_image(self, node):
super(CleanHTMLTranslator, self).visit_image(node)
if self.body[-1].startswith('<img'):
align = None

if 'align' in node:
# image with alignment
align = node['align']

elif node.parent.tagname == 'figure' and 'align' in node.parent:
# figure with alignment
align = node.parent['align']

if align:
self.body[-1] = self.body[-1].replace(' />', ' align="%s" />' % align)



def rest2html(content, enable_exit_status=None, **kwargs):
"""
Expand Down
22 changes: 22 additions & 0 deletions creole/tests/test_rest2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ def test_raw_enabled(self):
<hr width=50 size=10>
""", raw_enabled=True)

def test_preserve_image_alignment(self):
self.assert_rest2html("""
Image alignment should be preserved.

.. image:: foo.png
:align: right
""", """
<p>Image alignment should be preserved.</p>
<img alt="foo.png" src="foo.png" align="right" />
""")

def test_preserve_figure_alignment(self):
self.assert_rest2html("""
Image alignment should be preserved.

.. figure:: bar.png
:align: right
""", """
<p>Image alignment should be preserved.</p>
<img alt="bar.png" src="bar.png" align="right" />
""")


if __name__ == '__main__':
unittest.main()