Körperbewegung
This commit is contained in:
parent
b16b24e4f7
commit
95945c0306
78 changed files with 12503 additions and 0 deletions
27
mods/modlib/web/html.lua
Normal file
27
mods/modlib/web/html.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
local html = setmetatable({}, {__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.utf8.char(tonumber(digits)) end) -- decimal
|
||||
:gsub("&#x(%x+);", function(digits) return modlib.utf8.char(tonumber(digits, 16)) end) -- hex
|
||||
end
|
||||
self.unescape = unescape
|
||||
return unescape
|
||||
end
|
||||
end})
|
||||
|
||||
function html.escape(text)
|
||||
return text:gsub(".", {
|
||||
["<"] = "<",
|
||||
[">"] = ">",
|
||||
["&"] = "&",
|
||||
["'"] = "'",
|
||||
['"'] = """,
|
||||
})
|
||||
end
|
||||
|
||||
return html
|
3
mods/modlib/web/html/entities.lua
Normal file
3
mods/modlib/web/html/entities.lua
Normal file
File diff suppressed because one or more lines are too long
42
mods/modlib/web/uri.lua
Normal file
42
mods/modlib/web/uri.lua
Normal file
|
@ -0,0 +1,42 @@
|
|||
-- URI escaping utilities
|
||||
-- See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
|
||||
|
||||
local uri_unescaped_chars = {}
|
||||
for char in ("-_.!~*'()"):gmatch(".") do
|
||||
uri_unescaped_chars[char] = true
|
||||
end
|
||||
local function add_unescaped_range(from, to)
|
||||
for byte = from:byte(), to:byte() do
|
||||
uri_unescaped_chars[string.char(byte)] = true
|
||||
end
|
||||
end
|
||||
add_unescaped_range("0", "9")
|
||||
add_unescaped_range("a", "z")
|
||||
add_unescaped_range("A", "Z")
|
||||
|
||||
local uri_allowed_chars = table.copy(uri_unescaped_chars)
|
||||
for char in (";,/?:@&=+$#"):gmatch(".") do
|
||||
-- Reserved characters are allowed
|
||||
uri_allowed_chars[char] = true
|
||||
end
|
||||
|
||||
local function encode(text, allowed_chars)
|
||||
return text:gsub(".", function(char)
|
||||
if allowed_chars[char] then
|
||||
return char
|
||||
end
|
||||
return ("%%%02X"):format(char:byte())
|
||||
end)
|
||||
end
|
||||
|
||||
local uri = {}
|
||||
|
||||
function uri.encode_component(text)
|
||||
return encode(text, uri_unescaped_chars)
|
||||
end
|
||||
|
||||
function uri.encode(text)
|
||||
return encode(text, uri_allowed_chars)
|
||||
end
|
||||
|
||||
return uri
|
Loading…
Add table
Add a link
Reference in a new issue