summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/tex4ebook
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-03-21 20:57:24 +0000
committerKarl Berry <karl@freefriends.org>2019-03-21 20:57:24 +0000
commita5de2c33c167bd9438ec901fd013cbd3ded17861 (patch)
treed5153925188fec09cf1a15f83b658bccc89b1cbb /Master/texmf-dist/scripts/tex4ebook
parent042522d56eecc50b11be37d5284fc43d2a6b51fe (diff)
tex4ebook (21mar19)
git-svn-id: svn://tug.org/texlive/trunk@50512 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/tex4ebook')
-rwxr-xr-xMaster/texmf-dist/scripts/tex4ebook/exec_epub.lua41
-rwxr-xr-xMaster/texmf-dist/scripts/tex4ebook/exec_epub3.lua4
-rwxr-xr-xMaster/texmf-dist/scripts/tex4ebook/tex4ebook2
3 files changed, 30 insertions, 17 deletions
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("<guide>%s*</guide>","")
+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("<spine([^>]*)>", "<spine%1>\n<itemref idref=\"htmltoc\" linear=\"no\"/>\n")
-- remove empty guide element
end
- content = content:gsub("<guide>%s*</guide>","")
+ -- content = content:gsub("<guide>%s*</guide>","")
+ 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