Module:See also/sandbox
Appearance
This is the module sandbox page for Module:See also (diff). |
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local error_message = require('Module:Error')['error']
function p._see_also(args)
local link_count = 0
for k, v in pairs(args) do
if type(k) == 'number' then
link_count = math.max(link_count, k)
end
end
local links = {}
for i = 1, link_count do
if args[i] then
table.insert(links, '[[:' .. args[i] .. '|' .. (args['l' .. i] or args[i]) .. ']]')
end
end
local link
if #links == 0 then
link = error_message({'[[Module:See also]] error: Module must be given at least one article name'})
elseif #links == 1 then
link = links[1]
else
link = table.concat(links, ', ', 1, math.min(#links - 1, 14)) .. ' and ' .. links[math.min(#links, 15)]
if #links > 15 then
link = link .. '<br/>' .. error_message({'[[Module:See also]] error: Too many links specified (maximum is 15)'})
end
end
local text = (args.altphrase or 'See also') .. ': ' .. link
return tostring(mw.html.create('div'):addClass('rellink boilerplate seealso'):css({['margin-left'] = '2em', ['font-style'] = 'italic'}):wikitext(text))
end
function p.see_also(frame)
return p._see_also(getArgs(frame))
end
return p