Toggle menu
14
236
69
27.3K
Kenshi Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 07:17, 19 February 2025 by Prd (talk | contribs) (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_content, '[\r\n]...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This module implements template:get entries from dab.

Usage

{{#invoke:Get entries from dab|main}}


-- 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.*', '')
		page_content = mw.ustring.gsub(page_content, '([\r\n]%*)([^%s])', '%1 %2')
	end
	local k = 2
	args[2] = (args[2] or '') == '' and '.' or args[2]
	
	while (args[k] or '') ~= '' do
		local pattern = args[k]
		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
		k = k + 1
	end
	return frame:preprocess(table.concat(entries, '\n'))
end

return p
Contents