Ugrás a tartalomhoz

„Modul:CactaceaeTaxonok” változatai közötti eltérés

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Nincs szerkesztési összefoglaló
5. sor: 5. sor:
     if not szoveg or szoveg == "" then return "" end
     if not szoveg or szoveg == "" then return "" end
      
      
    -- "Type:" cseréje "Típusfaj:"-ra
     local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
     local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
      
      
29. sor: 28. sor:
end
end


-- Szinonimák feldolgozása
-- Szinonimák feldolgozása (támogatja a nyers szöveget és a blokkokat is)
local function formazSzinonimak(sor)
local function formazSzinonimak(sor)
     if not sor or sor == "" then return "" end
     if not sor or sor == "" then return "" end


     local lista = {}
     local lista = {}
    -- 1. Típusfaj kinyerése (ami a :: és az 1# között van)
    local nyers_resz = sor:match("^([^%d]+)1#")
    if nyers_resz then
        local tisztitott = mw.text.trim(nyers_resz:gsub("^::%s*", ""))
        if tisztitott ~= "" then
            -- A típusfaj általában fajnév (tartalmaz szóközt), így nem lesz bold-italic
            table.insert(lista, "<li>" .. taxonFormazo(tisztitott, false) .. "</li>")
        end
    end
    -- 2. Számozott blokkok kinyerése (3-as és 4-es szint)
     local aktualis_sor = ""
     local aktualis_sor = ""
    for szint, jel, tartalom in mw.ustring.gmatch(sor, "(%d)%s*([^%d%s#]+)%s*([^#]+)%s*%d#") do
        if szint == "3" or szint == "4" then
            local tiszta_jel = mw.ustring.sub(jel, 1, 1)
            local trimmed_tartalom = mw.text.trim(tartalom)
            local is_syn_genus = not trimmed_tartalom:find(" ")
           
            local formalt_nev = taxonFormazo(trimmed_tartalom, is_syn_genus)
            local elem = tiszta_jel .. " " .. formalt_nev


    for szint, jel, tartalom in sor:gmatch("(%d)%s*([^%d%s#]+)%s*([^#]+)%s*%d#") do
            if szint == "3" then
        local tiszta_jel = mw.ustring.sub(jel, 1, 1)
                if aktualis_sor ~= "" then table.insert(lista, "<li>" .. aktualis_sor .. "</li>") end
        local trimmed_tartalom = mw.text.trim(tartalom)
                aktualis_sor = elem
        local is_syn_genus = not trimmed_tartalom:find(" ")
            else
       
                aktualis_sor = aktualis_sor .. " " .. elem
        local formalt_nev = taxonFormazo(trimmed_tartalom, is_syn_genus)
        local elem = tiszta_jel .. " " .. formalt_nev
 
        if szint == "3" then
            if aktualis_sor ~= "" then
                table.insert(lista, "<li>" .. aktualis_sor .. "</li>")
             end
             end
            aktualis_sor = elem
        elseif szint == "4" then
            aktualis_sor = aktualis_sor .. " " .. elem
         end
         end
     end
     end
78. sor: 88. sor:


         if szint == "1" then
         if szint == "1" then
            -- Kinyerjük a nemzetségnevet (az első szó az 1-es után)
             local nemz = sor:match("^1%s+([^%s:]+)")
             local nemz = sor:match("^1%s+([^%s:]+)")
           
             if nemz then
             if nemz then
                 if szuro == "" or nemz == szuro then
                 if szuro == "" or nemz == szuro then
                     isVisible = true
                     isVisible = true
                     counter = counter + 1
                     counter = counter + 1
                   
                    -- FONTOS: [[:Kategória:...]] kell, hogy látható legyen a link!
                     local nemz_display = "'''''" .. nemz .. "'''''"
                     local nemz_display = "'''''" .. nemz .. "'''''"
                     local nemz_link = "[[:Kategória:" .. nemz .. "|" .. nemz_display .. "]]"
                     local nemz_link = "[[:Kategória:" .. nemz .. "|" .. nemz_display .. "]]"
                      
                      
                     -- A szinonimák az első "::" után kezdődnek
                     -- A teljes maradékot átadjuk (a nemzetségnév utáni részt)
                     local szin_adat = sor:match("::%s*(.*)$") or ""
                     local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                   
                     table.insert(rows, "|-\n| " .. counter .. "\n| " .. nemz_link .. "\n| " .. formazSzinonimak(maradek))
                     table.insert(rows, "|-\n| " .. counter .. "\n| " .. nemz_link .. "\n| " .. formazSzinonimak(szin_adat))
                 else
                 else
                     isVisible = false
                     isVisible = false
                 end
                 end
             end
             end
         elseif szint == "2" and isVisible then
         elseif szint == "2" and isVisible then
             local fajnev, maradek = sor:match("^2%s+([^2#]+)2#%s*(.*)")
             local fajnev, maradek = sor:match("^2%s+([^2#]+)2#%s*(.*)")
104. sor: 108. sor:
                 counter = counter + 1
                 counter = counter + 1
                 local tiszta_fajnev = mw.text.trim(fajnev)
                 local tiszta_fajnev = mw.text.trim(fajnev)
                local faj_link = "[[" .. tiszta_fajnev .. "|''" .. tiszta_fajnev .. "'']]"
                 table.insert(rows, "|-\n| " .. counter .. "\n| [[" .. tiszta_fajnev .. "|''" .. tiszta_fajnev .. "'']]\n| " .. formazSzinonimak(maradek))
                 table.insert(rows, "|-\n| " .. counter .. "\n| " .. faj_link .. "\n| " .. formazSzinonimak(maradek))
             end
             end
         end
         end
111. sor: 114. sor:


     if #rows == 0 then return "Nincs találat." end
     if #rows == 0 then return "Nincs találat." end
     local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonimák\n'
     local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonimák\n'
     return frame:preprocess(head .. table.concat(rows, "\n") .. "\n|}")
     return frame:preprocess(head .. table.concat(rows, "\n") .. "\n|}")

A lap 2026. január 10., 00:25-kori változata

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

local p = {}

-- Speciális formázó a taxonómiai nevekhez
local function taxonFormazo(szoveg, isGenus)
    if not szoveg or szoveg == "" then return "" end
    
    local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
    
    local s = ""
    if isGenus then
        s = "'''''" .. tiszta_szoveg .. "'''''"
    else
        s = "''" .. tiszta_szoveg .. "''"
    end
    
    local kulcsszavak = {
        "subgen%.", "subg%.", "sect%.", "subsect%.", 
        "subsp%.", "var%.", "subvar%.", "f%.", "Típusfaj:"
    }
    
    for _, kulcs in ipairs(kulcsszavak) do
        local tiszta_kulcs = kulcs:gsub("%%", "")
        s = s:gsub(kulcs, "''" .. tiszta_kulcs .. "''")
    end
    
    s = s:gsub("''''''", ""):gsub("''''", "")
    return s
end

-- Szinonimák feldolgozása (támogatja a nyers szöveget és a blokkokat is)
local function formazSzinonimak(sor)
    if not sor or sor == "" then return "" end

    local lista = {}

    -- 1. Típusfaj kinyerése (ami a :: és az 1# között van)
    local nyers_resz = sor:match("^([^%d]+)1#")
    if nyers_resz then
        local tisztitott = mw.text.trim(nyers_resz:gsub("^::%s*", ""))
        if tisztitott ~= "" then
            -- A típusfaj általában fajnév (tartalmaz szóközt), így nem lesz bold-italic
            table.insert(lista, "<li>" .. taxonFormazo(tisztitott, false) .. "</li>")
        end
    end

    -- 2. Számozott blokkok kinyerése (3-as és 4-es szint)
    local aktualis_sor = ""
    for szint, jel, tartalom in mw.ustring.gmatch(sor, "(%d)%s*([^%d%s#]+)%s*([^#]+)%s*%d#") do
        if szint == "3" or szint == "4" then
            local tiszta_jel = mw.ustring.sub(jel, 1, 1)
            local trimmed_tartalom = mw.text.trim(tartalom)
            local is_syn_genus = not trimmed_tartalom:find(" ") 
            
            local formalt_nev = taxonFormazo(trimmed_tartalom, is_syn_genus)
            local elem = tiszta_jel .. " " .. formalt_nev

            if szint == "3" then
                if aktualis_sor ~= "" then table.insert(lista, "<li>" .. aktualis_sor .. "</li>") end
                aktualis_sor = elem
            else
                aktualis_sor = aktualis_sor .. " " .. elem
            end
        end
    end

    if aktualis_sor ~= "" then
        table.insert(lista, "<li>" .. aktualis_sor .. "</li>")
    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 ""
    
    local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: Modul:CactaceaeTaxonokData nem található." end
    local nyers = dataModul.getAdatok()

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

    for sor in nyers:gmatch("[^\r\n]+") do
        local szint = sor:sub(1, 1)

        if szint == "1" then
            local nemz = sor:match("^1%s+([^%s:]+)")
            if nemz then
                if szuro == "" or nemz == szuro then
                    isVisible = true
                    counter = counter + 1
                    local nemz_display = "'''''" .. nemz .. "'''''"
                    local nemz_link = "[[:Kategória:" .. nemz .. "|" .. nemz_display .. "]]"
                    
                    -- A teljes maradékot átadjuk (a nemzetségnév utáni részt)
                    local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                    table.insert(rows, "|-\n| " .. counter .. "\n| " .. nemz_link .. "\n| " .. formazSzinonimak(maradek))
                else
                    isVisible = false
                end
            end
        elseif szint == "2" and isVisible then
            local fajnev, maradek = sor:match("^2%s+([^2#]+)2#%s*(.*)")
            if fajnev then
                counter = counter + 1
                local tiszta_fajnev = mw.text.trim(fajnev)
                table.insert(rows, "|-\n| " .. counter .. "\n| [[" .. tiszta_fajnev .. "|''" .. tiszta_fajnev .. "'']]\n| " .. formazSzinonimak(maradek))
            end
        end
    end

    if #rows == 0 then return "Nincs találat." end
    local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonimák\n'
    return frame:preprocess(head .. table.concat(rows, "\n") .. "\n|}")
end

return p