diff options
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/filters')
3 files changed, 37 insertions, 5 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua b/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua index f93e776717f..fb921a631a3 100644 --- a/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua +++ b/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua @@ -1,13 +1,15 @@ -- convert Unicode characters encoded as XML entities back to Unicode --- list of disabled characters -local disabled = { ["&"] = "&", ["<"] = "<", [">"] = ">" } local utfchar = unicode.utf8.char +-- list of disabled characters +local disabled = { ["&"] = "&", ["<"] = "<", [">"] = ">"} return function(content) - return content:gsub("%&%#x([A-Fa-f0-9]+);", function(entity) + local content = content:gsub("%&%#x([A-Fa-f0-9]+);", function(entity) -- convert hexadecimal entity to Unicode local newchar = utfchar(tonumber(entity, 16)) -- we don't want to break XML validity with forbidden characters return disabled[newchar] or newchar end) + -- the non-breaking space character cause issues in the ODT opening + return content:gsub(string.char(160), " ") end diff --git a/Master/texmf-dist/scripts/make4ht/filters/make4ht-filter.lua b/Master/texmf-dist/scripts/make4ht/filters/make4ht-filter.lua index bef44f585b5..41804aea39d 100644 --- a/Master/texmf-dist/scripts/make4ht/filters/make4ht-filter.lua +++ b/Master/texmf-dist/scripts/make4ht/filters/make4ht-filter.lua @@ -4,9 +4,9 @@ local function load_filter(filtername) return require("filters.make4ht-"..filtername) end -function filter(filters,parameters) +function filter(filters) local sequence = filter_lib.load_filters(filters, load_filter) - return function(filename) + return function(filename, parameters) if not filename then return false, "filters: no filename" end local input = filter_lib.load_input_file(filename) if not input then return nil, "Cannot load the input file" end diff --git a/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua b/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua new file mode 100644 index 00000000000..cadcbfcd478 --- /dev/null +++ b/Master/texmf-dist/scripts/make4ht/filters/make4ht-odttemplate.lua @@ -0,0 +1,30 @@ +local mkutils = require "mkutils" +local zip = require "zip" + + +local function get_template_filename(settings) + -- either get the template odt filename from tex4ht.sty options (make4ht filename.tex "odttemplate=test.odt") + local tex4ht_settings = settings.tex4ht_sty_par + local templatefile = tex4ht_settings:match("odttemplate=([^%,]+)") + if templatefile then return templatefile end + -- read the template odt filename from settings + local filtersettings = get_filter_settings "odttemplate" + return settings.template or filtersettings.template +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) + -- don't do anything if the template file doesn't exist + if not templatefile or not mkutils.file_exists(templatefile) then return content end + local odtfile = zip.open(templatefile) + if odtfile then + local stylesfile = odtfile:open("styles.xml") + -- just break if the styles cannot be found + if not stylesfile then return content end + local styles = stylesfile:read("*all") + return styles + end + -- just return content in the case of problems + return content +end |