diff --git a/dsRag/Test/TestPandoc.py b/dsRag/Test/TestPandoc.py index ad71fa35..65cd0d1a 100644 --- a/dsRag/Test/TestPandoc.py +++ b/dsRag/Test/TestPandoc.py @@ -5,8 +5,6 @@ if __name__ == '__main__': docx_file = 'D:\dsWork\dsProject\dsRag\static\Txt\化学方程式_CHEMISTRY_1.docx' # 整合最终的拼接完的文本 - sb = get_docx_content_by_pandoc(docx_file) + content = get_docx_content_by_pandoc(docx_file) - # 输出 - for x in sb: - print(x) + print(content) \ No newline at end of file diff --git a/dsRag/Util/DocxUtil.py b/dsRag/Util/DocxUtil.py index 83946eff..fdad080e 100644 --- a/dsRag/Util/DocxUtil.py +++ b/dsRag/Util/DocxUtil.py @@ -3,6 +3,7 @@ import subprocess import os import uuid + # 获取MathType对应的Latex公式 def get_latex_list(docx_file): # 获取当前目录的父级目录 @@ -18,13 +19,13 @@ def get_latex_list(docx_file): res.append(line.strip()) return res + # 结合Pandoc和mtef-go的结果,合并成最终的输出文本 def get_docx_content_by_pandoc(docx_file): # 一、获取Latex公式列表 formula_list = get_latex_list(docx_file) - - # StringBuilder结果 - sb = [] + # 最后拼接的内容 + content = "" # output_file 设置为临时目录下的uuid.md temp_markdown = os.path.join(os.environ['TEMP'], uuid.uuid4().hex + '.md') # 调用pandoc将docx文件转换成markdown @@ -37,13 +38,11 @@ def get_docx_content_by_pandoc(docx_file): # 改进后的正则表达式,匹配更多格式的MathType公式 if re.search(r'!\[]\(media/image\d+\.\w+\)', line) or \ re.search(r'\.!\[]\(media/image\d+\.\w+\)\.', line): - sb.append(formula_list[idx]) + content = content + formula_list[idx] + "\n" idx = idx + 1 else: - sb.append(line.strip()) + content = content + line.strip() + "\n" # 删除临时文件 output_file os.remove(temp_markdown) - return sb - - + return content diff --git a/dsRag/Util/__pycache__/DocxUtil.cpython-310.pyc b/dsRag/Util/__pycache__/DocxUtil.cpython-310.pyc index fe0e16ee..ae1b8836 100644 Binary files a/dsRag/Util/__pycache__/DocxUtil.cpython-310.pyc and b/dsRag/Util/__pycache__/DocxUtil.cpython-310.pyc differ