Module:Excerpt

This is an old revision of this page, as edited by Certes (talk | contribs) at 10:45, 25 April 2018 (Remove footnotes {{efn|not valid in Tennessee}} etc.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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
	text=mw.ustring.gsub(text,"<noinclude>.-</noinclude>","") -- remove noinclude bits
	repeat
		oldtext=text
		text=mw.ustring.gsub(text,"^%A-%b{}%s*","") -- remove infoboxes, hatnotes, tags, etc. from the front
	until text==oldtext
	text=mw.ustring.gsub(text,"{{%s*[Ee]fn%s*|.-}}","") -- remove {{efn|footnote}}
	text=mw.ustring.gsub(text,"{{%s*[Ee]fn-la%s*|.-}}","") -- {{efn-la}} alias for {{efn}}
	text=mw.ustring.gsub(text,"{{%s*[Ee]l[mn]%s*|.-}}","") -- {{elm}} and {{eln}} alias for {{efn}}
	text=mw.ustring.gsub(text,"<%s*ref[^>]-/%s*>","") -- remove refs cited elsewhere
	text=mw.ustring.gsub(text,"<%s*ref.->.-<%s*/%s*ref%s*>","") -- remove refs
	text=mw.ustring.match(text,"%C*'''.*") or text -- start at the first line with bold text, if any
	return 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