(self)
Create table of contents

        :Args:
          - self (:class:`ExportBook`): current class instance
Create table of contents
Create table of contents
def _create_toc(self):
        """
        Create table of contents

        :Args:
          - self (:class:`ExportBook`): current class instance
        """

        self.toc = OrderedDict()
        self.spine = ['nav']

        self.hold_chapters_urls = [i.url_title for i in self.book_version.get_hold_chapters()]

        for chapter in self.book_version.get_toc():
            if chapter.chapter:
                c1 = epub.EpubHtml(
                    title=chapter.chapter.title,
                    file_name='%s.xhtml' % (chapter.chapter.url_title, )
                )

                # hook for some extra customizations
                cont = self._chapter_content_hook(chapter.chapter.content)

                try:
                    tree = parse_html_string(cont.encode('utf-8'))
                except Exception as err:
                    logger.error('Error parsing chapter content %s' % err)
                    continue

                # hook for some extra customizations
                self._chapter_tree_hook(tree)

                for elem in tree.iter():
                    self._handle_chapter_element(elem)

                c1.content = etree.tostring(tree, pretty_print=True, encoding='utf-8', xml_declaration=True)

                # hook for some extra customizations
                self._epub_chapter_hook(c1)

                self.epub_book.add_item(c1)
                self.spine.append(c1)

                if chapter.parent:
                    self.toc[chapter.parent.id][1].append(c1)
                else:
                    if chapter.has_children():
                        self.toc[chapter.id] = [c1, []]
                    else:
                        self.toc[chapter.id] = c1
            else:
                epub_sec = epub.Section(chapter.name)

                if chapter.parent:
                    self.toc[chapter.parent.id][1].append(epub_sec)
                else:
                    self.toc[chapter.id] = [epub_sec, []]
def _create_toc ( self ) : self . toc = OrderedDict ( ) self . spine = [ 'nav' ] self . hold_chapters_urls = [ i . url_title for i in self . book_version . get_hold_chapters ( ) ] for chapter in self . book_version . get_toc ( ) : if chapter . chapter : c1 = epub . EpubHtml ( title = chapter . chapter . title , file_name = '%s.xhtml' % ( chapter . chapter . url_title , ) ) # hook for some extra customizations cont = self . _chapter_content_hook ( chapter . chapter . content ) try : tree = parse_html_string ( cont . encode ( 'utf-8' ) ) except Exception as err : logger . error ( 'Error parsing chapter content %s' % err ) continue # hook for some extra customizations self . _chapter_tree_hook ( tree ) for elem in tree . iter ( ) : self . _handle_chapter_element ( elem ) c1 . content = etree . tostring ( tree , pretty_print = True , encoding = 'utf-8' , xml_declaration = True ) # hook for some extra customizations self . _epub_chapter_hook ( c1 ) self . epub_book . add_item ( c1 ) self . spine . append ( c1 ) if chapter . parent : self . toc [ chapter . parent . id ] [ 1 ] . append ( c1 ) else : if chapter . has_children ( ) : self . toc [ chapter . id ] = [ c1 , [ ] ] else : self . toc [ chapter . id ] = c1 else : epub_sec = epub . Section ( chapter . name ) if chapter . parent : self . toc [ chapter . parent . id ] [ 1 ] . append ( epub_sec ) else : self . toc [ chapter . id ] = [ epub_sec , [ ] ]