feat: localize parameter names in export_to_word_cn.py and bump to v0.4.1

This commit is contained in:
fujie
2026-01-05 23:37:14 +08:00
parent 58452a8441
commit 4b9790df00
7 changed files with 124 additions and 124 deletions

View File

@@ -1,7 +1,7 @@
# Export to Word # Export to Word
<span class="category-badge action">Action</span> <span class="category-badge action">Action</span>
<span class="version-badge">v0.4.0</span> <span class="version-badge">v0.4.1</span>
Export conversation to Word (.docx) with **syntax highlighting**, **native math equations**, **Mermaid diagrams**, **citations**, and **enhanced table formatting**. Export conversation to Word (.docx) with **syntax highlighting**, **native math equations**, **Mermaid diagrams**, **citations**, and **enhanced table formatting**.

View File

@@ -1,7 +1,7 @@
# Export to Word导出为 Word # Export to Word导出为 Word
<span class="category-badge action">Action</span> <span class="category-badge action">Action</span>
<span class="version-badge">v0.4.0</span> <span class="version-badge">v0.4.1</span>
将当前对话导出为完美格式的 Word 文档,支持**代码语法高亮**、**原生数学公式**、**Mermaid 图表**、**引用资料**以及**增强表格**渲染。 将当前对话导出为完美格式的 Word 文档,支持**代码语法高亮**、**原生数学公式**、**Mermaid 图表**、**引用资料**以及**增强表格**渲染。
@@ -33,35 +33,35 @@ Export to Word 插件会把聊天消息从 Markdown 转成精致的 Word 文档
| Valve | 说明 | 默认值 | | Valve | 说明 | 默认值 |
| :--- | :--- | :--- | | :--- | :--- | :--- |
| `TITLE_SOURCE` | 文档标题/文件名的来源。选项:`chat_title` (对话标题), `ai_generated` (AI 生成), `markdown_title` (Markdown 标题) | `chat_title` | | `文档标题来源` | 文档标题/文件名的来源。选项:`chat_title` (对话标题), `ai_generated` (AI 生成), `markdown_title` (Markdown 标题) | `chat_title` |
| `MAX_EMBED_IMAGE_MB` | 嵌入图片的最大大小 (MB)。 | `20` | | `最大嵌入图片大小MB` | 嵌入图片的最大大小 (MB)。 | `20` |
| `UI_LANGUAGE` | 界面语言。选项:`en` (英语), `zh` (中文)。 | `zh` | | `界面语言` | 界面语言。选项:`en` (英语), `zh` (中文)。 | `zh` |
| `FONT_LATIN` | 英文字体名称。 | `Calibri` | | `英文字体` | 英文字体名称。 | `Calibri` |
| `FONT_ASIAN` | 中文字体名称。 | `SimSun` | | `中文字体` | 中文字体名称。 | `SimSun` |
| `FONT_CODE` | 代码字体名称。 | `Consolas` | | `代码字体` | 代码字体名称。 | `Consolas` |
| `TABLE_HEADER_COLOR` | 表头背景色(十六进制,不带#)。 | `F2F2F2` | | `表头背景色` | 表头背景色(十六进制,不带#)。 | `F2F2F2` |
| `TABLE_ZEBRA_COLOR` | 表格隔行背景色(十六进制,不带#)。 | `FBFBFB` | | `表格隔行背景色` | 表格隔行背景色(十六进制,不带#)。 | `FBFBFB` |
| `MERMAID_JS_URL` | Mermaid.js 库的 URL。 | `https://cdn.jsdelivr.net/npm/mermaid@11.12.2/dist/mermaid.min.js` | | `Mermaid_JS地址` | Mermaid.js 库的 URL。 | `https://cdn.jsdelivr.net/npm/mermaid@11.12.2/dist/mermaid.min.js` |
| `MERMAID_JSZIP_URL` | JSZip 库的 URL用于 DOCX 操作)。 | `https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js` | | `JSZip库地址` | JSZip 库的 URL用于 DOCX 操作)。 | `https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js` |
| `MERMAID_PNG_SCALE` | Mermaid PNG 生成缩放比例(分辨率)。 | `3.0` | | `Mermaid_PNG缩放比例` | Mermaid PNG 生成缩放比例(分辨率)。 | `3.0` |
| `MERMAID_DISPLAY_SCALE` | Mermaid 在 Word 中的显示比例(视觉大小)。 | `1.0` | | `Mermaid显示比例` | Mermaid 在 Word 中的显示比例(视觉大小)。 | `1.0` |
| `MERMAID_OPTIMIZE_LAYOUT` | 优化 Mermaid 布局: 自动将 LR (左右) 转换为 TD (上下)。 | `False` | | `Mermaid布局优化` | 优化 Mermaid 布局: 自动将 LR (左右) 转换为 TD (上下)。 | `False` |
| `MERMAID_BACKGROUND` | Mermaid 图表背景色(如 `white`, `transparent`)。 | `transparent` | | `Mermaid背景色` | Mermaid 图表背景色(如 `white`, `transparent`)。 | `transparent` |
| `MERMAID_CAPTIONS_ENABLE` | 启用/禁用 Mermaid 图表的图注。 | `True` | | `启用Mermaid图注` | 启用/禁用 Mermaid 图表的图注。 | `True` |
| `MERMAID_CAPTION_STYLE` | Mermaid 图注的段落样式名称。 | `Caption` | | `Mermaid图注样式` | Mermaid 图注的段落样式名称。 | `Caption` |
| `MERMAID_CAPTION_PREFIX` | 图注前缀(如 '图')。留空则根据语言自动检测。 | `""` | | `Mermaid图注前缀` | 图注前缀(如 '图')。留空则根据语言自动检测。 | `""` |
| `MATH_ENABLE` | 启用 LaTeX 数学公式块转换。 | `True` | | `启用数学公式` | 启用 LaTeX 数学公式块转换。 | `True` |
| `MATH_INLINE_DOLLAR_ENABLE` | 启用行内 `$ ... $` 数学公式转换。 | `True` | | `启用行内公式` | 启用行内 `$ ... $` 数学公式转换。 | `True` |
### 用户级配置 (UserValves) ### 用户级配置 (UserValves)
用户可以在个人设置中覆盖以下配置: 用户可以在个人设置中覆盖以下配置:
- `TITLE_SOURCE` - `文档标题来源`
- `UI_LANGUAGE` - `界面语言`
- `FONT_LATIN`, `FONT_ASIAN`, `FONT_CODE` - `英文字体`, `中文字体`, `代码字体`
- `TABLE_HEADER_COLOR`, `TABLE_ZEBRA_COLOR` - `表头背景色`, `表格隔行背景色`
- `MERMAID_...` (部分 Mermaid 设置) - `Mermaid_...` (部分 Mermaid 设置)
- `MATH_...` (数学公式设置) - `启用数学公式`, `启用行内公式`
--- ---

View File

@@ -63,7 +63,7 @@ Actions are interactive plugins that:
Export the current conversation to a formatted Word doc with **syntax highlighting**, **native math equations**, **Mermaid diagrams**, **citations**, and **enhanced table formatting**. Export the current conversation to a formatted Word doc with **syntax highlighting**, **native math equations**, **Mermaid diagrams**, **citations**, and **enhanced table formatting**.
**Version:** 0.4.0 **Version:** 0.4.1
[:octicons-arrow-right-24: Documentation](export-to-word.md) [:octicons-arrow-right-24: Documentation](export-to-word.md)

View File

@@ -63,7 +63,7 @@ Actions 是交互式插件,能够:
将当前对话导出为完美格式的 Word 文档,支持**代码语法高亮**、**原生数学公式**、**Mermaid 图表**、**引用资料**以及**增强表格**渲染。 将当前对话导出为完美格式的 Word 文档,支持**代码语法高亮**、**原生数学公式**、**Mermaid 图表**、**引用资料**以及**增强表格**渲染。
**版本:** 0.4.0 **版本:** 0.4.1
[:octicons-arrow-right-24: 查看文档](export-to-word.md) [:octicons-arrow-right-24: 查看文档](export-to-word.md)

View File

@@ -20,28 +20,28 @@
您可以通过插件设置中的 **Valves** 按钮配置以下选项: 您可以通过插件设置中的 **Valves** 按钮配置以下选项:
- **TITLE_SOURCE**:选择文档标题/文件名的生成方式。 - **文档标题来源**:选择文档标题/文件名的生成方式。
- `chat_title`:使用对话标题(默认)。 - `chat_title`:使用对话标题(默认)。
- `ai_generated`:使用 AI 根据内容生成简短标题。 - `ai_generated`:使用 AI 根据内容生成简短标题。
- `markdown_title`:从 Markdown 内容中提取第一个一级或二级标题。 - `markdown_title`:从 Markdown 内容中提取第一个一级或二级标题。
- **MAX_EMBED_IMAGE_MB**:嵌入图片的最大大小 (MB)。默认:`20` - **最大嵌入图片大小MB**:嵌入图片的最大大小 (MB)。默认:`20`
- **UI_LANGUAGE**:界面语言,支持 `en` (英语) 和 `zh` (中文)。默认:`zh` - **界面语言**:界面语言,支持 `en` (英语) 和 `zh` (中文)。默认:`zh`
- **FONT_LATIN**:英文字体名称。默认:`Calibri` - **英文字体**:英文字体名称。默认:`Calibri`
- **FONT_ASIAN**:中文字体名称。默认:`SimSun` - **中文字体**:中文字体名称。默认:`SimSun`
- **FONT_CODE**:代码字体名称。默认:`Consolas` - **代码字体**:代码字体名称。默认:`Consolas`
- **TABLE_HEADER_COLOR**:表头背景色(十六进制,不带#)。默认:`F2F2F2` - **表头背景色**:表头背景色(十六进制,不带#)。默认:`F2F2F2`
- **TABLE_ZEBRA_COLOR**:表格隔行背景色(十六进制,不带#)。默认:`FBFBFB` - **表格隔行背景色**:表格隔行背景色(十六进制,不带#)。默认:`FBFBFB`
- **MERMAID_JS_URL**Mermaid.js 库的 URL。 - **Mermaid_JS地址**Mermaid.js 库的 URL。
- **MERMAID_JSZIP_URL**JSZip 库的 URL用于 DOCX 操作)。 - **JSZip库地址**JSZip 库的 URL用于 DOCX 操作)。
- **MERMAID_PNG_SCALE**Mermaid PNG 生成缩放比例(分辨率)。默认:`3.0` - **Mermaid_PNG缩放比例**Mermaid PNG 生成缩放比例(分辨率)。默认:`3.0`
- **MERMAID_DISPLAY_SCALE**Mermaid 在 Word 中的显示比例(视觉大小)。默认:`1.0` - **Mermaid显示比例**Mermaid 在 Word 中的显示比例(视觉大小)。默认:`1.0`
- **MERMAID_OPTIMIZE_LAYOUT**:自动将 LR左右流程图转换为 TD上下。默认`False` - **Mermaid布局优化**:自动将 LR左右流程图转换为 TD上下。默认`False`
- **MERMAID_BACKGROUND**Mermaid 图表背景色(如 `white`, `transparent`)。默认:`transparent` - **Mermaid背景色**Mermaid 图表背景色(如 `white`, `transparent`)。默认:`transparent`
- **MERMAID_CAPTIONS_ENABLE**:启用/禁用 Mermaid 图表的图注。默认:`True` - **启用Mermaid图注**:启用/禁用 Mermaid 图表的图注。默认:`True`
- **MERMAID_CAPTION_STYLE**Mermaid 图注的段落样式名称。默认:`Caption` - **Mermaid图注样式**Mermaid 图注的段落样式名称。默认:`Caption`
- **MERMAID_CAPTION_PREFIX**:图注前缀(如 '图')。留空则根据语言自动检测。 - **Mermaid图注前缀**:图注前缀(如 '图')。留空则根据语言自动检测。
- **MATH_ENABLE**:启用 LaTeX 数学公式块转换(`\[...\]``$$...$$`)。默认:`True` - **启用数学公式**:启用 LaTeX 数学公式块转换(`\[...\]``$$...$$`)。默认:`True`
- **MATH_INLINE_DOLLAR_ENABLE**:启用行内 `$ ... $` 数学公式转换。默认:`True` - **启用行内公式**:启用行内 `$ ... $` 数学公式转换。默认:`True`
## 支持的 Markdown 语法 ## 支持的 Markdown 语法
@@ -88,6 +88,10 @@
## 更新日志 ## 更新日志
### v0.4.1
- **中文参数名**: 将插件配置项名称和描述全部汉化,提升中文用户体验。
### v0.4.0 ### v0.4.0
- **多语言支持**: 新增界面语言切换(中文/英文),提示信息更友好。 - **多语言支持**: 新增界面语言切换(中文/英文),提示信息更友好。

View File

@@ -3,7 +3,7 @@ title: Export to Word (Enhanced)
author: Fu-Jie author: Fu-Jie
author_url: https://github.com/Fu-Jie author_url: https://github.com/Fu-Jie
funding_url: https://github.com/Fu-Jie/awesome-openwebui funding_url: https://github.com/Fu-Jie/awesome-openwebui
version: 0.4.0 version: 0.4.1
icon_url: data:image/svg+xml;base64,PHN2ZwogIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICB3aWR0aD0iMjQiCiAgaGVpZ2h0PSIyNCIKICB2aWV3Qm94PSIwIDAgMjQgMjQiCiAgZmlsbD0ibm9uZSIKICBzdHJva2U9ImN1cnJlbnRDb2xvciIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNNiAyMmEyIDIgMCAwIDEtMi0yVjRhMiAyIDAgMCAxIDItMmg4YTIuNCAyLjQgMCAwIDEgMS43MDQuNzA2bDMuNTg4IDMuNTg4QTIuNCAyLjQgMCAwIDEgMjAgOHYxMmEyIDIgMCAwIDEtMiAyeiIgLz4KICA8cGF0aCBkPSJNMTQgMnY1YTEgMSAwIDAgMCAxIDFoNSIgLz4KICA8cGF0aCBkPSJNMTAgOUg4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxM0g4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxN0g4IiAvPgo8L3N2Zz4K icon_url: data:image/svg+xml;base64,PHN2ZwogIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICB3aWR0aD0iMjQiCiAgaGVpZ2h0PSIyNCIKICB2aWV3Qm94PSIwIDAgMjQgMjQiCiAgZmlsbD0ibm9uZSIKICBzdHJva2U9ImN1cnJlbnRDb2xvciIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNNiAyMmEyIDIgMCAwIDEtMi0yVjRhMiAyIDAgMCAxIDItMmg4YTIuNCAyLjQgMCAwIDEgMS43MDQuNzA2bDMuNTg4IDMuNTg4QTIuNCAyLjQgMCAwIDEgMjAgOHYxMmEyIDIgMCAwIDEtMiAyeiIgLz4KICA8cGF0aCBkPSJNMTQgMnY1YTEgMSAwIDAgMCAxIDFoNSIgLz4KICA8cGF0aCBkPSJNMTAgOUg4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxM0g4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxN0g4IiAvPgo8L3N2Zz4K
requirements: python-docx, Pygments, latex2mathml, mathml2omml requirements: python-docx, Pygments, latex2mathml, mathml2omml
description: Export current conversation from Markdown to Word (.docx) with Mermaid diagrams rendered client-side (Mermaid.js, SVG+PNG), LaTeX math, real hyperlinks, improved tables, syntax highlighting, and blockquote support. description: Export current conversation from Markdown to Word (.docx) with Mermaid diagrams rendered client-side (Mermaid.js, SVG+PNG), LaTeX math, real hyperlinks, improved tables, syntax highlighting, and blockquote support.

View File

@@ -3,7 +3,7 @@ title: 导出为 Word (增强版)
author: Fu-Jie author: Fu-Jie
author_url: https://github.com/Fu-Jie author_url: https://github.com/Fu-Jie
funding_url: https://github.com/Fu-Jie/awesome-openwebui funding_url: https://github.com/Fu-Jie/awesome-openwebui
version: 0.4.0 version: 0.4.1
icon_url: data:image/svg+xml;base64,PHN2ZwogIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICB3aWR0aD0iMjQiCiAgaGVpZ2h0PSIyNCIKICB2aWV3Qm94PSIwIDAgMjQgMjQiCiAgZmlsbD0ibm9uZSIKICBzdHJva2U9ImN1cnJlbnRDb2xvciIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNNiAyMmEyIDIgMCAwIDEtMi0yVjRhMiAyIDAgMCAxIDItMmg4YTIuNCAyLjQgMCAwIDEgMS43MDQuNzA2bDMuNTg4IDMuNTg4QTIuNCAyLjQgMCAwIDEgMjAgOHYxMmEyIDIgMCAwIDEtMiAyeiIgLz4KICA8cGF0aCBkPSJNMTQgMnY1YTEgMSAwIDAgMCAxIDFoNSIgLz4KICA8cGF0aCBkPSJNMTAgOUg4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxM0g4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxN0g4IiAvPgo8L3N2Zz4K icon_url: data:image/svg+xml;base64,PHN2ZwogIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICB3aWR0aD0iMjQiCiAgaGVpZ2h0PSIyNCIKICB2aWV3Qm94PSIwIDAgMjQgMjQiCiAgZmlsbD0ibm9uZSIKICBzdHJva2U9ImN1cnJlbnRDb2xvciIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNNiAyMmEyIDIgMCAwIDEtMi0yVjRhMiAyIDAgMCAxIDItMmg4YTIuNCAyLjQgMCAwIDEgMS43MDQuNzA2bDMuNTg4IDMuNTg4QTIuNCAyLjQgMCAwIDEgMjAgOHYxMmEyIDIgMCAwIDEtMiAyeiIgLz4KICA8cGF0aCBkPSJNMTQgMnY1YTEgMSAwIDAgMCAxIDFoNSIgLz4KICA8cGF0aCBkPSJNMTAgOUg4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxM0g4IiAvPgogIDxwYXRoIGQ9Ik0xNiAxN0g4IiAvPgo8L3N2Zz4K
requirements: python-docx, Pygments, latex2mathml, mathml2omml requirements: python-docx, Pygments, latex2mathml, mathml2omml
description: 将对话导出为 Word (.docx),支持 Mermaid 图表 (客户端渲染 SVG+PNG)、LaTeX 数学公式、真实超链接、增强表格格式、代码高亮和引用块。 description: 将对话导出为 Word (.docx),支持 Mermaid 图表 (客户端渲染 SVG+PNG)、LaTeX 数学公式、真实超链接、增强表格格式、代码高亮和引用块。
@@ -135,147 +135,147 @@ class Action:
} }
class Valves(BaseModel): class Valves(BaseModel):
TITLE_SOURCE: str = Field( 文档标题来源: str = Field(
default="chat_title", default="chat_title",
description="Title Source: 'chat_title' (Chat Title), 'ai_generated' (AI Generated), 'markdown_title' (Markdown Title)", description="Title Source: 'chat_title' (Chat Title), 'ai_generated' (AI Generated), 'markdown_title' (Markdown Title)",
) )
MAX_EMBED_IMAGE_MB: int = Field( 最大嵌入图片大小MB: int = Field(
default=20, default=20,
description="Maximum image size to embed into DOCX (MB). Applies to data URLs and /api/v1/files/<id>/content images.", description="Maximum image size to embed into DOCX (MB). Applies to data URLs and /api/v1/files/<id>/content images.",
) )
# Font configuration # Font configuration
FONT_LATIN: str = Field( 英文字体: str = Field(
default="Calibri", default="Calibri",
description="Font for Latin characters (e.g., 'Times New Roman', '', 'Arial')", description="Font for Latin characters (e.g., 'Times New Roman', '', 'Arial')",
) )
FONT_ASIAN: str = Field( 中文字体: str = Field(
default="SimSun", default="SimSun",
description="Font for Asian characters (e.g., 'SimSun', 'Microsoft YaHei', 'PingFang SC')", description="Font for Asian characters (e.g., 'SimSun', 'Microsoft YaHei', 'PingFang SC')",
) )
FONT_CODE: str = Field( 代码字体: str = Field(
default="Consolas", default="Consolas",
description="Font for code blocks and inline code (e.g., 'Consolas', 'Courier New', 'Monaco')", description="Font for code blocks and inline code (e.g., 'Consolas', 'Courier New', 'Monaco')",
) )
# Table styling # Table styling
TABLE_HEADER_COLOR: str = Field( 表头背景色: str = Field(
default="F2F2F2", default="F2F2F2",
description="Table header background color (hex, without #)", description="Table header background color (hex, without #)",
) )
TABLE_ZEBRA_COLOR: str = Field( 表格隔行背景色: str = Field(
default="FBFBFB", default="FBFBFB",
description="Table zebra stripe background color for alternate rows (hex, without #)", description="Table zebra stripe background color for alternate rows (hex, without #)",
) )
MERMAID_JS_URL: str = Field( Mermaid_JS地址: str = Field(
default="https://cdn.jsdelivr.net/npm/mermaid@11.12.2/dist/mermaid.min.js", default="https://cdn.jsdelivr.net/npm/mermaid@11.12.2/dist/mermaid.min.js",
description="Mermaid JS CDN URL", description="Mermaid JS CDN URL",
) )
MERMAID_JSZIP_URL: str = Field( JSZip库地址: str = Field(
default="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js", default="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js",
description="JSZip CDN URL (DOCX manipulation)", description="JSZip CDN URL (DOCX manipulation)",
) )
MERMAID_PNG_SCALE: float = Field( Mermaid_PNG缩放比例: float = Field(
default=3.0, default=3.0,
description="PNG render resolution multiplier (higher = clearer, larger file)", description="PNG render resolution multiplier (higher = clearer, larger file)",
) )
MERMAID_DISPLAY_SCALE: float = Field( Mermaid显示比例: float = Field(
default=1.0, default=1.0,
description="Diagram width relative to available page width (<=1 recommended)", description="Diagram width relative to available page width (<=1 recommended)",
) )
MERMAID_OPTIMIZE_LAYOUT: bool = Field( Mermaid布局优化: bool = Field(
default=False, default=False,
description="Optimize Mermaid layout: convert LR to TD for graph/flowchart", description="Optimize Mermaid layout: convert LR to TD for graph/flowchart",
) )
MERMAID_BACKGROUND: str = Field( Mermaid背景色: str = Field(
default="", default="",
description="Mermaid background color. Empty = transparent (recommended for Word dark mode). Used only for optional PNG fill.", description="Mermaid background color. Empty = transparent (recommended for Word dark mode). Used only for optional PNG fill.",
) )
MERMAID_CAPTIONS_ENABLE: bool = Field( 启用Mermaid图注: bool = Field(
default=True, default=True,
description="Add figure captions under Mermaid images/charts", description="Add figure captions under Mermaid images/charts",
) )
MERMAID_CAPTION_STYLE: str = Field( Mermaid图注样式: str = Field(
default="Caption", default="Caption",
description="Paragraph style name for Mermaid captions (uses 'Caption' if available, otherwise creates a safe custom style)", description="Paragraph style name for Mermaid captions (uses 'Caption' if available, otherwise creates a safe custom style)",
) )
MERMAID_CAPTION_PREFIX: str = Field( Mermaid图注前缀: str = Field(
default="", default="",
description="Caption prefix label (e.g., 'Figure' or ''). Empty = auto-detect based on user language.", description="Caption prefix label (e.g., 'Figure' or ''). Empty = auto-detect based on user language.",
) )
MATH_ENABLE: bool = Field( 启用数学公式: bool = Field(
default=True, default=True,
description="Enable LaTeX math block conversion (\\[...\\] and $$...$$) into Word equations", description="Enable LaTeX math block conversion (\\[...\\] and $$...$$) into Word equations",
) )
MATH_INLINE_DOLLAR_ENABLE: bool = Field( 启用行内公式: bool = Field(
default=True, default=True,
description="Enable inline $...$ math conversion into Word equations (conservative parsing to reduce false positives)", description="Enable inline $...$ math conversion into Word equations (conservative parsing to reduce false positives)",
) )
# Language configuration # Language configuration
UI_LANGUAGE: str = Field( 界面语言: str = Field(
default="zh", default="zh",
description="UI language for export messages. Options: 'en' (English), 'zh' (Chinese)", description="UI language for export messages. Options: 'en' (English), 'zh' (Chinese)",
) )
class UserValves(BaseModel): class UserValves(BaseModel):
TITLE_SOURCE: str = Field( 文档标题来源: str = Field(
default="chat_title", default="chat_title",
description="Title Source: 'chat_title' (Chat Title), 'ai_generated' (AI Generated), 'markdown_title' (Markdown Title)", description="Title Source: 'chat_title' (Chat Title), 'ai_generated' (AI Generated), 'markdown_title' (Markdown Title)",
) )
UI_LANGUAGE: str = Field( 界面语言: str = Field(
default="zh", default="zh",
description="UI language for export messages. Options: 'en' (English), 'zh' (Chinese)", description="UI language for export messages. Options: 'en' (English), 'zh' (Chinese)",
) )
FONT_LATIN: str = Field( 英文字体: str = Field(
default="Calibri", default="Calibri",
description="Font for Latin characters (e.g., 'Times New Roman', '', 'Arial')", description="Font for Latin characters (e.g., 'Times New Roman', '', 'Arial')",
) )
FONT_ASIAN: str = Field( 中文字体: str = Field(
default="SimSun", default="SimSun",
description="Font for Asian characters (e.g., 'SimSun', 'Microsoft YaHei', 'PingFang SC')", description="Font for Asian characters (e.g., 'SimSun', 'Microsoft YaHei', 'PingFang SC')",
) )
FONT_CODE: str = Field( 代码字体: str = Field(
default="Consolas", default="Consolas",
description="Font for code blocks and inline code (e.g., 'Consolas', 'Courier New', 'Monaco')", description="Font for code blocks and inline code (e.g., 'Consolas', 'Courier New', 'Monaco')",
) )
TABLE_HEADER_COLOR: str = Field( 表头背景色: str = Field(
default="F2F2F2", default="F2F2F2",
description="Table header background color (hex, without #)", description="Table header background color (hex, without #)",
) )
TABLE_ZEBRA_COLOR: str = Field( 表格隔行背景色: str = Field(
default="FBFBFB", default="FBFBFB",
description="Table zebra stripe background color for alternate rows (hex, without #)", description="Table zebra stripe background color for alternate rows (hex, without #)",
) )
MERMAID_PNG_SCALE: float = Field( Mermaid_PNG缩放比例: float = Field(
default=3.0, default=3.0,
description="PNG render resolution multiplier (higher = clearer, larger file)", description="PNG render resolution multiplier (higher = clearer, larger file)",
) )
MERMAID_DISPLAY_SCALE: float = Field( Mermaid显示比例: float = Field(
default=1.0, default=1.0,
description="Diagram width relative to available page width (<=1 recommended)", description="Diagram width relative to available page width (<=1 recommended)",
) )
MERMAID_OPTIMIZE_LAYOUT: bool = Field( Mermaid布局优化: bool = Field(
default=False, default=False,
description="Optimize Mermaid layout: convert LR to TD for graph/flowchart", description="Optimize Mermaid layout: convert LR to TD for graph/flowchart",
) )
MERMAID_BACKGROUND: str = Field( Mermaid背景色: str = Field(
default="", default="",
description="Mermaid background color. Empty = transparent (recommended for Word dark mode). Used only for optional PNG fill.", description="Mermaid background color. Empty = transparent (recommended for Word dark mode). Used only for optional PNG fill.",
) )
MERMAID_CAPTIONS_ENABLE: bool = Field( 启用Mermaid图注: bool = Field(
default=True, default=True,
description="Add figure captions under Mermaid images/charts", description="Add figure captions under Mermaid images/charts",
) )
MATH_ENABLE: bool = Field( 启用数学公式: bool = Field(
default=True, default=True,
description="Enable LaTeX math block conversion (\\\\[...\\\\] and $$...$$) into Word equations", description="Enable LaTeX math block conversion (\\\\[...\\\\] and $$...$$) into Word equations",
) )
MATH_INLINE_DOLLAR_ENABLE: bool = Field( 启用行内公式: bool = Field(
default=True, default=True,
description="Enable inline $...$ math conversion into Word equations (conservative parsing to reduce false positives)", description="Enable inline $...$ math conversion into Word equations (conservative parsing to reduce false positives)",
) )
@@ -345,7 +345,7 @@ class Action:
setattr(self.valves, key, value) setattr(self.valves, key, value)
# Get user language from Valves configuration # Get user language from Valves configuration
self._user_lang = self._get_lang_key(self.valves.UI_LANGUAGE) self._user_lang = self._get_lang_key(self.valves.界面语言)
if __event_emitter__: if __event_emitter__:
last_assistant_message = body["messages"][-1] last_assistant_message = body["messages"][-1]
@@ -381,22 +381,22 @@ class Action:
chat_title = await self.fetch_chat_title(chat_id, user_id) chat_title = await self.fetch_chat_title(chat_id, user_id)
if ( if (
self.valves.TITLE_SOURCE.strip() == "chat_title" self.valves.文档标题来源.strip() == "chat_title"
or not self.valves.TITLE_SOURCE.strip() or not self.valves.文档标题来源.strip()
): ):
title = chat_title title = chat_title
elif self.valves.TITLE_SOURCE.strip() == "markdown_title": elif self.valves.文档标题来源.strip() == "markdown_title":
title = self.extract_title(message_content) title = self.extract_title(message_content)
elif self.valves.TITLE_SOURCE.strip() == "ai_generated": elif self.valves.文档标题来源.strip() == "ai_generated":
title = await self.generate_title_using_ai( title = await self.generate_title_using_ai(
body, message_content, user_id, __request__ body, message_content, user_id, __request__
) )
# Fallback logic # Fallback logic
if not title: if not title:
if self.valves.TITLE_SOURCE.strip() != "chat_title" and chat_title: if self.valves.文档标题来源.strip() != "chat_title" and chat_title:
title = chat_title title = chat_title
elif self.valves.TITLE_SOURCE.strip() != "markdown_title": elif self.valves.文档标题来源.strip() != "markdown_title":
extracted = self.extract_title(message_content) extracted = self.extract_title(message_content)
if extracted: if extracted:
title = extracted title = extracted
@@ -450,11 +450,11 @@ class Action:
(async function() {{ (async function() {{
const base64Data = "{base64_blob}"; const base64Data = "{base64_blob}";
const filename = "{js_filename}"; const filename = "{js_filename}";
const mermaidUrl = "{self.valves.MERMAID_JS_URL}"; const mermaidUrl = "{self.valves.Mermaid_JS地址}";
const jszipUrl = "{self.valves.MERMAID_JSZIP_URL}"; const jszipUrl = "{self.valves.JSZip库地址}";
const pngScale = {float(self.valves.MERMAID_PNG_SCALE)}; const pngScale = {float(self.valves.Mermaid_PNG缩放比例)};
const displayScale = {float(self.valves.MERMAID_DISPLAY_SCALE)}; const displayScale = {float(self.valves.Mermaid显示比例)};
const bgRaw = "{(self.valves.MERMAID_BACKGROUND or '').strip()}"; const bgRaw = "{(self.valves.Mermaid背景色 or '').strip()}";
const bg = (bgRaw || "").trim(); const bg = (bgRaw || "").trim();
const bgFill = (bg && bg.toLowerCase() !== "transparent") ? bg : ""; const bgFill = (bg && bg.toLowerCase() !== "transparent") ? bg : "";
const themeBackground = bgFill || "transparent"; const themeBackground = bgFill || "transparent";
@@ -1006,7 +1006,7 @@ class Action:
return cleaned[:50].strip() return cleaned[:50].strip()
def _max_embed_image_bytes(self) -> int: def _max_embed_image_bytes(self) -> int:
mb = getattr(self.valves, "MAX_EMBED_IMAGE_MB", 20) mb = getattr(self.valves, "最大嵌入图片大小MB", 20)
try: try:
mb_i = int(mb) mb_i = int(mb)
except Exception: except Exception:
@@ -1149,7 +1149,7 @@ class Action:
self._add_image_placeholder( self._add_image_placeholder(
paragraph, paragraph,
alt, alt,
f"invalid data URL or exceeds {self.valves.MAX_EMBED_IMAGE_MB}MB", f"invalid data URL or exceeds {self.valves.最大嵌入图片大小MB}MB",
) )
return return
else: else:
@@ -1239,7 +1239,7 @@ class Action:
line = lines[i] line = lines[i]
# Handle display math blocks (\[...\] or $$...$$) # Handle display math blocks (\[...\] or $$...$$)
if not in_code_block and self.valves.MATH_ENABLE: if not in_code_block and self.valves.启用数学公式:
single_line = self._extract_single_line_math(line) single_line = self._extract_single_line_math(line)
if single_line is not None: if single_line is not None:
if in_list and list_items: if in_list and list_items:
@@ -1689,12 +1689,12 @@ class Action:
def _insert_mermaid_placeholder(self, doc: Document, mermaid_source: str): def _insert_mermaid_placeholder(self, doc: Document, mermaid_source: str):
caption_title: Optional[str] = ( caption_title: Optional[str] = (
self._extract_mermaid_title(mermaid_source) self._extract_mermaid_title(mermaid_source)
if self.valves.MERMAID_CAPTIONS_ENABLE if self.valves.启用Mermaid图注
else None else None
) )
source_for_render = mermaid_source source_for_render = mermaid_source
if self.valves.MERMAID_OPTIMIZE_LAYOUT: if self.valves.Mermaid布局优化:
source_for_render = re.sub( source_for_render = re.sub(
r"^(graph|flowchart)\s+LR\b", r"^(graph|flowchart)\s+LR\b",
r"\1 TD", r"\1 TD",
@@ -1833,7 +1833,7 @@ class Action:
if self._caption_style_name is not None: if self._caption_style_name is not None:
return self._caption_style_name return self._caption_style_name
style_name = (self.valves.MERMAID_CAPTION_STYLE or "").strip() style_name = (self.valves.Mermaid图注样式 or "").strip()
if style_name == "": if style_name == "":
# Empty means: do not apply a caption style. # Empty means: do not apply a caption style.
self._caption_style_name = "" self._caption_style_name = ""
@@ -1872,11 +1872,11 @@ class Action:
return "Normal" return "Normal"
def _add_mermaid_caption(self, doc: Document, title: Optional[str]): def _add_mermaid_caption(self, doc: Document, title: Optional[str]):
if not self.valves.MERMAID_CAPTIONS_ENABLE: if not self.valves.启用Mermaid图注:
return return
# Use configured prefix, or auto-detect from user language # Use configured prefix, or auto-detect from user language
prefix = (self.valves.MERMAID_CAPTION_PREFIX or "").strip() prefix = (self.valves.Mermaid图注前缀 or "").strip()
if prefix == "": if prefix == "":
prefix = self._get_msg("figure_prefix") prefix = self._get_msg("figure_prefix")
@@ -1944,10 +1944,10 @@ class Action:
"""Set document default font using configured fonts.""" """Set document default font using configured fonts."""
style = doc.styles["Normal"] style = doc.styles["Normal"]
font = style.font font = style.font
font.name = self.valves.FONT_LATIN font.name = self.valves.英文字体
font.size = Pt(11) font.size = Pt(11)
# Set Asian font # Set Asian font
style._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.FONT_ASIAN) style._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.中文字体)
# Set paragraph format # Set paragraph format
paragraph_format = style.paragraph_format paragraph_format = style.paragraph_format
@@ -1972,7 +1972,7 @@ class Action:
""" """
Parse Markdown inline formatting and add to paragraph. Parse Markdown inline formatting and add to paragraph.
Supports: bold, italic, inline code, links, strikethrough, auto-link URLs, Supports: bold, italic, inline code, links, strikethrough, auto-link URLs,
and inline LaTeX math \\(...\\) when MATH_ENABLE is on. and inline LaTeX math \\(...\\) when 启用数学公式 is on.
""" """
self._add_inline_segments( self._add_inline_segments(
paragraph, text or "", bold=False, italic=False, strike=False paragraph, text or "", bold=False, italic=False, strike=False
@@ -1997,8 +1997,8 @@ class Action:
if not chunk: if not chunk:
return return
run = paragraph.add_run(chunk) run = paragraph.add_run(chunk)
run.font.name = self.valves.FONT_CODE run.font.name = self.valves.代码字体
run._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.FONT_CODE) run._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.代码字体)
run.font.size = Pt(10) run.font.size = Pt(10)
shading = OxmlElement("w:shd") shading = OxmlElement("w:shd")
shading.set(qn("w:fill"), "E8E8E8") shading.set(qn("w:fill"), "E8E8E8")
@@ -2052,9 +2052,9 @@ class Action:
rPr = OxmlElement("w:rPr") rPr = OxmlElement("w:rPr")
rFonts = OxmlElement("w:rFonts") rFonts = OxmlElement("w:rFonts")
rFonts.set(qn("w:ascii"), self.valves.FONT_CODE) rFonts.set(qn("w:ascii"), self.valves.代码字体)
rFonts.set(qn("w:hAnsi"), self.valves.FONT_CODE) rFonts.set(qn("w:hAnsi"), self.valves.代码字体)
rFonts.set(qn("w:eastAsia"), self.valves.FONT_CODE) rFonts.set(qn("w:eastAsia"), self.valves.代码字体)
rPr.append(rFonts) rPr.append(rFonts)
sz = OxmlElement("w:sz") sz = OxmlElement("w:sz")
@@ -2190,11 +2190,7 @@ class Action:
continue continue
# Inline $...$ math (conservative parsing) # Inline $...$ math (conservative parsing)
if ( if text[i] == "$" and self.valves.启用数学公式 and self.valves.启用行内公式:
text[i] == "$"
and self.valves.MATH_ENABLE
and self.valves.MATH_INLINE_DOLLAR_ENABLE
):
# Avoid treating $$ as inline math here (block math uses $$ on its own line). # Avoid treating $$ as inline math here (block math uses $$ on its own line).
if text.startswith("$$", i): if text.startswith("$$", i):
self._add_text_run(paragraph, "$", bold, italic, strike) self._add_text_run(paragraph, "$", bold, italic, strike)
@@ -2439,7 +2435,7 @@ class Action:
if not latex: if not latex:
return return
if not self.valves.MATH_ENABLE or not LATEX_MATH_AVAILABLE: if not self.valves.启用数学公式 or not LATEX_MATH_AVAILABLE:
self._add_text_run( self._add_text_run(
paragraph, f"\\({latex}\\)", bold=bold, italic=italic, strike=strike paragraph, f"\\({latex}\\)", bold=bold, italic=italic, strike=strike
) )
@@ -2511,7 +2507,7 @@ class Action:
lang_para.paragraph_format.space_after = Pt(0) lang_para.paragraph_format.space_after = Pt(0)
lang_para.paragraph_format.left_indent = Cm(0.5) lang_para.paragraph_format.left_indent = Cm(0.5)
lang_run = lang_para.add_run(language.upper()) lang_run = lang_para.add_run(language.upper())
lang_run.font.name = self.valves.FONT_CODE lang_run.font.name = self.valves.代码字体
lang_run.font.size = Pt(8) lang_run.font.size = Pt(8)
lang_run.font.color.rgb = RGBColor(100, 100, 100) lang_run.font.color.rgb = RGBColor(100, 100, 100)
lang_run.font.bold = True lang_run.font.bold = True
@@ -2540,8 +2536,8 @@ class Action:
if not token_value: if not token_value:
continue continue
run = paragraph.add_run(token_value) run = paragraph.add_run(token_value)
run.font.name = self.valves.FONT_CODE run.font.name = self.valves.代码字体
run._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.FONT_CODE) run._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.代码字体)
run.font.size = Pt(10) run.font.size = Pt(10)
# Apply color # Apply color
@@ -2555,8 +2551,8 @@ class Action:
else: else:
# No syntax highlighting, plain text display # No syntax highlighting, plain text display
run = paragraph.add_run(code) run = paragraph.add_run(code)
run.font.name = self.valves.FONT_CODE run.font.name = self.valves.代码字体
run._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.FONT_CODE) run._element.rPr.rFonts.set(qn("w:eastAsia"), self.valves.代码字体)
run.font.size = Pt(10) run.font.size = Pt(10)
def add_table(self, doc: Document, table_lines: List[str]): def add_table(self, doc: Document, table_lines: List[str]):
@@ -2570,8 +2566,8 @@ class Action:
return c return c
return default return default
header_fill = _validate_hex(self.valves.TABLE_HEADER_COLOR, "F2F2F2") header_fill = _validate_hex(self.valves.表头背景色, "F2F2F2")
zebra_fill = _validate_hex(self.valves.TABLE_ZEBRA_COLOR, "FBFBFB") zebra_fill = _validate_hex(self.valves.表格隔行背景色, "FBFBFB")
def _split_row(line: str) -> List[str]: def _split_row(line: str) -> List[str]:
# Keep empty cells, trim surrounding pipes. # Keep empty cells, trim surrounding pipes.