mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #3218 (Adding a book in an existing format causes a temporary duplication of formats)
This commit is contained in:
parent
83acd63c45
commit
516e1ca962
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user