Log what type of ToC is used

This commit is contained in:
Kovid Goyal 2013-07-11 10:41:32 +05:30
parent 0f6161e5ba
commit 6c310278c9
2 changed files with 7 additions and 5 deletions

View File

@ -279,7 +279,7 @@ class Convert(object):
self.styles.resolve_numbering(numbering)
def write(self, doc):
toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map)
toc = create_toc(doc, self.body, self.resolved_link_map, self.styles, self.object_map, self.log)
raw = html.tostring(self.html, encoding='utf-8', doctype='<!DOCTYPE html>')
with open(os.path.join(self.dest_dir, 'index.html'), 'wb') as f:
f.write(raw)

View File

@ -21,7 +21,7 @@ class Count(object):
def __init__(self):
self.val = 0
def from_headings(body):
def from_headings(body, log):
' Create a TOC from headings in the document '
headings = ('h1', 'h2', 'h3')
tocroot = TOC()
@ -58,6 +58,7 @@ def from_headings(body):
level_prev[i] = None
if len(tuple(tocroot.flat())) > 1:
log('Generating Table of Contents from headings')
return tocroot
def structure_toc(entries):
@ -98,7 +99,7 @@ def link_to_txt(a, styles, object_map):
return tostring(a, method='text', with_tail=False, encoding=unicode).strip()
def from_toc(docx, link_map, styles, object_map):
def from_toc(docx, link_map, styles, object_map, log):
toc_level = None
level = 0
TI = namedtuple('TI', 'text anchor indent')
@ -132,9 +133,10 @@ def from_toc(docx, link_map, styles, object_map):
ml = 0
toc.append(TI(txt, href[1:], ml))
if toc:
log('Found Word Table of Contents, using it to generate the Table of Contents')
return structure_toc(toc)
def create_toc(docx, body, link_map, styles, object_map):
return from_toc(docx, link_map, styles, object_map) or from_headings(body)
def create_toc(docx, body, link_map, styles, object_map, log):
return from_toc(docx, link_map, styles, object_map, log) or from_headings(body, log)