Module:TaxonList: Difference between revisions

Content deleted Content added
updated to tested sandbox version (doesn't italicize botanical connecting forms if not linked)
Copy from sandbox per request on talk
 
(9 intermediate revisions by 3 users not shown)
Line 5:
taxoboxes.
]]
 
-- use a function from Module:TaxonItalics to italicize a taxon name
local TaxonItalics = require("Module:TaxonItalics")
local IfPreview = require([[Module:If preview]])
 
local p = {}
Line 31 ⟶ 35:
else
-- did the taxon name originally have {{extinct}} before it?
if (string.sub(taxonName,1,5) == '<spanabbr') and mw.ustring.find(taxonName, '†') then
taxonName = string.gsub(taxonName, '^.*</spanabbr>', '', 1)
dagger = '†'
end
Line 40 ⟶ 44:
end
 
--[[=========================================================================
--Utility function to italicizedo the taxon name. Any connecting forms used infollowing:
 
--botanical names (e.g. 'subsp.', 'f.') should not be italicized. However,
1. Strip off any initial † present to mark the taxon as extinct. We outsource
--simply de-italicizing won't work if the taxon name is also linked, since it
to p.stripDagger() for this.
--will produce output of the form '<i>[[X Y</i> subsp. <i>Z]]</i>'.
 
--(What is needed in this case is to output
2. Strip off any double quotation marks present to mark the taxon as invalid.
-- [[X Y subsp. Z|<i>X Y</i> subsp. <i>Z</i>]]
The double-quotation marks, too, should not be formatted.
--but this is not currently implemented.)
 
--=============================================================================
3. Strip off any Candidatus or Ca. to mark the taxon as Candidatus.
function p.italicize(taxonName, linked)
 
if not linked then
The function returns four values:
taxonName = string.gsub(taxonName, ' %a*%. ', '</i> %0 <i>', 1)
* the taxon name with all of the three modifiers removed
* either '†' if it was present or the empty string if not
* either a single dquote if it was present in a pair or the empty string if not
* either italicized "Candidatus " or "Ca. " if it was present or the empty string if not
 
The function can error in case of an unpaired quotation mark. In that case, a
IfPreview._warning() is mixed into the first return.
--=============================================================================]]
function p.italicizeparseName(taxonName, linked)
taxonName local name, dagger = p.stripDagger(taxonName)
local dquote = ''
if string.sub(name,1,1) == '"' then
name = string.sub(name,2)
daggerdquote = '"'
if string.sub(name,#name) == '"' then
name = string.sub(name,1,#name-1)
else
name = '|' .. IfPreview._warning({'"' .. name .. ' has an unpaired double quote.'})
end
end
 
return '<i>' .. taxonName .. '</i>'
local candidatus = ''
if string.sub(name,1,11) == 'Candidatus ' then
name = string.sub(name,12)
candidatus = "''Candidatus'' "
elseif string.sub(name,1,4) == 'Ca. ' then
name = string.sub(name,5)
candidatus = "''Ca.'' "
end
 
return name, dagger, dquote, candidatus
end
 
Line 75 ⟶ 108:
local linked = frame.args['linked'] == 'yes'
if bold then linked = false end -- must not have bold and wikilinked
local abbreviated = frame.args['abbreviated'] == 'yes'
local incomplete = frame.args['incomplete'] == 'yes'
local taxonArgs = frame:getParent().args
Line 81 ⟶ 115:
local taxonName
local dagger
local dquote
local candidatus
local first = true -- is this the first of a taxon name/author pair?
for param, value in pairs(taxonArgs) do
Line 86 ⟶ 122:
if first then
taxonName = mw.text.trim(value)
-- if necessary separate any initial † from the taxon namemodifier
taxonName, dagger, dquote, candidatus = p.parseName(taxonName)
if linked orand not (italic orand candidatus == bold'') then
taxonName, dagger = p.stripDagger(taxonName)
else
dagger = ''
end
if linked then
taxonName = '[[' .. taxonName .. ']]'
end
if italic and candidatus == '' then
taxonName = pTaxonItalics.italicizeitalicizeTaxonName(taxonName, linked, abbreviated)
end
taxonName = candidatus .. taxonName
if bold then
taxonName = '<b>' .. taxonName .. '</b>'
end
result = result .. '<li>' .. dagger .. dquote .. taxonName .. dquote
else
result = result .. ' <small>' .. value .. '</small></li>'
Line 111 ⟶ 144:
result = result .. '<small>(incomplete list)</small>'
end
return '<ul styleclass="plainlisttaxonlist">' .. result .. '</ul>'
end