summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua')
-rw-r--r--Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua13
1 files changed, 13 insertions, 0 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
new file mode 100644
index 00000000000..f93e776717f
--- /dev/null
+++ b/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua
@@ -0,0 +1,13 @@
+-- convert Unicode characters encoded as XML entities back to Unicode
+
+-- list of disabled characters
+local disabled = { ["&"] = "&amp;", ["<"] = "&lt;", [">"] = "&gt;" }
+local utfchar = unicode.utf8.char
+return function(content)
+ return 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)
+end