Skip to content

Instantly share code, notes, and snippets.

@skoji
Last active December 31, 2015 12:09
Show Gist options
  • Save skoji/7984149 to your computer and use it in GitHub Desktop.
Save skoji/7984149 to your computer and use it in GitHub Desktop.
遅すぎですが。 ちょっと変更しました。EPUB前提なら、XMLで読んだようがいろいろとよいのでNokogiri::HTMLではなくNokogiri::XMLにしてみました
$ gem install nokogiri
$ ruby zen-to-han.rb < source.html > destination.html
# -*- 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