diff --git a/bin/review-epub2html b/bin/review-epub2html
new file mode 100755
index 000000000..d5d30bfa2
--- /dev/null
+++ b/bin/review-epub2html
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+#
+# Copyright (c) 2018 Kenshi Muto
+#
+# This program is free software.
+# You can distribute or modify this program under the terms of
+# the GNU LGPL, Lesser General Public License version 2.1.
+# For details of the GNU LGPL, see the file "COPYING".
+
+require 'pathname'
+
+bindir = Pathname.new(__FILE__).realpath.dirname
+$LOAD_PATH.unshift((bindir + '../lib').realpath)
+
+require 'review/epub2html'
+
+if File.basename($PROGRAM_NAME) == File.basename(__FILE__)
+ ReVIEW::Epub2Html.execute(*ARGV)
+end
diff --git a/lib/review/book/base.rb b/lib/review/book/base.rb
index b2d529583..f318bdab2 100644
--- a/lib/review/book/base.rb
+++ b/lib/review/book/base.rb
@@ -249,11 +249,11 @@ def part_exist?
end
def read_bib
- File.read(File.join(@basedir, bib_file))
+ File.read(File.join(contentdir, bib_file))
end
def bib_exist?
- File.exist?(File.join(@basedir, bib_file))
+ File.exist?(File.join(contentdir, bib_file))
end
def prefaces
diff --git a/lib/review/epub2html.rb b/lib/review/epub2html.rb
new file mode 100644
index 000000000..27a1e20d0
--- /dev/null
+++ b/lib/review/epub2html.rb
@@ -0,0 +1,133 @@
+#
+# Copyright (c) 2018 Kenshi Muto
+#
+# This program is free software.
+# You can distribute or modify this program under the terms of
+# the GNU LGPL, Lesser General Public License version 2.1.
+# For details of the GNU LGPL, see the file "COPYING".
+
+require 'zip'
+require 'rexml/document'
+require 'cgi'
+
+module ReVIEW
+ class Epub2Html
+ def self.execute(*args)
+ new.execute(*args)
+ end
+
+ def execute(*args)
+ if args[0].nil? || !File.exist?(args[0])
+ STDERR.puts < HTMLfile
+ file_for_head_and_foot: HTML file to extract header and footer area.
+ This file must be contained in the EPUB.
+ If omitted, the first found file is used.
+EOT
+ exit 1
+ end
+
+ parse_epub(args[0])
+ puts join_html(args[1])
+ end
+
+ def initialize
+ @opfxml = nil
+ @htmls = {}
+ @head = nil
+ @tail = nil
+ end
+
+ def parse_epub(epubname)
+ Zip::File.open(epubname) do |zio|
+ zio.each do |entry|
+ if entry.name =~ /.+\.opf\Z/
+ opf = entry.get_input_stream.read
+ @opfxml = REXML::Document.new(opf)
+ elsif entry.name =~ /.+\.x?html\Z/
+ @htmls[entry.name.sub('OEBPS/', '')] = entry.get_input_stream.read.force_encoding('utf-8')
+ end
+ end
+ end
+ nil
+ end
+
+ def take_headtail(html)
+ @head = html.sub(/().*/m, '\1')
+ @tail = html.sub(%r{.*(