Module:Sandbox/Link list
Jump to navigation
Jump to search
local p = {}
local function fixExternal(args)
local r = {}
local i = 1
while true do
if args[i] then
table.insert(r, tostring(string.gsub(args[i], ' ', '_')))
else
break
end
i = i + 1
end
return r
end
function p.extlink(f)
local args = f:getParent().args
-- Separators. Here, spaces are handled. If you need to use spaces, you will have to use
local sep = args.sep or ', ' -- comma
local sepLast = args.seplast or ' and ' -- and (last)
local unspecified = args.unspencified or 'unspecified location'
local urlStart = args.url or 'https://minecraft.wiki/w/'
local result = {}
local urlArgs = fixExternal(args)
if args[1] and args[1] ~= '' then
table.insert(result, '[' .. urlStart .. urlArgs[1] ..' ' .. args[1] .. ']')
else
table.insert(result, unspecified)
end
if args[2] and args[2] ~= '' then
local i = 2
while true do
if args[i] and args[i] ~= '' then
if args[i+1] then
table.insert(result, sep)
else
table.insert(result, sepLast)
end
table.insert(result, '[' .. urlStart .. urlArgs[i] .. ' ' ..args[i] .. ']')
else
break
end
i = i + 1
end
end
return table.concat(result)
end
function p.link(f)
local args = f:getParent().args
local sep = args.sep or ', ' -- comma
local sepLast = args.seplast or ' and ' -- and (last)
local unspecified = args.unspencified or 'unspecified location'
local result = {}
if args[1] and args[1] ~= '' then
table.insert(result, '[[' .. args[1] .. '|' .. tostring(string.gsub(args.title1 or args[1], '#', ' § ')) ..']]')
else
table.insert(result, unspecified)
end
if args[2] and args[2] ~= '' then
local i = 2
while true do
if args[i] and args[i] ~= '' then
if args[i+1] then
table.insert(result, sep)
else
table.insert(result, sepLast)
end
table.insert(result, '[[' .. args[i] .. '|' .. tostring(string.gsub(args['title' .. i] or args[i], '#', ' § ')) .. ']]')
else
break
end
i = i + 1
end
end
return table.concat(result)
end
return p