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

View File

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