Module:Cite taxon/utilities
Appearance
local p = {}
p.format_species_list = function(frame)
local list = frame.args[1] or frame:getParent().args[1]
local expand = frame.args['expand'] or frame:getParent().args['expand'] -- want to subst template code
list = mw.text.trim( list )
local names = mw.text.split( list, "\n", plain )
--local genus, species, authority
local output = { } -- table of species names for output
local i = 1
while names[i] do
local name, match
local sep = " " -- space between genus and species
local genus, species, authority
if not match then
for g, s in string.gmatch(names[i], "(%S+) × (%S+).*" ) do -- else match hybrid genus × species
genus = g
species = s
sep = " × "
if a ~= "" then authority = a end
match = true
end
end
if not match then
for g, s, a in string.gmatch(names[i], "(%S+) (%S+) (.*)" ) do -- match genus, species, authority
genus = g
species = s
if a ~= "" then authority = a end -- no authority after space
match = true -- we have a match for genus, species, authority
end
end
if not match then
for g, s in string.gmatch(names[i], "(%S+) (%S+).*" ) do -- else match genus, species
genus = g
species = s
match = true
end
end
if match then
name = "''[[" .. genus .. sep .. species .. "]]'' "
if authority and expand then
name = name .. frame:expandTemplate{ title = 'small', args = { authority } } --expand template
elseif authority then
name = name .. "{{small|" .. authority .."}}" -- don't expand template
end
end
if name then
table.insert ( output , name )
else
table.insert ( output ,'<span class="error">unsupported format: expects "genus species authority"</span>' )
end
i=i+1
end
return "*" .. table.concat(output, "\n*")
end
return p