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

rst: use CSS for image alignment. #1222

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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 @@ -82,6 +82,8 @@ [email protected]

Press :kbd:`Ctrl+C` to quit

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

.. raw:: html

Expand Down
6 changes: 2 additions & 4 deletions test/markups/README.rst.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ <h2><a href="#id2">Field list</a></h2>
</tr>
</tbody>
</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;}