Skip to content

Hab1nA/chm-reader-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chm-reader-cli

CHM (Compiled HTML Help) 文件命令行读取工具。基于 7-Zip 后端,提供 PowerShell 模块和 Python 脚本两种使用方式。

功能

功能 PowerShell 命令 Python 命令
列出 CHM 所有文件 Get-CHMContent / chm python chm_reader.py <file> list
列出 HTML 主题 chm -TopicsOnly python chm_reader.py <file> topics
读取指定文件 Read-CHMFile / chm-read python chm_reader.py <file> read <name>
搜索文本 Search-CHMContent / chm-search python chm_reader.py <file> search <query>
提取全部文件 Expand-CHMFile / chm-extract python chm_reader.py <file> extract
生成浏览索引 Open-CHMBrowser / chm-browse python chm_reader.py <file> index
系统查看器打开 Open-CHMFile / chm-open

前置依赖

  • 7-Zip(完整安装版):https://www.7-zip.org/
    • 便携版 7zr.exe / 7za.exe 不支持 CHM 格式
    • 需要完整安装到 C:\Program Files\7-Zip\
  • Python 3.8+(PowerShell 模块需要)

安装

方式一:PowerShell 模块(推荐)

将整个目录复制到 PowerShell 模块路径:

# 复制模块
$modulePath = "$env:USERPROFILE\Documents\PowerShell\Modules\CHMReader"
Copy-Item -Path . -Destination $modulePath -Recurse -Force

# 验证安装
Import-Module CHMReader
Get-Command -Module CHMReader

若要每次启动自动加载,在 PowerShell profile 中添加:

# 编辑 profile
notepad $PROFILE.CurrentUserAllHosts

# 添加以下内容
Import-Module CHMReader -ErrorAction SilentlyContinue

方式二:直接使用 Python 脚本

python chm_reader.py <chm文件> <动作> [参数]

使用示例

PowerShell 模块

# 列出 CHM 中的 HTML 主题
chm "C:\docs\help.chm" -TopicsOnly

# 读取特定文件内容
chm-read "help.chm" "Introduction.htm"

# 搜索关键词
chm-search "help.chm" "CreateBody"

# 提取全部文件
chm-extract "help.chm" -o "C:\docs\extracted"

# 生成可浏览的 HTML 索引页
chm-browse "help.chm"

Python 脚本

# 列出文件
python chm_reader.py help.chm list

# 列出 HTML 主题
python chm_reader.py help.chm topics

# 读取文件
python chm_reader.py help.chm read Introduction.htm

# 搜索文本
python chm_reader.py help.chm search "keyword"

# 提取全部文件
python chm_reader.py help.chm extract -o output_dir

# 生成索引页面
python chm_reader.py help.chm index -o browse_dir

PowerShell 别名

别名 完整命令
chm Get-CHMContent
chm-read Read-CHMFile
chm-search Search-CHMContent
chm-extract Expand-CHMFile
chm-browse Open-CHMBrowser
chm-open Open-CHMFile

临时文件管理

  • listtopicsreadsearch 命令使用临时目录,命令结束后自动清理
  • extractindex 输出到用户指定目录,文件保留
  • browse 在浏览器打开后自动清理临时文件

项目结构

chm-reader-cli/
├── chm_reader.py      # Python 核心脚本
├── CHMReader.psm1     # PowerShell 模块
├── CHMReader.psd1     # PowerShell 模块清单
└── README.md

许可

MIT

About

CHM文件命令行读取工具

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors