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:
Kovid Goyal 2013-06-27 13:01:52 +05:30
parent 87dda89378
commit c3009256c4

View File

@ -281,14 +281,17 @@ 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:
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