'Return the docname for the filename if the file is document.
*filename* should be absolute or relative to the source directory.'

def path2doc(self, filename):

    if filename.startswith(self.srcdir):
        filename = filename[(len(self.srcdir) + 1):]
    for suffix in self.config.source_suffix:
        if fnmatch.fnmatch(filename, ('*' + suffix)):
            return filename[:(- len(suffix))]
    else:
        return None
