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 7c27fbd
Show file tree
Hide file tree
Showing 3 changed files with 21 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
2 changes: 2 additions & 0 deletions test/markups/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ [email protected]

Press :kbd:`Ctrl+C` to quit

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

.. raw:: html

Expand Down
2 changes: 2 additions & 0 deletions test/markups/README.rst.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ <h2><a href="#id2">Field list</a></h2>

<p>Press <kbd>Ctrl+C</kbd> to quit</p>

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

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

0 comments on commit 7c27fbd

Please sign in to comment.