diff options
author | Karl Berry <karl@freefriends.org> | 2018-05-01 17:59:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-05-01 17:59:54 +0000 |
commit | fa4484fd40909b7d8d5205c08917375a1287748b (patch) | |
tree | abe111fb7ff72f17bd1033f3bab13a51adf005be /Master/texmf-dist/scripts | |
parent | a71a4dcee161662cf17d488c19db04ced2ab6ba7 (diff) |
make4ht lua files in runtime
git-svn-id: svn://tug.org/texlive/trunk@47548 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
8 files changed, 201 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/extensions/common_domfilters.lua b/Master/texmf-dist/scripts/make4ht/extensions/common_domfilters.lua new file mode 100644 index 00000000000..7c9a2dfaea4 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/extensions/common_domfilters.lua @@ -0,0 +1,27 @@ +local M = {} + + +local filter = require "make4ht-domfilter" +-- local process = filter {"fixinlines", "idcolons", "joincharacters" } + +-- filters support only html formats +function M.test(format) + if format == "odt" then return false end + return true +end + +function M.modify_build(make) + local process = filter {"fixinlines", "idcolons", "joincharacters"} + make:match("html$", process) + local matches = make.matches + -- the filters should be first match to be executed, especially if tidy + -- should be executed as well + if #matches > 1 then + local last = matches[#matches] + table.insert(matches, 1, last) + matches[#matches] = nil + end + return make +end + +return M diff --git a/Master/texmf-dist/scripts/make4ht/extensions/common_filters.lua b/Master/texmf-dist/scripts/make4ht/extensions/common_filters.lua new file mode 100644 index 00000000000..513fbed34ee --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/extensions/common_filters.lua @@ -0,0 +1,26 @@ +local M = {} + + +local filter = require "make4ht-filter" +local process = filter {"cleanspan-nat", "fixligatures", "hruletohr", "entities", "fix-links"} + +-- filters support only html formats +function M.test(format) + if format == "odt" then return false end + return true +end + +function M.modify_build(make) + make:match("html$", process) + local matches = make.matches + -- the filters should be first match to be executed, especially if tidy + -- should be executed as well + if #matches > 1 then + local last = matches[#matches] + table.insert(matches, 1, last) + matches[#matches] = nil + end + return make +end + +return M diff --git a/Master/texmf-dist/scripts/make4ht/extensions/latexmk.lua b/Master/texmf-dist/scripts/make4ht/extensions/latexmk.lua new file mode 100644 index 00000000000..bf4dcdde5a4 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/extensions/latexmk.lua @@ -0,0 +1,31 @@ +-- use Latexmk in first LaTeX call +-- only in the first call, because we don't need to execute biber, etc. in the subsequent +-- LaTeX calls, these are only for resolving the cross-references +local M = {} +function M.modify_build(make) + local used = false + local first + local build_seq = make.build_seq + -- find first htlatex call in the build sequence + for pos,v in ipairs(build_seq) do + if v.name == "htlatex" and not first then + first = pos + end + end + -- if htlatex was found + if first then + -- add dummy latexmk call to the build sequence + make:latexmk {} + -- replace name, command and type in the first htlatex + -- call with values from the dummy latexmk call + local replaced = build_seq[first] + local latexmk = build_seq[#build_seq] + replaced.name = latexmk.name + replaced.command = latexmk.command + replaced.type = latexmk.type + -- remove the dummy latexmk + table.remove(build_seq) + end + return make +end +return M diff --git a/Master/texmf-dist/scripts/make4ht/extensions/mathjaxnode.lua b/Master/texmf-dist/scripts/make4ht/extensions/mathjaxnode.lua new file mode 100644 index 00000000000..cbad897d4ec --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/extensions/mathjaxnode.lua @@ -0,0 +1,16 @@ +local M = {} + + +local filter = require "make4ht-filter" +function M.test(format) + if format == "odt" then return false end + return true +end + +function M.modify_build(make) + local mathjax = filter { "mathjaxnode"} + make:match("html$",mathjax) + return make +end + +return M diff --git a/Master/texmf-dist/scripts/make4ht/extensions/tidy.lua b/Master/texmf-dist/scripts/make4ht/extensions/tidy.lua new file mode 100644 index 00000000000..cf8ea9785a5 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/extensions/tidy.lua @@ -0,0 +1,57 @@ +local M = {} + +function M.test(format) + if format == "odt" then return false end + return true +end + +local empty_elements = { + area=true, + base=true, + br=true, + col=true, + embed=true, + hr=true, + img=true, + input=true, + keygen=true, + link=true, + meta=true, + param=true, + source=true, + track=true, + wbr=true, +} + +-- LuaXML cannot read HTML with unclosed tags (like <meta name="hello" content="world">) +-- Tidy removes end slashes in the HTML output, so +-- this function will add them back +local function close_tags(s) + return s:gsub("<(%w+)([^>]-)>", function(tag, rest) + local endslash = "" + if empty_elements[tag] then endslash = " /" end + return string.format("<%s%s%s>", tag, rest, endslash) + end) +end + + + +function M.modify_build(make) + make:match("html$", function(filename, par) + local settings = get_filter_settings "tidy" or {} + par.options = par.options or settings.options or "-utf8 -w 512 -ashtml -q" + local command = "tidy ${options} ${filename}" % par + print("execute: ".. command) + -- os.execute(command) + local run = io.popen(command, "r") + local result = run:read("*all") + run:close() + result = close_tags(result) + local f = io.open(filename, "w") + f:write(result) + f:close() + end) + return make +end + +return M diff --git a/Master/texmf-dist/scripts/make4ht/formats/html5.lua b/Master/texmf-dist/scripts/make4ht/formats/html5.lua new file mode 100644 index 00000000000..633a45e7f34 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/formats/html5.lua @@ -0,0 +1,17 @@ +local M = {} + +local mkutils = require "mkutils" + +function M.prepare_extensions(extensions) + -- return mkutils.add_extensions("+common_domfilters", extensions) + return extensions --mkutils.add_extensions("+tidy", extensions) +end + +function M.prepare_parameters(parameters,extensions) + parameters.tex4ht_sty_par = parameters.tex4ht_sty_par .. ",html5" + parameters = mkutils.extensions_prepare_parameters(extensions,parameters) + return parameters +end + + +return M diff --git a/Master/texmf-dist/scripts/make4ht/formats/odt.lua b/Master/texmf-dist/scripts/make4ht/formats/odt.lua new file mode 100644 index 00000000000..66105166f32 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/formats/odt.lua @@ -0,0 +1,11 @@ +local M = {} +local mkutils = require "mkutils" + +function M.prepare_parameters(settings, extensions) + settings.tex4ht_sty_par = settings.tex4ht_sty_par ..",ooffice" + settings.tex4ht_par = settings.tex4ht_par .. " ooffice/! -cmozhtf" + settings.t4ht_par = settings.t4ht_par .. " -cooxtpipes -coo " + settings = mkutils.extensions_prepare_parameters(extensions, settings) + return settings +end +return M diff --git a/Master/texmf-dist/scripts/make4ht/formats/xhtml.lua b/Master/texmf-dist/scripts/make4ht/formats/xhtml.lua new file mode 100644 index 00000000000..4a4ac6689ca --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/formats/xhtml.lua @@ -0,0 +1,16 @@ +local M = {} + +local mkutils = require "mkutils" + +function M.prepare_extensions(extensions) + -- return mkutils.add_extensions("+common_domfilters", extensions) + return extensions +end + +function M.prepare_parameters(parameters,extensions) + parameters = mkutils.extensions_prepare_parameters(extensions,parameters) + return parameters +end + + +return M |