'Collect section titles, their depth in the toc and the refuri.'

def get_refnodes(self, doctree, result):

    if (isinstance(doctree, nodes.reference) and ('refuri' in doctree)):
        refuri = doctree['refuri']
        if (refuri.startswith('http://') or refuri.startswith('https://') or refuri.startswith('irc:') or refuri.startswith('mailto:')):
            return result
        classes = doctree.parent.attributes['classes']
        for level in range(8, 0, (-1)):
            if ((self.toctree_template % level) in classes):
                result.append({'level': level, 'refuri': self.esc(refuri), 'text': ssp(self.esc(doctree.astext()))})
                break
    else:
        for elem in doctree.children:
            result = self.get_refnodes(elem, result)
    return result
