'Force filenames that might be HTML file paths into proper URL\'s
This basically means stripping / and .html endings and then re-adding them properly.'

def _fix_filename(self, project, filename):

    if (('.' in filename) and ('.html' not in filename)):
        return filename
    filename = filename.lstrip('/')
    filename = re.sub('(^|/)index(?:.html)?$', '\\1', filename)
    if filename:
        if (filename.endswith('/') or filename.endswith('.html')):
            path = filename
        elif (project.documentation_type == 'sphinx_singlehtml'):
            path = ('index.html#document-' + filename)
        elif (project.documentation_type in ['sphinx_htmldir', 'mkdocs']):
            path = (filename + '/')
        elif ('#' in filename):
            path = filename
        else:
            path = (filename + '.html')
    else:
        path = ''
    return path
