Module:CodeClean
From A KoL Wiki
Documentation for this module may be created at Module:CodeClean/doc
local p = {}
local include = "[Ii][Nn][Cc][Ll][Uu][Dd][Ee]"
local no = "[Nn][Oo]"
local only = "[Oo][Nn][Ll][Yy]"
local lt, gt = "<", ">"
function p.main(frame)
local text = (frame and frame.args and frame.args[1]) or ""
if not text and frame and frame.getParent then
local parent = frame:getParent()
if parent and parent.args then text = parent.args[1] or "" end
end
-- Remove all <noinclude>...</noninclude>
local r = text:gsub(lt .. no .. include .. gt .. ".-" .. lt .. "/" .. no .. include .. gt, "")
-- Truncate string at any unterminated <noinclude> tag
r = r:gsub(lt .. no .. include .. gt .. ".*", "")
-- Strip presence of <includeonly> and <onlyinclude> tags including their closing tags
r = r:gsub(lt .. include .. only ..gt, "")
r = r:gsub(lt .. "/" .. include .. only .. gt, "")
r = r:gsub(lt .. only .. include ..gt, "")
r = r:gsub(lt .. "/" .. only .. include .. gt, "")
end
return p