Module:GlossaryTerms: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 33: | Line 33: | ||
for _, term in ipairs(terms) do | for _, term in ipairs(terms) do | ||
local anchor = termToAnchor(term) | local anchor = termToAnchor(term) | ||
-- Create | -- Create link that will be styled by .glossary-terms-pills a CSS | ||
local link = string.format("[[%s#%s| | local link = string.format("[[%s#%s|%s]]", glossary_page, anchor, term) | ||
table.insert(links, link) | table.insert(links, link) | ||
end | end | ||
Latest revision as of 05:28, 22 May 2026
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 link that will be styled by .glossary-terms-pills a CSS
local link = string.format("[[%s#%s|%s]]", glossary_page, anchor, term)
table.insert(links, link)
end
-- Join with space or newline depending on preference
return table.concat(links, " ")
end
return p