Jump to content

Module:NamespaceTable

From Costa Sano KB
Revision as of 21:29, 10 April 2026 by Mngr (talk | contribs)

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

local p = {}

function p.table(frame)
    local pages = frame.args.pages or ""
    local list = mw.text.split(pages, "\n")

    local out = '{| class="wikitable"\n! Page !! Description\n'

    for _, line in ipairs(list) do
        line = mw.text.trim(line)

        if line ~= "" then
            -- Split "Page|Description"
            local parts = mw.text.split(line, "|")
            local title = mw.text.trim(parts[1] or "")
            local desc = mw.text.trim(parts[2] or "")

            -- Determine subpage depth
            local depth = select(2, title:gsub("/", ""))
            local indent = string.rep("— ", depth)

            -- Output row
            out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n'
        end
    end

    out = out .. '|}'
    return out
end

return p