@@ -1341,25 +1341,21 @@ def render_template(self, template_name, output_name, context, url_type=None, is
1341
1341
doc = lxml .html .fragment_fromstring (data , parser )
1342
1342
else :
1343
1343
doc = lxml .html .document_fromstring (data , parser )
1344
- self .rewrite_links (doc , src , context ['lang' ], url_type , is_fragment = is_fragment )
1344
+ self .rewrite_links (doc , src , context ['lang' ], url_type )
1345
1345
if is_fragment :
1346
1346
data = (doc .text or '' ).encode ('utf-8' ) + '' .encode ('utf-8' ).join ([lxml .html .tostring (child , encoding = 'utf-8' , method = 'html' ) for child in doc .iterchildren ()])
1347
1347
else :
1348
1348
data = b'<!DOCTYPE html>\n ' + lxml .html .tostring (doc , encoding = 'utf8' , method = 'html' , pretty_print = True )
1349
1349
with open (output_name , "wb+" ) as post_file :
1350
1350
post_file .write (data )
1351
1351
1352
- def rewrite_links (self , doc , src , lang , url_type = None , is_fragment = False ):
1352
+ def rewrite_links (self , doc , src , lang , url_type = None ):
1353
1353
"""Replace links in document to point to the right places."""
1354
1354
# First let lxml replace most of them
1355
1355
doc .rewrite_links (lambda dst : self .url_replacer (src , dst , lang , url_type ), resolve_base_href = False )
1356
1356
1357
1357
# lxml ignores srcset in img and source elements, so do that by hand
1358
- if is_fragment :
1359
- # With the asterisk, top-level <img> and <source> tags are not found
1360
- objs = list (doc .xpath ('(//img|//source)' ))
1361
- else :
1362
- objs = list (doc .xpath ('(*//img|*//source)' ))
1358
+ objs = list (doc .xpath ('(//img|//source)' ))
1363
1359
for obj in objs :
1364
1360
if 'srcset' in obj .attrib :
1365
1361
urls = [u .strip () for u in obj .attrib ['srcset' ].split (',' )]
0 commit comments