Compare commits

..

1 Commits

6 changed files with 2238 additions and 281 deletions

View File

@@ -57,13 +57,13 @@ Actions are interactive plugins that:
[:octicons-arrow-right-24: Documentation](export-to-excel.md) [:octicons-arrow-right-24: Documentation](export-to-excel.md)
- :material-file-word-box:{ .lg .middle } **Export to Word** - :material-file-word-box:{ .lg .middle } **Export to Word (Enhanced Formatting)**
--- ---
Export chat content as Word (.docx) with Markdown formatting and syntax highlighting. Export the current conversation to a formatted Word doc with syntax highlighting, AI-generated titles, and perfect Markdown rendering (tables, quotes, lists).
**Version:** 0.1.0 **Version:** 0.1.1
[:octicons-arrow-right-24: Documentation](export-to-word.md) [:octicons-arrow-right-24: Documentation](export-to-word.md)

View File

@@ -57,13 +57,13 @@ Actions 是交互式插件,能够:
[:octicons-arrow-right-24: 查看文档](export-to-excel.md) [:octicons-arrow-right-24: 查看文档](export-to-excel.md)
- :material-file-word-box:{ .lg .middle } **Export to Word** - :material-file-word-box:{ .lg .middle } **Word 导出 (格式增强)**
--- ---
聊天内容按 Markdown 格式导出为 Word (.docx),支持语法高亮。 当前对话导出为完美格式的 Word 文档,支持代码语法高亮、AI 智能标题生成以及表格、引用等 Markdown 元素的精准渲染
**版本:** 0.1.0 **版本:** 0.1.1
[:octicons-arrow-right-24: 查看文档](export-to-word.md) [:octicons-arrow-right-24: 查看文档](export-to-word.md)

View File

@@ -1,14 +1,19 @@
# Export to Word # Export to Word
Export current conversation from Markdown to Word (.docx) with **syntax highlighting**, **blockquote support**, and smarter filenames. Export conversation to Word (.docx) with **syntax highlighting**, **native math equations**, **Mermaid diagrams**, **citations**, and **enhanced table formatting**.
## Features ## Features
- **One-Click Export**: Adds an "Export to Word" action button to the chat. - **One-Click Export**: Adds an "Export to Word" action button to the chat.
- **Markdown Conversion**: Converts Markdown syntax to Word formatting (headings, bold, italic, code, tables, lists). - **Markdown Conversion**: Converts Markdown syntax to Word formatting (headings, bold, italic, code, tables, lists).
- **Syntax Highlighting**: Code blocks are highlighted with Pygments (supports 500+ languages). - **Syntax Highlighting**: Code blocks are highlighted with Pygments (supports 500+ languages).
- **Native Math Equations**: LaTeX math (`$$...$$`, `\[...\]`, `$...$`, `\(...\)`) converted to editable Word equations.
- **Mermaid Diagrams**: Mermaid flowcharts and sequence diagrams rendered as images in the document.
- **Citations & References**: Auto-generates a References section from OpenWebUI sources with clickable citation links.
- **Reasoning Stripping**: Automatically removes AI thinking blocks (`<think>`, `<analysis>`) from exports.
- **Enhanced Tables**: Smart column widths, column alignment (`:---`, `---:`, `:---:`), header row repeat across pages.
- **Blockquote Support**: Markdown blockquotes are rendered with left border and gray styling. - **Blockquote Support**: Markdown blockquotes are rendered with left border and gray styling.
- **Multi-language Support**: Properly handles both Chinese and English text without garbled characters. - **Multi-language Support**: Properly handles both Chinese and English text.
- **Smarter Filenames**: Configurable title source (Chat Title, AI Generated, or Markdown Title). - **Smarter Filenames**: Configurable title source (Chat Title, AI Generated, or Markdown Title).
## Configuration ## Configuration
@@ -19,24 +24,33 @@ You can configure the following settings via the **Valves** button in the plugin
- `chat_title`: Use the conversation title (default). - `chat_title`: Use the conversation title (default).
- `ai_generated`: Use AI to generate a short title based on the content. - `ai_generated`: Use AI to generate a short title based on the content.
- `markdown_title`: Extract the first h1/h2 heading from the Markdown content. - `markdown_title`: Extract the first h1/h2 heading from the Markdown content.
- **MERMAID_JS_URL**: URL for the Mermaid.js library (for diagram rendering).
- **MERMAID_PNG_SCALE**: Scale factor for Mermaid PNG generation (Resolution). Default: `3.0`.
- **MERMAID_DISPLAY_SCALE**: Scale factor for Mermaid visual size in Word. Default: `1.5`.
- **MERMAID_OPTIMIZE_LAYOUT**: Automatically convert LR (Left-Right) flowcharts to TD (Top-Down). Default: `True`.
- **MERMAID_CAPTIONS_ENABLE**: Enable/disable figure captions for Mermaid diagrams.
## Supported Markdown Syntax ## Supported Markdown Syntax
| Syntax | Word Result | | Syntax | Word Result |
| :---------------------------------- | :-------------------------------- | | :---------------------------------- | :------------------------------------ |
| `# Heading 1` to `###### Heading 6` | Heading levels 1-6 | | `# Heading 1` to `###### Heading 6` | Heading levels 1-6 |
| `**bold**` or `__bold__` | Bold text | | `**bold**` or `__bold__` | Bold text |
| `*italic*` or `_italic_` | Italic text | | `*italic*` or `_italic_` | Italic text |
| `***bold italic***` | Bold + Italic | | `***bold italic***` | Bold + Italic |
| `` `inline code` `` | Monospace with gray background | | `` `inline code` `` | Monospace with gray background |
| ` ``` code block ``` ` | **Syntax highlighted** code block | | ` ``` code block ``` ` | **Syntax highlighted** code block |
| `> blockquote` | Left-bordered gray italic text | | `> blockquote` | Left-bordered gray italic text |
| `[link](url)` | Blue underlined link text | | `[link](url)` | Blue underlined link text |
| `~~strikethrough~~` | Strikethrough text | | `~~strikethrough~~` | Strikethrough text |
| `- item` or `* item` | Bullet list | | `- item` or `* item` | Bullet list |
| `1. item` | Numbered list | | `1. item` | Numbered list |
| Markdown tables | Table with grid | | Markdown tables | **Enhanced table** with smart widths |
| `---` or `***` | Horizontal rule | | `---` or `***` | Horizontal rule |
| `$$LaTeX$$` or `\[LaTeX\]` | **Native Word equation** (display) |
| `$LaTeX$` or `\(LaTeX\)` | **Native Word equation** (inline) |
| ` ```mermaid ... ``` ` | **Mermaid diagram** as image |
| `[1]` citation markers | **Clickable links** to References |
## Usage ## Usage
@@ -44,19 +58,14 @@ You can configure the following settings via the **Valves** button in the plugin
2. In any chat, click the "Export to Word" button. 2. In any chat, click the "Export to Word" button.
3. The .docx file will be automatically downloaded to your device. 3. The .docx file will be automatically downloaded to your device.
## Requirements
### Notes
- Title detection only considers h1/h2 headings.
- If the request carries `chat_id` (body or metadata), the plugin will fetch the chat title from the database when the body lacks one.
- Default fonts: Times New Roman (en), SimSun/SimHei (zh), Consolas (code).
### Requirements
- `python-docx==1.1.2` - Word document generation - `python-docx==1.1.2` - Word document generation
- `Pygments>=2.15.0` - Syntax highlighting (optional but recommended) - `Pygments>=2.15.0` - Syntax highlighting
- `latex2mathml` - LaTeX to MathML conversion
- `mathml2omml` - MathML to Office Math (OMML) conversion
Both are declared in the plugin docstring; ensure they are installed in your environment. All dependencies are declared in the plugin docstring.
## Font Configuration ## Font Configuration
@@ -64,6 +73,18 @@ Both are declared in the plugin docstring; ensure they are installed in your env
- **Chinese Text**: SimSun (宋体) for body, SimHei (黑体) for headings - **Chinese Text**: SimSun (宋体) for body, SimHei (黑体) for headings
- **Code**: Consolas - **Code**: Consolas
## Changelog
### v0.2.0
- Added native math equation support (LaTeX → OMML)
- Added Mermaid diagram rendering
- Added citations and references section generation
- Added automatic reasoning block stripping
- Enhanced table formatting with smart column widths and alignment
### v0.1.1
- Initial release with basic Markdown to Word conversion
## Author ## Author
Fu-Jie Fu-Jie

View File

@@ -1,17 +1,22 @@
# 导出为 Word # 导出为 Word
当前对话内容从 Markdown 转换并导出为 Word (.docx) 文件,支持**代码语法高亮**、**引用块样式**和更智能的文件命名 对话导出为 Word (.docx),支持**代码语法高亮**、**原生数学公式**、**Mermaid 图表**、**引用参考**和**增强表格格式**
## 功能特点 ## 功能特点
- **一键导出**:在聊天界面添加导出为 Word动作按钮。 - **一键导出**:在聊天界面添加"导出为 Word"动作按钮。
- **Markdown 转换**:将 Markdown 语法转换为 Word 格式(标题、粗体、斜体、代码、表格、列表)。 - **Markdown 转换**:将 Markdown 语法转换为 Word 格式(标题、粗体、斜体、代码、表格、列表)。
- **代码语法高亮**:使用 Pygments 库为代码块添加语法高亮(支持 500+ 种语言)。 - **代码语法高亮**:使用 Pygments 库为代码块添加语法高亮(支持 500+ 种语言)。
- **引用块支持**Markdown 引用块会渲染为带左侧边框的灰色斜体样式。 - **原生数学公式**LaTeX 公式(`$$...$$``\[...\]``$...$``\(...\)`)转换为可编辑的 Word 公式。
- **Mermaid 图表**Mermaid 流程图和时序图渲染为文档中的图片。
- **引用与参考**:自动从 OpenWebUI 来源生成参考资料章节,支持可点击的引用链接。
- **移除思考过程**:自动移除 AI 思考块(`<think>``<analysis>`)。
- **增强表格**:智能列宽、列对齐(`:---``---:``:---:`)、表头跨页重复。
- **引用块支持**Markdown 引用块渲染为带左侧边框的灰色斜体样式。
- **多语言支持**:正确处理中文和英文文本,无乱码问题。 - **多语言支持**:正确处理中文和英文文本,无乱码问题。
- **智能文件名**可配置标题来源对话标题、AI 生成或 Markdown 标题)。 - **智能文件名**可配置标题来源对话标题、AI 生成或 Markdown 标题)。
## 配置 (Configuration) ## 配置
您可以通过插件设置中的 **Valves** 按钮配置以下选项: 您可以通过插件设置中的 **Valves** 按钮配置以下选项:
@@ -19,24 +24,33 @@
- `chat_title`:使用对话标题(默认)。 - `chat_title`:使用对话标题(默认)。
- `ai_generated`:使用 AI 根据内容生成简短标题。 - `ai_generated`:使用 AI 根据内容生成简短标题。
- `markdown_title`:从 Markdown 内容中提取第一个一级或二级标题。 - `markdown_title`:从 Markdown 内容中提取第一个一级或二级标题。
- **MERMAID_JS_URL**Mermaid.js 库的 URL用于图表渲染
- **MERMAID_PNG_SCALE**Mermaid PNG 生成缩放比例(分辨率)。默认:`3.0`
- **MERMAID_DISPLAY_SCALE**Mermaid 在 Word 中的显示比例(视觉大小)。默认:`1.5`
- **MERMAID_OPTIMIZE_LAYOUT**:自动将 LR左右流程图转换为 TD上下。默认`True`
- **MERMAID_CAPTIONS_ENABLE**:启用/禁用 Mermaid 图表的图注。
## 支持的 Markdown 语法 ## 支持的 Markdown 语法
| 语法 | Word 效果 | | 语法 | Word 效果 |
| :-------------------------- | :----------------------- | | :---------------------------- | :-------------------------------- |
| `# 标题1``###### 标题6` | 标题级别 1-6 | | `# 标题1``###### 标题6` | 标题级别 1-6 |
| `**粗体**``__粗体__` | 粗体文本 | | `**粗体**``__粗体__` | 粗体文本 |
| `*斜体*``_斜体_` | 斜体文本 | | `*斜体*``_斜体_` | 斜体文本 |
| `***粗斜体***` | 粗体 + 斜体 | | `***粗斜体***` | 粗体 + 斜体 |
| `` `行内代码` `` | 等宽字体 + 灰色背景 | | `` `行内代码` `` | 等宽字体 + 灰色背景 |
| ` ``` 代码块 ``` ` | **语法高亮**的代码块 | | ` ``` 代码块 ``` ` | **语法高亮**的代码块 |
| `> 引用文本` | 带左侧边框的灰色斜体文本 | | `> 引用文本` | 带左侧边框的灰色斜体文本 |
| `[链接](url)` | 蓝色下划线链接文本 | | `[链接](url)` | 蓝色下划线链接文本 |
| `~~删除线~~` | 删除线文本 | | `~~删除线~~` | 删除线文本 |
| `- 项目``* 项目` | 无序列表 | | `- 项目``* 项目` | 无序列表 |
| `1. 项目` | 有序列表 | | `1. 项目` | 有序列表 |
| Markdown 表格 | 带边框表格 | | Markdown 表格 | **增强表格**(智能列宽) |
| `---``***` | 水平分割线 | | `---``***` | 水平分割线 |
| `$$LaTeX$$``\[LaTeX\]` | **原生 Word 公式**(块级) |
| `$LaTeX$``\(LaTeX\)` | **原生 Word 公式**(行内) |
| ` ```mermaid ... ``` ` | **Mermaid 图表**(图片形式) |
| `[1]` 引用标记 | **可点击链接**到参考资料 |
## 使用方法 ## 使用方法
@@ -44,18 +58,14 @@
2. 在任意对话中,点击"导出为 Word"按钮。 2. 在任意对话中,点击"导出为 Word"按钮。
3. .docx 文件将自动下载到你的设备。 3. .docx 文件将自动下载到你的设备。
### 说明 ## 依赖
- 标题检测仅考虑一级/二级标题h1/h2
- 若请求体或 metadata 提供 `chat_id`,当正文缺少标题时会从数据库查询对话标题。
- 默认字体:英文 Times New Roman中文宋体/黑体,代码 Consolas。
### 依赖
- `python-docx==1.1.2` - Word 文档生成 - `python-docx==1.1.2` - Word 文档生成
- `Pygments>=2.15.0` - 语法高亮(可选但建议安装) - `Pygments>=2.15.0` - 语法高亮
- `latex2mathml` - LaTeX 转 MathML
- `mathml2omml` - MathML 转 Office Math (OMML)
两者已在插件文档字符串中声明,请确保环境已安装 所有依赖已在插件文档字符串中声明。
## 字体配置 ## 字体配置
@@ -63,6 +73,18 @@
- **中文文本**:宋体(正文)、黑体(标题) - **中文文本**:宋体(正文)、黑体(标题)
- **代码**Consolas - **代码**Consolas
## 更新日志
### v0.2.0
- 新增原生数学公式支持LaTeX → OMML
- 新增 Mermaid 图表渲染
- 新增引用与参考资料章节生成
- 新增自动移除 AI 思考块
- 增强表格格式(智能列宽、对齐)
### v0.1.1
- 初始版本,支持基本 Markdown 转 Word
## 作者 ## 作者
Fu-Jie Fu-Jie

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff