@cliven/mddocx 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +8 -0
- package/.codex-plugin/plugin.json +16 -0
- package/.cursor-plugin/plugin.json +9 -0
- package/.opencode/INSTALL.md +31 -0
- package/.opencode/plugins/mddocx.js +41 -0
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/bin/mddocx.js +29 -0
- package/hooks/hooks.json +12 -0
- package/hooks/session-start +29 -0
- package/package.json +25 -0
- package/skills/mddoc/SKILL.md +493 -0
- package/skills/mddoc/evals/evals.json +23 -0
- package/skills/mddoc/evals/test-sample.md +67 -0
- package/skills/mddoc/scripts/__pycache__/md2docx.cpython-312.pyc +0 -0
- package/skills/mddoc/scripts/md2docx.py +1200 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mddocx",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Markdown 转学术格式 Word 文档 (DOCX)。支持三线表、图题/表题自动编号、页码、页眉等学术论文排版规范。",
|
|
5
|
+
"author": "Quan Guanyu",
|
|
6
|
+
"homepage": "https://github.com/Trisia/mddocx",
|
|
7
|
+
"keywords": ["markdown", "docx", "word", "academic", "paper"],
|
|
8
|
+
"skills": "./skills/",
|
|
9
|
+
"hooks": {},
|
|
10
|
+
"interface": {
|
|
11
|
+
"displayName": "mddocx",
|
|
12
|
+
"shortDescription": "Markdown → 学术格式 DOCX",
|
|
13
|
+
"brandColor": "#0984e3",
|
|
14
|
+
"logo": ""
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mddocx",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Markdown 转学术格式 Word 文档 (DOCX)。支持三线表、图题/表题自动编号、页码、页眉等学术论文排版规范。",
|
|
5
|
+
"author": "Quan Guanyu",
|
|
6
|
+
"homepage": "https://github.com/Trisia/mddocx",
|
|
7
|
+
"keywords": ["markdown", "docx", "word", "academic", "论文", "学术", "转换"],
|
|
8
|
+
"skills": "./skills/"
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# mddocx — OpenCode 安装
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
1. 在 OpenCode 配置 (`opencode.json`) 中添加插件:
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"plugins": [
|
|
10
|
+
"git:https://github.com/Trisia/mddocx"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. 重启 OpenCode,插件自动加载。
|
|
16
|
+
|
|
17
|
+
3. 确保已安装 Python 依赖:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install python-docx Pillow requests mistune
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 使用
|
|
24
|
+
|
|
25
|
+
在 OpenCode 对话中输入:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
/mddoc paper.md
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
或直接粘贴 Markdown 内容要求转换为 Word 文档。
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// mddocx — Markdown 转学术格式 DOCX
|
|
2
|
+
// OpenCode 插件:注册 mddoc 技能并在会话启动时注入引导
|
|
3
|
+
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { join, dirname } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
|
10
|
+
const SKILL_MD_PATH = join(PLUGIN_ROOT, 'skills', 'mddoc', 'SKILL.md');
|
|
11
|
+
|
|
12
|
+
/** @param {import('opencode').Plugin} plugin */
|
|
13
|
+
export default async function mddocx(plugin) {
|
|
14
|
+
// 注册技能目录
|
|
15
|
+
plugin.config({
|
|
16
|
+
skills: [join(PLUGIN_ROOT, 'skills')],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// 会话启动时注入 mddoc 技能引导
|
|
20
|
+
plugin.hook('experimental.chat.messages.transform', async (messages) => {
|
|
21
|
+
try {
|
|
22
|
+
const skillContent = readFileSync(SKILL_MD_PATH, 'utf-8');
|
|
23
|
+
const bootstrap = `<EXTREMELY_IMPORTANT>
|
|
24
|
+
本会话已安装 mddocx 插件。以下是 mddoc 技能:
|
|
25
|
+
|
|
26
|
+
${skillContent}
|
|
27
|
+
</EXTREMELY_IMPORTANT>`;
|
|
28
|
+
|
|
29
|
+
// 注入到第一条用户消息之前
|
|
30
|
+
const systemMsg = messages.find(m => m.role === 'system');
|
|
31
|
+
if (systemMsg) {
|
|
32
|
+
systemMsg.content = bootstrap + '\n\n' + (systemMsg.content || '');
|
|
33
|
+
} else {
|
|
34
|
+
messages.unshift({ role: 'system', content: bootstrap });
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.warn('[mddocx] 无法注入技能引导:', e.message);
|
|
38
|
+
}
|
|
39
|
+
return messages;
|
|
40
|
+
});
|
|
41
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Quan Guanyu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# mddocx — Markdown 转学术格式 DOCX
|
|
2
|
+
|
|
3
|
+
[](https://claude.com/code)
|
|
4
|
+
[](https://github.com/openai/codex)
|
|
5
|
+
[](https://cursor.com)
|
|
6
|
+
[](https://opencode.ai)
|
|
7
|
+
[](https://github.com/Trisia/mddocx/releases)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://python.org)
|
|
10
|
+
[](https://github.com/Trisia/mddocx/actions/workflows/release.yml)
|
|
11
|
+
[](https://clawhub.ai/Trisia/mddoc)
|
|
12
|
+
|
|
13
|
+
将 Markdown 转换为符合学术规范的 Word 文档的Agent Skill,支持 LaTeX 公式(OMML)、三线表、图题/表题自动编号、页码、页眉等学术论文排版规范。
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
### 🤖 一键安装
|
|
20
|
+
|
|
21
|
+
复制粘贴给任意智能体即可安装:
|
|
22
|
+
|
|
23
|
+
```copy
|
|
24
|
+
请帮我安装 mddocx 插件:
|
|
25
|
+
|
|
26
|
+
git clone https://github.com/Trisia/mddocx /tmp/mddocx
|
|
27
|
+
mkdir -p ~/.claude/skills/mddoc
|
|
28
|
+
cp -r /tmp/mddocx/skills/mddoc/* ~/.claude/skills/mddoc/
|
|
29
|
+
rm -rf /tmp/mddocx
|
|
30
|
+
|
|
31
|
+
python3 -m venv ~/.claude/venvs/mddocx
|
|
32
|
+
~/.claude/venvs/mddocx/bin/pip install python-docx Pillow requests mistune
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 📖 完整安装指南
|
|
36
|
+
|
|
37
|
+
支持 **Claude Code** / **Codex** / **OpenCode** / **Cursor** / **通用** 等多种方式,详见 **[INSTALL.md](INSTALL.md)**。
|
|
38
|
+
|
|
39
|
+
### 依赖
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install python-docx Pillow requests mistune
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 使用
|
|
46
|
+
|
|
47
|
+
### npx(无需安装)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx @cliven/mddocx paper.md # 转换文件
|
|
51
|
+
npx @cliven/mddocx paper.md -o output.docx # 指定输出
|
|
52
|
+
npx @cliven/mddocx --text "# 标题" -o out.docx # 转换文本
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Claude Code 中
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
/mddoc paper.md # 转换 Markdown 文件
|
|
59
|
+
/mddoc @paper.md # @引用文件
|
|
60
|
+
/mddoc 把这段内容转成Word # 粘贴 Markdown 文本
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 命令行直接使用
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# 转换文件(输出到同目录)
|
|
67
|
+
python skills/mddoc/scripts/md2docx.py paper.md
|
|
68
|
+
|
|
69
|
+
# 指定输出路径
|
|
70
|
+
python skills/mddoc/scripts/md2docx.py paper.md -o output.docx
|
|
71
|
+
|
|
72
|
+
# 直接转换文本
|
|
73
|
+
python skills/mddoc/scripts/md2docx.py --text "# 标题\n\n正文" -o out.docx
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 格式规范
|
|
77
|
+
|
|
78
|
+
生成的文档自动应用以下学术排版规范:
|
|
79
|
+
|
|
80
|
+
| 元素 | 格式 |
|
|
81
|
+
|------|------|
|
|
82
|
+
| 题目 | 三号黑体(16pt)、居中、上下空一行 |
|
|
83
|
+
| 一级标题 | 三号黑体、居中、前加分页符、outline_level=1 |
|
|
84
|
+
| 二级标题 | 四号黑体(14pt)、顶格、不加粗、outline_level=2 |
|
|
85
|
+
| 三级标题 | 小四宋体(12pt)、首行缩进、不加粗、outline_level=3 |
|
|
86
|
+
| 正文 | 五号(10.5pt)、首行缩进2字符、1.3倍行距 |
|
|
87
|
+
| 表格 | 三线表(顶线粗/表头底线细/底线粗)、表头重复 |
|
|
88
|
+
| 图题 | 小五(9pt)宋体加粗居中、"图1-1 xxx"格式 |
|
|
89
|
+
| 表题 | 五号(10.5pt)宋体加粗居中、"表1-1 xxx"格式 |
|
|
90
|
+
| 页码 | "第×页 共×页"、页脚边距1cm |
|
|
91
|
+
| 列表 | 有序列表用(1)(2)(3)序号 |
|
|
92
|
+
| 行内公式 | $...$ 转 OMML、嵌于段落、WPS/Word 可渲染 |
|
|
93
|
+
| 行间公式 | $$...$$ 转 OMML 居中、编号(章-序号)右对齐 |
|
|
94
|
+
| 页边距 | 左3cm 右2cm 上2cm 下2cm |
|
|
95
|
+
|
package/bin/mddocx.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// mddocx CLI — 调用 Python 转换脚本
|
|
3
|
+
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const script = join(__dirname, '..', 'skills', 'mddoc', 'scripts', 'md2docx.py');
|
|
11
|
+
|
|
12
|
+
if (!existsSync(script)) {
|
|
13
|
+
console.error('错误: 找不到转换脚本', script);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 优先找 venv python,否则用系统 python3
|
|
18
|
+
const pythonCmd = process.env.MDDOCX_PYTHON || 'python3';
|
|
19
|
+
|
|
20
|
+
const args = [script, ...process.argv.slice(2)];
|
|
21
|
+
|
|
22
|
+
const child = spawn(pythonCmd, args, { stdio: 'inherit' });
|
|
23
|
+
|
|
24
|
+
child.on('close', (code) => {
|
|
25
|
+
if (code !== 0) {
|
|
26
|
+
console.error(`\n提示: 确认已安装依赖: pip install python-docx Pillow requests mistune`);
|
|
27
|
+
}
|
|
28
|
+
process.exit(code);
|
|
29
|
+
});
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# mddocx session-start hook — 在每个会话开始时注入 mddoc 技能
|
|
3
|
+
# 参考 superpowers hooks/session-start 实现
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
SKILL_DIR="${CLAUDE_PLUGIN_ROOT:-$(dirname "$(dirname "$0")")}"
|
|
8
|
+
SKILL_MD="$SKILL_DIR/skills/mddoc/SKILL.md"
|
|
9
|
+
|
|
10
|
+
if [ ! -f "$SKILL_MD" ]; then
|
|
11
|
+
echo '{"additionalContext":"[mddocx] mddoc skill not found at '"$SKILL_MD"'"}'
|
|
12
|
+
exit 0
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
# 读取 SKILL.md 内容
|
|
16
|
+
CONTENT=$(cat "$SKILL_MD")
|
|
17
|
+
|
|
18
|
+
# 构建注入内容
|
|
19
|
+
INJECT="<EXTREMELY_IMPORTANT>
|
|
20
|
+
本会话已安装 mddocx 插件。以下是 mddoc 技能——当用户要求将 Markdown 转换为 Word 文档时自动触发。
|
|
21
|
+
|
|
22
|
+
$CONTENT
|
|
23
|
+
</EXTREMELY_IMPORTANT>"
|
|
24
|
+
|
|
25
|
+
# 输出为 JSON(Claude Code SessionStart 格式)
|
|
26
|
+
python3 -c "
|
|
27
|
+
import json, sys
|
|
28
|
+
print(json.dumps({'additionalContext': open('$SKILL_MD').read()}))
|
|
29
|
+
"
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cliven/mddocx",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Markdown 转学术格式 DOCX",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": ".opencode/plugins/mddocx.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mddocx": "./bin/mddocx.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"skills/",
|
|
12
|
+
"bin/",
|
|
13
|
+
".opencode/",
|
|
14
|
+
".claude-plugin/",
|
|
15
|
+
".codex-plugin/",
|
|
16
|
+
".cursor-plugin/",
|
|
17
|
+
"hooks/"
|
|
18
|
+
],
|
|
19
|
+
"keywords": ["markdown", "docx", "academic", "claude-code", "codex", "opencode", "skill"],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/Trisia/mddocx"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT"
|
|
25
|
+
}
|