mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-20 13:24:11 +02:00
28 lines
861 B
Lua
28 lines
861 B
Lua
|
-- TODO incorporate https://github.com/minetest/minetest/pull/11578
|
||
|
return {
|
||
|
html = setmetatable({
|
||
|
escape = function(text)
|
||
|
return text:gsub(".", {
|
||
|
["<"] = "<",
|
||
|
[">"] = ">",
|
||
|
["&"] = "&",
|
||
|
["'"] = "'",
|
||
|
['"'] = """,
|
||
|
})
|
||
|
end
|
||
|
}, {__index = function(self, key)
|
||
|
if key == "unescape" then
|
||
|
local func = assert(loadfile(modlib.mod.get_resource("modlib", "web", "html", "entities.lua")))
|
||
|
setfenv(func, {})
|
||
|
local named_entities = assert(func())
|
||
|
local function unescape(text)
|
||
|
return text
|
||
|
:gsub("&([A-Za-z]+);", named_entities) -- named
|
||
|
:gsub("&#(%d+);", function(digits) return modlib.text.utf8(tonumber(digits)) end) -- decimal
|
||
|
:gsub("&#x(%x+);", function(digits) return modlib.text.utf8(tonumber(digits, 16)) end) -- hex
|
||
|
end
|
||
|
self.unescape = unescape
|
||
|
return unescape
|
||
|
end
|
||
|
end})
|
||
|
}
|