Jump to content

Module:TaxonList

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Peter coxhead (talk | contribs) at 10:03, 11 November 2017. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.stripDagger(taxon)
	local dagger = ''
	if string.sub(taxon,1,1) == '†' then
		taxon = string.sub(taxon,2,#taxon)
		dagger = '†'
	else 
		if string.sub(taxon,1,8) == '†' then
			taxon = string.sub(taxon,9,#taxon)
			dagger = '†'
		else
			if string.sub(taxon,1,12) == '{{extinct}}' then
				taxon = string.sub(taxon,13,#taxon)
				dagger = '†'
			end
		end
	end
	return taxon, dagger
end

function p.main(frame)
	local italic = frame.args['italic'] == 'yes'
	local linked = frame.args['linked'] == 'yes'
	local incomplete = frame.args['incomplete'] == 'yes'
	local taxonArgs = frame:getParent().args
	local result = ''
	local num
	-- iterate over unnamed variables
	local taxon
	local dagger
	local first = true
	for name, value in pairs(taxonArgs) do
		if tonumber(name) then
			if first then
				taxon = value
				if linked or italic then
					taxon, dagger = p.stripDagger(taxon)
				else
					dagger = ''
				end
				if linked then
					taxon = '[[' .. taxon .. ']]'
				end
				if italic then
					taxon = "''" .. taxon .. "''"
				end
				result = result .. '<li>' .. dagger .. taxon
			else
				result = result .. ' <small>' .. value .. '</small></li>'
			end
			first = not first
		end
	end
	if incomplete then
		result = result .. '<small>(incomplete list)</small>'
	end
	return '<ul style="plainlist">' .. result .. '</ul>'
end

return p