모듈:glossary
부록:용어사전에서 사용되는 모듈입니다.
하위 문서
편집local export = {}
local ugsub = mw.ustring.gsub
local umatch = mw.ustring.match
function format_def(term, definition)
local anchor = ugsub(term, "%[%[([^%]]+)%]%]", "%1") -- Remove wikilinks
anchor = ugsub(anchor, "^%w+:", "") -- Remove interwiki prefixes
return "; <span id=\""..anchor.."\">"..term.."</span>\n: "..definition
end
function export.def (frame)
local params = {
[1] = { required = true, default = "", },
[2] = { required = true, default = "", },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local term = args[1]
local definition = args[2]
return format_def (term, definition)
end
function export.link(frame)
local args = frame:getParent().args
for k, v in pairs(args) do
if not (k == 1 or k == 2) then
require "Module:debug".track "glossary/invalid argument"
require "Module:debug".track("glossary/invalid argument/" .. k)
mw.log("invalid argument in {{glossary}}: " .. k)
end
end
local anchor, text = args[1] or "", args[2]
text = text and not umatch(text, "^%s*$") and text
local data = mw.loadData("Module:glossary/data")
local formatted_anchor = ugsub(anchor, "[%s_]+", "_")
if data[formatted_anchor] then
return "[[부록:용어사전#" .. formatted_anchor .. "|" .. (text or anchor) .. "]]"
else
local lower_anchor = anchor:ulower()
formatted_anchor = formatted_anchor:ulower()
local link = "[[부록:용어사전#" .. formatted_anchor .. "|" .. (text or anchor) .. "]]"
if data[formatted_anchor] or formatted_anchor:find "^_*$" then
return link
else
mw.log("The anchor " .. lower_anchor
.. (lower_anchor ~= anchor and " or " .. anchor or "")
.. "부록:용어사전에 해당 용어가 없습니다. 추가하거나 해당 링크를 제거해주세요.")
return link
.. "[[분류:용어사전에 수록되지 않은 용어가 있는 문서|"
.. lower_anchor .. "]]"
end
end
end
return export