Module:SmartMobLinks: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
-- Always return a <ul> of wiki links from a delimited list | -- Always return a <ul> of wiki links from a delimited list | ||
function p. | function p.fromDelimited(frame) | ||
local raw = frame.args[1] or "" | local raw = frame.args[1] or "" | ||
local delimiter = frame.args.delimiter or "," | local delimiter = frame.args.delimiter or "," | ||
Revision as of 07:33, 13 May 2025
Documentation for this module may be created at Module:SmartMobLinks/doc
local p = {}
-- Always return a <ul> of wiki links from a delimited list
function p.fromDelimited(frame)
local raw = frame.args[1] or ""
local delimiter = frame.args.delimiter or ","
local items = mw.text.split(raw, delimiter)
local output = {}
table.insert(output, '<ul style="margin-left: 1em;">')
for _, fullPath in ipairs(items) do
fullPath = mw.text.trim(fullPath)
if fullPath ~= "" then
local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
local label = fullPath
if not prefix or not rest then
prefix = nil
rest = fullPath
end
if prefix == "Mob" then
local base, zone = string.match(rest, "^(.-)/(.+)$")
if base and zone then
label = base .. " (" .. zone .. ")"
else
label = rest
end
elseif prefix == "Named Mob" then
label = rest
else
label = rest
end
table.insert(output, string.format('<li>[[%s|%s]]</li>', fullPath, label))
end
end
table.insert(output, '</ul>')
return table.concat(output, "\n")
end
return p