Last active
December 31, 2015 12:09
-
-
Save skoji/7984149 to your computer and use it in GitHub Desktop.
遅すぎですが。
ちょっと変更しました。EPUB前提なら、XMLで読んだようがいろいろとよいのでNokogiri::HTMLではなくNokogiri::XMLにしてみました
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install nokogiri | |
$ ruby zen-to-han.rb < source.html > destination.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'nokogiri' | |
doc = Nokogiri::XML.parse($stdin.read) | |
def zen_to_han(e) | |
e.content = e.content.tr("a-zA-Z","a-zA-Z") if e.text? | |
e.children.each { |ec| zen_to_han ec } if e.elem? | |
end | |
zen_to_han doc.at 'body' | |
puts doc.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment