PDF Output: When a link with a fragment points to a non-existent anchor link to the top of the file instead of not linking at all

This commit is contained in:
Kovid Goyal 2019-10-20 13:19:06 +05:30
parent 882d09b7e0
commit 06a6ef5612
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -432,7 +432,7 @@ def add_all_links(container, margin_files):
return uuid
def make_anchors_unique(container):
def make_anchors_unique(container, log):
mapping = {}
count = 0
base = None
@ -461,6 +461,10 @@ def make_anchors_unique(container):
key = name, frag
new_frag = mapping.get(key)
if new_frag is None:
if name in spine_names:
log.warn('Link anchor: {}#{} not found, linking to top of file instead'.format(name, frag))
replacer.replaced = True
return 'https://calibre-pdf-anchor.n#' + name
return url.rstrip('#')
replacer.replaced = True
return 'https://calibre-pdf-anchor.a#' + new_frag
@ -1120,7 +1124,7 @@ def convert(opf_path, opts, metadata=None, output_path=None, log=default_log, co
has_maths = add_maths_script(container)
fix_fullscreen_images(container)
name_anchor_map = make_anchors_unique(container)
name_anchor_map = make_anchors_unique(container, log)
margin_files = tuple(create_margin_files(container))
toc = get_toc(container, verify_destinations=False)
has_toc = toc and len(toc)