diff options
author | Karl Berry <karl@freefriends.org> | 2015-07-03 23:26:48 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-07-03 23:26:48 +0000 |
commit | f71a40ca0224f4683054fbb9e1cf9fa26561f829 (patch) | |
tree | 62f2c1cda8a9743edfeb4b4634355f9cdf6ef951 /Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua | |
parent | f1073f0dfaaeabd2edda00c472a3d814fad132fa (diff) |
tex4ebook (29jul15)
git-svn-id: svn://tug.org/texlive/trunk@37751 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua')
-rwxr-xr-x | Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua b/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua new file mode 100755 index 00000000000..55f7f71c309 --- /dev/null +++ b/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua @@ -0,0 +1,92 @@ +module(...,package.seeall) +local eb = require("exec_epub") + +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.packages = params.packages .. "\\Configure{ext}{xhtml}" + return eb.prepare(params) +end + +function run(out,params) + return eb.run(out, params) +end + + +local function makeTOC(document) + local template = [[ +<!DOCTYPE html> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:epub="http://www.idpf.org/2007/ops" +> +<head><title>TOC</title></head> +<body> +<nav id="pub-toc" epub:type="toc"> + <h1>Table of contents</h1> + <ol class="toc" hidden="hidden"> + <li> + <a href="${document}">Document</a> + </li> + </ol> +</nav> +</body> +</html> +]] % {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 pattern = input.."(%..?html)" + local ext = content:match(pattern) + 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("<manifest>","<manifest>\n<item id='htmltoc'" .. + " properties=\"nav\" media-type=\"application/xhtml+xml\" href=\"".. + toc_name .."\" />\n") + content = content:gsub("<spine([^>]*)>", "<spine%1>\n<itemref idref=\"htmltoc\" linear=\"no\"/>\n") + -- remove empty guide element + end + content = content:gsub("<guide>%s*</guide>","") + 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 |