Module:StripWikitext: Difference between revisions
From Computing Classics Wiki
Created page with "-- 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]..." |
m 1 revision imported: All kinds of templates for CCW to emulate AEW's old hard drive stock |
(No difference)
| |
Latest revision as of 06:15, 24 September 2024
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