Module:Lead: Difference between revisions
From Teriock
More actions
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 7: | Line 7: | ||
end | end | ||
-- | -- Create a new title object | ||
local | local pageTitle = mw.title.new(title) | ||
if not | if not pageTitle then | ||
return "Error: | return "Error: Invalid page title." | ||
end | end | ||
-- Find position of the first heading ( | -- Transclude and expand templates from the page | ||
local | local fullContent = frame:expandTemplate{ title = title } | ||
if | |||
-- Find the position of the first heading (== Heading ==) | |||
local headingStart = string.find(fullContent, "\n==+[^=]") | |||
local leadContent | |||
if headingStart then | |||
leadContent = string.sub(fullContent, 1, headingStart - 1) | |||
else | |||
leadContent = fullContent | |||
end | end | ||
return leadContent .. frame:preprocess("<div>{{Button|Full Rules Text|l=" .. title .. "}}</div>") | |||
end | end | ||
return p | return p | ||
Latest revision as of 20:22, 29 March 2025
Documentation for this module may be created at Module:Lead/doc
local p = {}
function p.lead(frame)
local title = frame.args[1]
if not title then
return "Error: No page title provided."
end
-- Create a new title object
local pageTitle = mw.title.new(title)
if not pageTitle then
return "Error: Invalid page title."
end
-- Transclude and expand templates from the page
local fullContent = frame:expandTemplate{ title = title }
-- Find the position of the first heading (== Heading ==)
local headingStart = string.find(fullContent, "\n==+[^=]")
local leadContent
if headingStart then
leadContent = string.sub(fullContent, 1, headingStart - 1)
else
leadContent = fullContent
end
return leadContent .. frame:preprocess("<div>{{Button|Full Rules Text|l=" .. title .. "}}</div>")
end
return p