-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chmファイル生成方法変更 #20
chmファイル生成方法変更 #20
Conversation
dogatana
commented
Sep 7, 2016
- hhp, hhc, hhk ファイルのエンコーディングを Windows-31J 固定へ変更
- hhc, hhk ファイルに meta タグ追加
- html ファイルのエンコーディングを可能な限り Windows-31J へ変更
- カタログディレクトリのデフォルト指定追加
- encode('windows-31j') でエラーになる文字を可能な限り、MSのUnicode文字へ置き換え
- hhp, hhc, hhk ファイルのエンコーディングを Windows-31J 固定へ変更 - hhc, hhk ファイルに meta タグ追加 - html ファイルのエンコーディングを可能な限り Windows-31J へ変更 - カタログディレクトリのデフォルト指定追加 - encode('windows-31j') でエラーになる文字を可能な限り、MSのUnicode文字へ置き換え
ひとまず妥当な chm ファイルが作成できるまでの修正です。 |
あとで見ます。 |
# TODO Use String#encode when we drop 1.8 support | ||
str = str.tosjis if sjis_flag | ||
path.open('w') do |f| | ||
str = ms_unicode(str).gsub(/charset=utf-8/i, 'charset=Shift_JIS').encode('windows-31j') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
↓のように fallback option を使うのがいいと思いますー。
str.gsub(/charset=utf-8/i, 'charset=Shift_JIS').encode('windows-31j', fallback: { "\u00a5" => "\\"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よく見たら UTF-8 で見た目の似ている別の文字に置き換えてから Windows-31J に変換してたんですね。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうです。
見た目を同じにして例外を回避し、対象HTMLを日本語文字で検索可能とするための措置です。
chm_subcommand.rb の方はこの週末に follback へ変更し、再度 pull request を発行したいところです。
確認ありがとうございます。
これは知らなかったので2.3.0のマニュアルの String#encode を見たのですが、option として記載がありませんでした。どこかで詳細を確認できますか?
MIME typeでこれらは見たことがないのと、Shift_JISなら包含するのであまり考えずに決めました。 RubyKaigiは良く切れるのですが、なんとか書けました。^^; |
http://docs.ruby-lang.org/en/2.3.0/String.html#method-i-encode Shift_JIS と Windows-31J は Windows-31J の方が範囲広いです。CP932のIBM拡張とNEC拡張の両方を含むのです。Windows-31JとCP932は同じです。 なので、Windows-31Jにしかない文字が含まれていればWindows-31Jにして、含まれていなければ Shift_JIS にするのがいいと思いました。 |
1. String#encode について
rdoc ベース?の方ですね。見てみます。 2. charset について
rubydoc の下のファイルで例外の原因となる文字は次のとおりです。 Shift_JIS "¥", "·", "ä", "ö", "à", "̈" 実際のところ、Windows-31J の方がより多くの文字で例外が出ます。 実装(ruby-2.4.0-preview2/enc/windows_31j.c )では
そもそもCHMファイル内部に取り込まれるものでもあるので、動いて(表示ができて)いれば、あまり神経質にならなくても良いかもしれません。Windows-31J にしますかね。 Windows で表示する前提に立つとき、"¥", "〜", "—", "−", "·" が例外となる方が問題としては大きいですし。 ただ Shift_JIS, Windows-31J の違いや、Microsoft Unicode の特殊性(同じ見た目の文字に対して別のコードポイントが当てられている)などは、進んでいくと深みにはまりそうな予感がします。 |
charaset の Windows-31Jへの変更と String#tr から String#encode 時の fallback オプション変更の対応が完了したので、改めて pull request します。 |
遅くなって申し訳ないです。。。マージしました。 |