|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
import re
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
def html_to_word_pandoc(html_file, output_file):
|
|
|
|
|
subprocess.run(['pandoc', html_file, '-o', output_file])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# docx 转 markdown
|
|
|
|
|
def docx_to_markdown_pandoc(docx_file, output_file):
|
|
|
|
|
subprocess.run(['pandoc', docx_file, '-f', 'docx', '-t', 'markdown', '-o', output_file])
|
|
|
|
|
|
|
|
|
@ -16,7 +16,7 @@ docx_to_markdown_pandoc(docx_file, output_file)
|
|
|
|
|
finalFile = "c:/new.txt"
|
|
|
|
|
|
|
|
|
|
# 读取然后修改内容,输出到新的文件
|
|
|
|
|
idx=0
|
|
|
|
|
idx = 0
|
|
|
|
|
with open(finalFile, 'w', encoding='utf-8') as f1:
|
|
|
|
|
with open(output_file, 'r', encoding='utf-8') as f:
|
|
|
|
|
for line in f:
|
|
|
|
@ -24,11 +24,13 @@ with open(finalFile, 'w', encoding='utf-8') as f1:
|
|
|
|
|
# 改进后的正则表达式,匹配更多格式的MathType公式
|
|
|
|
|
if re.search(r'!\[]\(media/image\d+\.\w+\)', line) or \
|
|
|
|
|
re.search(r'\.!\[]\(media/image\d+\.\w+\)\.', line):
|
|
|
|
|
idx=idx+1
|
|
|
|
|
f1.write("【MathType"+str(idx)+"】\n")
|
|
|
|
|
idx = idx + 1
|
|
|
|
|
f1.write("【MathType" + str(idx) + "】\n")
|
|
|
|
|
else:
|
|
|
|
|
f1.write(line.strip()+"\n")
|
|
|
|
|
f1.write(line.strip() + "\n")
|
|
|
|
|
# 删除临时文件 output_file
|
|
|
|
|
os.remove(output_file)
|
|
|
|
|
|
|
|
|
|
# 输出finalFile
|
|
|
|
|
with open(finalFile, 'r', encoding='utf-8') as f:
|
|
|
|
|
print(f.read())
|
|
|
|
|
print(f.read())
|
|
|
|
|