Module:LinkParser
Appearance
Documentation for this module may be created at Module:LinkParser/doc
-- Parses links inserted by editors in templates, strips them of the protocol part, and otherwise prints exactly what was entered to minimize spoofing
local p = {}
----------------------------------
-- Remove protocol and leading www.
----------------------------------
function p.strip(link)
-- Remove the protocol part: http://, https://, ftp://, etc.
-- (%a+ matches one or more letters, so it will strip e.g. http, https, ftp.)
link = link:gsub("^%a+://", "")
-- Remove leading "www."
link = link:gsub("^www%.", "")
return link
end
----------------------------------
-- Return a MediaWiki link with:
-- [ originalURL strippedDisplayText ]
----------------------------------
function p.render(frame)
local args = frame:getParent().args
local rawLink = args["link"] or ""
if rawLink == "" then
return ""
end
-- Strip protocol and leading 'www.'
local displayText = p.strip(rawLink)
-- Construct an external link of the form:
-- [ rawLink displayText ]
return string.format("[%s %s]", rawLink, displayText)
end
return p