Jump to content

Module:Sandbox/Black lemon

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Plastikspork (talk | contribs) at 15:41, 25 March 2023 (Fix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local page_content = {}
local function get_section(frame, page_name, section_name, error_text)
	if page_content[page_name] == nil then
		local title = mw.title.new(page_name)
		if title then
			if title.redirectTarget then title = title.redirectTarget end
			page_content[page_name] = title:getContent()
		end
	end
	if page_content[page_name] then
		if section_name ~= '' then
			if mw.ustring.find(page_content[page_name], "=%s*" .. section_name .. "%s*=", 1, false) then
				return frame:preprocess("{{#section-h::" .. page_name .. "|".. section_name .. "}}")
			end
		else
			return page_content[page_name]
		end
	end
	return error_text
end

local function trim(s)
	return s:match('^%s*(.-)%s*$')
end

function p.sectionh(frame)
	local args = require('Module:Arguments').getArgs(frame)
	return get_section(frame, trim(args[1] or ''), trim(args[2] .. ''), args['error'] or '')
end

return p