Difference between revisions of "Module:TaxonItalics"
blackwiki>Peter coxhead |
blackwiki>Peter coxhead |
||
| Line 48: | Line 48: | ||
local italMarker = "''" | local italMarker = "''" | ||
if name ~= '' then | if name ~= '' then | ||
| − | if string.sub(name, 1, 2) == "''" then | + | if string.sub(name, 1, 2) == "''" or string.sub(name, -2) == "''" then |
| − | -- do nothing if the name already has italic markers at the start | + | -- do nothing if the name already has italic markers at the start or end |
else | else | ||
| + | name = string.gsub(name, "''", "") -- remove internal italics | ||
local words = mw.text.split(name, " ", true) | local words = mw.text.split(name, " ", true) | ||
if #words == 4 then | if #words == 4 then | ||
Revision as of 13:50, 10 February 2018
Module:TaxonItalics Template:Toolbar
| This Lua module is used on approximately 513,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. Transclusion count updated automatically (see documentation). |
Purpose
The module 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
It can also be used via {{Taxon italics}}.
Examples
Just italicized
- Connecting terms
- Pinus subg. Pinus → Script error: The function "main" does not exist.
- P. subgenus Pinus → Script error: The function "main" does not exist.
- P. subsect. Pinaster → Script error: The function "main" does not exist.
- Acer tataricum subsp. ginnala → Script error: The function "main" does not exist.
- Aster ericoides var. ericoides → Script error: The function "main" does not exist.
- A. ericoides varietas ericoides → Script error: The function "main" does not exist.
- A. e. subvar. ericoides → Script error: The function "main" does not exist.
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 → Script error: The function "main" does not exist.
- ×Beallara → Script error: The function "main" does not exist.
- × Beallara → Script error: The function "main" does not exist.
- {{hybrid}}Beallara → Script error: The function "main" does not exist.
Linked
Using |linked=yes
- Populus sect. Aigeiros → Script error: The function "main" does not exist.
- Elaeagnus × submacrophylla → Script error: The function "main" does not exist.
Abbreviated
Using |abbreviated=yes
- Populus sect. Aigeiros → Script error: The function "main" does not exist.
- Acer tataricum subsp. ginnala → Script error: The function "main" does not exist.
- [also linked] × Sorbaronia mitschurinii → Script error: The function "main" does not exist.
- [also linked] Elaeagnus × submacrophylla → Script error: The function "main" does not exist.
- Elaeagnus ×submacrophylla → Script error: The function "main" does not exist.
- Elaeagnus {{hybrid}} submacrophylla → Script error: The function "main" does not exist.
For even more examples, see the testcases.
local p = {}
local cTerms3 = {
subspecies = "subsp.",
["subsp."] = "subsp.",
subsp = "subsp.",
["ssp."] = "subsp.",
ssp = "subsp.",
varietas = "var.",
["var."] = "var.",
var = "var.",
subvarietas = "subvar.",
["subvar."] = "subvar.",
subvar = "subvar.",
forma = "f.",
["f."] = "f.",
f = "f.",
subforma = "subf.",
["subf."] = "subf.",
subf = "subf."
}
local cTerms2 = {
subgenus = "subg.",
["subg."] = "subg.",
subg = "subg.",
section = "sect.",
["sect."] = "sect.",
["cf."] = "cf.",
cf = "cf.",
["c.f."] = "cf."
}
--[[=========================================================================
Italicize a taxon name appropriately.
* If the name is already italicized, do nothing.
* If the name is not made up of four words or the name is made up of four
words and the third word is not a botanical connecting term, add italic
markup to the outside of the name.
* If the name is made up of four words and the third word is a botanical
connecting term, add italic markup so as not to italicize the connecting
term.
=============================================================================]]
function p.italicizeTaxonName(frame)
local name = frame.args[1] or ''
-- replace any use of the HTML italic tags by Wikimedia markup
name = string.gsub(string.gsub(name, "<i>", "''"), "</i>", "''")
local result = name
local italMarker = "''"
if name ~= '' then
if string.sub(name, 1, 2) == "''" or string.sub(name, -2) == "''" then
-- do nothing if the name already has italic markers at the start or end
else
name = string.gsub(name, "''", "") -- remove internal italics
local words = mw.text.split(name, " ", true)
if #words == 4 then
if string.find(name, "''", 1, true) then
-- add outside italic markup to four word names already containing internal italic markup
result = italMarker .. name .. italMarker
else
-- test for the third word of a four word name being a connecting term
if cTerms3[words[3]] then
-- de-italicize the connecting term by adding internal italic markup
result = italMarker .. words[1] .. " " .. words[2] .. italMarker .. " " .. cTerms3[words[3]] .. " " .. italMarker .. words[4] .. italMarker
else
-- third word is not a connecting term, so add outside italic markup
result = italMarker .. name .. italMarker
end
end
elseif #words == 3 then
if string.find(name, "''", 1, true) then
-- add outside italic markup to three word names already containing internal italic markup
result = italMarker .. name .. italMarker
else
-- test for the second word of a three word name being a connecting term
if cTerms2[words[2]] then
-- de-italicize the connecting term by adding internal italic markup
result = italMarker .. words[1] .. " " .. italMarker .. cTerms2[words[2]] .. " " .. italMarker .. words[3] .. italMarker
else
-- second word is not a connecting term, so add outside italic markup
result = italMarker .. name .. italMarker
end
end
else
-- add outside italic markup to names not made up of four words
result = italMarker .. name .. italMarker
end
end
end
return result
end
return p