File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,23 @@ class GitHubHTMLTranslator(HTMLTranslator):
207
207
def depart_table (self , node ):
208
208
self .body .append ('</table>\n ' )
209
209
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
+
210
227
def depart_image (self , node ):
211
228
uri = node ['uri' ]
212
229
ext = os .path .splitext (uri )[1 ].lower ()
Original file line number Diff line number Diff line change @@ -80,3 +80,6 @@ Press :kbd:`Ctrl+C` to quit
80
80
.. raw :: html
81
81
82
82
<p ><strong >RAW HTML!</strong ></p ><style > p {color :blue ;} </style >
83
+
84
+ .. image :: foo.png
85
+ :align: right
Original file line number Diff line number Diff line change @@ -93,3 +93,5 @@ <h2><a href="#id2">Field list</a></h2>
93
93
< p > Press < kbd > Ctrl+C</ kbd > to quit</ p >
94
94
95
95
< p > < strong > RAW HTML!</ strong > </ p > p {color:blue;}
96
+
97
+ < img alt ="foo.png " class ="align-right " src ="foo.png " style ="float: right " />
You can’t perform that action at this time.
0 commit comments