Module:Get entries from dab
Jump to navigation
Jump to search
File:Test Template Info-Icon - Version (2).svg Module documentation[view] [edit] [history] [purge]
| File:Greek lc beta icon.svg | This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
This module implements template:get entries from dab.
Usage
[edit source]{{#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