summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-01-27 22:49:22 +0000
committerKarl Berry <karl@freefriends.org>2019-01-27 22:49:22 +0000
commit520f13ff78f411f89fa1e20e60f11d2036c9a6da (patch)
treee884cee9fb34a03ff2250e2ac28c9e2f3cb41b96 /Master/texmf-dist/scripts/make4ht
parente89a762d6eff1447eae6d9f96e8c28c42833c794 (diff)
make4ht
git-svn-id: svn://tug.org/texlive/trunk@49840 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht')
-rw-r--r--Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua32
-rwxr-xr-xMaster/texmf-dist/scripts/make4ht/make4ht2
2 files changed, 32 insertions, 2 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua b/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua
index cadcbfcd478..c323d206c10 100644
--- a/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua
+++ b/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua
@@ -1,5 +1,6 @@
local mkutils = require "mkutils"
local zip = require "zip"
+local domobject = require "luaxml-domobject"
local function get_template_filename(settings)
@@ -12,6 +13,34 @@ local function get_template_filename(settings)
return settings.template or filtersettings.template
end
+local function join_styles(old, new)
+ local old_dom = domobject.parse(old)
+ local new_dom = domobject.parse(new)
+
+ local template_styles = {}
+ local template_obj -- <office:styles> element, we will add new styles from the generated ODT here
+
+ -- detect style names in the template file and save them in a table for easy accesss
+ for _, style in ipairs(new_dom:query_selector("office|styles *")) do
+ template_obj = template_obj or style:get_parent()
+ local name = style:get_attribute("style:name") -- get the <office:styles> element
+ if name then
+ template_styles[name] = true
+ end
+ end
+
+ -- process the generated styles and add ones not used in the template
+ for _, style in ipairs(old_dom:query_selector("office|styles *")) do
+ local name = style:get_attribute("style:name")
+ if name and not template_styles[name] then
+ template_obj:add_child_node(style)
+ end
+ end
+
+ -- return template with additional styles from the generated file
+ return new_dom:serialize()
+end
+
return function(content, settings)
-- use settings added from the Make:match, or default settings saved in Make object
local templatefile = get_template_filename(settings)
@@ -23,7 +52,8 @@ return function(content, settings)
-- just break if the styles cannot be found
if not stylesfile then return content end
local styles = stylesfile:read("*all")
- return styles
+ local newstyle = join_styles(content, styles)
+ return newstyle
end
-- just return content in the case of problems
return content
diff --git a/Master/texmf-dist/scripts/make4ht/make4ht b/Master/texmf-dist/scripts/make4ht/make4ht
index 1d558e59579..44c3582134a 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.2d"
+local version = "v0.2e"
mkparams.version_number = version
local args = mkparams.get_args()