Module:NamespaceTable: Difference between revisions
Appearance
Created page with "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 _, title in ipairs(list) do title = mw.text.trim(title) if title ~= "" then local t = mw.title.new(title) local desc = "" if t and t.exists then -- Get SHORTDESC via page properties local prop..." |
No edit summary |
||
| Line 7: | Line 7: | ||
local out = '{| class="wikitable"\n! Page !! Description\n' | local out = '{| class="wikitable"\n! Page !! Description\n' | ||
for _, | for _, line in ipairs(list) do | ||
line = mw.text.trim(line) | |||
if | if line ~= "" then | ||
local | -- Split "Page|Description" | ||
local desc = "" | 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) | |||
out = out .. '|-\n| [[' .. title .. ']] || ' .. desc .. '\n' | -- Output row | ||
out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n' | |||
end | end | ||
end | end | ||
Revision as of 21:29, 10 April 2026
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