Модуль:parsepage
Выгляд
Дакументацыю да гэтага модуля можна стварыць у Модуль:parsepage/Дакументацыя
local function escre(s)
return s:gsub("[?^$%(%)%%.%[%]*+-]","%%%0")
end
local function getSection(page, secs) -- page,[level1, level2, ...]
local npage = mw.title.new(page);
local content = (npage and npage:getContent()) or ''
local code = content:gsub("<!--.*-->",'');
-- Памыляецца, калі каментары складзены ў тэгі тыпу nowiki, але будзем спадзявацца, гэтага ў артыкулах не будзе
for i = 1, 6 do
if secs[i] then
local c = table.concat{ ('='):rep(i),"%s*",escre(secs[i]),"%s*",('='):rep(i),"%s*\n" }
local hs,hf = code:find( "\n"..c )
if not hs then
hs,hf = code:find( "^"..c )
end
if not hs then return nil end
-- Канец секцыі - не больш за i знакаў = ці канец кода
local eos = code:find( "\n(="..("=?"):rep(i-1)..")[^=\n][^\n]*%1%s*\n", hf )
if eos then code = code:sub(hf+1,eos-1) else code = code:sub(hf+1) end
end
end
return code
end
return {
getSection = getSection,
section = function(frame) -- page="Page", 3="Section"; з параметрам u=... берэт ліку з шаблону
local pf,a = frame:getParent()
if frame.args.u then a = pf.args else a=frame.args end
return getSection( (frame.args.page or pf.args.page), a )
end
}