]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
Made URLs absolute in <img src="">
authorOleg Broytman <phd@phdru.name>
Tue, 16 Oct 2012 22:31:55 +0000 (22:31 +0000)
committerOleg Broytman <phd@phdru.name>
Tue, 16 Oct 2012 22:31:55 +0000 (22:31 +0000)
git-svn-id: file:///home/phd/archive/SVN/phdru.name/scripts@133 7bb0bf08-9e0d-0410-b083-99cee3bf18b8

reindex_blog.py

index 3f10016e569d1d79daaaa2fc97b46150356501b9..ec6adc05a227b99c1e4bda9fc1a048686dfeff64 100755 (executable)
@@ -480,6 +480,19 @@ class AbsURLHTMLParser(_HTMLParser):
    def end_a(self):
       self.accumulator += '</a>'
 
+   def start_img(self, attrs):
+      self.accumulator += '<img'
+      for attrname, value in attrs:
+         value = cgi.escape(value, True)
+         if attrname == 'src':
+            self.accumulator += ' src="%s"' % urljoin(self.base, value)
+         else:
+            self.accumulator += ' %s="%s"' % (attrname, value)
+      self.accumulator += '>'
+
+   def end_img(self):
+       pass
+
 def absolute_urls(body, base):
    parser = AbsURLHTMLParser(base)