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,14 +281,17 @@ def find_text(node):
|
|||||||
|
|
||||||
def from_files(container):
|
def from_files(container):
|
||||||
toc = TOC()
|
toc = TOC()
|
||||||
for spinepath in container.spine_items:
|
for i, spinepath in enumerate(container.spine_items):
|
||||||
name = container.abspath_to_name(spinepath)
|
name = container.abspath_to_name(spinepath)
|
||||||
root = container.parsed(name)
|
root = container.parsed(name)
|
||||||
body = XPath('//h:body')(root)
|
body = XPath('//h:body')(root)
|
||||||
if not body:
|
if not body:
|
||||||
continue
|
continue
|
||||||
text = find_text(body[0])
|
text = find_text(body[0])
|
||||||
if text:
|
if not text:
|
||||||
|
text = name.rpartition('/')[-1]
|
||||||
|
if i == 0 and text.rpartition('.')[0].lower() in {'titlepage', 'cover'}:
|
||||||
|
text = _('Cover')
|
||||||
toc.add(text, name)
|
toc.add(text, name)
|
||||||
return toc
|
return toc
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user