'Create the toc navigation structure.
Subelements of a node are nested inside the navpoint.  For nested nodes
the parent node is reinserted in the subnav.'

def build_navpoints(self, nodes):

    navstack = []
    navstack.append(NavPoint('dummy', '', '', '', []))
    level = 0
    lastnode = None
    for node in nodes:
        if (not node['text']):
            continue
        file = node['refuri'].split('#')[0]
        if (file in self.ignored_files):
            continue
        if (node['level'] > self.config.epub_tocdepth):
            continue
        if (node['level'] == level):
            navpoint = self.new_navpoint(node, level)
            navstack.pop()
            navstack[(-1)].children.append(navpoint)
            navstack.append(navpoint)
        elif (node['level'] == (level + 1)):
            level += 1
            if (lastnode and self.config.epub_tocdup):
                navstack[(-1)].children.append(self.new_navpoint(lastnode, level, False))
            navpoint = self.new_navpoint(node, level)
            navstack[(-1)].children.append(navpoint)
            navstack.append(navpoint)
        elif (node['level'] < level):
            while (node['level'] < len(navstack)):
                navstack.pop()
            level = node['level']
            navpoint = self.new_navpoint(node, level)
            navstack[(-1)].children.append(navpoint)
            navstack.append(navpoint)
        else:
            raise
        lastnode = node
    return navstack[0].children
