Module:GlossaryTerms
Appearance
Documentation for this module may be created at Module:GlossaryTerms/doc
-- Module:GlossaryTerms
-- Processes glossary terms and generates linked pills for display
local p = {}
-- Trim whitespace from string
local function trim(str)
return str:match("^%s*(.-)%s*$")
end
-- Convert term to anchor format (spaces to underscores)
local function termToAnchor(term)
return trim(term):gsub(" ", "_")
end
-- Main function to render glossary terms
function p.renderTerms(frame)
local glossary_page = trim(frame.args.glossary_page or "")
local terms_str = trim(frame.args.terms or "")
if terms_str == "" then
return ""
end
-- Split terms by comma
local terms = {}
for term in terms_str:gmatch("[^,]+") do
table.insert(terms, trim(term))
end
-- Generate links as inline elements
local links = {}
for _, term in ipairs(terms) do
local anchor = termToAnchor(term)
-- Create inline link with glossary-term class for styling
local link = string.format("[[%s#%s|<span class=\"glossary-term\">%s</span>]]", glossary_page, anchor, term)
table.insert(links, link)
end
-- Join with space or newline depending on preference
return table.concat(links, " ")
end
return p