Jump to content

Module:AcronymTerms

From ClimateKG
Revision as of 06:59, 22 May 2026 by Laura (talk | contribs) (Created page with "-- Module:AcronymTerms -- Processes acronyms and generates linked pills for display local p = {} -- Trim whitespace from string local function trim(str) return str:match("^%s*(.-)%s*$") end -- Convert acronym to anchor format (spaces and special chars to underscores) local function acronymToAnchor(acronym) return trim(acronym):gsub(" ", "_"):gsub("₂", "2"):gsub("°", "") end -- Main function to render acronyms function p.renderTerms(frame) local acronym...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:AcronymTerms/doc

-- Module:AcronymTerms
-- Processes acronyms and generates linked pills for display

local p = {}

-- Trim whitespace from string
local function trim(str)
    return str:match("^%s*(.-)%s*$")
end

-- Convert acronym to anchor format (spaces and special chars to underscores)
local function acronymToAnchor(acronym)
    return trim(acronym):gsub(" ", "_"):gsub("₂", "2"):gsub("°", "")
end

-- Main function to render acronyms
function p.renderTerms(frame)
    local acronym_page = trim(frame.args.acronym_page or "")
    local acronyms_str = trim(frame.args.acronyms or "")
    
    if acronyms_str == "" then
        return ""
    end
    
    -- Split acronyms by comma
    local acronyms = {}
    for acronym in acronyms_str:gmatch("[^,]+") do
        table.insert(acronyms, trim(acronym))
    end
    
    -- Generate links as plain wiki syntax
    local links = {}
    for _, acronym in ipairs(acronyms) do
        local anchor = acronymToAnchor(acronym)
        -- Plain wiki link - CSS will style as pill
        local link = string.format("[[%s#%s|%s]]", acronym_page, anchor, acronym)
        table.insert(links, link)
    end
    
    -- Join with space
    return table.concat(links, " ")
end

return p