Join our discord
In partnership with NodeCraft Logo NodeCraft


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

Difference between revisions of "Module:PullSection"

From Pixelmon Wiki
(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...")
 
m
Line 33: Line 33:
 
     end
 
     end
  
     return sectionContent
+
    -- Remove HTML tags from section content
 +
    local cleanedContent = mw.text.strip(mw.html.removeTags(sectionContent))
 +
 
 +
    -- Return the cleaned content
 +
     return cleanedContent
 
end
 
end
  
 
return p
 
return p

Revision as of 13:28, 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 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

    -- 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