mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
3484c9bddf
commit
27e2b265e4
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user