모듈:TaxonItalics
IT 위키
이 모듈에 대한 설명문서는 모듈:TaxonItalics/설명문서에서 만들 수 있습니다
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."
}
-- [[학명에서 첫 단어(속)만 잘라내는 함수 ]]
function p.extractGenus(frame)
local name = frame.args[1] or frame
if type(name) == 'table' then name = name.args[1] or '' end
name = mw.text.trim(name or '')
-- [추가] 한글이 포함되어 있으면 학명이 아니므로 처리를 중단하고 빈값 반환
if string.match(name, "[가-힣]") then
return ""
end
name = string.gsub(name, "^×%s*", "") -- 교잡종 기호 제거
local genus = string.match(name, "^([^%s]+)") -- 첫 번째 공백 이전까지 추출
return genus or ""
end
-- [[ 학명에서 첫 단어를 제외한 나머지(종명 등)만 추출 ]]
function p.extractSpecies(frame)
local name = frame.args[1] or frame
if type(name) == 'table' then name = name.args[1] or '' end
name = mw.text.trim(name or '')
-- [안전장치] 한글이 포함되어 있으면 학명이 아니므로 처리를 중단하고 빈값 반환
if string.match(name, "[가-힣]") then
return ""
end
-- 첫 번째 공백 이후의 모든 텍스트(종소명 + 아종명 등) 추출
local species = string.match(name, "%s+(.*)$")
return species or ""
end
function p.main(frame)
local name = frame.args[1] or ''
local linked = frame.args['linked'] == 'yes'
return p.italicizeTaxonName(name, linked)
end
function p.italicizeTaxonName(name, linked)
local italMarker = "''"
name = string.gsub(string.gsub(mw.text.trim(name), "<i>", italMarker), "</i>", italMarker)
local result = name
if name ~= '' then
if string.sub(name, 1, 2) == "''" or string.sub(name, -2) == "''" then
-- 이미 이탤릭체면 무시
else
name = string.gsub(name, "''", "")
local words = mw.text.split(name, " ", true)
local deitalicized = false
if #words == 4 and cTerms3[words[3]] then
result = words[1] .. " " .. words[2] .. italMarker .. " " .. cTerms3[words[3]] .. italMarker .. " " .. words[4]
deitalicized = true
elseif #words == 3 and cTerms2[words[2]] then
result = words[1] .. " " .. italMarker .. cTerms2[words[2]] .. italMarker .. " " .. words[3]
deitalicized = true
else
result = name
end
if linked then
if deitalicized then result = "[[" .. name .. "|" .. italMarker .. result .. italMarker .. "]]"
else result = italMarker .. "[[" .. name .. "]]" .. italMarker end
else result = italMarker .. result .. italMarker end
end
end
return result
end
return p
