From 4a3df07974a277af6ad927e1c190b0d4a9e84b00 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Oct 2019 20:20:18 +0530 Subject: [PATCH] Viewer: If the book has no ToC try to generate one from headings, if any. Fixes #1847277 [Book viewer don't display content of fb2](https://bugs.launchpad.net/calibre/+bug/1847277) --- src/calibre/srv/render_book.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 965cbdff71..32cd0d2d2d 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -27,7 +27,7 @@ from calibre.ebooks.oeb.iterator.book import extract_book from calibre.ebooks.oeb.polish.container import Container as ContainerBase from calibre.ebooks.oeb.polish.cover import find_cover_image, set_epub_cover from calibre.ebooks.oeb.polish.css import transform_css -from calibre.ebooks.oeb.polish.toc import get_landmarks, get_toc +from calibre.ebooks.oeb.polish.toc import from_xpaths, get_landmarks, get_toc from calibre.ebooks.oeb.polish.utils import extract, guess_type from calibre.srv.metadata import encode_datetime from calibre.utils.date import EPOCH @@ -220,7 +220,10 @@ class Container(ContainerBase): name == self.opf_name or mt == guess_type('a.ncx') or name.startswith('META-INF/') or name == 'mimetype' or not self.has_name_and_is_not_empty(name)} raster_cover_name, titlepage_name = self.create_cover_page(input_fmt.lower()) + toc = get_toc(self).to_dict(count()) + if not toc or not toc.get('children'): + toc = from_xpaths(self, ['//h:h1', '//h:h2', '//h:h3']).to_dict(count()) spine = [name for name, is_linear in self.spine_names] spineq = frozenset(spine) landmarks = [l for l in get_landmarks(self) if l['dest'] in spineq]