Module:TaxonList and Module:TaxonList/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
-plainlist per discussion |
Artoria2e5 (talk | contribs) ~ |
||
Line 8: | Line 8: | ||
-- use a function from Module:TaxonItalics to italicize a taxon name |
-- use a function from Module:TaxonItalics to italicize a taxon name |
||
local TaxonItalics = require("Module:TaxonItalics") |
local TaxonItalics = require("Module:TaxonItalics") |
||
local IfPreview = require([[Module:If preview]]) |
|||
local p = {} |
local p = {} |
||
Line 41: | Line 42: | ||
end |
end |
||
return taxonName, dagger |
return taxonName, dagger |
||
⚫ | |||
--[[========================================================================= |
|||
Utility function to do the following: |
|||
1. Strip off any initial † present to mark the taxon as extinct. We outsource |
|||
to p.stripDagger() for this. |
|||
2. Strip off any double quotation marks present to mark the taxon as invalid. |
|||
The double-quotation marks, too, should not be formatted. |
|||
3. Strip off any Candidatus or Ca. to mark the taxon as Candidatus. |
|||
The function returns four values: |
|||
* 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.parseName(taxonName) |
|||
⚫ | |||
local dquote = '' |
|||
if string.sub(name,1,1) == '"' then |
|||
name = string.sub(name,2) |
|||
⚫ | |||
if string.sub(name,#name) == '"' then |
|||
name = string.sub(name,1,#name-1) |
|||
⚫ | |||
name = '|' .. IfPreview._warning({'"' .. name .. ' has an unpaired double quote.'}) |
|||
end |
|||
end |
|||
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 |
end |
||
Line 69: | Line 115: | ||
local taxonName |
local taxonName |
||
local dagger |
local dagger |
||
local dquote |
|||
local candidatus |
|||
local first = true -- is this the first of a taxon name/author pair? |
local first = true -- is this the first of a taxon name/author pair? |
||
for param, value in pairs(taxonArgs) do |
for param, value in pairs(taxonArgs) do |
||
Line 74: | Line 122: | ||
if first then |
if first then |
||
taxonName = mw.text.trim(value) |
taxonName = mw.text.trim(value) |
||
-- if necessary separate any initial |
-- if necessary separate any initial modifier |
||
taxonName, dagger, dquote, candidatus = p.parseName(taxonName) |
|||
if linked |
if linked and not (italic and candidatus == '') then |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if linked and not italic then |
|||
taxonName = '[[' .. taxonName .. ']]' |
taxonName = '[[' .. taxonName .. ']]' |
||
end |
end |
||
if italic then |
if italic and candidatus == '' then |
||
taxonName = TaxonItalics.italicizeTaxonName(taxonName, linked, abbreviated) |
taxonName = TaxonItalics.italicizeTaxonName(taxonName, linked, abbreviated) |
||
end |
end |
||
taxonName = candidatus .. taxonName |
|||
if bold then |
if bold then |
||
taxonName = '<b>' .. taxonName .. '</b>' |
taxonName = '<b>' .. taxonName .. '</b>' |
||
end |
end |
||
result = result .. '<li>' .. dagger .. taxonName |
result = result .. '<li>' .. dagger .. dquote .. taxonName .. dquote |
||
else |
else |
||
result = result .. ' <small>' .. value .. '</small></li>' |
result = result .. ' <small>' .. value .. '</small></li>' |