Module:Excerpt: Difference between revisions

Content deleted Content added
Module to extract the lead from an article. Unlike #lsth, it removes infoboxes, hatnotes, etc.
 
Fix comments; return blank string on certain errors
Line 4:
-- 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
-- %b{} removes any leading
if not title then return "" end
-- If the page exists, protected or not, this is some other value
text=title.getContent(title) or ""
-- Note: this check does NOT record a wikilink or transclusion from the calling page to pagename
title=mw.title.new(pagename)
text=title.getContent(title)
text=mw.ustring.gsub(text,"%c%s*==.*","") -- remove first heading and everything after it
text=mw.ustring.gsub(text,"<noinclude>.-</noinclude>","") -- remove noinclude bits
Line 15 ⟶ 13:
text=mw.ustring.gsub(text,"<ref.->.-</ref>","") -- remove refs
text=mw.ustring.match(text,"%C*'''.*") or text -- start at the first line with bold text, if any
return text;
end
 
Line 23 ⟶ 21:
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