mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ToC Editor: Use filenames when generating from files
ToC Editor: When generating a ToC from files, if the file has no text, do not skip it. Instead create an entry using the filename of the file.
This commit is contained in:
parent
87dda89378
commit
c3009256c4
@ -281,15 +281,18 @@ def find_text(node):
|
||||
|
||||
def from_files(container):
|
||||
toc = TOC()
|
||||
for spinepath in container.spine_items:
|
||||
for i, spinepath in enumerate(container.spine_items):
|
||||
name = container.abspath_to_name(spinepath)
|
||||
root = container.parsed(name)
|
||||
body = XPath('//h:body')(root)
|
||||
if not body:
|
||||
continue
|
||||
text = find_text(body[0])
|
||||
if text:
|
||||
toc.add(text, name)
|
||||
if not text:
|
||||
text = name.rpartition('/')[-1]
|
||||
if i == 0 and text.rpartition('.')[0].lower() in {'titlepage', 'cover'}:
|
||||
text = _('Cover')
|
||||
toc.add(text, name)
|
||||
return toc
|
||||
|
||||
def add_id(container, name, loc):
|
||||
|
Loading…
x
Reference in New Issue
Block a user