Fix for pre-existing epubs with stripped img tags.

This commit is contained in:
Jim Miller 2012-03-01 21:27:48 -06:00
parent 3bb26c2b58
commit 0917460e68
2 changed files with 6 additions and 2 deletions

View file

@ -284,8 +284,10 @@ class BaseSiteAdapter(Configurable):
if self.getConfig('include_images'):
acceptable_attributes.extend(('src','alt','longdesc'))
for img in soup.findAll('img'):
img['longdesc']=img['src']
img['src']=self.story.addImgUrl(self,url,img['src'],fetch)
# some pre-existing epubs have img tags that had src stripped off.
if 'src' in img:
img['longdesc']=img['src']
img['src']=self.story.addImgUrl(self,url,img['src'],fetch)
for attr in soup._getAttrMap().keys():
if attr not in acceptable_attributes:

View file

@ -56,6 +56,8 @@ def get_update_data(inputio,
if getsoups:
soup = bs.BeautifulSoup(epub.read(href).decode("utf-8"))
for img in soup.findAll('img'):
newsrc=''
longdesc=''
try:
newsrc=get_path_part(href)+img['src']
# remove all .. and the path part above it, if present.