mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Fix some links not being adjusted when splitting HTML files. Fixes #1787892 [Footnote not updating when file split used in editor](https://bugs.launchpad.net/calibre/+bug/1787892)
This commit is contained in:
parent
7cb5118aba
commit
594d89460b
@ -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():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user