Module:TaxonItalics/sandbox
![]() | This is the module sandbox page for Module:TaxonItalics (diff). See also the companion subpage for test cases (run). |
Module:TaxonItalics (talk · · hist · links · doc · subpages · sandbox · testcases)
![]() | This Lua module is used on approximately 601,000 pages, or roughly 1% of all pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
Purpose
The module is primarily intended for use by the automated taxobox system. It supports the correct italicization of scientific names. Botanical (ICNafp) names may contain "connecting terms"; these must not be italicized. The hybrid symbol, ×, should also not be italicized. The module optionally wikilinks and abbreviates italicized names.
For non-virus taxa, italics are used at the rank of genus or below. The module does not decide whether a scientific name should be italicized. Use {{Is italic taxon}}
for this purpose.
Usage
- {{#invoke:TaxonItalics|main|TAXON_NAME}} – italicizes a taxon name
- {{#invoke:TaxonItalics|main|TAXON_NAME|linked=yes}} – italicizes a taxon name, wikilinking the italicized output to the unchanged input
- {{#invoke:TaxonItalics|main|TAXON_NAME|abbreviated=yes}} – italicizes a taxon name, abbreviating all but the last part to the first letter
- {{#invoke:TaxonItalics|main|TAXON_NAME|dab=yes}} – italicizes a taxon name, treating any parenthesized part as a disambiguation term, and not italicizing it
The parameters can be combined. It can also be used via {{Taxon italics}}.
Examples
Just italicized
- Connecting terms
- Pinus subg. Pinus → Pinus subg. Pinus
- P. subgenus Pinus → P. subg. Pinus
- P. subsect. Pinaster → P. subsect. Pinaster
- Acer tataricum subsp. ginnala → Acer tataricum subsp. ginnala
- Aster ericoides var. ericoides → Aster ericoides var. ericoides
- A. ericoides varietas ericoides → A. ericoides var. ericoides
- A. e. subvar. ericoides → A. e. subvar. ericoides
Botanical names may contain only one infraspecific epithet; a string like "Fragaria vesca subsp. vesca f. semperflorens" is a classification, not a name, and is not handled by the module.
- Hybrid symbols
- Elaeagnus × submacrophylla → Elaeagnus × submacrophylla
- ×Beallara → ×Beallara
- × Beallara → × Beallara
- {{hybrid}}Beallara → ×Beallara
Linked
Using |linked=yes
- Populus sect. Aigeiros → Populus sect. Aigeiros
- Elaeagnus × submacrophylla → Elaeagnus × submacrophylla
Abbreviated
Using |abbreviated=yes
- Populus sect. Aigeiros → P. sect. Aigeiros
- Acer tataricum subsp. ginnala → A. t. subsp. ginnala
- [also linked] × Sorbaronia fallax → × S. fallax
- [also linked] Elaeagnus × submacrophylla → E. × submacrophylla
- Elaeagnus ×submacrophylla → E. ×submacrophylla
- Elaeagnus {{hybrid}} submacrophylla → E. × submacrophylla
Disambiguation terms
By default, a parenthesized part of a taxon name is assumed to be a subgenus name, and is italicized:
- Varanus (Hapturosaurus) → Varanus (Hapturosaurus)
- Caia (plant) → Caia (plant) – wrong
To treat a parenthesized part as a disambiguation term, use |dab=yes
- Caia (plant) → Caia (plant)
- (also linked) Caia (plant) → Caia (plant)
For even more examples, see the testcases.
--[[
This module provides the core functionality to a set of templates used to
display a list of taxon name/authority pairs, with the taxon names optionally
italicized, wikilinked and/or emboldened. Such lists are usually part of
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 = {}
--[[=========================================================================
Utility function to strip off any initial † present to mark the taxon as
extinct. The † must not be italicized, emboldened, or included in the
wikilinked text, so needs to be added back afterwards.
† is assumed to be present as one of:
* the unicode character †
* the HTML entity †
* the output of {{extinct}} – this will have been expanded before reaching this
module and is assumed to have the form '<span ... </span>'
The function returns two values: the taxon name with any † before it removed
and either '†' if it was present or the empty string if not.
=============================================================================]]
function p.stripDagger(taxonName)
local dagger = ''
if mw.ustring.sub(taxonName,1,1) == '†' then
taxonName = mw.ustring.sub(taxonName,2,#taxonName)
dagger = '†'
else
if string.sub(taxonName,1,8) == '†' then
taxonName = string.sub(taxonName,9,#taxonName)
dagger = '†'
else
-- did the taxon name originally have {{extinct}} before it?
if (string.sub(taxonName,1,5) == '<abbr') and mw.ustring.find(taxonName, '†') then
taxonName = string.gsub(taxonName, '^.*</abbr>', '', 1)
dagger = '†'
end
end
end
return taxonName, dagger
end
--[[=========================================================================
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 name, dagger = p.stripDagger(taxonName)
local dquote = ''
return name, dagger, '', ''
--[[
if string.sub(name,1,1) == '"' then
name = string.sub(name,2)
dquote = '"'
if string.sub(name,1,1) == '"' then
name = string.sub(name,1,#name-1)
else
name = IfPreview._warning('Unmatched double quotation mark in taxon name: ' .. name)
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
--[[=========================================================================
The function returns a list of taxon names and authorities, appropriately
formatted.
Usage:
{{#invoke:TaxonList|main
|italic = yes - to italicize the taxon name
|linked = yes - to wikilink the taxon name
|bold = yes - to emboldent the taxon name
|incomplete = yes - to output "(incomplete)" at the end of the list
}}
The template that transcludes the invoking template must supply an indefinite
even number of arguments in the format
|Name1|Author1 |Name2|Author2| ... |NameN|AuthorN
=============================================================================]]
function p.main(frame)
local italic = frame.args['italic'] == 'yes'
local bold = frame.args['bold'] == 'yes'
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
local result = ''
-- iterate over unnamed variables
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
if tonumber(param) then
if first then
taxonName = mw.text.trim(value)
-- if necessary separate any initial modifier
taxonName, dagger, dquote, candidatus = p.parseName(taxonName)
if linked and not italic then
taxonName = '[[' .. taxonName .. ']]'
end
if italic and candidatus == '' then
taxonName = TaxonItalics.italicizeTaxonName(taxonName, linked, abbreviated)
end
if bold then
taxonName = '<b>' .. taxonName .. '</b>'
end
result = result .. '<li>' .. dagger .. dquote .. candidatus .. taxonName .. dquote
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 class="taxonlist">' .. result .. '</ul>'
end
return p