撤回了mathjax本地化

This commit is contained in:
xunbu
2025-05-26 12:39:45 +08:00
parent 0b40d96222
commit 76e56532e2
8 changed files with 95 additions and 92 deletions

124
.idea/workspace.xml generated
View File

@@ -5,18 +5,14 @@
</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$/docutranslate/static/MathJax.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/docutranslate/static/mermaid.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/docutranslate/template/__init__.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/docutranslate/template/markdown.html" 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$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/__init__.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/__init__.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/agents/agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/agents/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/global_values/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/global_values/__init__.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/static/MathJax.js" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/static/MathJax.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/static/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/static/index.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/static/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/static/index.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/template/markdown.html" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/template/markdown.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/translater.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/translater.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" />
@@ -47,62 +43,62 @@
<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">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;DefaultHtmlFileTemplate&quot;: &quot;HTML File&quot;, "DefaultHtmlFileTemplate": "HTML File",
&quot;JavaScript 调试.output.html (1).executor&quot;: &quot;Run&quot;, "JavaScript 调试.output.html (1).executor": "Run",
&quot;JavaScript 调试.output.html.executor&quot;: &quot;Run&quot;, "JavaScript 调试.output.html.executor": "Run",
&quot;JavaScript 调试.regex.md_中文.html.executor&quot;: &quot;Run&quot;, "JavaScript 调试.regex.md_中文.html.executor": "Run",
&quot;JavaScript 调试.regex_中文.html.executor&quot;: &quot;Run&quot;, "JavaScript 调试.regex_中文.html.executor": "Run",
&quot;JavaScript 调试.test.html.executor&quot;: &quot;Run&quot;, "JavaScript 调试.test.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 调试.test2_英文.html.executor": "Run",
&quot;JavaScript 调试.test4-1_中文.html.executor&quot;: &quot;Run&quot;, "JavaScript 调试.test4-1_中文.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;, "JavaScript 调试.毕业论文_英文.html.executor": "Run",
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;, "ModuleVcsDetector.initialDetectionPerformed": "true",
&quot;Python 测试.Python 测试 (markdown_mask.py 内).executor&quot;: &quot;Run&quot;, "Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run",
&quot;Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor&quot;: &quot;Run&quot;, "Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run",
&quot;Python 测试.pytest (test_html.py 内).executor&quot;: &quot;Run&quot;, "Python 测试.pytest (test_html.py 内).executor": "Run",
&quot;Python.1test.executor&quot;: &quot;Run&quot;, "Python.1test.executor": "Run",
&quot;Python.2test2 (1).executor&quot;: &quot;Run&quot;, "Python.2test2 (1).executor": "Run",
&quot;Python.PDFtranslater (1).executor&quot;: &quot;Run&quot;, "Python.PDFtranslater (1).executor": "Run",
&quot;Python.PDFtranslater (2).executor&quot;: &quot;Run&quot;, "Python.PDFtranslater (2).executor": "Run",
&quot;Python.agent.executor&quot;: &quot;Debug&quot;, "Python.agent.executor": "Debug",
&quot;Python.agent_utils.executor&quot;: &quot;Run&quot;, "Python.agent_utils.executor": "Run",
&quot;Python.app (1).executor&quot;: &quot;Run&quot;, "Python.app (1).executor": "Run",
&quot;Python.app.executor&quot;: &quot;Run&quot;, "Python.app.executor": "Run",
&quot;Python.app2.executor&quot;: &quot;Run&quot;, "Python.app2.executor": "Run",
&quot;Python.app_test (1).executor&quot;: &quot;Run&quot;, "Python.app_test (1).executor": "Run",
&quot;Python.convert.executor&quot;: &quot;Run&quot;, "Python.convert.executor": "Run",
&quot;Python.converter_docling.executor&quot;: &quot;Run&quot;, "Python.converter_docling.executor": "Run",
&quot;Python.converter_mineru.executor&quot;: &quot;Run&quot;, "Python.converter_mineru.executor": "Run",
&quot;Python.markdown_splitter.executor&quot;: &quot;Debug&quot;, "Python.markdown_splitter.executor": "Debug",
&quot;Python.markdown_utils.executor&quot;: &quot;Run&quot;, "Python.markdown_utils.executor": "Run",
&quot;Python.test.executor&quot;: &quot;Run&quot;, "Python.test.executor": "Run",
&quot;Python.test1.executor&quot;: &quot;Run&quot;, "Python.test1.executor": "Run",
&quot;Python.test2.executor&quot;: &quot;Run&quot;, "Python.test2.executor": "Run",
&quot;Python.test3.executor&quot;: &quot;Run&quot;, "Python.test3.executor": "Run",
&quot;Python.test4.executor&quot;: &quot;Run&quot;, "Python.test4.executor": "Run",
&quot;Python.testhtml.executor&quot;: &quot;Run&quot;, "Python.testhtml.executor": "Run",
&quot;Python.translater.executor&quot;: &quot;Run&quot;, "Python.translater.executor": "Run",
&quot;Python.切分测试.executor&quot;: &quot;Run&quot;, "Python.切分测试.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager&quot;: &quot;true&quot;, "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager": "true",
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, "RunOnceActivity.git.unshallow": "true",
&quot;git-widget-placeholder&quot;: &quot;dev&quot;, "git-widget-placeholder": "main",
&quot;last_opened_file_path&quot;: &quot;C:/Users/jxgm/Desktop/translate/docutranslate&quot;, "last_opened_file_path": "C:/Users/jxgm/Desktop/translate/docutranslate",
&quot;list.type.of.created.stylesheet&quot;: &quot;CSS&quot;, "list.type.of.created.stylesheet": "CSS",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.pluginManager",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\jxgm\Desktop\translate\docutranslate" /> <recent name="C:\Users\jxgm\Desktop\translate\docutranslate" />
@@ -642,14 +638,14 @@
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" suspend="THREAD" type="python-line"> <line-breakpoint enabled="true" suspend="THREAD" type="python-line">
<url>file://$PROJECT_DIR$/docutranslate/translater.py</url> <url>file://$PROJECT_DIR$/docutranslate/translater.py</url>
<line>250</line> <line>240</line>
<option name="timeStamp" value="2" /> <option name="timeStamp" value="2" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>
</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="1748227675220" 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="1748234136289" 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="1747472297913" 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="1747472297913" 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

@@ -188,7 +188,6 @@ translater = FileTranslater(base_url="<baseurl>", # 默认的模型baseurl
docling_artifact=None, # 使用提前下载好的docling模型 docling_artifact=None, # 使用提前下载好的docling模型
convert_engin="mineru", # 可选minerU或docling convert_engin="mineru", # 可选minerU或docling
mineru_token="<mineru-token>", # minerU的token使用minerU时必填 mineru_token="<mineru-token>", # minerU的token使用minerU时必填
tips=True # 开场提示
) )
``` ```

View File

@@ -1,4 +1,4 @@
__version__="0.2.25" __version__="0.2.26"

View File

@@ -119,7 +119,6 @@ async def _perform_translation(params: Dict[str, Any], file_contents: bytes, ori
model_id=params['model_id'], model_id=params['model_id'],
convert_engin=params['convert_engin'], convert_engin=params['convert_engin'],
mineru_token=params['mineru_token'], mineru_token=params['mineru_token'],
tips=False # Assuming tips are not needed for server-side processing
) )
await ft.translate_bytes_async( await ft.translate_bytes_async(
name=original_filename, name=original_filename,
@@ -376,10 +375,12 @@ async def get_logs_from_queue():
async def download_markdown(filename_with_ext: str): async def download_markdown(filename_with_ext: str):
if not current_state["download_ready"] or not current_state["markdown_content"] or not current_state[ if not current_state["download_ready"] or not current_state["markdown_content"] or not current_state[
"original_filename_stem"]: "original_filename_stem"]:
print("Markdown 内容尚未准备好或不可用。")
raise HTTPException(status_code=404, detail="Markdown 内容尚未准备好或不可用。") raise HTTPException(status_code=404, detail="Markdown 内容尚未准备好或不可用。")
requested_stem = Path(filename_with_ext).stem.replace("_translated", "") requested_stem = Path(filename_with_ext).stem.replace("_translated", "")
if requested_stem != current_state["original_filename_stem"]: if requested_stem != current_state["original_filename_stem"]:
print("请求的文件名与当前结果不符。")
raise HTTPException(status_code=404, detail="请求的文件名与当前结果不符。") raise HTTPException(status_code=404, detail="请求的文件名与当前结果不符。")
actual_filename = f"{current_state['original_filename_stem']}_translated.md" actual_filename = f"{current_state['original_filename_stem']}_translated.md"

File diff suppressed because one or more lines are too long

View File

@@ -699,7 +699,6 @@
try { try {
const response = await fetch("/meta") const response = await fetch("/meta")
let meta = await response.json(); let meta = await response.json();
console.log(meta)
versionDisplay.textContent = `版本号${meta.version}`; versionDisplay.textContent = `版本号${meta.version}`;
} catch (error) { } catch (error) {
console.warn("获取版本号失败", error); console.warn("获取版本号失败", error);

View File

@@ -10,14 +10,24 @@
font-size: 15px; font-size: 15px;
} }
</style> </style>
<script type="text/x-mathjax-config"> <script>
MathJax.Hub.Config({ MathJax = {
messageStyle: "none", loader: {load: ['[tex]/ams']},
tex2jax: { tex: {
inlineMath: [ ['$','$'], ["\\\\(","\\\\)"] ], inlineMath: [['$', '$'], ['\\(', '\\)']],
processEscapes: true displayMath: [['$$', '$$'], ['\\[', '\\]']],
} processEscapes: true,
}); formatError: (error) => {
}, // 空函数,不显示任何错误
packages: {'[+]': ['ams']}, // 启用AMS宏包
autoload: {color: [], colorv2: ['color']} // 颜色支持
},
options: {
renderActions: {
addMenu: [0, '', '']
}
},
};
</script> </script>
{{MathJax}} {{MathJax}}
</head> </head>

View File

@@ -22,8 +22,7 @@ class FileTranslater:
max_concurrent=20, timeout=2000, max_concurrent=20, timeout=2000,
convert_engin: Literal["docling", "mineru"] = "mineru", convert_engin: Literal["docling", "mineru"] = "mineru",
docling_artifact: Path | str | None = None, docling_artifact: Path | str | None = None,
mineru_token: str = None, mineru_token: str = None):
tips=True):
self.convert_engin = convert_engin self.convert_engin = convert_engin
self.mineru_token = mineru_token.strip() if mineru_token is not None else None self.mineru_token = mineru_token.strip() if mineru_token is not None else None
if isinstance(file_path, str): if isinstance(file_path, str):
@@ -46,15 +45,6 @@ class FileTranslater:
translater_logger.info("检测到docling_artifact文件夹") translater_logger.info("检测到docling_artifact文件夹")
self.docling_artifact = artifact_path self.docling_artifact = artifact_path
self.timeout = timeout self.timeout = timeout
if tips:
print("""
=======
[docutranslate](https://github.com/xunbu/docutranslate)
>以下操作会自动从[huggingface](https://huggingface.co)下载模型windows需要使用**管理员模式**打开IDE运行脚本并按需换源
- 第一次使用该库读取、翻译非markdown文本
- 第一次使用该库的公式识别或代码识别功能
=======
""")
def _markdown_format(self): def _markdown_format(self):
# 该方法还需要改进 # 该方法还需要改进
@@ -305,18 +295,20 @@ class FileTranslater:
def export_to_html(self, title="title") -> str: def export_to_html(self, title="title") -> str:
markdowner = markdown2.Markdown(extras=['tables', 'fenced-code-blocks', 'mermaid', "code-friendly"]) markdowner = markdown2.Markdown(extras=['tables', 'fenced-code-blocks', 'mermaid', "code-friendly"])
# TODO:实现完全本地化css和js
# language=html # language=html
pico=Path(__file__).parent / "static" / "pico.css" pico=Path(__file__).parent / "static" / "pico.css"
html = Path(__file__).parent / "template" / "markdown.html" html = Path(__file__).parent / "template" / "markdown.html"
MathJax=Path(__file__).parent / "static" / "MathJax.js" MathJax=Path(__file__).parent / "static" / "MathJax.js"
mermaid=Path(__file__).parent / "static" / "mermaid.js" mermaid=Path(__file__).parent / "static" / "mermaid.js"
#TODO:实现MathJax本地化
render = jinja2.Template(html.read_text()).render( render = jinja2.Template(html.read_text()).render(
title=title, title=title,
pico=f"<style>{pico.read_text()}</style>", pico=f"<style>\n{pico.read_text()}\n</style>",
# markdown=markdowner.convert(self.markdown),
markdown=markdowner.convert(self.markdown.replace("\\", "\\\\")), markdown=markdowner.convert(self.markdown.replace("\\", "\\\\")),
MathJax=f"<script>{MathJax.read_text()}</script>", MathJax=r'<script src=" https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-mml-chtml.min.js "></script>',
mermaid=f"<script>{mermaid.read_text()}</script>", # MathJax=f'<script>\n{MathJax.read_text()}\n</script>',
mermaid=f"<script>\n{mermaid.read_text()}\n</script>",
) )
return render return render