Module:links: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
(47 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
function export.language_link(data) | |||
if | if not data.term then | ||
error(" | error("language link data must contain term") | ||
end | end | ||
local | local link = data.term | ||
local alt = data.alt or data.term | |||
local | local anchor = data.anchor | ||
local | |||
local plaenk_alt = mw.loadData("Module:lnk-pro-morph/data").alt | |||
local | |||
if data.language then | |||
if | if data.language.code == "lnk-pro" and plaenk_alt[link] then link = plaenk_alt[link] end | ||
link = | |||
if data.hypo then alt = "**" .. alt end | |||
if data.language.proto then | |||
if not data.nostar and not data.hypo then alt = "*" .. alt end -- * is an asterisk but sometimes the asterisk gets mistaken for wiki formatting | |||
link = "Appendix:" .. data.language.name .. "/" .. data.term | |||
if anchor then link = link .. "#" .. data.language.name .. anchor end | |||
else | else | ||
link = link .. | local jump = data.language.name | ||
if anchor then jump = data.language.name .. anchor end | |||
link = link .. "#" .. string.gsub(jump, " ", "_") | |||
end | end | ||
end | end | ||
local | local term = mw.ustring.match(mw.ustring.gsub(link, " ", " "),"([^%#]+)") | ||
if | if term == mw.title.getCurrentTitle().text and not data.nobold then | ||
return "<b>" .. alt .. "</b>" | |||
elseif mw.ustring.match(term, "^[%?%-–—]+$") or mw.ustring.match(term, ":[%?%-–—]+$") or data.nolink then | |||
return alt | |||
else | |||
return "[[" .. link .. "|" .. alt .. "]]" | |||
end | end | ||
end | end | ||
function export. | function export.link_extras(data) | ||
if not (data.pos or data.gloss) then return nil end | |||
return | 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 | end | ||
function export. | function export.full_link(data, face) | ||
local link = export.language_link(data) | |||
return | 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 | end | ||
return export | return export |
Latest revision as of 16:04, 31 May 2024
Documentation for this module may be created at Module:links/documentation
local export = {}
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
local anchor = data.anchor
local plaenk_alt = mw.loadData("Module:lnk-pro-morph/data").alt
if data.language then
if data.language.code == "lnk-pro" and plaenk_alt[link] then link = plaenk_alt[link] end
if data.hypo then alt = "**" .. alt end
if data.language.proto then
if not data.nostar and not data.hypo then alt = "*" .. alt end -- * is an asterisk but sometimes the asterisk gets mistaken for wiki formatting
link = "Appendix:" .. data.language.name .. "/" .. data.term
if anchor then link = link .. "#" .. data.language.name .. anchor end
else
local jump = data.language.name
if anchor then jump = data.language.name .. anchor end
link = link .. "#" .. string.gsub(jump, " ", "_")
end
end
local term = mw.ustring.match(mw.ustring.gsub(link, " ", " "),"([^%#]+)")
if term == mw.title.getCurrentTitle().text and not data.nobold then
return "<b>" .. alt .. "</b>"
elseif mw.ustring.match(term, "^[%?%-–—]+$") or mw.ustring.match(term, ":[%?%-–—]+$") or data.nolink 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