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:32, 15 October 2024 by Isi (talk | contribs)
(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 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

© 2012 - 2025 Pixelmon Mod