Skip to content

Commit 2439ddf

Browse files
joneflying-sheep
authored andcommitted
rst: use CSS for image alignment.
1 parent 4359089 commit 2439ddf

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/github/commands/rest2html

+17
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ class GitHubHTMLTranslator(HTMLTranslator):
207207
def depart_table(self, node):
208208
self.body.append('</table>\n')
209209

210+
def visit_image(self, node):
211+
"""Custom visit_image for using the HTML align attribute for
212+
image alignment, since css-classes will be stripped.
213+
"""
214+
HTMLTranslator.visit_image(self, node)
215+
if self.body[-1].startswith('<img'):
216+
# image with alignment
217+
align = node.get('align')
218+
219+
if align is None and node.parent.tagname == 'figure':
220+
# figure with alignment
221+
align = node.parent.get('align')
222+
223+
if align:
224+
self.body[-1] = self.body[-1].replace(
225+
' />', ' style="float: %s" />' % align)
226+
210227
def depart_image(self, node):
211228
uri = node['uri']
212229
ext = os.path.splitext(uri)[1].lower()

test/markups/README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ someone@somewhere.org
7676

7777
Press :kbd:`Ctrl+C` to quit
7878

79+
.. image:: foo.png
80+
:align: right
7981

8082
.. raw:: html
8183

test/markups/README.rst.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ <h2><a href="#id2">Field list</a></h2>
9191
<p><a href="mailto:someone@somewhere.org">someone@somewhere.org</a></p>
9292

9393
<p>Press <kbd>Ctrl+C</kbd> to quit</p>
94-
94+
<img alt="foo.png" src="foo.png" style="float: right" />
9595
<p><strong>RAW HTML!</strong></p> p {color:blue;}

0 commit comments

Comments
 (0)