Merge branch 'master' of github.com:kovidgoyal/calibre

This commit is contained in:
Kovid Goyal 2018-08-21 22:44:23 +05:30
commit 6a7c77c41c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -220,7 +220,7 @@ def split(container, name, loc_or_xpath, before=True, totals=None):
bottom_name = container.href_to_name(manifest_item.get('href'), container.opf_name) bottom_name = container.href_to_name(manifest_item.get('href'), container.opf_name)
# Fix links in the split trees # Fix links in the split trees
for r, rname, anchors in [(root1, bottom_name, anchors_in_bottom), (root2, name, anchors_in_top)]: for r in (root1, root2):
for a in r.xpath('//*[@href]'): for a in r.xpath('//*[@href]'):
url = a.get('href') url = a.get('href')
if url.startswith('#'): if url.startswith('#'):
@ -229,8 +229,16 @@ def split(container, name, loc_or_xpath, before=True, totals=None):
fname = container.href_to_name(url, name) fname = container.href_to_name(url, name)
if fname == name: if fname == name:
purl = urlparse(url) purl = urlparse(url)
if purl.fragment in anchors: if purl.fragment in anchors_in_top:
a.set('href', '%s#%s' % (container.name_to_href(rname, name), purl.fragment)) if r is root2:
a.set('href', '%s#%s' % (container.name_to_href(name, bottom_name), purl.fragment))
else:
a.set('href', '#' + purl.fragment)
elif purl.fragment in anchors_in_bottom:
if r is root1:
a.set('href', '%s#%s' % (container.name_to_href(bottom_name, name), purl.fragment))
else:
a.set('href', '#' + purl.fragment)
# Fix all links in the container that point to anchors in the bottom tree # Fix all links in the container that point to anchors in the bottom tree
for fname, media_type in container.mime_map.iteritems(): for fname, media_type in container.mime_map.iteritems():