add support for eml file parser (#1768)

### What problem does this PR solve?

add support for eml file parser
#1363

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
黄腾
2024-08-06 16:42:14 +08:00
committed by GitHub
parent b67484e77d
commit ede733e130
12 changed files with 178 additions and 28 deletions

View File

@ -30,10 +30,15 @@ class RAGFlowHtmlParser:
else:
with open(fnm, "r",encoding=get_encoding(fnm)) as f:
txt = f.read()
return self.parser_txt(txt)
@classmethod
def parser_txt(cls, txt):
if type(txt) != str:
raise TypeError("txt type should be str!")
html_doc = readability.Document(txt)
title = html_doc.title()
content = html_text.extract_text(html_doc.summary(html_partial=True))
txt = f'{title}\n{content}'
txt = f"{title}\n{content}"
sections = txt.split("\n")
return sections