Skip to content

Instantly share code, notes, and snippets.

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-requiv="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")
html =
html.sub!(/^.+?<h1>/m, %q[<h1 class="chapter">])
html.gsub!(/<h2>/, "<h3>")
html.sub!(%r[</body>.*]m, '')
all_html << html
all_html << '</body></html>'
puts all_html
Copy link

miyagawa commented Oct 20, 2013

Save the output to all.html and then run: ebook-convert all.html --mobi-keep-original-image --mobi-file-type both and you get the MOBI:

module.html seems to have invalid characters by the way you have to eliminate before running the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment