关于 CHM to Markdown Converter
CHM to Markdown Converter 是一个 Python 工具,可将编译后的 CHM 帮助文件转换为整洁的 Markdown,并生成索引文件以便检索和 AI 集成。最初为 Autodesk Revit API 文档开发,通用配置适用于任意 CHM 文件。
主要功能
- 01基于配置文件(profile)的转换,支持 generic 与 revit
- 02自动检测编码,支持 GB18030、GBK 等
- 03跨平台检测 7-Zip 并解压 CHM
- 04保留代码块语言并规范化表格
- 05生成 file_index.json、id_lookup.json 与 index.md
- 06异步分批处理,适合大型 CHM 文件
适用场景
- 01将 Revit API 帮助文档转换为 Markdown
- 02为 RAG 或全文检索准备 CHM 文档的索引
- 03批量转换多个 CHM 文件用于知识整理
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
CHM 转 Markdown 转换器
一个 Python 工具,可将已编译 HTML 帮助(.chm)文件转换为简洁的 Markdown,并通过配置文件系统内置支持多种文档类型。
最初为 Autodesk Revit API 文档开发;通用配置文件适用于任何 CHM 文件。
功能
- 基于配置文件的转换 —
generic配置文件适用于任何 CHM,revit配置文件适用于 Autodesk Revit API 文档 - 自动检测编码 — 通过
chardet处理 UTF-8、GB18030、GBK、GB2312 等编码 - 跨平台检测 7-Zip — 可在 PATH 中查找
7z/7za/7zz(Windows、Linux、macOS) - 灵活支持 CHM 结构 — 支持
html/子目录、扁平结构和深层嵌套结构(例如 DirectX SDK) --preserve-structure— 可选择在输出中保留 CHM 内部文件夹层级,而不是将所有内容扁平化到data/中- 保留代码块 — 根据类名和命名 div 检测语言;支持 C#、VB、C++、F#、Python、Java、JS/TS、Bash、SQL、XML、JSON
- 表格规范化 — 清理并重新格式化 Markdown 表格
- 生成索引 — 生成
file_index.json、id_lookup.json和index.md,用于搜索和 AI 集成 - 异步与批处理 — 有界并发和定期 GC 可防止处理大型 CHM 文件(6 000 多个页面)时内存溢出
项目结构
chm_converter/ # Core package
├── config.py # ConversionConfig dataclass + built-in profiles
├── encoding.py # Encoding detection (chardet + CJK fallbacks)
├── extractor.py # CHM extraction via 7-Zip; HTML folder detection
├── html_processor.py # HTML cleaning, link rewriting, code block extraction
├── md_converter.py # HTML → Markdown conversion + post-processing
├── indexer.py # File dictionary building + index file generation
└── pipeline.py # High-level async pipeline (process_chm_file, process_all_chm_files)
chm_to_markdown.py # CLI entry point
resources/ # Place CHM files here
output/ # Generated Markdown (created automatically)
输出布局
output/
└── <name>/
├── core/
│ ├── file_index.json # id → {title, filename, version}
│ ├── id_lookup.json # lowercase id → {title, filename, keywords, version}
│ └── index.md # alphabetical navigation page
└── data/
├── Topic1.md
├── Topic2.md
└── ...
要求
- Python 3.10+
- 7-Zip —
7z必须可通过默认安装路径或PATH访问- Windows:默认安装到
C:\Program Files\7-Zip\7z.exe,也可将其添加到PATH - Linux:
sudo apt install p7zip-full - macOS:
brew install p7zip
- Windows:默认安装到
安装
git clone https://github.com/DTDucas/chm-converter.git
cd chm-converter
pip install -r requirements.txt
使用方法
将 .chm 文件放入 resources/ 文件夹,然后运行:
# Interactive menu (lists available CHM files)
python chm_to_markdown.py
# Convert a single file
python chm_to_markdown.py --single resources/docs.chm
# Convert all CHM files in resources/
python chm_to_markdown.py --all
# Use the Revit API profile (strips Revit help-viewer boilerplate)
python chm_to_markdown.py --all --profile revit
# Preserve the original folder hierarchy inside data/ (e.g. for DirectX SDK)
python chm_to_markdown.py --single resources/directx_sdk.chm --preserve-structure
# Keep extracted HTML for debugging
python chm_to_markdown.py --single resources/docs.chm --keep-html
# Tune performance
python chm_to_markdown.py --all --workers 4 --batch-size 25 --semaphore 10
CLI 参数
| 参数 | 短选项 | 默认值 | 说明 |
|---|---|---|---|
--single FILE | -s | — | 转换单个 CHM 文件 |
--all | -a | — | 转换 resources/ 中的所有 CHM 文件 |
--profile | -p | generic | 转换配置文件:generic 或 revit |
--keep-html | -k | 关闭 | 转换后保留提取的 HTML |
--workers N | -w | 8 | 用于受 CPU 限制的转换任务的线程池大小 |
--batch-size N | -b | 50 | 每个异步批次处理的文件数 |
--semaphore N | — | 20 | 最大并发 I/O 操作数 |
--preserve-structure | — | 关闭 | 在 data/ 中保留 CHM 文件夹层级;保留相对链接 |
配置文件
| 配置文件 | 说明 |
|---|---|
generic | 仅进行最基本的清理 — 适用于任何 CHM 文件 |
revit | 移除 Autodesk Revit 帮助查看器界面元素(可折叠区域、反馈链接、代码选项卡工具栏、样板文本) |
可通过编程方式创建自定义配置文件:
from chm_converter.config import ConversionConfig
from chm_converter.pipeline import process_chm_file
import asyncio
cfg = ConversionConfig(
classes_to_remove=["my-nav-bar", "site-footer"],
ids_to_remove=["cookie-banner"],
cleanup_patterns=[
(r"Rate this article.*?---", "---"),
],
)
asyncio.run(process_chm_file("docs.chm", "extracted", "output", cfg=cfg))
AI 集成
core/ 文件夹专为 RAG 和 AI 搜索工作流设计:
file_index.json— 将每个文件 ID 映射到其标题、文件名和版本id_lookup.json— 使用小写键,并附带提取的关键词列表,用于全文搜索index.md— 带有锚点链接、按字母顺序排列的易读索引
故障排除
| 问题 | 解决方案 |
|---|---|
7z not found | 安装 7-Zip 并确保它位于 PATH 中;参见上文的“要求” |
输出为空 / No HTML files found | CHM 使用嵌套文件夹结构 — 添加 --preserve-structure 以启用递归遍历 |
| Revit 2025+ 页面仅包含标题,没有正文 | 已在当前版本中修复:Revit 配置文件不再剥离 TopicContent |
| CJK 文本乱码 | 工具通过 chardet 自动检测编码;如果问题仍然存在,请尝试使用 --profile generic |
| 处理大型 CHM 时发生内存错误 | 降低 --workers 和 --batch-size |
| 权限错误 | 使用管理员 / sudo 权限运行终端 |
许可证
MIT 许可证
作者
Duong Tran Quang (DTDucas) [email protected] github.com/DTDucas 作者:dtducas.com
贡献者
- Jiangxumin — 中文编码支持、跨平台 7-Zip 检测、安全的内存批处理(PR #11)
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。