Module:ExtractSection
From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 15:22, 6 August 2024 by Vish (talk | contribs) (Created page with "local p = {} -- Helper function to extract content under a specific section header function p.extractSection(content, header) -- Define the pattern to find the section header local startPattern = mw.ustring.gsub(header, "=", "%%=") -- Find the start of the specified header local sectionStart, sectionEnd = mw.ustring.find(content, startPattern) -- If the section is not found, return nil if not sectionStart then return nil end -- Fi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Documentation for this module may be created at Module:ExtractSection/doc
local p = {}
-- Helper function to extract content under a specific section header
function p.extractSection(content, header)
-- Define the pattern to find the section header
local startPattern = mw.ustring.gsub(header, "=", "%%=")
-- Find the start of the specified header
local sectionStart, sectionEnd = mw.ustring.find(content, startPattern)
-- If the section is not found, return nil
if not sectionStart then
return nil
end
-- Find the next section header (either === or higher)
local nextHeaderPattern = "\n==+%s*[^=]"
local nextHeaderStart, nextHeaderEnd = mw.ustring.find(content, nextHeaderPattern, sectionEnd + 1)
-- Extract the content until the next section header or the end of the content
if nextHeaderStart then
return mw.ustring.sub(content, sectionEnd + 1, nextHeaderStart - 1)
else
return mw.ustring.sub(content, sectionEnd + 1)
end
end
return p
- Manga ▾
- Media ▾
- Characters ▾
- World ▾
- Archives ▾
- Misc ▾
- Wiki ▾