Skip to content
Open
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
20 changes: 20 additions & 0 deletions lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ class GitHubHTMLTranslator(HTMLTranslator):
def depart_table(self, node):
self.body.append('</table>\n')

def visit_image(self, node):
"""Custom visit_image for using the HTML align attribute for
image alignment, since css-classes will be stripped.
"""
HTMLTranslator.visit_image(self, node)
if self.body[-1].startswith('<img'):
# image with alignment
align = node.get('align')

if align is None and node.parent.tagname == 'figure':
# figure with alignment
align = node.parent.get('align')

if align:
if ' style="' in self.body[-1]:
old, new = ' style="', ' style="float: %s; ' % align
else:
old, new = ' />', ' style="float: %s" />' % align
self.body[-1] = self.body[-1].replace(old, new)

def depart_image(self, node):
uri = node['uri']
ext = os.path.splitext(uri)[1].lower()
Expand Down
2 changes: 2 additions & 0 deletions test/markups/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ [email protected]

Press :kbd:`Ctrl+C` to quit

.. image:: foo.png
:align: right

.. raw:: html

Expand Down
3 changes: 2 additions & 1 deletion test/markups/README.rst.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ <h2><a href="#toc-entry-2">Field list</a></h2>
</table>
<p><a href="mailto:[email protected]">[email protected]</a></p>
<p>Press <kbd>Ctrl+C</kbd> to quit</p>
<p><strong>RAW HTML!</strong></p> p {color:blue;}
<img alt="foo.png" src="foo.png" style="float: right">
<p><strong>RAW HTML!</strong></p> p {color:blue;}