Skip to content
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

Merged
merged 3 commits into from
Oct 26, 2016
Merged

chmファイル生成方法変更 #20

merged 3 commits into from
Oct 26, 2016

Conversation

dogatana
Copy link
Contributor

@dogatana 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文字へ置き換え
@dogatana
Copy link
Contributor Author

dogatana commented Sep 7, 2016

ひとまず妥当な chm ファイルが作成できるまでの修正です。
ナビゲーション(目次)はkindle (epub) も含めて見直したいと考えています。

@okkez
Copy link
Member

okkez commented Sep 8, 2016

あとで見ます。

# 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')
Copy link
Member

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" => "\\"})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よく見たら UTF-8 で見た目の似ている別の文字に置き換えてから Windows-31J に変換してたんですね。。。

Copy link
Contributor Author

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 を発行したいところです。

@dogatana
Copy link
Contributor Author

dogatana commented Sep 10, 2016

確認ありがとうございます。

fallback option を使うのがいいと思います

これは知らなかったので2.3.0のマニュアルの String#encode を見たのですが、option として記載がありませんでした。どこかで詳細を確認できますか?

Windows-31J とか CP932 の方がよかったりしませんか?

MIME typeでこれらは見たことがないのと、Shift_JISなら包含するのであまり考えずに決めました。
改めてRFCから辿ってみると、
http://www.iana.org/assignments/character-sets/character-sets.xhtml
では Preferred MIEM tpye としてあるのは Shift_JIS。Windows-31Jも Nameとして掲載。CP932はありません。なのでShjift_JISで良いのではと思うのですが、どうでしょうか。
添付のCSVとかもあるようなので、後で見てみます。

RubyKaigiは良く切れるのですが、なんとか書けました。^^;

@okkez
Copy link
Member

okkez commented Sep 11, 2016

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 にするのがいいと思いました。
調べるのが面倒なら Windows-31J にすると良いように思います。

@dogatana
Copy link
Contributor Author

1. String#encode について

実は英語のドキュメントに載っているのです。。。

rdoc ベース?の方ですね。見てみます。

2. charset について

調べるのが面倒なら Windows-31J にすると良いように思います。

rubydoc の下のファイルで例外の原因となる文字は次のとおりです。

Shift_JIS "¥", "·", "ä", "ö", "à", "̈"
Windows-31J "¥", "〜", "—", "−", "·", "ä", "ö", "à", "̈"

実際のところ、Windows-31J の方がより多くの文字で例外が出ます。

実装(ruby-2.4.0-preview2/enc/windows_31j.c )では

  • Windows-31J を定義
  • shift_jis.c を include
  • エイリアスとして CP932, csWindows31J, SJIS を定義
  • コメントに "IE6 don't accept Windows-31J but csWindows31J." の記述あり
    となっています。

そもそもCHMファイル内部に取り込まれるものでもあるので、動いて(表示ができて)いれば、あまり神経質にならなくても良いかもしれません。Windows-31J にしますかね。
なおWindows-31Jとしても表示されるのは確認済みです。

Windows で表示する前提に立つとき、"¥", "〜", "—", "−", "·" が例外となる方が問題としては大きいですし。

ただ Shift_JIS, Windows-31J の違いや、Microsoft Unicode の特殊性(同じ見た目の文字に対して別のコードポイントが当てられている)などは、進んでいくと深みにはまりそうな予感がします。

@dogatana
Copy link
Contributor Author

charaset の Windows-31Jへの変更と String#tr から String#encode 時の fallback オプション変更の対応が完了したので、改めて pull request します。

@okkez okkez merged commit 3d9d62d into rurema:master Oct 26, 2016
@okkez
Copy link
Member

okkez commented Oct 26, 2016

遅くなって申し訳ないです。。。マージしました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants