Module:DetailedList

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, table, yesno = loader.require('String', 'Table', 'Yesno') local data = loader.loadData('Module:DetailedList/Data')

local p = {}

local function mergeMultiListSyntax(args, start) -- Check if list format is being used local start = tonumber(start) or 1 local function _tostring(v) if type(v) == 'table' then return table.concat(v) elseif type(v) == 'boolean' or v == nil or type(v) == 'number' or type(v) == 'function' then return tostring(v) else return v		end end --errors checkType(1, args, 'table') checkType(2, start, 'number', true) args[start] = _tostring(args[start]) if args[start]:match('%*') then local list = {} for v in (args[start]):gmatch('%*+[^%*]+') do			v = v:gsub('\n',' ') table.push(list, string.trim(v)) end list[1] = _tostring(list[1]) if not list[1] or list[1] == '' then table.remove(list,1) end return list elseif args[start] and not args[start]:match('%*') and not args[start+1] then return {args[start]} end --else local list, i = {}, start while args[i] do		list[#list+1] = _tostring(args[i]) i = i + 1 end return list end

function p.detailedResourceList( frame ) local args = getArgs(frame) local list = mergeMultiListSyntax(args) local showimage = yesno(args.showimage, true) return mw.getCurrentFrame:preprocess(p._detailedResourceList(list, showimage)) end

function p._detailedResourceList(list, showimage) local ret = {} local function addmod(var, mod) var = var or '' return var:match(mod) and var or var..mod end local function resolve(depth1, num1, item1, mod1) mod1 = mod1 or '' if item1:match('/[^/]+/') then item1 = item1:match('/([^/]+)/') mod1 = addmod(mod1, '//') end for _,m in ipairs{'{','}'} do			if item1:match(m) then mod1 = addmod(mod1, m) end end local queryResult = data[item1] if mod1:match('//') and queryResult then mod1 = addmod(mod1, '{') -- wrap span (start) end if not mod1:match('h') then local mods = '' if depth1 > 0 and mod1:match('{') then mods = mods .. (mod1:match('n') and ' '					or mod1:match('u') and ' '					or ' '				) end mods = mods .. (depth1 > 0 and mod1:match('}') and ' ' or '') table.push(ret, (showimage and '%s %s' or '%s %s %s'):format( string._repeat('*',depth1), tostring(num1), item1, mods ))		end if mod1:match('//') and queryResult then queryResult = type(queryResult[1]) ~= 'table' and { queryResult } or queryResult for _, entry in ipairs(queryResult) do				local iDepth, iNum, iItem, iMod = entry[1], entry[2], entry[3], entry[4] resolve(depth1+iDepth, num1*iNum, iItem, iMod) end ret[#ret] = ret[#ret]..' ' -- wrap span (end) end end local shallow = 999 for _,line in ipairs(list) do		local asterisks = line:match('^%*+') local depth = asterisks and #asterisks or 1 shallow = depth < shallow and depth or shallow local item, num, itemname, queryResult local modifiers = '' if line:match('^[%*%s]*/[^/]+/') then item, modifiers = line:match('^[%*%s]*/([^/]+)/(%S*)') modifiers = addmod(modifiers, '//') else item = line:match('^[%*%s]*(.*)') end for _,m in ipairs{'{','}'} do			if line:match(m) then modifiers = addmod(modifiers, m) end end if not modifiers:match('c') and not modifiers:match('u') and depth == shallow then modifiers = addmod(modifiers, 'n') -- make the most shallow item(s) in list a normal list (no collapse option) end item = string.trim(item) if item:match('^%d+ .*') then num, itemname = item:match('^(%d+) ([^%{%}]*)') num = tonumber(num) or 1 else num, itemname = 1, item:gsub('{',):gsub('}',) end itemname = string.trim(itemname) resolve(depth, num, itemname, modifiers or '') end return (' \n%s\n '):format(table.concat(ret, '\n')) end

return p