Module:italics

Hello, you have come here looking for the meaning of the word Module:italics. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:italics, but we will also tell you about its etymology, its characteristics and you will know how to say Module:italics in singular and plural. Everything you need to know about the word Module:italics you have here. The definition of the word Module:italics will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:italics, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module applies proper italicization to the taxonomic name of a genus, species, subspecies, variety, or form; or italicizes a title while not italicizing a parenthetical disambiguator. It is intended to be used in interwiki link modules, but might be useful elsewhere too.

Testcases

{{#invoke:italics|test|<cite>A Voyage around the World.  In Two Volumes</cite>|quote=1}}
{{#invoke:italics|test|<cite>A Response to a Scurrilous Libel by J S.  In Two Volumes</cite>|quote=1}}
{{#invoke:italics|test|<cite>]</cite>|quote=1}}
{{#invoke:italics|test|<cite> In Two Volumes]]</cite>|quote=1}}
{{#invoke:italics|test|1=|quote=1}}
{{#invoke:italics|test|Pinus contorta subsp. latifolia}}
{{#invoke:italics|test|Cupressus arizonica var. glabra}}
{{#invoke:italics|test|Fragaria vesca subsp. vesca f. semperflorens}}
{{#invoke:italics|test|Fragaria × ananassa}}
{{#invoke:italics|test|Argentina (plant)}}
{{#invoke:italics|test|× Agroelymus}} <!-- This now passess 20181225-19:12 -->
{{#invoke:italics|test|A sample item containing a continuation, &c {{...}} <!-- This fails currently --> }} 
{{#invoke:italics|test|A sample item containing a continuation, &c {{nb...}} <!-- This fails currently --> }} 
{{#invoke:italics|test|] <!-- This fails currently --> }}
{{#invoke:italics|test|]<!-- This fails currently, Generates a missing span... -->}}
{{#invoke:italics|test|'''Polygonum''' aviculare}}

{{taxlink|Rosa × alba|nothospecies}} - Rosa × alba


local export = {}
local m_string_utils = require("Module:string utilities")

local find = m_string_utils.find
local match = m_string_utils.match
local gsub = m_string_utils.gsub

function export.i(text)
	if text == "" or text == nil then
		return nil
	end
	
	if type(text) == "table" and text.args then
		text = text.args
	end
	
	-- Remove whitespace from beginning and end of text.
	text = mw.text.trim(text)
	
	-- Find parenthesized text.
	local parenthesis = ""
	if find(text, "%b()$") then
		text, parenthesis = match(text, "^(.*)(%b())$")
		if text == "" or text == nil then
			error("Malformed page name: " .. text)
		end
	end
	
	text = "''" .. text .. "''"
	
	--[[ Adds italics toggle ('') around the whitespace
		that surrounds various things that aren't supposed to be italicized:
		for instance, Fragaria × ananassa becomes ''Fragaria'' × ''ananassa''.
		(The hybridization symbol × isn't supposed to be italicized.) ]]
	local notItalicized = {
		 = true,  = true,  = true,  = true,
		 = true,  = true,  = true,  =  true,
         = true,  = true,
         = true,  = true,
         = true,  = true,  = true,  = true
	}
	local hybrid = "×"
	
	text = text:gsub("(%s*(+%.)%s*)",
		function(wholeMatch, abbreviation)
			if notItalicized then
				return "''" .. wholeMatch .. "''"
			end
		end)
	
	text = text:gsub("%s*" .. hybrid .. "%s*", "''%0''"):gsub("%f''''%f", "")
	
	return text .. parenthesis
end

function export.unitalicize_brackets(text)
	if type(text) == "table" and text.args then
		text = text.args
	end
	
	if not text or text == "" then
		return nil
	end
	
	local function unitalicize(text)
		return '<span style="font-style: normal;">' .. text .. '</span>'
	end
	
	local function process(text)
		if text:find("[[", 1, true) then
			if text:find("|") then
				return text:gsub(
					"|.-%]%]",
					function (piping)
						return piping:gsub("%b", process)
					end)
			end
			-- do nothing with un-piped wikilinks
		--[=[
		elseif text:find("[http", 1, true) then
			return text:gsub(
				"%+ )(]+)%]",
				function (URL, link_text)
					return ""
				end)
		--]=]
		elseif text:find("^%[https?://") then
				return text:gsub(
					" .+",
					function (link_text)
						return link_text:gsub("%b", process)
					end)
		else
			local inside_brackets = text:sub(2, -2)
			if inside_brackets == "..." or inside_brackets == "…" then
				return unitalicize(text)
			else
				return unitalicize("")
			end
		end
	end
	
	text = text:gsub("%b", process)
	
	return text
end

function export.test(frame)
	local text = frame.args
	local quote = require("Module:yesno")(frame.args.quote)
	if quote then
		return export.unitalicize_brackets(text)
	else
		return export.i(text)
	end
end

return export