Fix #3218 (Adding a book in an existing format causes a temporary duplication of formats)

This commit is contained in:
Kovid Goyal 2009-08-20 10:15:26 -06:00
parent 83acd63c45
commit 516e1ca962
2 changed files with 8 additions and 6 deletions

View File

@ -358,25 +358,25 @@ class EPUBOutput(OutputFormatPlugin):
if body:
body = body[0]
else:
return 0 # Impossible?
return False
tree = body.getroottree()
elem = XPath('//*[@id="%s" or @name="%s"]'%(frag, frag))(root)
if elem:
elem = elem[0]
else:
return 0
return False
path = tree.getpath(elem)
for el in body.iterdescendants():
epath = tree.getpath(el)
if epath == path:
break
if el.text and el.text.strip():
return 0
return False
if not path.startswith(epath):
# Only check tail of non-parent elements
if el.tail and el.tail.strip():
return 0
return 1
return False
return True
def simplify_toc_entry(toc):
if toc.href:
@ -385,6 +385,8 @@ class EPUBOutput(OutputFormatPlugin):
for x in self.oeb.spine:
if x.href == href:
if frag_is_at_top(x.data, frag):
self.log.debug('Removing anchor from TOC href:',
href+'#'+frag)
toc.href = href
break
for x in toc:

View File

@ -144,7 +144,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
ext = os.path.splitext(_file)[1].lower().replace('.', '')
for row in range(self.formats.count()):
fmt = self.formats.item(row)
if fmt.ext == ext:
if fmt.ext.lower() == ext:
self.formats.takeItem(row)
break
Format(self.formats, ext, size, path=_file)