Jump to content

Module:TaxonItalics

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Peter coxhead (talk | contribs) at 09:45, 8 February 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

--[[=========================================================================
=============================================================================]]
function p.italicizeTaxonName(frame)
	local name = frame.args[1] or ''
	name = string.gsub(string.gsub(name, "<i>", "''"), "</i>", "''")
	local result = name
	local italbegin = "''"
	local italend = "''"
	if name ~= '' then
		if string.sub(name, 1, 2) == "''" then
			-- do nothing if already contains italic markers at the start
		else
			local words = mw.text.split(name, " ", true)
			if #words ~= 4 then
				result = italbegin .. name .. italend
			elseif string.find(name, "''", 1, true) then
				result = italbegin .. name .. italend
			else
				-- test here for words[3] being connecting term
				if words[3] == "subsp." or words[3] == "var." or words[3] == "subvar." or words[3] == "f." or words[3] == "subf." then
					result = italbegin .. words[1] .. " " .. words[2] .. italend .. " " .. words[3] .. " " .. italbegin .. words[4] .. italend
				else
					result = italbegin .. name .. italend
				end
			end
		end
	end
	return result
end

return p