Module:string/encode entities

From Linguifex
Revision as of 10:57, 9 May 2026 by Sware (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


-- TO BE REPLACED BY encode_entities in [[Module:string utilities]]. This function decodes on input by default to prevent double-encoding, which the new function does not, so implementations need to take this into account when being converted.

local string_decode_entities_module = "Module:string/decodeEntities"
local string_utilities_module = "Module:string utilities"

local require = require

local function decode_entities(...)
	decode_entities = require(string_decode_entities_module)
	return decode_entities(...)
end

local function encode_entities(...)
	encode_entities = require(string_utilities_module).encode_entities
	return encode_entities(...)
end

return function(str, charset, raw)
	if not raw then
		local decoded = decode_entities(str)
		str = decoded
	end
	return encode_entities(str, charset, nil, true)
end