优化html模板与ai提示词

This commit is contained in:
xunbu
2025-05-16 18:38:19 +08:00
parent a1d6725321
commit e46c2664dc
3 changed files with 64 additions and 191 deletions

104
.idea/workspace.xml generated
View File

@@ -5,17 +5,9 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment=""> <list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment="">
<change afterPath="$PROJECT_DIR$/LICENSE" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/agents/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/agent_async.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/agents/agent.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/agent_sync.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/agent_thread.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/markdown_agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/agents/markdown_agent.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/agents/markdown_agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/agents/markdown_agent.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/app.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/app.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/translater.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/utils/convert.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/utils/convert.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pyproject.toml" beforeDir="false" afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -41,54 +33,54 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"DefaultHtmlFileTemplate": "HTML File", &quot;DefaultHtmlFileTemplate&quot;: &quot;HTML File&quot;,
"JavaScript 调试.output.html (1).executor": "Run", &quot;JavaScript 调试.output.html (1).executor&quot;: &quot;Run&quot;,
"JavaScript 调试.output.html.executor": "Run", &quot;JavaScript 调试.output.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.regex.md_中文.html.executor": "Run", &quot;JavaScript 调试.regex.md_中文.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.regex_中文.html.executor": "Run", &quot;JavaScript 调试.regex_中文.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.test2.html.executor": "Run", &quot;JavaScript 调试.test2.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.test2_英文.html.executor": "Run", &quot;JavaScript 调试.test2_英文.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.test4-1_中文.html.executor": "Run", &quot;JavaScript 调试.test4-1_中文.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.互联网认证授权机制.html.executor": "Run", &quot;JavaScript 调试.互联网认证授权机制.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.互联网认证授权机制_英文.html.executor": "Run", &quot;JavaScript 调试.互联网认证授权机制_英文.html.executor&quot;: &quot;Run&quot;,
"JavaScript 调试.毕业论文_英文.html.executor": "Run", &quot;JavaScript 调试.毕业论文_英文.html.executor&quot;: &quot;Run&quot;,
"ModuleVcsDetector.initialDetectionPerformed": "true", &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
"Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run", &quot;Python 测试.Python 测试 (markdown_mask.py 内).executor&quot;: &quot;Run&quot;,
"Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run", &quot;Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor&quot;: &quot;Run&quot;,
"Python.PDFtranslater (1).executor": "Run", &quot;Python.PDFtranslater (1).executor&quot;: &quot;Run&quot;,
"Python.PDFtranslater (2).executor": "Run", &quot;Python.PDFtranslater (2).executor&quot;: &quot;Run&quot;,
"Python.agent.executor": "Debug", &quot;Python.agent.executor&quot;: &quot;Debug&quot;,
"Python.agent_utils.executor": "Run", &quot;Python.agent_utils.executor&quot;: &quot;Run&quot;,
"Python.app (1).executor": "Run", &quot;Python.app (1).executor&quot;: &quot;Run&quot;,
"Python.app.executor": "Run", &quot;Python.app.executor&quot;: &quot;Run&quot;,
"Python.app2.executor": "Run", &quot;Python.app2.executor&quot;: &quot;Run&quot;,
"Python.app_test (1).executor": "Run", &quot;Python.app_test (1).executor&quot;: &quot;Run&quot;,
"Python.convert.executor": "Run", &quot;Python.convert.executor&quot;: &quot;Run&quot;,
"Python.markdown_splitter.executor": "Debug", &quot;Python.markdown_splitter.executor&quot;: &quot;Debug&quot;,
"Python.markdown_utils.executor": "Run", &quot;Python.markdown_utils.executor&quot;: &quot;Run&quot;,
"Python.test.executor": "Run", &quot;Python.test.executor&quot;: &quot;Run&quot;,
"Python.test1.executor": "Run", &quot;Python.test1.executor&quot;: &quot;Run&quot;,
"Python.test2.executor": "Run", &quot;Python.test2.executor&quot;: &quot;Run&quot;,
"Python.test3.executor": "Run", &quot;Python.test3.executor&quot;: &quot;Run&quot;,
"Python.test4.executor": "Run", &quot;Python.test4.executor&quot;: &quot;Run&quot;,
"Python.translater.executor": "Run", &quot;Python.translater.executor&quot;: &quot;Run&quot;,
"Python.切分测试.executor": "Run", &quot;Python.切分测试.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true", &quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/docutranslate/agents", &quot;last_opened_file_path&quot;: &quot;C:/Users/jxgm/Desktop/FileTranslate/docutranslate/agents&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"settings.editor.selected.configurable": "preferences.pluginManager", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\jxgm\Desktop\FileTranslate\docutranslate\agents" /> <recent name="C:\Users\jxgm\Desktop\FileTranslate\docutranslate\agents" />
@@ -634,7 +626,7 @@
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/filetranslate$app_test__1_.coverage" NAME="app_test (1) 覆盖结果" MODIFIED="1747390450384" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" /> <SUITE FILE_PATH="coverage/filetranslate$app_test__1_.coverage" NAME="app_test (1) 覆盖结果" MODIFIED="1747391624450" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" />
<SUITE FILE_PATH="coverage/filetranslate$test.coverage" NAME="test 覆盖结果" MODIFIED="1747301959211" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" /> <SUITE FILE_PATH="coverage/filetranslate$test.coverage" NAME="test 覆盖结果" MODIFIED="1747301959211" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/tests" />
<SUITE FILE_PATH="coverage/filetranslate$convert.coverage" NAME="convert 覆盖结果" MODIFIED="1746963490689" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/docutranslate/utils" /> <SUITE FILE_PATH="coverage/filetranslate$convert.coverage" NAME="convert 覆盖结果" MODIFIED="1746963490689" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/docutranslate/utils" />
<SUITE FILE_PATH="coverage/PDFtranslate$PDFtranslater__1_.coverage" NAME="PDFtranslater (1) 覆盖结果" MODIFIED="1746633258205" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/pdftranslate_packages" /> <SUITE FILE_PATH="coverage/PDFtranslate$PDFtranslater__1_.coverage" NAME="PDFtranslater (1) 覆盖结果" MODIFIED="1746633258205" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/pdftranslate_packages" />

View File

@@ -67,10 +67,10 @@ hello<ph-aaaaaa>, what's your name?
## 公式要为合法latex行内公式使用$包裹) ## 公式要为合法latex行内公式使用$包裹)
输入: 输入:
The equation is E=mc 2. This is famous. The equation is E=mc 2. This is famous.
{{c_0,c_1,c^2}}is a set. ({{c_0,c_1,c^2}})is a set.
输出: 输出:
这个方程是 $E=mc^2$。这很有名。 这个方程是 $E=mc^2$。这很有名。
{{$c_0$,$c_1$,$c^2$}}是一个集合。 ${{c_0,c_1,c^2}}$是一个集合。
## 引用的参考文献要保持原文不要翻译 ## 引用的参考文献要保持原文不要翻译
输入:【假设目标语言为中文】 输入:【假设目标语言为中文】
[2] M. Castro, B. Liskov, et al. Practical byzantine fault tolerance. In OSDI, [2] M. Castro, B. Liskov, et al. Practical byzantine fault tolerance. In OSDI,

View File

@@ -25,31 +25,14 @@ HTML_TEMPLATE = """
<title>DocuTranslate</title> <title>DocuTranslate</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css">
<style> <style>
:root {
--primary-color: #1e88e5;
--border-radius: 0.25rem;
}
body { body {
padding: 20px; padding: 20px;
background-color: #f9f9f9;
} }
.container { .container {
max-width: 800px; max-width: 800px;
margin: auto; margin: auto;
background-color: white; padding: 1rem;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}
h1 {
font-size: 1.8rem;
margin-bottom: 1.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
} }
.log-area { .log-area {
@@ -59,33 +42,22 @@ HTML_TEMPLATE = """
height: 200px; height: 200px;
overflow-y: scroll; overflow-y: scroll;
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-all;
font-family: monospace; font-family: monospace;
font-size: 0.85em;
line-height: 1.4;
margin-top: 1rem; margin-top: 1rem;
} }
.error-message { .error-message {
color: #d32f2f; color: #d32f2f;
font-weight: 500;
} }
.success-message { .success-message {
color: #2e7d32; color: #2e7d32;
font-weight: 500;
} }
.form-group { .form-group {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
.form-group label {
margin-bottom: 0.2rem;
font-weight: 500;
font-size: 0.9rem;
}
.form-grid { .form-grid {
display: grid; display: grid;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
@@ -100,31 +72,9 @@ HTML_TEMPLATE = """
} }
details { details {
background: transparent;
border: none;
box-shadow: none;
padding: 0;
border-bottom: 1px solid #eee;
margin-bottom: 1rem; margin-bottom: 1rem;
} }
summary {
font-weight: 500;
padding: 0.5rem 0;
}
details[open] > summary {
border-bottom: none;
margin-bottom: 0;
}
.checkbox-label {
display: flex;
align-items: center;
margin-right: 1rem;
margin-bottom: 0.5rem;
}
.checkbox-group { .checkbox-group {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
@@ -142,46 +92,8 @@ HTML_TEMPLATE = """
margin-top: 1rem; margin-top: 1rem;
} }
.section-header { .hidden {
display: flex; display: none !important;
align-items: center;
margin-bottom: 0.5rem;
font-size: 1.1rem;
font-weight: 500;
}
select, input[type="text"], input[type="password"], input[type="file"] {
padding: 0.5rem;
border: 1px solid #ddd;
background-color: white;
}
button, a[role="button"] {
padding: 0.5rem 1rem;
}
.options-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
margin-bottom: 1rem;
}
@media print {
.no-print {
display: none !important;
}
body {
padding: 0;
background-color: white;
}
.container {
box-shadow: none;
max-width: 100%;
padding: 0;
}
} }
.modal { .modal {
@@ -197,7 +109,6 @@ HTML_TEMPLATE = """
} }
.modal-content { .modal-content {
position: relative;
background-color: #fff; background-color: #fff;
margin: 2% auto; margin: 2% auto;
padding: 20px; padding: 20px;
@@ -205,27 +116,9 @@ HTML_TEMPLATE = """
max-width: 900px; max-width: 900px;
max-height: 90vh; max-height: 90vh;
border-radius: 8px; border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
overflow: auto; overflow: auto;
} }
.close-modal {
position: absolute;
top: 10px;
right: 10px;
font-size: 24px;
font-weight: bold;
color: #666;
cursor: pointer;
}
.modal-actions {
display: flex;
justify-content: flex-end;
margin-top: 20px;
gap: 10px;
}
#previewFrame { #previewFrame {
width: 100%; width: 100%;
min-height: 500px; min-height: 500px;
@@ -236,23 +129,15 @@ HTML_TEMPLATE = """
display: none; display: none;
} }
.hidden {
display: none !important;
}
@media (max-width: 768px) { @media (max-width: 768px) {
.form-grid, .options-grid { .form-grid {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.container {
padding: 1rem;
}
} }
</style> </style>
</head> </head>
<body> <body>
<main class="container no-print"> <main class="container">
<h1> <h1>
<a href="https://github.com/xunbu/docutranslate" target="_blank">DocuTranslate</a> <a href="https://github.com/xunbu/docutranslate" target="_blank">DocuTranslate</a>
</h1> </h1>
@@ -295,7 +180,7 @@ HTML_TEMPLATE = """
<label for="file">文档选择</label> <label for="file">文档选择</label>
<input type="file" id="file" name="file" required> <input type="file" id="file" name="file" required>
</div> </div>
<div class="options-grid"> <div class="form-grid">
<div class="form-group"> <div class="form-group">
<label for="to_lang">目标语言</label> <label for="to_lang">目标语言</label>
<select id="to_lang" name="to_lang"> <select id="to_lang" name="to_lang">
@@ -316,14 +201,10 @@ HTML_TEMPLATE = """
<div class="form-group"> <div class="form-group">
<label>高级选项</label> <label>高级选项</label>
<div class="checkbox-group"> <div class="checkbox-group">
<label class="checkbox-label" for="formula_ocr"><input type="checkbox" <label for="formula_ocr"><input type="checkbox" id="formula_ocr" name="formula_ocr">公式识别</label>
id="formula_ocr" <label for="code_ocr"><input type="checkbox" id="code_ocr" name="code_ocr">代码识别</label>
name="formula_ocr">公式识别</label> <label for="refine_markdown"><input type="checkbox" id="refine_markdown"
<label class="checkbox-label" for="code_ocr"><input type="checkbox" id="code_ocr" name="refine_markdown">修正文本</label>
name="code_ocr">代码识别</label>
<label class="checkbox-label" for="refine_markdown"><input type="checkbox"
id="refine_markdown"
name="refine_markdown">修正文本(耗时,有概率修复文本流和公式识别错误)</label>
</div> </div>
</div> </div>
</div> </div>
@@ -332,22 +213,22 @@ HTML_TEMPLATE = """
<div id="resultArea"> <div id="resultArea">
<p id="statusMessage"></p> <p id="statusMessage"></p>
<div id="downloadButtons" class="button-group"> <div id="downloadButtons" class="button-group">
<div class="section-header">翻译结果</div> <h4>翻译结果</h4>
<a id="downloadMarkdown" href="#" role="button" class="outline">下载 Markdown</a> <a id="downloadMarkdown" href="#" role="button" class="outline">下载 Markdown</a>
<a id="downloadHtml" href="#" role="button" class="outline">下载 HTML</a> <a id="downloadHtml" href="#" role="button" class="outline">下载 HTML</a>
<button id="downloadPdf" class="outline">下载 PDF</button> <button id="downloadPdf" class="outline">下载 PDF</button>
<button id="previewHtml" class="outline">预览</button> <button id="previewHtml" class="outline">预览</button>
</div> </div>
</div> </div>
<div class="section-header" style="margin-top: 1.5rem;">运行日志</div> <h4 style="margin-top: 1.5rem;">运行日志</h4>
<div class="log-area" id="logArea"></div> <div class="log-area" id="logArea"></div>
</main> </main>
<div id="previewModal" class="modal"> <div id="previewModal" class="modal">
<div class="modal-content"> <div class="modal-content">
<span class="close-modal" id="closeModalBtn">×</span> <span id="closeModalBtn" style="cursor:pointer; float:right;">×</span>
<h3>HTML 预览</h3> <h3>HTML 预览</h3>
<iframe id="previewFrame"></iframe> <iframe id="previewFrame"></iframe>
<div class="modal-actions"> <div class="button-group">
<button id="printFromPreview" class="primary">打印/保存为PDF</button> <button id="printFromPreview" class="primary">打印/保存为PDF</button>
<button id="closePreviewBtn" class="outline">关闭</button> <button id="closePreviewBtn" class="outline">关闭</button>
</div> </div>