'Return a TOC nodetree -- for use on the same page only!'

def get_toc_for(self, docname, builder):

    tocdepth = self.env.metadata[docname].get('tocdepth', 0)
    try:
        toc = self.env.tocs[docname].deepcopy()
        self._toctree_prune(toc, 2, tocdepth)
    except KeyError:
        return nodes.paragraph()
    self.process_only_nodes(toc)
    for node in toc.traverse(nodes.reference):
        node['refuri'] = (node['anchorname'] or '#')
    return toc
