Module:NamespaceTable
Appearance
Documentation for this module may be created at Module:NamespaceTable/doc
local p = {}
-- Extract Shortdesc from page content
local function getShortdesc(title)
local t = mw.title.new(title)
if not t or not t.exists then
return ""
end
local content = t:getContent()
if not content then
return ""
end
-- Match {{Shortdesc|...}}
local desc = content:match("{{%s*[Ss]hortdesc%s*|([^}]+)}}")
if desc then
return mw.text.trim(desc)
end
return ""
end
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 depth = select(2, title:gsub("/", ""))
local indent = string.rep("— ", depth)
local desc = getShortdesc(title)
out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n'
end
end
out = out .. '|}'
return out
end
return p