Moss 文件格式转换插件
v1.0.0 · 文档处理 · 官方
简介
Moss 文件格式转换插件 v1.0,AI 一键转换本地文档:
- md_to_html Markdown → 带样式 HTML
- html_to_md HTML → Markdown
- md_to_txt / html_to_txt 提取纯文本
- txt_to_docx 文本 → Word 文档
- docx_to_pdf Word → PDF(LibreOffice 或 Word)
- 支持 input 文件 或 content 字符串 两种输入
适用:README 转网页、网页转 MD、纪要转 Word、报告转 PDF。
操作说明
| action | 转换 | 依赖 |
|---|---|---|
md_to_html | MD→HTML | markdown |
html_to_md | HTML→MD | html2text |
md_to_txt | MD→TXT | 无 |
html_to_txt | HTML→TXT | 无 |
txt_to_docx | TXT→docx | python-docx |
docx_to_pdf | docx→PDF | LibreOffice/docx2pdf |
formats | 查支持列表 | 无 |
安装
- 解压到
D:\moss-plugins\文档处理\文件格式转换插件\ - 复制
python/到本目录 - 安装依赖:
python\python.exe -m pip install markdown html2text python-docx
- Word→PDF 额外装 LibreOffice(推荐)或
pip install docx2pdf(需 MS Word) - 测试:
run.bat --action formats
| 文件 | 说明 |
|---|---|
file_convert_plugin.py | 主程序 |
run.bat / run.sh | 启动脚本 |
文件格式转换插件.md | 用户文档 |
命令行
run.bat --action md_to_html --input D:\docs\readme.md --output D:\docs\readme.html
run.bat --action html_to_md --input D:\docs\page.html
run.bat --action txt_to_docx --input D:\docs\notes.txt --title 会议纪要
run.bat --action docx_to_pdf --input D:\docs\报告.docx --output D:\docs\报告.pdf
run.bat --action md_to_html --content "# 标题\n正文" --output D:\docs\out.html
注册技能 file_convert
名称: file_convert
描述: 文件格式转换 v1.0。md_to_html/html_to_md/md_to_txt/html_to_txt/txt_to_docx/docx_to_pdf/formats。Markdown、HTML、TXT、Word、PDF互转。用户需要格式转换、md转html、txt转word、docx转pdf时使用。input文件或content内容,output输出路径。
脚本: D:\moss-plugins\文档处理\文件格式转换插件\run.bat
参数 JSON:
{
"type": "object",
"properties": {
"action": {"type": "string", "enum": ["md_to_html", "html_to_md", "md_to_txt", "html_to_txt", "txt_to_docx", "docx_to_pdf", "formats"], "description": "转换类型"},
"input": {"type": "string", "description": "输入文件路径"},
"output": {"type": "string", "description": "输出文件路径"},
"content": {"type": "string", "description": "直接传入文本"},
"title": {"type": "string", "description": "txt_to_docx标题"}
},
"required": ["action"]
}
对话示例
| 场景 | 说法 |
|---|---|
| MD转HTML | 把 readme.md 转成 HTML |
| HTML转MD | 把 page.html 转成 Markdown |
| TXT转Word | notes.txt 转成 Word,标题「会议纪要」 |
| Word转PDF | 把 报告.docx 转成 PDF |
| 查支持 | 有哪些格式可以转换? |
常见错误
| 现象 | 处理 |
|---|---|
| 缺 markdown/html2text | pip install |
| docx_to_pdf 失败 | 装 LibreOffice 或 docx2pdf+Word |
| 文件不存在 | 检查 input 路径 |
能力边界
| 支持 | 不支持 |
|---|---|
| MD/HTML/TXT/Word/PDF 基础互转 | 复杂 CSS 完美保留 |
| LibreOffice/Word 转 PDF | PDF 转 Word |
| content 字符串输入 | 在线 URL 拉取 |
配合:pdf_tool 读 PDF · word_tool 编辑 docx · word/excel/ppt 生成文档
详见包内 文件格式转换插件.md。