diff options
author | Karl Berry <karl@freefriends.org> | 2019-01-10 22:21:14 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-01-10 22:21:14 +0000 |
commit | 8368bb1a1e80c128b441a121a8fda08f0e32d5ae (patch) | |
tree | fb96d623f66cd3bd555c48c0874af9c5ec85fc07 /Master/texmf-dist/scripts/make4ht/formats | |
parent | 59da7b9e7d480f0bc7e89000998103cd707436e7 (diff) |
make4ht (10jan19)
git-svn-id: svn://tug.org/texlive/trunk@49664 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/formats')
-rw-r--r-- | Master/texmf-dist/scripts/make4ht/formats/docbook.lua | 38 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/make4ht/formats/odt.lua | 93 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/make4ht/formats/tei.lua | 14 |
3 files changed, 77 insertions, 68 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/formats/docbook.lua b/Master/texmf-dist/scripts/make4ht/formats/docbook.lua new file mode 100644 index 00000000000..9e5ffe9488b --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/formats/docbook.lua @@ -0,0 +1,38 @@ +local M = {} +local mkutils = require "mkutils" +local lfs = require "lfs" +local os = require "os" +local kpse = require "kpse" +local filter = require "make4ht-filter" +local domfilter = require "make4ht-domfilter" +local xtpipeslib = require "make4ht-xtpipes" + +function M.prepare_parameters(settings, extensions) + settings.tex4ht_sty_par = settings.tex4ht_sty_par ..",docbook" + settings = mkutils.extensions_prepare_parameters(extensions, settings) + return settings +end + +local move_matches = xtpipeslib.move_matches + +-- call xtpipes from Lua +local function call_xtpipes(make) + -- we must find root of the TeX distribution + local selfautoparent = xtpipeslib.get_selfautoparent() + + if selfautoparent then + local matchfunction = xtpipeslib.get_xtpipes(selfautoparent) + make:match("xml$", matchfunction) + move_matches(make) + else + print "Cannot locate xtpipes. Try to set TEXMFROOT variable to a root directory of your TeX distribution" + end +end + +function M.modify_build(make) + -- use xtpipes to fix some common docbook issues + call_xtpipes(make) + return make +end + +return M diff --git a/Master/texmf-dist/scripts/make4ht/formats/odt.lua b/Master/texmf-dist/scripts/make4ht/formats/odt.lua index d5a6b0c9ba5..453c46aff5e 100644 --- a/Master/texmf-dist/scripts/make4ht/formats/odt.lua +++ b/Master/texmf-dist/scripts/make4ht/formats/odt.lua @@ -4,6 +4,8 @@ local lfs = require "lfs" local os = require "os" local kpse = require "kpse" local filter = require "make4ht-filter" +local domfilter = require "make4ht-domfilter" +local xtpipeslib = require "make4ht-xtpipes" function M.prepare_parameters(settings, extensions) @@ -75,82 +77,27 @@ function Odtfile:pack() mkutils.delete_dir(self.archivelocation) end --- find if tex4ht.jar exists in a path -local function find_tex4ht_jar(path) - local jar_file = path .. "/tex4ht/bin/tex4ht.jar" - return mkutils.file_exists(jar_file) +-- escape string to be used in the gsub search +local function escape_file(filename) + local quotepattern = '(['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..'])' + return filename:gsub(quotepattern, "%%%1") end --- return value of TEXMFROOT variable if it exists and if tex4ht.jar can be located inside -local function get_texmfroot() - -- user can set TEXMFROOT environmental variable as the last resort - local root_directories = {kpse.var_value("TEXMFROOT"), kpse.var_value("TEXMFDIST"), os.getenv("TEXMFROOT")} - for _, root in ipairs(root_directories) do - if root then - if find_tex4ht_jar(root) then return root end - -- TeX live locates files in texmf-dist subdirectory, but Miktex doesn't - local path = root .. "/texmf-dist" - if find_tex4ht_jar(path) then return path end - end - end -end - --- Miktex doesn't seem to set TeX variables such as TEXMFROOT --- we will try to find the TeX root using trick with locating package in TeX root --- there is a danger that this file is located in TEXMFHOME, the location will fail then -local function find_texmfroot() - local tex4ht_path = kpse.find_file("tex4ht.sty") - if tex4ht_path then - local path = tex4ht_path:gsub("/tex/generic/tex4ht/tex4ht.sty$","") - if find_tex4ht_jar(path) then return path end - end - return nil -end +local move_matches = xtpipeslib.move_matches -- call xtpipes from Lua local function call_xtpipes(make) -- we must find root of the TeX distribution - local selfautoparent = get_texmfroot() or find_texmfroot() + local selfautoparent = xtpipeslib.get_selfautoparent() + if selfautoparent then - -- make pattern using TeX distro path - local pattern = string.format("java -classpath %s/tex4ht/bin/tex4ht.jar xtpipes -i %s/tex4ht/xtpipes/ -o ${outputfile} ${filename}", selfautoparent, selfautoparent) - -- call xtpipes on a temporary file - local matchfunction = function(filename) - -- move the matched file to a temporary file, xtpipes will write it back to the original file - local basename = mkutils.remove_extension(filename) - local tmpfile = basename ..".tmp" - mkutils.mv(filename, tmpfile) - local command = pattern % {filename = tmpfile, outputfile = filename} - print(command) - local status = os.execute(command) - if status > 0 then - -- if xtpipes failed to process the file, it may mean that it was bad-formed xml - -- we can try to make it well-formed using Tidy - local tidy_command = "tidy -utf8 -xml -asxml -q -o ${filename} ${tmpfile}" % {tmpfile = tmpfile, filename = filename} - print("xtpipes failed trying tidy") - print(tidy_command) - local status = os.execute(tidy_command) - if status > 0 then - -- if tidy failed as well, just use the original file - -- it will probably produce corrupted ODT file though - print("Tidy failed as well") - mkutils.mv(tmpfile, filename) - end - end - end + local matchfunction = xtpipeslib.get_xtpipes(selfautoparent) make:match("4oo", matchfunction) make:match("4om", matchfunction) - -- is is necessary to execute the above matches as first in the build file - local matches = make.matches -- move last match to a first place - local function move_matches() - local last = matches[#matches] - table.insert(matches, 1, last) - matches[#matches] = nil - end -- we need to move last two matches, for 4oo and 4om files - move_matches() - move_matches() + move_matches(make) + move_matches(make) else print "Cannot locate xtpipes. Try to set TEXMFROOT variable to a root directory of your TeX distribution" end @@ -182,10 +129,19 @@ function M.modify_build(make) -- execute xtpipes from the build file, instead of t4ht. this fixes issues with wrong paths -- expanded in tex4ht.env in Miktex or Debian call_xtpipes(make) - -- convert XML entities for Unicoe characters produced by Xtpipes to characters + -- fix the image dimensions wrongly set by xtpipes + local domfilters = domfilter {"t4htlinks","odtimagesize"} + make:match("4oo$", domfilters) + -- execute it before xtpipes, because we don't want xtpipes to mess with t4htlink elements + move_matches(make) + -- convert XML entities for Unicode characters produced by Xtpipes to characters local fixentities = filter {"entities-to-unicode"} make:match("4oo", fixentities) make:match("4om", fixentities) + -- execute fixentities as first + move_matches(make) + move_matches(make) + -- build the ODT file. This match must be executed as a last one -- this will be executed as a first match, just to find the last filename -- in the lgfile @@ -194,8 +150,9 @@ function M.modify_build(make) if not executed then -- this is list of processed files local lgfiles = make.lgfile.files - -- find the last one - local lastfile = lgfiles[#lgfiles] .."$" + -- find the last file and escape it so it can be used + -- in filename match + local lastfile = escape_file(lgfiles[#lgfiles]) .."$" -- make match for the last file -- odt packing will be done here make:match(lastfile, function() diff --git a/Master/texmf-dist/scripts/make4ht/formats/tei.lua b/Master/texmf-dist/scripts/make4ht/formats/tei.lua new file mode 100644 index 00000000000..f81953a8b31 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/formats/tei.lua @@ -0,0 +1,14 @@ +local M = {} +local xtpipeslib = require "make4ht-xtpipes" + +function M.prepare_parameters(settings, extensions) + settings.tex4ht_sty_par = settings.tex4ht_sty_par ..",tei" + settings = mkutils.extensions_prepare_parameters(extensions, settings) + return settings +end + +function M.prepare_extensions(extensions) + return extensions +end + +return M |