Skip to content

Commit

Permalink
rst: use CSS for image alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone authored and flying-sheep committed Aug 10, 2018
1 parent 4359089 commit 3020bf6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ 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:
self.body[-1] = self.body[-1].replace(
' />', ' style="float: %s" />' % align)

def depart_image(self, node):
uri = node['uri']
ext = os.path.splitext(uri)[1].lower()
Expand Down
3 changes: 3 additions & 0 deletions test/markups/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ Press :kbd:`Ctrl+C` to quit
.. raw:: html

<p><strong>RAW HTML!</strong></p><style> p {color:blue;} </style>

.. image:: foo.png
:align: right
2 changes: 2 additions & 0 deletions test/markups/README.rst.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ <h2><a href="#id2">Field list</a></h2>
<p>Press <kbd>Ctrl+C</kbd> to quit</p>

<p><strong>RAW HTML!</strong></p> p {color:blue;}

<img alt="foo.png" class="align-right" src="foo.png" style="float: right" />

0 comments on commit 3020bf6

Please sign in to comment.