diff options
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht')
-rw-r--r-- | Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua | 32 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/make4ht/make4ht | 2 |
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() |