Module:SmartMobLinks: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Returns a <ul> of pretty links from a comma-delimited list of mob paths | -- Returns a <ul> of pretty links with custom bullets from a comma-delimited list of mob paths | ||
function p.fromDelimited(frame) | 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 "," | ||
local items = mw.text.split(raw, delimiter) | local items = mw.text.split(raw, delimiter) | ||
-- | -- Hide default bullets; we'll insert our own markers | ||
local output = { '<ul style="margin-left: 1em; list-style-type: none; padding-left: 0;">' } | local output = { '<ul style="margin-left: 1em; list-style-type: none; padding-left: 0;">' } | ||
| Line 14: | Line 14: | ||
-- Parse prefix (Mob or Named Mob) and the rest of the path | -- Parse prefix (Mob or Named Mob) and the rest of the path | ||
local prefix, rest = string.match(fullPath, "^(.-)/(.+)$") | local prefix, rest = string.match(fullPath, "^(.-)/(.+)$") | ||
if not rest then | if not rest then prefix, rest = nil, fullPath end | ||
-- | -- Extract name and optional zone | ||
local base, zone = string.match(rest, "^(.-)/(.+)$") | local base, zone = string.match(rest, "^(.-)/(.+)$") | ||
local label = rest | local label = rest | ||
| Line 26: | Line 23: | ||
end | end | ||
-- Determine marker for named | -- Determine custom marker: bullet for regular mobs, star for named | ||
local marker = "" | local marker = "• " | ||
if prefix == "Named Mob" then | if prefix == "Named Mob" then marker = "★ " end | ||
-- | -- Insert list item with custom marker | ||
table.insert(output, string.format('<li style="margin-bottom: 0.5em;">[[%s|%s]] | table.insert(output, string.format( | ||
'<li style="margin-bottom: 0.5em;">%s[[%s|%s]]</li>', | |||
marker, fullPath, label | |||
)) | |||
end | end | ||
end | end | ||
Revision as of 07:34, 28 May 2025
Documentation for this module may be created at Module:SmartMobLinks/doc
local p = {}
-- Returns a <ul> of pretty links with custom bullets from a comma-delimited list of mob paths
function p.fromDelimited(frame)
local raw = frame.args[1] or ""
local delimiter = frame.args.delimiter or ","
local items = mw.text.split(raw, delimiter)
-- Hide default bullets; we'll insert our own markers
local output = { '<ul style="margin-left: 1em; list-style-type: none; padding-left: 0;">' }
for _, entry in ipairs(items) do
local fullPath = mw.text.trim(entry)
if fullPath ~= "" then
-- Parse prefix (Mob or Named Mob) and the rest of the path
local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
if not rest then prefix, rest = nil, fullPath end
-- Extract name and optional zone
local base, zone = string.match(rest, "^(.-)/(.+)$")
local label = rest
if base and zone then
label = base .. " (" .. zone .. ")"
end
-- Determine custom marker: bullet for regular mobs, star for named
local marker = "• "
if prefix == "Named Mob" then marker = "★ " end
-- Insert list item with custom marker
table.insert(output, string.format(
'<li style="margin-bottom: 0.5em;">%s[[%s|%s]]</li>',
marker, fullPath, label
))
end
end
table.insert(output, '</ul>')
return table.concat(output, "\n")
end
return p