

def convert(file_path, image_handler=None, fall_back=None, converter=None):
    '\n    ``file_path`` is a path to the file on the file system that you want to be\n        converted to html.\n    ``image_handler`` is a function that takes an image_id and a\n        relationship_dict to generate the src attribute for images. (see readme\n        for more details)\n    ``fall_back`` is a function that takes a ``file_path``. This function will\n        only be called if for whatever reason the conversion fails.\n    ``converter`` is a function to convert a document that is not docx to docx\n        (examples in docx2html.converters)\n\n    Returns html extracted from ``file_path``\n    '
    (file_base, extension) = os.path.splitext(os.path.basename(file_path))
    if ((extension == '.html') or (extension == '.htm')):
        return read_html_file(file_path)
    docx_path = replace_ext(file_path, '.docx')
    if (extension == '.docx'):
        docx_path = file_path
    else:
        if (converter is None):
            raise FileNotDocx('The file passed in is not a docx.')
        converter(docx_path, file_path)
        if (not os.path.isfile(docx_path)):
            if (fall_back is None):
                raise ConversionFailed('Conversion to docx failed.')
            else:
                return fall_back(file_path)
    try:
        zf = get_zip_file_handler(docx_path)
    except BadZipfile:
        raise MalformedDocx('This file is not a docx')
    (tree, meta_data) = _get_document_data(zf, image_handler)
    return create_html(tree, meta_data)

dataset/ETHPy150Open PolicyStat/docx2html/docx2html/core.py convert/original