Module:Sandbox/Lemondoge/SpellcheckerTM

local p = {} require('Module:Module wikitext')._addText("")

function spellChecker(str, replacements) local function adjust_case(first, second, disable_case_transmission) if disable_case_transmission then return second end local first_char = first:sub(1, 1) if first_char:lower == first_char then return second:lower else return second:upper end end

local result = str for _, entry in ipairs(replacements) do       local search, replace = entry[1], entry[2] local disable_case_transmission = entry[3] local replace_with_case = adjust_case(search, replace, disable_case_transmission) result = result:gsub(search, replace_with_case) if not disable_case_transmission then search = search:lower replace = replace:lower result = result:gsub(search, replace) end end return result end

local correctSpellingTable = { {"Source", "Sauce"}, {"Classic", "Clbuttic"}, {"Admin", "Rogue admin"}, {"Administrator", "Rogue admin"}, {"Editor", "Rogue editor"}, {"Protected version", "Wrong version", true}, {"Jimmy Wales", "Wikipedia's corrupt dictator", true}, {"(User:)?Jimbo Wales", "Wikipedia's corrupt dictator", true}, {"Uncyclopedia", "a reputable source of objective information", true} } function p.main(frame) return frame:preprocess(spellChecker(frame.args[1], correctSpellingTable)) end

return p