'Create the toc navigation structure.
This method is almost same as build_navpoints method in epub.py.
This is because the logical navigation structure of epub3 is not
different from one of epub2.
The difference from build_navpoints method is templates which are used
when generating navigation documents.'

def build_navlist(self, navnodes):

    navstack = []
    navstack.append(NavPoint('', '', []))
    level = 0
    for node in navnodes:
        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
        navpoint = NavPoint(node['text'], node['refuri'], [])
        if (node['level'] == level):
            navstack.pop()
            navstack[(-1)].children.append(navpoint)
            navstack.append(navpoint)
        elif (node['level'] == (level + 1)):
            level += 1
            navstack[(-1)].children.append(navpoint)
            navstack.append(navpoint)
        elif (node['level'] < level):
            while (node['level'] < len(navstack)):
                navstack.pop()
            level = node['level']
            navstack[(-1)].children.append(navpoint)
            navstack.append(navpoint)
        else:
            raise
    return navstack[0].children
