summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht/filters/make4ht-entities-to-unicode.lua
blob: f93e776717f6ad6484676dec1cd43c5a35785a7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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