+ def load_toc(self):
+ self.toc = ''
+ if self.html_file:
+ parser = html.HTMLParser(encoding='utf-8')
+ tree = html.parse(self.html_file.path, parser=parser)
+ toc = tree.find('//div[@id="toc"]/ol')
+ if toc is None or not len(toc):
+ return
+ html_link = reverse('book_text', args=[self.slug])
+ for a in toc.findall('.//a'):
+ a.attrib['href'] = html_link + a.attrib['href']
+ self.toc = html.tostring(toc, encoding='unicode')
+ # div#toc
+