def fixLinks(document, ext):
    supported_schemes=['http', 'https', 'ftp', 'mailto']
    for node in domhelpers.findElementsWithAttribute(document, 'href'):
        href = node.getAttribute("href")
        if urlparse.urlparse(href)[0] in supported_schemes:
            continue
        if node.getAttribute("class") == "absolute":
            continue
        if node.getAttribute("class").find('listing') != -1:
            continue

        # This is a relative link, so it should be munged.
        if href.endswith('html') or href[:href.rfind('#')].endswith('html'):
            fname, fext = os.path.splitext(href)
            if '#' in fext:
                fext = ext+'#'+fext.split('#', 1)[1]
            else:
                fext = ext
            node.setAttribute("href", fname + fext)
Rewrite links to XHTML lore input documents so they point to lore XHTML
dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/lore/tree.py/fixLinks