Module:StripWikitext
From Computing Classics Wiki
Documentation for this module may be created at Module:StripWikitext/doc
-- Removes wikilink characters to make them safe for insertion into a category or alt text.
local p = {}
function p.strip_wikitext( frame )
toStrip = frame.args[1]
preferTargetInPipedWikilink = frame.args[2] or true
-- If string contains a "|", then handle according to whether preferDisplayName is enabled
if string.match(toStrip, "|") then
local stringExploder = require("Module:ExplodeString")
wikitextPieces = stringExploder.explode_string(toStrip, "|")
if preferTargetInPipedWikilink then
toStrip = wikitextPieces[1]
else
toStrip = wikitextPieces[2]
end
end
toStrip = string.gsub(toStrip, "%[%[", "") -- Remove leading square brackets
toStrip = string.gsub(toStrip, "%]%]", "") -- Remove trailing square brackets
return toStrip
end
return p