Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Sort: Difference between revisions

From Teriock
// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 4: Line 4:


     local input = frame.args[1] or ""
     local input = frame.args[1] or ""
    local pre = ""
    local post = ""
    if args['wrap'] then
        pre = "{{L|" .. args['wrap'] .. "|"
        post = "}}"
    end


     local items = {}
     local items = {}
     for item in string.gmatch(input, "([^,]+)") do
     for item in string.gmatch(input, "([^,]+)") do
         table.insert(items, item:match("^%s*(.-)%s*$")) -- Trim whitespace
         local trimmed_item = item:match("^%s*(.-)%s*$") -- Trim whitespace
        table.insert(items, pre .. trimmed_item .. post)
     end
     end



Revision as of 23:44, 18 January 2025

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

local p = {}

function p.parse(frame)

    local input = frame.args[1] or ""
    local pre = ""
    local post = ""
    if args['wrap'] then
        pre = "{{L|" .. args['wrap'] .. "|"
        post = "}}"
    end

    local items = {}
    for item in string.gmatch(input, "([^,]+)") do
        local trimmed_item = item:match("^%s*(.-)%s*$") -- Trim whitespace
        table.insert(items, pre .. trimmed_item .. post)
    end

    table.sort(items)
    return frame:preprocess(table.concat(items, ", "))
end

return p