Join our discord
In partnership with NodeCraft Logo NodeCraft


You are not logged in! Create an account or login to contribute! Log in here!

Module:PullSection

From Pixelmon Wiki
Revision as of 13:18, 15 October 2024 by Isi (talk | contribs) (Created page with "local p = {} function p.main(frame) local pageName = frame.args.page local sectionName = frame.args.section if not pageName or not sectionName then retur...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 sectionContent = mw.text.split(pageContent, '== ' .. sectionName .. ' ==')[2]
    if not sectionContent then
        return "Error: Section not found."
    end

    -- Return the content of the section
    local nextSection = mw.text.split(sectionContent, '==')[2]
    if nextSection then
        sectionContent = mw.text.trim(sectionContent:sub(1, nextSection:find('==') - 1))
    end

    return sectionContent
end

return p

© 2012 - 2025 Pixelmon Mod