Modul:CactaceaeTaxonok
Megjelenés
A modult a Modul:CactaceaeTaxonok/doc lapon tudod dokumentálni
local p = {}
-- Gyorsított formázó: csak akkor fut le, ha a sor megjelenítésre kerül
local function formazSzinonimak(szoveg)
if not szoveg or szoveg == "" then return "" end
-- Gyorsabb karaktercsere
local tiszta = szoveg:gsub("[đ÷]", ""):gsub("¤+", "")
tiszta = tiszta:gsub(">−", "−"):gsub(">≡", "≡"):gsub(">=", "=")
tiszta = tiszta:gsub("≡≡", "|≡"):gsub("==", "|="):gsub("−−", "|−"):gsub("%%-%%-", "|−")
local lista_elemek = {}
local reszek = mw.text.split(tiszta, "|", true)
for i=1, #reszek do
local tiszta_resz = mw.text.trim(reszek[i])
if tiszta_resz ~= "" then
-- Hatékonyabb dőltetés
local formazott = "''" .. tiszta_resz .. "''"
formazott = formazott:gsub("≡", "''≡''"):gsub("=", "''=''"):gsub("−", "''−''")
formazott = formazott:gsub("Type:", "''Type:''"):gsub("var%.", "''var.''")
formazott = formazott:gsub("subsp%.", "''subsp.''"):gsub("f%.", "''f.''")
formazott = formazott:gsub("''''", "")
table.insert(lista_elemek, "<li>" .. formazott .. "</li>")
end
end
if #lista_elemek == 0 then return "" end
return '<ul style="margin-left: 1.1em; list-style-type: disc; padding: 0; margin: 0;">' .. table.concat(lista_elemek) .. "</ul>"
end
function p.tablazat(frame)
local args = frame.args[1] and frame.args or frame:getParent().args
local szuroNemzettseg = args[1] and mw.text.trim(args[1]) or nil
if szuroNemzettseg == "" then szuroNemzettseg = nil end
local status, adatModul = pcall(require, 'Modul:CactaceaeTaxonokData')
if not status then return "Hiba: Adatmodul nem található!" end
local nyers_adat = adatModul.getAdatok()
local rows = {}
local sorszam = 0
local jelenlegiNemzettseg = ""
local megjelenit = true
-- Soronkénti feldolgozás (a string.gmatch gyorsabb, mint az ustring, ha nincs szükség speciális Unicode match-re)
for sor in nyers_adat:gmatch("[^\r\n]+") do
local taxon_link = ""
local szinonimak_nyers = ""
local elotag = sor:sub(1, 2) -- Az első két karaktert nézzük (gyorsabb)
if elotag:find("^ß") then
local nemz, tip = sor:match("^ß%s*([^:]+)::%s*(.+)")
if nemz then
jelenlegiNemzettseg = mw.text.trim(nemz):gsub("¤+", "")
if not szuroNemzettseg or szuroNemzettseg == jelenlegiNemzettseg then
taxon_link = "'''[[:Kategória:" .. jelenlegiNemzettseg .. "|" .. jelenlegiNemzettseg .. "]]'''"
szinonimak_nyers = tip
megjelenit = true
else
megjelenit = false
end
end
elseif elotag:find("^Ł") and megjelenit then
local tiszta_sor = sor:gsub("^Ł%s*", "")
local t, sz = tiszta_sor:match("([^¤]+)¤¤¤(.*)")
if t then
local tiszta_nev = mw.text.trim(t)
taxon_link = "''[[" .. tiszta_nev .. "]]''"
szinonimak_nyers = sz
end
end
-- Csak akkor formázunk, ha a sor átment a szűrőn
if taxon_link ~= "" then
sorszam = sorszam + 1
table.insert(rows, "|-\n| " .. sorszam .. "\n| " .. taxon_link .. "\n| " .. formazSzinonimak(szinonimak_nyers))
end
end
local header = '{| class="wikitable sortable datatable-hook stripe hover compact" data-page-length="50" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonima\n'
return frame:preprocess(header .. table.concat(rows, "\n") .. "\n|}")
end
return p