Skip to content
Browse files
refactor link rewriter into a separate function
  • Loading branch information
ralsina committed Aug 15, 2015
1 parent 52f0b8c commit 1a819018063e197559278dbd3fb6c8ead1572000
Showing 1 changed file with 5 additions and 1 deletion.
@@ -1052,11 +1052,15 @@ def render_template(self, template_name, output_name, context):
parser = lxml.html.HTMLParser(remove_blank_text=True)
doc = lxml.html.document_fromstring(data, parser)
doc.rewrite_links(lambda dst: self.url_replacer(src, dst, context['lang']), resolve_base_href=False)
self.rewrite_links(doc, src, context['lang'])
data = b'<!DOCTYPE html>\n' + lxml.html.tostring(doc, encoding='utf8', method='html', pretty_print=True)
with open(output_name, "wb+") as post_file:

def rewrite_links(self, doc, src, lang):
"""Replace links in document to point to the right places."""
doc.rewrite_links(lambda dst: self.url_replacer(src, dst, lang), resolve_base_href=False)

def url_replacer(self, src, dst, lang=None, url_type=None):
"""Mangle URLs.

0 comments on commit 1a81901

Please sign in to comment.