Ugrás a tartalomhoz

Modul:CactaceaeTaxonok

Innen: MKOE wiki
A lap korábbi változatát látod, amilyen Dr. Gyúró Zoltán (vitalap | szerkesztései) 2026. január 7., 10:21-kor történt szerkesztése után volt.

A modult a Modul:CactaceaeTaxonok/doc lapon tudod dokumentálni

local p = {}

-- Villámgyors formázó: csak a ténylegesen megjelenő sorokon fut le
local function formazSzinonimak(szoveg)
    if not szoveg or szoveg == "" then return "" end

    -- Gyors csere, csak a legszükségesebbekre
    local tiszta = mw.ustring.gsub(szoveg, "[đ÷¤]", "")
    
    -- Elválasztó csere (egyszerű karakternélküli kereséssel)
    tiszta = mw.ustring.gsub(tiszta, "≡≡", "###")
    tiszta = mw.ustring.gsub(tiszta, "==", "###")
    tiszta = mw.ustring.gsub(tiszta, "−−", "###")
    tiszta = mw.ustring.gsub(tiszta, "%%-%%-", "###")

    local reszek = mw.text.split(tiszta, "###", true)
    local lista = {}
    
    for i=1, #reszek do
        local r = mw.text.trim(reszek[i])
        if r ~= "" then
            -- Minimális dőltetés-korrekció
            r = "''" .. r .. "''"
            r = r:gsub("≡", "''≡''"):gsub("=", "''=''"):gsub("−", "''−''")
            r = r:gsub("var%.", "''var.''"):gsub("subsp%.", "''subsp.''")
            r = r:gsub("''''", "")
            table.insert(lista, "<li>" .. r .. "</li>")
        end
    end
    
    return #lista > 0 and ('<ul style="margin-left: 1.1em; list-style-type: disc; padding: 0; margin: 0;">' .. table.concat(lista) .. "</ul>") or ""
end

function p.tablazat(frame)
    -- Paraméter átvétele a sablonból
    local args = frame:getParent().args
    local szuro = args[1] and mw.text.trim(args[1]) or ""
    if szuro == "" then szuro = nil end

    local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: Adatmodul nem érhető el." end
    local nyers = dataModul.getAdatok()

    local rows = {}
    local counter = 0
    local isVisible = true

    -- Iteráció a sorokon
    for sor in mw.ustring.gmatch(nyers, "[^\r\n]+") do
        local prefix = mw.ustring.sub(sor, 1, 1)
        
        if prefix == "ß" then
            -- Nemzetség detektálása
            local nemz, tip = mw.ustring.match(sor, "^ß%s*([^:]+)::%s*(.+)")
            if nemz then
                local tisztaNemz = mw.text.trim(nemz):gsub("¤", "")
                if not szuro or szuro == tisztaNemz then
                    isVisible = true
                    counter = counter + 1
                    local taxon_link = "'''[[:Kategória:" .. tisztaNemz .. "|" .. tisztaNemz .. "]]'''"
                    table.insert(rows, "|-\n| " .. counter .. "\n| " .. taxon_link .. "\n| " .. formazSzinonimak(tip))
                else
                    isVisible = false
                end
            end
        elseif prefix == "Ł" and isVisible then
            -- Faj detektálása (csak ha a nemzetség szűrő engedi)
            local tiszta_sor = mw.ustring.sub(sor, 2)
            local t, sz = mw.ustring.match(tiszta_sor, "^%s*([^¤]+)¤¤¤(.*)")
            if t then
                counter = counter + 1
                local taxon_link = "''[[" .. mw.text.trim(t) .. "]]''"
                table.insert(rows, "|-\n| " .. counter .. "\n| " .. taxon_link .. "\n| " .. formazSzinonimak(sz))
            end
        end

        -- Kényszerített leállás, ha túl sok az adat (Wiki CPU korlát védelem)
        if counter > 1000 then 
            table.insert(rows, "|-\n| colspan='3' style='color:red;' | A lista túl hosszú, kérlek használj nemzetség szűrőt!")
            break 
        end
    end

    local head = '{| 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(head .. table.concat(rows, "\n") .. "\n|}")
end

return p