Jump to content

Module:SmartMobLinks: Difference between revisions

From Drifters Almanac
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Returns a <ul> of pretty links from a comma-delimited list of mob paths
-- Always return a <ul> of wiki links 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 ""
Line 11: Line 11:
         local fullPath = mw.text.trim(entry)
         local fullPath = mw.text.trim(entry)
         if fullPath ~= "" then
         if fullPath ~= "" then
             -- Parse prefix (Mob or Named Mob) and the rest of the path
             -- Parse prefix (Mob or Named Mob) and path remainder
             local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
             local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
             if not rest then
             if not rest then
Line 25: Line 25:
             end
             end


             -- Add marker for named mobs
             -- Star marker for named mobs, appended after the link
             local marker = ""
             local marker = ""
             if prefix == "Named Mob" then
             if prefix == "Named Mob" then
                 marker = "★ " -- star marker for named mobs
                 marker = " ★"
             end
             end


             -- Format the list item
             -- Generate list item with default bullet and optional marker
             table.insert(output, string.format('<li>%s[[%s|%s]]</li>', marker, fullPath, label))
             table.insert(output, string.format('<li>[[%s|%s]]%s</li>', fullPath, label, marker))
         end
         end
     end
     end

Latest revision as of 07:39, 28 May 2025

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

local p = {}

-- Always return a <ul> of wiki links 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)
    local output = { '<ul style="margin-left: 1em;">' }

    for _, entry in ipairs(items) do
        local fullPath = mw.text.trim(entry)
        if fullPath ~= "" then
            -- Parse prefix (Mob or Named Mob) and path remainder
            local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
            if not rest then
                prefix = nil
                rest = fullPath
            end

            -- Separate name and zone if present
            local base, zone = string.match(rest, "^(.-)/(.+)$")
            local label = rest
            if base and zone then
                label = base .. " (" .. zone .. ")"
            end

            -- Star marker for named mobs, appended after the link
            local marker = ""
            if prefix == "Named Mob" then
                marker = " ★"
            end

            -- Generate list item with default bullet and optional marker
            table.insert(output, string.format('<li>[[%s|%s]]%s</li>', fullPath, label, marker))
        end
    end

    table.insert(output, '</ul>')
    return table.concat(output, "\n")
end

return p