summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-03-21 20:55:01 +0000
committerKarl Berry <karl@freefriends.org>2019-03-21 20:55:01 +0000
commit042522d56eecc50b11be37d5284fc43d2a6b51fe (patch)
tree2db37cb0741816116a1ce464676f8966b14f5c2d /Master/texmf-dist/scripts
parent15bbde433ae20973daca814631a22c558eaecd57 (diff)
make4ht (21mar19)
git-svn-id: svn://tug.org/texlive/trunk@50511 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rw-r--r--Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincolors.lua73
-rw-r--r--Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtimagesize.lua4
-rw-r--r--Master/texmf-dist/scripts/make4ht/extensions/join_colors.lua16
-rw-r--r--Master/texmf-dist/scripts/make4ht/formats/odt.lua2
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht2
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht-config.lua2
6 files changed, 94 insertions, 5 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincolors.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincolors.lua
new file mode 100644
index 00000000000..1b7a97be0a2
--- /dev/null
+++ b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-joincolors.lua
@@ -0,0 +1,73 @@
+local cssfiles = {}
+
+
+-- keep mapping between span ids and colors
+local colors = {}
+
+local function extract_colors(csscontent)
+ local used_colors = {}
+ -- delete the color ids and save the used colors
+ csscontent = csscontent:gsub("[%a]*%#(textcolor.-)%s*{%s*color%s*%:%s*(.-)%s*%}%s", function(id, color)
+ -- convert rgb() function to hex value and generate the span name
+ local converted = "textcolor-" .. color:gsub("rgb%((.-),(.-),(.-)%)", function(r,g,b)
+ return string.format("%02x%02x%02x", tonumber(r), tonumber(g), tonumber(b))
+ end)
+ -- save the id and used color
+ colors[id] = converted
+ used_colors[converted] = color
+ return ""
+ end)
+ -- add the used colors to css
+ local t = {}
+ for class, color in pairs(used_colors) do
+ t[#t+1] = string.format(".%s{color:%s;}", class, color)
+ end
+ return csscontent .. table.concat(t, "\n")
+end
+
+local function process_css(cssfile)
+ local f = io.open(cssfile,"r")
+ if not f then return nil, "Cannot open the CSS file: ".. cssfile end
+ local content = f:read("*all")
+ f:close()
+ -- delete color ids and replace them with joined spans
+ local newcontent = extract_colors(content)
+ -- save the updated css file
+ local f=io.open(cssfile, "w")
+ f:write(newcontent)
+ f:close()
+end
+
+
+local function process_css_files(dom)
+ for _, el in ipairs(dom:query_selector("link")) do
+ local href = el:get_attribute("href") or ""
+ if not cssfiles[href] and href:match("css$") then
+ print("Load CSS file ", href)
+ cssfiles[href] = true
+ process_css(href)
+ end
+ end
+
+end
+
+local function join_colors(dom)
+ -- find css files in the current HTML file and join the colors
+ process_css_files(dom)
+ for _, span in ipairs(dom:query_selector("span")) do
+ local id = span:get_attribute("id")
+ if id then
+ -- test if the id is in the saved colors
+ local class = colors[id]
+ if class then
+ -- remove the id
+ span:set_attribute("id", nil)
+ span:set_attribute("class", class)
+ end
+ end
+ end
+
+ return dom
+end
+
+return join_colors
diff --git a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtimagesize.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtimagesize.lua
index 92ce68dee4c..4ce8f0d92ea 100644
--- a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtimagesize.lua
+++ b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtimagesize.lua
@@ -7,8 +7,8 @@ return function(dom)
local image = images[1]
local width = image:get_attribute("svg:width")
local height = image:get_attribute("svg:height")
- frame:set_attribute("svg:width", width)
- frame:set_attribute("svg:height", height)
+ if widht then frame:set_attribute("svg:width", width) end
+ if height then frame:set_attribute("svg:height", height) end
print("image dimensions", width, height)
end
end
diff --git a/Master/texmf-dist/scripts/make4ht/extensions/join_colors.lua b/Master/texmf-dist/scripts/make4ht/extensions/join_colors.lua
new file mode 100644
index 00000000000..182661fbdbc
--- /dev/null
+++ b/Master/texmf-dist/scripts/make4ht/extensions/join_colors.lua
@@ -0,0 +1,16 @@
+local M = {}
+
+local filter = require "make4ht-domfilter"
+
+-- 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 {"joincolors"}
+ make:match("html$", process)
+ 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 453c46aff5e..64b8793e2a7 100644
--- a/Master/texmf-dist/scripts/make4ht/formats/odt.lua
+++ b/Master/texmf-dist/scripts/make4ht/formats/odt.lua
@@ -130,7 +130,7 @@ function M.modify_build(make)
-- expanded in tex4ht.env in Miktex or Debian
call_xtpipes(make)
-- fix the image dimensions wrongly set by xtpipes
- local domfilters = domfilter {"t4htlinks","odtimagesize"}
+ local domfilters = domfilter {"t4htlinks"}
make:match("4oo$", domfilters)
-- execute it before xtpipes, because we don't want xtpipes to mess with t4htlink elements
move_matches(make)
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht b/Master/texmf-dist/scripts/make4ht/make4ht
index 44c3582134a..ab8e1cfbc6f 100755
--- a/Master/texmf-dist/scripts/make4ht/make4ht
+++ b/Master/texmf-dist/scripts/make4ht/make4ht
@@ -27,7 +27,7 @@ make4ht [options] filename ["tex4ht.sty op." "tex4ht op." "t4ht op" "latex op"]
-- set version number. the template should be replaced by the
-- actual version number by the build script
-local version = "v0.2e"
+local version = "v0.2f"
mkparams.version_number = version
local args = mkparams.get_args()
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht-config.lua b/Master/texmf-dist/scripts/make4ht/make4ht-config.lua
index bd83632a574..310f5afd7bf 100755
--- a/Master/texmf-dist/scripts/make4ht/make4ht-config.lua
+++ b/Master/texmf-dist/scripts/make4ht/make4ht-config.lua
@@ -21,7 +21,7 @@ local xdg_config = function(filename, xdg_config_name)
local dotfilename = "." .. filename
local xdg_config_name = xdg_config_name or "config.lua"
local xdg = os.getenv("XDG_CONFIG_HOME") or ((os.getenv("HOME") or "") .. "/.config")
- local home = os.getenv("HOME")
+ local home = os.getenv("HOME") or os.getenv("USERPROFILE")
if xdg then
-- filename like ~/.config/make4ht/config.lua
local fn = make_name{ xdg ,filename , xdg_config_name }