Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:TOC: Difference between revisions

From Zenniverse Media
Created page with "return { letters = function(frame) local origArgs = frame.args if not origArgs[1] and not(tonumber(origArgs['start']) and tonumber(origArgs['start'])) then origArgs = frame:getParent().args if not origArgs[1] and not(tonumber(origArgs['start']) and tonumber(origArgs['start'])) then return '' end end local args local prefix = origArgs.prefix or '' local start = tonumber(origArgs['start']) local limit = tonumber(origArgs['end']) if start an..."
 
(No difference)

Latest revision as of 09:18, 31 July 2025

Documentation for this module may be created at Module:TOC/doc

return {
	letters = function(frame)
		local origArgs = frame.args
		if not origArgs[1] and not(tonumber(origArgs['start']) and tonumber(origArgs['start'])) then
			origArgs = frame:getParent().args
			if not origArgs[1] and not(tonumber(origArgs['start']) and tonumber(origArgs['start'])) then
				return ''
			end
		end
		
		local args
		local prefix = origArgs.prefix or ''
		local start = tonumber(origArgs['start'])
		local limit = tonumber(origArgs['end'])
		if start and limit then
			args = {}
			local incr = tonumber(origArgs.by) or 1
			local form = '%0' .. math.floor(math.log10(limit) + 1) .. 'd'
			local i = 1
			for v = start, limit, incr do
				v = string.format(form, v)
				args[i] = v
				if tonumber(v) ~= (prefix .. v) and not origArgs[i .. 'T'] then
					origArgs[i .. 'T'] = tonumber(v)
				end
				i = i + 1
			end
		else
			args = origArgs	
		end
		
		local out = {}
		local currentTitle = mw.title.getCurrentTitle()
		for i, v in ipairs(args) do
			local title = origArgs[v .. 'L'] or origArgs[i .. 'T'] or v
			if currentTitle.namespace == 14 then --Category namespace
				local url = currentTitle:fullUrl('from=' .. prefix .. v)
				table.insert(out, '<li>[' .. url .. ' ' .. title .. ']</li>')
			else
				table.insert(out, '<li>[[#' .. prefix .. v .. '|' .. title .. ']]</li>')
			end
		end
		
		return '<ul class="hlist plainlist" style="display:inline;margin:0;padding:0">' .. table.concat(out, ' ') .. '</ul>'
	end
}