View source for Module:ExtractSection

Jump to navigation Jump to search

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Users.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page.

local p = {}
-- Helper function to extract content under a specific section header
function p.extractSection(content, header, strict)
-- Define the pattern to find the section header
local patternHeader = string.gsub(header, "[%^%$%(%)%%%.%[%]%*%+%-%?]","%%%0")
-- Find the start of the specified header
local sectionStart, sectionEnd = mw.ustring.find(content, patternHeader .. "%s-=+%s-\n")
-- If the section is not found, return nil
if not sectionStart then
return "Error: Could not find section."
end
-- Get section header level
local headerLevel = mw.ustring.match(content, "=+", sectionStart)
if not strict or strict == "" then
headerLevel = "=" .. mw.ustring.gsub(mw.ustring.sub(headerLevel,2), "=", "=?") .. "%s*[^=]"
end
-- Find the next section header of equal or higher level
local nextHeaderPattern = "\n" .. headerLevel
local nextHeaderStart, nextHeaderEnd = mw.ustring.find(content, nextHeaderPattern, sectionEnd + 1)
-- Extract the content until the next section header or the end of the content
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
000
1:0
Debug console
* The module exports are available as the variable "p", including unsaved modifications. * Precede a line with "=" to evaluate it as an expression or use print(). Use mw.logObject() for tables. * Use mw.log() and mw.logObject() in module code to send messages to this console.

Template used on this page:

Return to Module:ExtractSection.