diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c4e415f..9e4c220 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,7 +7,6 @@
-
@@ -33,40 +32,43 @@
- {
- "keyToString": {
- "DefaultHtmlFileTemplate": "HTML File",
- "JavaScript 调试.output.html (1).executor": "Run",
- "JavaScript 调试.output.html.executor": "Run",
- "JavaScript 调试.regex_中文.html.executor": "Run",
- "JavaScript 调试.test2_英文.html.executor": "Run",
- "JavaScript 调试.互联网认证授权机制_英文.html.executor": "Run",
- "ModuleVcsDetector.initialDetectionPerformed": "true",
- "Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run",
- "Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run",
- "Python.PDFtranslater (1).executor": "Run",
- "Python.PDFtranslater (2).executor": "Run",
- "Python.agent_utils.executor": "Run",
- "Python.convert.executor": "Run",
- "Python.markdown_splitter.executor": "Run",
- "Python.markdown_utils.executor": "Run",
- "Python.test.executor": "Run",
- "Python.test1.executor": "Run",
- "Python.test2.executor": "Run",
- "Python.translater.executor": "Debug",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.git.unshallow": "true",
- "git-widget-placeholder": "main",
- "last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/tests/resource",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "Errors",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -79,7 +81,7 @@
-
+
@@ -101,15 +103,15 @@
-
-
-
-
+
+
+
+
@@ -156,7 +158,7 @@
-
+
@@ -170,7 +172,7 @@
-
+
@@ -278,11 +280,11 @@
-
+
+
-
-
-
+
+
@@ -313,7 +315,8 @@
-
+
+
@@ -323,11 +326,12 @@
-
+
+
diff --git a/docutranslate/translater.py b/docutranslate/translater.py
index 205de34..e3ef745 100644
--- a/docutranslate/translater.py
+++ b/docutranslate/translater.py
@@ -53,7 +53,7 @@ class FileTranslater:
你是一个修正markdown文本的专家。
# 工作
找到markdown片段的不合理之处,对于缺失的句子,应该查看缺失的语句是否可能被错误的放在了其他位置,并通过重组段落、去掉异常字词修复不合理之处。
-尽量忠实于原文。形如的占位符不要改变。latex不要改变。
+尽量忠实于原文。形如的占位符不要改变。code和latex保持原文。
# 输出
修正后的markdown纯文本
# 示例
@@ -86,7 +86,7 @@ Blockchain's origination was Bitcoin, the most successful of the digital currenc
将输入的markdown文本翻译成{0}。
尽量忠实于原文(如空行)。
形如的占位符不要改变。
-code和formula保持原文。
+code和latex保持原文。
# 输出
翻译后的markdown纯文本
# 示例
@@ -97,12 +97,12 @@ hello, what's your name?
你好,你叫什么名字?\no_think""".format(to_lang)
return agent
- def read_pdf_as_markdown(self, pdf: Path |str|None = None, formula=False, code=False, save=False):
+ def read_pdf_as_markdown(self, pdf: Path | str | None = None, formula=False, code=False, save=False):
print("正在将pdf转换为markdown")
if pdf is None:
pdf = self.file_path
- if isinstance(pdf,str):
- pdf=Path(pdf)
+ if isinstance(pdf, str):
+ pdf = Path(pdf)
self.markdown = pdf2markdown_embed_images(pdf, formula, code)
print("pdf已转换")
if save:
@@ -151,6 +151,9 @@ hello, what's your name?
print(f"文件已写入{full_name}")
return self
+ def export_to_markdown(self):
+ return self.markdown
+
def save_as_html(self, filename: str | Path = "output.html", output_dir: str | Path = "./output"):
if isinstance(filename, str):
filename = Path(filename)
@@ -160,13 +163,20 @@ hello, what's your name?
# 确保输出目录存在
output_dir.mkdir(parents=True, exist_ok=True)
full_name = output_dir / filename
- markdowner = markdown2.Markdown(extras=['tables', 'fenced-code-blocks', 'mermaid',"code-friendly"])
+ html = self.export_to_html(str(filename.resolve().stem))
+ with open(full_name, "w") as file:
+ file.write(html)
+ print(f"文件已写入{full_name}")
+ return self
+
+ def export_to_html(self, title="title") -> str:
+ markdowner = markdown2.Markdown(extras=['tables', 'fenced-code-blocks', 'mermaid', "code-friendly"])
html = f"""
- {filename}
+ {title}