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:34-kor történt szerkesztése után volt.

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

local p = {}

-- Gyors, de alapos formázó
local function formazSzinonimak(szoveg)
    if not szoveg or szoveg == "" then return "" end

    -- 1. Takarítás: töröljük a felesleges karaktereket (Unicode-biztosan)
    local tiszta = mw.ustring.gsub(szoveg, "[đ÷¤]", "")
    
    -- 2. Jelek egységesítése
    tiszta = tiszta:gsub(">−", "−"):gsub(">≡", "≡"):gsub(">=", "=")
    
    -- 3. Darabolás (a jelek mentén törünk új sorba)
    local lista = {}
    -- Unicode-biztos split alternatíva
    tiszta = mw.ustring.gsub(tiszta, "≡≡", "###")
    tiszta = mw.ustring.gsub(tiszta, "==", "###")
    tiszta = mw.ustring.gsub(tiszta, "−−", "###")
    tiszta = mw.ustring.gsub(tiszta, "%%-%%-", "###")
    tiszta = mw.ustring.gsub(tiszta, "|", "###")

    for r in mw.ustring.gmatch(tiszta, "[^#]+") do
        local tr = mw.text.trim(r)
        if tr ~= "" and tr ~= "''" then
            -- Dőltetés és speciális szavak javítása
            local f = "''" .. tr .. "''"
            f = f:gsub("≡", "''≡''"):gsub("=", "''=''"):gsub("−", "''−''")
            f = f:gsub("var%.", "''var.''"):gsub("subsp%.", "''subsp.''"):gsub("f%.", "''f.''")
            f = f:gsub("''''", "")
            table.insert(lista, "<li>" .. f .. "</li>")
        end
    end
    
    if #lista == 0 then return "" end
    return '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
end

function p.tablazat(frame)
    local args = frame:getParent().args
    local szuro = args[1] and mw.text.trim(args[1]) or ""
    
    if szuro == "" then
        return "<div style='color:red; font-weight:bold; padding:10px; border:1px solid;'>Hiba: Adj meg egy nemzetséget szűrőként! (pl. {{CactaceaeTaxonokTáblázat|Opuntia}})</div>"
    end

    local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: Adatmodul nem található." end
    local nyers = dataModul.getAdatok()

    local rows = {}
    local counter = 0
    local isVisible = false
    
    -- Soronkénti feldolgozás
    for sor in mw.ustring.gmatch(nyers, "[^\r\n]+") do
        local prefix = mw.ustring.sub(sor, 1, 1)
        
        if prefix == "ß" then
            -- Megnézzük, hogy ez a kért nemzetség-e
            local nemz, tip = mw.ustring.match(sor, "^ß%s*([^:]+)::%s*(.+)")
            if nemz then
                local tisztaNemz = mw.text.trim(mw.ustring.gsub(nemz, "¤", ""))
                if tisztaNemz == szuro then
                    isVisible = true
                    counter = counter + 1
                    table.insert(rows, "|-\n| " .. counter .. "\n| '''[[:Kategória:" .. tisztaNemz .. "|" .. tisztaNemz .. "]]'''\n| " .. formazSzinonimak(tip))
                else
                    isVisible = false
                end
            end
        elseif isVisible and prefix == "Ł" then
            -- Csak ha a szűrt nemzetségen belül vagyunk
            local t, sz = mw.ustring.match(sor, "^Ł%s*([^¤]+)¤¤¤(.*)")
            if t then
                counter = counter + 1
                table.insert(rows, "|-\n| " .. counter .. "\n| ''[[" .. mw.text.trim(t) .. "]]''\n| " .. formazSzinonimak(sz))
            end
        end
        
        -- Biztonsági korlát
        if counter >= 1000 then break end
    end

    if #rows == 0 then return "Nincs találat a következő nemzetségre: " .. szuro end

    local head = '{| class="wikitable sortable datatable-hook stripe hover compact" 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