summaryrefslogtreecommitdiff
path: root/support/make4ht/make4ht-odtfilter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'support/make4ht/make4ht-odtfilter.lua')
-rw-r--r--support/make4ht/make4ht-odtfilter.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/support/make4ht/make4ht-odtfilter.lua b/support/make4ht/make4ht-odtfilter.lua
new file mode 100644
index 0000000000..97f0b8df67
--- /dev/null
+++ b/support/make4ht/make4ht-odtfilter.lua
@@ -0,0 +1,33 @@
+local mkutils = require "mkutils"
+local zip = require "zip"
+
+
+-- use function to change contents of the ODT file
+local function update_odt(odtfilename, file_path, fn)
+ -- get name of the odt file
+ local odtname = mkutils.remove_extension(odtfilename) .. ".odt"
+ -- open and read contents of the requested file inside ODT file
+ local odtfile = zip.open(odtname)
+ local local_file = odtfile:open(file_path)
+ local content = local_file:read("*all")
+ local_file:close()
+ odtfile:close()
+ -- update the content using user function
+ content = fn(content)
+ -- write the updated file
+ local local_file_file = io.open(file_path,"w")
+ local_file_file:write(content)
+ local_file_file:close()
+ os.execute("zip " .. odtname .. " " .. file_path)
+ os.remove(file_path)
+end
+
+Make:match("tmp$", function(name, par)
+ update_odt(name, "content.xml", function(content)
+ return content:gsub("%&%#x([A-Fa-f0-9]+);", function(entity)
+ -- convert hexadecimal entity to Unicode
+ print(entity,utfchar(tonumber(entity, 16)))
+ return utfchar(tonumber(entity, 16))
+ end)
+ end)
+end)