Skip to content

Instantly share code, notes, and snippets.

Forked from miyagawa/rhg-mobi.rb
Last active Aug 30, 2018
What would you like to do?
#!/usr/bin/env ruby
file ="index.html", "r:iso-2022-jp:UTF-8")
content =
all_html = <<HTML
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="Author" content="Aoki Minero">
<title>Ruby Hacking Guide</title>
content.scan(%r[<li><a href="(.*?)">(.*?)</a>]) do |filename, title|
chap =, "r:iso-2022-jp:UTF-8", undef: :replace)
html =
html.sub!(/^.+?<h1>/m, %q[<h1 class="chapter">])
html.sub!(/^.+?<h2>はじめに<\/h2>/m, %q[<h1 class="chapter">はじめに</h1>])
html.gsub!(/<h2>/, "<h3>")
html.sub!(%r[</body>.*]m, '')
all_html << html
all_html << '</body></html>'
puts all_html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment