Module:CodeClean

From A KoL Wiki
Revision as of 16:17, 7 September 2025 by Gausie (talk | contribs) (Whoops, forgot to return)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.args[1] or ""

	-- 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, "")

	return r
end

return p