ToC Editor: Fix generate from links not working correctly when links have no fragments. Fixes #1856395 [Private bug](https://bugs.launchpad.net/calibre/+bug/1856395)

This commit is contained in:
Kovid Goyal 2019-12-18 16:14:28 +05:30
parent 3484c9bddf
commit 27e2b265e4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -477,18 +477,20 @@ def from_links(container):
toc = TOC()
link_path = XPath('//h:a[@href]')
seen_titles, seen_dests = set(), set()
for spinepath in container.spine_items:
name = container.abspath_to_name(spinepath)
for name, is_linear in container.spine_names:
root = container.parsed(name)
for a in link_path(root):
href = a.get('href')
if not href or not href.strip():
continue
frag = None
if href.startswith('#'):
dest = name
frag = href[1:]
else:
href, _, frag = href.partition('#')
dest = container.href_to_name(href, base=name)
frag = href.rpartition('#')[-1] or None
frag = frag or None
if (dest, frag) in seen_dests:
continue
seen_dests.add((dest, frag))