mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Fix #2117336 [Another page-list in EPUB 3 nav can be broken by conversion bug](https://bugs.launchpad.net/calibre/+bug/2117336)
This commit is contained in:
parent
a8079709a4
commit
d428b95fc1
@ -703,7 +703,8 @@ def ensure_container_has_nav(container, lang=None, previous_nav=None):
|
||||
tocname = nav_name
|
||||
container.apply_unique_properties(tocname, 'nav')
|
||||
if tocname is None:
|
||||
item = container.generate_item('nav.xhtml', id_prefix='nav')
|
||||
name = previous_nav[0] if previous_nav is not None else 'nav.xhtml'
|
||||
item = container.generate_item(name, id_prefix='nav')
|
||||
item.set('properties', 'nav')
|
||||
tocname = container.href_to_name(item.get('href'), base=container.opf_name)
|
||||
if previous_nav is not None:
|
||||
|
@ -65,14 +65,15 @@ class Split:
|
||||
self.log('Splitting markup on page breaks and flow limits, if any...')
|
||||
self.opts = opts
|
||||
self.map = {}
|
||||
nav_href = getattr(opts, 'epub3_nav_href', '')
|
||||
self.nav_href = getattr(opts, 'epub3_nav_href', '')
|
||||
self.existing_nav = getattr(opts, 'epub3_nav_parsed', None)
|
||||
output_supports_nav = False
|
||||
with suppress(Exception):
|
||||
output_supports_nav = int(opts.epub_version) >= 3
|
||||
def is_nav(item):
|
||||
ans = item.href == nav_href and output_supports_nav
|
||||
ans = item.href == self.nav_href and output_supports_nav
|
||||
if ans:
|
||||
self.log(f'Not splitting {nav_href} as it is the EPUB3 nav document')
|
||||
self.log(f'Not splitting {self.nav_href} as it is the EPUB3 nav document')
|
||||
return ans
|
||||
for item in list(self.oeb.manifest.items):
|
||||
if item.spine_position is not None and etree.iselement(item.data) and not is_nav(item):
|
||||
@ -171,10 +172,20 @@ class Split:
|
||||
'''
|
||||
Fix references to the split files in other content files.
|
||||
'''
|
||||
seen = set()
|
||||
for item in self.oeb.manifest:
|
||||
if etree.iselement(item.data):
|
||||
self.current_item = item
|
||||
rewrite_links(item.data, self.rewrite_links)
|
||||
seen.add(item.data)
|
||||
if self.existing_nav is not None and self.existing_nav not in seen:
|
||||
seen.add(self.existing_nav)
|
||||
from calibre.ebooks.oeb.base import rel_href
|
||||
class FakeManifestItem:
|
||||
href = self.nav_href
|
||||
def abshref(self): return self.href
|
||||
def relhref(self, href): return rel_href(self.href, href)
|
||||
rewrite_links(self.existing_nav, self.rewrite_links)
|
||||
|
||||
def rewrite_links(self, url):
|
||||
href, frag = urldefrag(url)
|
||||
|
Loading…
x
Reference in New Issue
Block a user