Module:Links

-- Creates links and changes wikitext when it detects external links -- Syntax -- local utility = require("Dev:Utility") local p = {}

function p.link(tArgs) local link, url, desc, separator = "", "", "", "" local sPrefix = ""   local sSuffix = ""

if tArgs then url = tArgs[1] or tArgs['page'] or "" desc = tArgs[2] or tArgs['desc'] or ""

if url:len < 1 or (tArgs['type'] == "ext" and url:len < 3) then return end

if (desc:len > 0) then separator = "|" end

if url and url:len > 2 then local isExternalUrl = url:match("www%.") or url:match("^http")

if (isExternalUrl and tArgs['type'] ~= "local" or tArgs['type'] == "ext") then sPrefix = "[//" sSuffix = "]" if desc:len > 0 then separator = " " end end end link = sPrefix .. url .. separator .. desc .. sSuffix end return link end

function p.main(frame) local tArgs = utility.getArgs(frame)

return p.link(tArgs) end

return p