Modul:Template:also
This module implements the template {{also}}
.
local unidata = require('Module:Unicode_data')
local export = {}
local function yesno(value)
if (value == '0') or (value == 'no') or (value == 'false') or not value then
return false
else
return true
end
end
local function serial_comma_join(seq)
if #seq == 1 then
return seq[1] -- nothing to join
end
local ret = seq[1]
for i = 2, #seq - 1, 1 do
ret = ret .. ", " .. seq[i]
end
return ret .. "<span class='serial-comma'>,</span>" ..
"''<span class='serial-and'> un</span>'' " ..
seq[#seq]
end
function export.main(frame)
local pargs = frame:getParent().args
local dsc = pargs.sc
local duni = yesno(pargs.uni) and 'auto' or false
local title = mw.title.getCurrentTitle()
local items = {}
for i, arg in ipairs(pargs) do
local uni = (pargs['uni' .. i] ~= nil) and pargs['uni' .. i] or duni
if uni == 'no' then
uni = false
end
local sc = pargs['sc' .. i] or dsc
local s
local has_piped_link, _, link_text = arg:find("%[%[[^%[%]|]+|(.+)]]")
if has_piped_link then
s = ("'''%s'''"):format(arg)
arg = link_text
local has_nowiki, _, inside = arg:find("^<nowiki>(.+)</nowiki>$")
if has_nowiki then
arg = inside
end
else
local has_link, _, link_text = arg:find("%[%[([^%[%]|]+)]]")
if has_link then
s = ("'''%s'''"):format(arg)
arg = link_text
else
s = ("'''[[%s]]'''"):format(arg)
end
end
if uni then
local codepoint = (uni == 'auto') and mw.ustring.codepoint(arg, 1, 1) or tonumber(uni)
s = s .. (" <small>[U+%04X %s]</small>"):format(
codepoint,
unidata.lookup_name(codepoint):gsub("<", "<")
)
end
if arg ~= title.fullText then
table.insert(items, s)
end
end
if #items == 0 then
table.insert(items, "{{{1}}}")
end
return ("<div class=\"disambig-see-also%s\">''Kiek ok bi:'' %s</div>"):format(
(#items == 2) and "-2" or "",
serial_comma_join(items)
)
end
return export