local function str_to_html(s) s = s:gsub("&", "&") s = s:gsub("<", "<") s = s:gsub(">", ">") s = s:gsub('"', """) s = s:gsub('%%', "%") -- avoid unwanted substitutions return s end local function str_to_pattern(s) s = s:gsub("([%(%)%%%.%+%-%*%?%^%$])", "%%%1") return s end return { str_to_html = str_to_html, str_to_pattern = str_to_pattern, }