local export = {}
local codepoint = mw.ustring.codepoint
local concat = table.concat
local find_best_script_without_lang = require("Module:scripts").findBestScriptWithoutLang
local insert = table.insert
local plain_link = require("Module:links").plain_link
local tag_text = require("Module:script utilities").tag_text
local PAGENAME = mw.loadData("Module:headword/data").pagename
function export.main(terms)
local items, use_semicolon = {}, false
for _, v in ipairs(terms) do
local term = type(v) == "string" and v or v.term
-- Don't add the link if it's the current pagename.
if term ~= PAGENAME then
local uni = v.uni
if uni == nil then -- Use uni_default iff uni is not specified at all.
uni = terms.uni_default
end
if not use_semicolon and term:find(",") then
use_semicolon = true
end
-- Get the script if not already given.
local sc = v.sc or find_best_script_without_lang(term)
-- Create the link.
local link = tag_text(plain_link{term = term, sc = sc}, nil, sc, "bold")
local cp
if uni then
require("Module:debug/track")("also/uni")
if uni == "auto" then
cp = term:match("^.[\128-\191]*$") and codepoint(term, 1, 1) or nil
else
cp = tonumber(uni)
require("Module:debug/track")(("also/uni/%s"):format(
term:match("^.[\128-\191]*$") and cp == codepoint(term, 1, 1) and "auto" or "noauto"
))
end
end
if cp then
link = link .. (" <small>[U+%04X %s]</small>"):format(
cp,
require("Module:Unicode data").lookup_name(cp):gsub("<", "<"):gsub(">", ">")
)
end
insert(items, link)
end
end
if #items == 0 then
error("Please specify at least one term which is not the current page title.")
end
local conjunction = use_semicolon and ";" or ","
return ("<div class=\"disambig-see-also\">''See also:'' %s</div>"):format(
mw.text.listToText(
items,
conjunction .. " ",
"<span class=\"serial-comma\">" .. conjunction .. "</span>" .. "<span class=\"serial-and\"> ''and''</span> "
)
)
end
return export