mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-27 01:24:28 +01:00
ToC Editor: When generating ToCs using headings/xpath ignore duplicate entries at the same level that have the same text. Fixes #1735799 [[Enhancement] Filter dupes in TOC editor](https://bugs.launchpad.net/calibre/+bug/1735799)
This commit is contained in:
parent
a6ef8f7efd
commit
1a3ed93de4
2 changed files with 14 additions and 0 deletions
|
|
@ -78,6 +78,19 @@ def iterdescendants(self):
|
|||
for gc in child.iterdescendants():
|
||||
yield gc
|
||||
|
||||
def remove_duplicates(self, only_text=True):
|
||||
seen = set()
|
||||
remove = []
|
||||
for child in self:
|
||||
key = child.title if only_text else (child.title, child.dest, (child.frag or None))
|
||||
if key in seen:
|
||||
remove.append(child)
|
||||
else:
|
||||
seen.add(key)
|
||||
child.remove_duplicates()
|
||||
for child in remove:
|
||||
self.remove(child)
|
||||
|
||||
@property
|
||||
def depth(self):
|
||||
"""The maximum depth of the navigation tree rooted at this node."""
|
||||
|
|
|
|||
|
|
@ -933,6 +933,7 @@ def create_from_xpath(self, xpaths):
|
|||
if len(toc) == 0:
|
||||
return error_dialog(self, _('No items found'),
|
||||
_('No items were found that could be added to the Table of Contents.'), show=True)
|
||||
toc.remove_duplicates()
|
||||
self.insert_toc_fragment(toc)
|
||||
|
||||
def create_from_links(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue