Module:Sort: Difference between revisions
From Teriock
More actions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 17: | Line 17: | ||
pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|" | pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|" | ||
post = "}}" | post = "}}" | ||
end | |||
if frame.args['item'] and frame.args['name'] and frame.args['ns'] then | |||
pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|" | |||
post = " equipment}}" | |||
end | end | ||
Revision as of 00:29, 21 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 ""
-- DPL-specific preprocessing
input = input:gsub("%s*%|%s*", ",") -- Convert DPL separators to commas if present
local pre = ""
local post = ""
if frame.args['wrap'] then
pre = "{{L|" .. frame.args['wrap'] .. "|"
post = "}}"
end
if frame.args['cat'] and frame.args['name'] and frame.args['ns'] then
pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|"
post = "}}"
end
if frame.args['item'] and frame.args['name'] and frame.args['ns'] then
pre = "{{Cat|name=" .. frame.args['name'] .. "|ns=" .. frame.args['ns'] .. "|"
post = " equipment}}"
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)
if frame.args['cat'] then
return frame:preprocess(table.concat(items, ""))
else
return frame:preprocess(table.concat(items, ", "))
end
end
return p