Module:glossary: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 33: | Line 33: | ||
-- This won't work if the initial letter is non-ASCII. | -- This won't work if the initial letter is non-ASCII. | ||
local lower_anchor = | local lower_anchor = mw.ustring.lower(anchor) | ||
return "[[wikt:Appendix:Glossary#" .. | return "[[wikt:Appendix:Glossary#" .. lower_anchor .. "|" .. (text or anchor) .. "]]" | ||
end | end | ||
return export | return export |
Latest revision as of 15:58, 25 June 2022
- The following documentation is located at Module:glossary/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local gsub = mw.ustring.gsub
function format_def (term, definition)
local anchor = gsub(term, "%[%[([^%]]+)%]%]", "%1") -- Remove wikilinks
anchor = gsub(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
local anchor, text = args[1] or "", args[2]
if text and text:match "^%s*$" then
text = nil
end
-- This won't work if the initial letter is non-ASCII.
local lower_anchor = mw.ustring.lower(anchor)
return "[[wikt:Appendix:Glossary#" .. lower_anchor .. "|" .. (text or anchor) .. "]]"
end
return export