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:
|
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:
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user