local p = {}
-- Entry point for Lua callers
-- Returns a string value: text of the lead of a page
function p._lead(pagename)
if not pagename then return "" end
title=mw.title.new(pagename) -- Find the lead section of the named page
if not title then return "" end
text=title.getContent(title) or ""
text=mw.ustring.gsub(text,"%c%s*==.*","") -- remove first heading and everything after it
t="\n*before first heading = '<code><nowiki>" .. mw.ustring.sub(text,1,50) .. "..." .. mw.ustring.sub(text,-50,-1) .. "</nowiki></code>'"
text=mw.ustring.gsub(text,"<noinclude>.-</noinclude>","") -- remove noinclude bits
t=t.."\n*without noinclude = '<code><nowiki>" .. mw.ustring.sub(text,1,50) .. "..." .. mw.ustring.sub(text,-50,-1) .. "</nowiki></code>'"
repeat
oldtext=text
text=mw.ustring.gsub(text,"^%A-%b{}%s*","") -- remove infoboxes, hatnotes, tags, etc. from the front
until text==oldtext
t=t.."\n*without infoboxes = '<code><nowiki>" .. mw.ustring.sub(text,1,50) .. "..." .. mw.ustring.sub(text,-50,-1) .. "</nowiki></code>'"
text=mw.ustring.gsub(text,"<%s*ref[^>]-/%s*>","") -- remove refs cited elsewhere
t=t.."\n*without ref names = '<code><nowiki>" .. mw.ustring.sub(text,1,50) .. "..." .. mw.ustring.sub(text,-50,-1) .. "</nowiki></code>'"
text=mw.ustring.gsub(text,"<%s*ref.->.-<%s*/%s*ref%s*>","") -- remove refs
t=t.."\n*without refs = '<code><nowiki>" .. mw.ustring.sub(text,1,50) .. "..." .. mw.ustring.sub(text,-50,-1) .. "</nowiki></code>'"
text=mw.ustring.match(text,"%C*'''.*") or text -- start at the first line with bold text, if any
t=t.."\n*from bold = '<code><nowiki>" .. mw.ustring.sub(text,1,50) .. "..." .. mw.ustring.sub(text,-50,-1) .. "</nowiki></code>'"
return t -- text
end
-- Entry point for template callers using #invoke:
function p.lead(frame)
-- args = { 1 = page name }
local args = frame.args -- from calling module
local pargs = frame:getParent().args -- from template
return frame:preprocess(p._lead(args[1] or pargs[1]))
end
return p