Jump to content

Module:Get entries from dab

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 21:40, 17 March 2023 (Created page with '-- this module implements template:get entries from dab local p = {} function p.main(frame) local args = require('Module:Arguments').getArgs(frame) local page_name = args[1] or '' local page_content = '' local entries = {} if page_name ~= '' then local title = mw.title.new(page_name) if title then if title.redirectTarget then title = title.redirectTarget end page_content = title:getContent() end page_content = mw.ustring.gsub(page_co...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- this module implements [[template:get entries from dab]]
local p = {}

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local page_name = args[1] or ''
	local page_content = ''
	local entries = {}
	if page_name ~= '' then
		local title = mw.title.new(page_name)
		if title then
			if title.redirectTarget then title = title.redirectTarget end
			page_content = title:getContent()
		end
		page_content = mw.ustring.gsub(page_content, '[\r\n]==*%s*[Ss]ee also.*', '')
	end
	local pattern = args[2] or ''
	if pattern ~= '' then
		for s in mw.ustring.gmatch(page_content, '[\r\n]%*[^\r\n]*[%s%[]' .. pattern .. '[%s%|][^\r\n]*') do
			table.insert(entries, s)
		end
	else
		for s in mw.ustring.gmatch(page_content, '[\r\n]%*[^\r\n]*') do
			table.insert(entries, s)
		end
	end
	return frame:preprocess(table.concat(entries, '\n'))
end

return p