Module:links: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) mNo edit summary |
TheNightAvl (talk | contribs) m (Added "???" and "—" delinking) |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local not_to_link = {["???"] = true, ["?"] = true, ["—"] = true, } | |||
function export.language_link(data) | function export.language_link(data) | ||
Line 16: | Line 18: | ||
if mw.ustring.match(mw.ustring.gsub(link, " ", " "),"([^%#]+)") == mw.title.getCurrentTitle().prefixedText and not data.nobold then | if mw.ustring.match(mw.ustring.gsub(link, " ", " "),"([^%#]+)") == mw.title.getCurrentTitle().prefixedText and not data.nobold then | ||
return "<b>" .. alt .. "</b>" | return "<b>" .. alt .. "</b>" | ||
elseif not_to_link[link] then | |||
return alt | |||
else | else | ||
return "[[" .. link .. "|" .. alt .. "]]" | return "[[" .. link .. "|" .. alt .. "]]" |
Revision as of 15:42, 25 December 2023
Documentation for this module may be created at Module:links/documentation
local export = {}
local not_to_link = {["???"] = true, ["?"] = true, ["—"] = true, }
function export.language_link(data)
if not data.term then
error("language link data must contain term")
end
local link = data.term
local alt = data.alt or data.term
if data.language and data.language.proto then
alt = "*" .. alt
link = "Appendix:" .. data.language.name .. "/" .. data.term
elseif data.language then
link = link .. "#" .. string.gsub(data.language.name, " ", "_")
end
if mw.ustring.match(mw.ustring.gsub(link, " ", " "),"([^%#]+)") == mw.title.getCurrentTitle().prefixedText and not data.nobold then
return "<b>" .. alt .. "</b>"
elseif not_to_link[link] then
return alt
else
return "[[" .. link .. "|" .. alt .. "]]"
end
end
function export.link_extras(data)
if not (data.pos or data.gloss) then return nil end
local out = {}
if data.gloss then table.insert(out, '“' .. data.gloss .. '”') end
if data.pos then table.insert(out, data.pos) end
return table.concat(out, ", ")
end
function export.full_link(data, face)
local link = export.language_link(data)
link = require("Module:formatting").wrap_face(link, data.language, face or "nil")
local extras = export.link_extras(data)
if extras then
extras = " (" .. extras .. ")"
end
local prefix
if data.language and data.showlanguage then
prefix = "[[" .. data.language.link .. "|" .. data.language.name .. "]] "
end
return (prefix or "") .. link .. (extras or "")
end
return export