21.36. .chm 怎麼在 Unix 底下觀看?

Contributed by: mison@bbs.ee.ntu.edu.tw

Last Update: 2003年 4月16日 周三 16時35分53秒 CST

目前都是將 .chm 解壓縮成 .html 後再,再用瀏覽器去看。 現有的 .chm 方案有兩個,一個是 misc/chmlib 以及 chmtools,不過兩套都沒有解壓縮的工具, 或是不適合中文的處理,因此 mison 利用 chmtools 寫了一個 chm2html 的工具,如果有興趣的人可以試試看。

outta-port/chm2html 的安裝:

# cd /usr/ports/outta-port/chm2html
# make install clean

在這邊以一個 braille.chm 為例子, 用 chm2html 來解壓縮,並解壓縮到 braille 的目錄下:

chm2html < braille.chm braille/

在 braille 的目錄下會產生一個 braille.hhc 的目錄檔, 接著再用 hhc2html.pl 將索引檔轉出來:

hhc2html.pl braille/braille.hhc > braille/braille.html

也可以用 hhc2bookmark.pl 將目錄檔轉成 mozilla 的 bookmark 來用:

hhc2bookmark.pl --lo=on --root=`pwd`/brailee brailee/braille.hhc > bookmark.html

中文檔名的部分,只是把 chm 裡的 unicode 轉成 big5, 這樣只是讓解出來的中文檔名可以讓人看得懂,hyper link還是會有問題。

參數 --lo=on 是指定把大寫檔名改為小寫, 這是因為 chm2thml 是根據 chm 檔頭解出檔案, 而 hhc 目錄、chm 檔頭裡的檔名,兩者可能不一致。 所以在第一步 chm 解開後、 自行判斷要不要加 --lo=on

bookmark 只是一個暫時的解決方案,可以用 hhc2bookmark.pl 轉出來的檔案替換原來 ~/.mozilla 裡的 bookmark, 這樣可以模擬 MircoSoft IE 的 text/sitemap;其實有更好 的方法, mozilla 有提供 sidebar 和 IE sitemap 類似,或是在 mozilla 讀取到特殊的副檔名或是 MIME Type 時去自動呼叫 chm2html 並作成網頁來讀去。

hyper link 檔名不一致的問題可能千奇百怪,轉目錄的程式是用 perl 寫的, 若有需要,請自行修改 perl 程式裡的 regular expressions

在將 hhc2html.pl 產生的目錄加到 sidebar 中, 測試的結果,使用如下的方式可以加入 sitebar:

javascript:window.sidebar.addPanel('title','http://','');

但是把 http:// 換成 file:// 就沒辦法加進去,所以還是直接執行 chm.sh braille.chm 囉。

在特殊檔名或是MIME Type的處理得感謝 bv1al 提供的靈感, 使用 mozilla 也可以用類似方法開啟。

mozilla pull-down toolbar:
        Edit->Preferences->Navigator->HelperApplications->NewType:
                Description of type: MicroSoft HTML Help
                File extension:      chm
                MIME Type: chemical/x-chemdraw application/mshelp
                Application to use:  chm.sh

不過以上的方法在筆者測試下,並沒有作用,如果有人成功請告訴我一下。

MicroSoft 有個程式可以 HTML 轉 CHM,也可以轉回來,應該是這個 HTMLHELP.EXE ,在 MicroSoft 下處理 HTML 與 CHM 互轉時蠻好用的。

WWW: http://66.93.236.84/~jedwin/projects/chmlib/

WWW: http://www.speakeasy.org/~russotto/chm/