Difference between revisions of "Module:PullSection"
From Pixelmon Wiki
m |
m |
||
Line 22: | Line 22: | ||
-- Extract the section | -- Extract the section | ||
− | local | + | local sections = mw.text.split(pageContent, '== ') |
+ | local sectionContent = nil | ||
+ | |||
+ | for i = 1, #sections do | ||
+ | if mw.text.trim(sections[i]) == sectionName then | ||
+ | sectionContent = sections[i + 1] -- Get the content of the next section | ||
+ | break | ||
+ | end | ||
+ | end | ||
+ | |||
if not sectionContent then | if not sectionContent then | ||
return "Error: Section not found." | return "Error: Section not found." | ||
end | end | ||
− | -- | + | -- Check for the next section |
− | local nextSection = mw.text.split(sectionContent, '==')[ | + | local nextSection = mw.text.split(sectionContent, '==')[1] |
if nextSection then | if nextSection then | ||
− | sectionContent = mw.text.trim( | + | sectionContent = mw.text.trim(nextSection) |
end | end | ||
Latest revision as of 13:32, 15 October 2024
Documentation for this module may be created at Module:PullSection/doc
local p = {} function p.main(frame) local pageName = frame.args.page local sectionName = frame.args.section if not pageName or not sectionName then return "Error: You must specify both a page and a section." end -- Fetch the page content local page = mw.title.new(pageName) if not page then return "Error: Page not found." end local pageContent = page:getContent() if not pageContent then return "Error: Unable to retrieve page content." end -- Extract the section local sections = mw.text.split(pageContent, '== ') local sectionContent = nil for i = 1, #sections do if mw.text.trim(sections[i]) == sectionName then sectionContent = sections[i + 1] -- Get the content of the next section break end end if not sectionContent then return "Error: Section not found." end -- Check for the next section local nextSection = mw.text.split(sectionContent, '==')[1] if nextSection then sectionContent = mw.text.trim(nextSection) end -- Remove HTML tags from section content local cleanedContent = mw.text.strip(mw.html.removeTags(sectionContent)) -- Return the cleaned content return cleanedContent end return p