Module:Excerpt
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 13,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
This module implements Template:Excerpt.
- See Template:Excerpt for documentation on the template parameters
- See mw:Module:Excerpt for documentation on this module
- See Module:Excerpt/config for configuration of this module
Portals
Portals use a previous version of this module:
- Module:Excerpt/portals / sandbox — Used by:
- {{Transclude lead excerpt}} / sandbox / testcases
- {{Transclude linked excerpt}} / sandbox / testcases
- {{Transclude list item excerpt}} / sandbox / testcases
- {{Transclude random excerpt}} / sandbox / testcases
- {{Transclude selected excerpt}} / sandbox / testcases
- Module:Excerpt slideshow / sandbox — Uses Module:Excerpt/portals and is used by:
- Module:Random slideshow / sandbox — Uses Module:Excerpt/portals and is used by:
- {{Random slideshow}} / sandbox / testcases
- {{Transclude files as random slideshow}} / sandbox / testcases
local p = {}
-- Entry point for Lua callers
-- Returns a string value: text of the lead of a page
function p._lead(pagename)
-- Find the lead section of the named page
-- %b{} removes any leading
-- If the page exists, protected or not, this is some other value
-- 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
text=mw.ustring.gsub(text,"^%A*%b{}%s*","") -- remove infoboxes, hatnotes, tags, etc. from the front
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
-- 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