module(...,package.seeall) local eb = require("exec_epub") local ext = "xhtml" local outputdir = nil local input = nil function prepare(params) local basedir = params.input.."-".. params.format local outputdir_name="OEBPS" outputdir= basedir.."/"..outputdir_name input = params.input params.ext = ext params.packages = params.packages .. string.format("\\Configure{ext}{%s}",ext) return eb.prepare(params) end function run(out,params) return eb.run(out, params) end local function makeTOC(document) local template = [[ TOC ]] % {document=document} return template end local function cleanOPF() -- in epub3, there must be table of contents -- if there is no toc in the document, we must add generic one local opf = "content.opf" local f = io.open(opf,"r") if not f then print("Cannot open "..opf .. " for toc searching") return nil end local content = f:read("*all") f:close() if content:find "properties[%s]*=[%s]*\"[^\"]*nav" then print "TOC nav found" else print "no TOC, using generic one" local inputfile = input .. "." .. ext print("Main file name", inputfile) -- write toc file local toc_name = "generic_toc" .."."..ext local f = io.open(outputdir .. "/" .. toc_name, "w") f:write(makeTOC(inputfile)) f:close() -- add toc file to the conten.opf content = content:gsub("","\n\n") content = content:gsub("]*)>", "\n\n") -- remove empty guide element end content = content:gsub("%s*","") f = io.open(outputdir .. "/" ..opf,"w") f:write(content) f:close() --makeTOC(inputfile) end function writeContainer() --local ret = eb.writeContainer() eb.make_opf() cleanOPF() local ret = eb.pack_container() return ret end function clean() return eb.clean() end