From a5de2c33c167bd9438ec901fd013cbd3ded17861 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 21 Mar 2019 20:57:24 +0000 Subject: tex4ebook (21mar19) git-svn-id: svn://tug.org/texlive/trunk@50512 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/tex4ebook/exec_epub.lua | 41 ++++++++++++++-------- Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua | 4 ++- Master/texmf-dist/scripts/tex4ebook/tex4ebook | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) (limited to 'Master/texmf-dist/scripts') diff --git a/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua b/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua index 8502f280597..d92a8d103c9 100755 --- a/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua +++ b/Master/texmf-dist/scripts/tex4ebook/exec_epub.lua @@ -20,7 +20,26 @@ tidy = false local include_fonts = false local metadir="" - +-- from https://stackoverflow.com/a/43407750/2467963 +local function deletedir(dir) + local attr = lfs.attributes(dir) + if attr then + for file in lfs.dir(dir) do + local file_path = dir..'/'..file + if file ~= "." and file ~= ".." then + if lfs.attributes(file_path, 'mode') == 'file' then + os.remove(file_path) + print('remove file',file_path) + elseif lfs.attributes(file_path, 'mode') == 'directory' then + print('dir', file_path) + deletedir(file_path) + end + end + end + lfs.rmdir(dir) + end + print('remove dir',dir) +end function prepare(params) local randname=tostring(math.random(12000)) @@ -42,6 +61,7 @@ function prepare(params) end basedir = params.input.."-".. params.format outputdir= basedir.."/"..outputdir_name --"outdir-"..randname --os.tmpdir() + deletedir(basedir) makedir(outputdir) -- lfs.mkdir(outputdir) --ebookutils.mkdirectories(ebookutils.prepare_path(outputdir.."/")) @@ -131,6 +151,10 @@ local mimetypes = { smil = "application/smil+xml" } +function remove_empty_guide(content) + return content:gsub("%s*","") +end + function make_opf() -- Join files content.opf and content-part2.opf -- make item record for every converted image @@ -183,21 +207,7 @@ function make_opf() -- the same filename is used in different directories. Is that a problem? used_files[filename] = true end - --[[for f in lfs.dir("./OEBPS") do - --table.insert(used_files,f) - --used_files[f] = true - end--]] - -- local all_html = find_all_files(table.concat(used_files,"\n")) local outside_spine = {} - -- This was duplicated code - --[[for i, ext in pairs(all_html) do - if not used_html[i] then - print("Prvni insert: ".. i .."."..ext) - local item, id = lg_item(i.."."..ext) - table.insert(opf_complete,item) - table.insert(outside_spine,id) - end - end--]] local all_used_files = find_all_files(opf_complete[1],"([%a%d%-%_]+%.[%a%d]+)") local used_paths = {} local used_ids = {} @@ -263,6 +273,7 @@ function make_opf() local opf_completed = table.concat(opf_complete,"\n") -- poor man's tidy: remove trailing whitespace befora xml tags opf_completed = opf_completed:gsub("[ ]*<","<") + opf_completed = remove_empty_guide(opf_completed) h_first:write(opf_completed) h_first:close() os.remove(opf_second_part) diff --git a/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua b/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua index 56eff3f341c..53173be9e9c 100755 --- a/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua +++ b/Master/texmf-dist/scripts/tex4ebook/exec_epub3.lua @@ -138,7 +138,9 @@ local function cleanOPF() content = content:gsub("]*)>", "\n\n") -- remove empty guide element end - content = content:gsub("%s*","") + -- content = content:gsub("%s*","") + content = eb.remove_empty_guide(content) + content = add_media_overlays(content) f = io.open(outputdir .. "/" ..opf,"w") f:write(content) diff --git a/Master/texmf-dist/scripts/tex4ebook/tex4ebook b/Master/texmf-dist/scripts/tex4ebook/tex4ebook index 9e396ffc3f8..a95bf44c236 100755 --- a/Master/texmf-dist/scripts/tex4ebook/tex4ebook +++ b/Master/texmf-dist/scripts/tex4ebook/tex4ebook @@ -66,7 +66,7 @@ else end if args.version then - print "tex4ebook v0.2b" + print "tex4ebook v0.2c" return end -- cgit v1.2.3