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ó
7. sor: 7. sor:
     local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
     local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
      
      
     -- Mindenféle idézőjel és link jelző eltávolítása a tiszta névhez
     -- Sallangok eltávolítása a tiszta névhez
     local tiszta_nev = tiszta_szoveg:gsub("['\"'\"„”@?]", "")
     local tiszta_nev = tiszta_szoveg:gsub("['\"'\"„”@?]", "")
     tiszta_nev = mw.text.trim(tiszta_nev)
     tiszta_nev = mw.text.trim(tiszta_nev)


     -- Link jelző (@) keresése
     -- Link jelző (@) kezelése
     local hasLinkMarker = tiszta_szoveg:find("@")
     local hasLinkMarker = tiszta_szoveg:find("@")
     local megjelenitendo = tiszta_szoveg:gsub("@", ""):gsub("'", "") -- Idézőjelek levetése
     local megjelenitendo = tiszta_szoveg:gsub("@", ""):gsub("'", "")


     -- 1. Típusfaj linkelés
     -- 1. Típusfaj linkelés
24. sor: 24. sor:
             megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
             megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
         end
         end
    -- 2. Jelölt szinonima linkelés (@)
     elseif hasLinkMarker then
     elseif hasLinkMarker then
         megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
         megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
30. sor: 29. sor:
      
      
     local s = ""
     local s = ""
     -- HA nemzetség (isGenus) ÉS nem linkelt, akkor félkövér-dőlt
     -- HA nemzetség-szintű (isGenus) ÉS nem linkelt, akkor félkövér-dőlt
     if isGenus and not isTypeLink and not hasLinkMarker then
     if isGenus and not isTypeLink and not hasLinkMarker then
         s = "'''''" .. megjelenitendo .. "'''''"
         s = "'''''" .. megjelenitendo .. "'''''"
39. sor: 38. sor:
     end
     end
      
      
     -- Álló betűs kulcsszavak
     -- Álló betűs kulcsszavak (subsp. és var. marad álló, de dőlt környezetben)
    -- A subg., sect. stb. kulcsszavaknál is biztosítjuk az álló betűt a vastag-dőltben
     local kulcsszavak = {"subgen%.", "subg%.", "sect%.", "subsect%.", "subsp%.", "var%.", "subvar%.", "f%.", "Típusfaj:"}
     local kulcsszavak = {"subgen%.", "subg%.", "sect%.", "subsect%.", "subsp%.", "var%.", "subvar%.", "f%.", "Típusfaj:"}
     for _, kulcs in ipairs(kulcsszavak) do
     for _, kulcs in ipairs(kulcsszavak) do
         local tiszta_kulcs = kulcs:gsub("%%", "")
         local tiszta_kulcs = kulcs:gsub("%%", "")
        -- Kicseréljük álló betűsre (kivesszük a dőlt/vastag hatása alól)
         s = s:gsub(kulcs, "''" .. tiszta_kulcs .. "''")
         s = s:gsub(kulcs, "''" .. tiszta_kulcs .. "''")
     end
     end
      
      
     return s:gsub("''''''", ""):gsub("''''", "")
     -- Tisztítás a felesleges markup-tól
    s = s:gsub("''''''", ""):gsub("''''", "")
    return s
end
end


local function formazSzinonimak(sor)
-- Szinonimák feldolgozása (szint-függő nemzetség-logikával)
local function formazSzinonimak(sor, isParentGenus)
     if not sor or sor == "" then return "" end
     if not sor or sor == "" then return "" end
     local lista = {}
     local lista = {}
69. sor: 73. sor:
             local trimmed_tartalom = mw.text.trim(tartalom)
             local trimmed_tartalom = mw.text.trim(tartalom)
              
              
             -- Szigorú nemzetség detektálás: szóköz nélkül
             -- NEMZETSÉG-SZINTŰ FORMÁZÁS LOGIKA:
             -- Eltávolítjuk a sallangokat a teszt idejére
            -- 1. Ha az 1-es sorban vagyunk (isParentGenus)
             local teszt_nev = trimmed_tartalom:gsub("['\"'\"„”@?]", "")
            -- 2. VAGY ha nincs szóköz (pl. Tunilla)
             teszt_nev = mw.text.trim(teszt_nev)
             -- 3. VAGY ha tartalmazza a subg./sect./subsect. kulcsszavakat
             local is_syn_genus = not teszt_nev:find(" ")  
             local subGenusKeywords = {"subgen%.", "subg%.", "sect%.", "subsect%."}
             local containsSubGenus = false
            for _, k in ipairs(subGenusKeywords) do
                if trimmed_tartalom:find(k) then containsSubGenus = true break end
            end
           
             local is_syn_genus = isParentGenus or (not trimmed_tartalom:gsub("@", ""):find(" ")) or containsSubGenus
              
              
             local formalt_nev = taxonFormazo(trimmed_tartalom, is_syn_genus, false)
             local formalt_nev = taxonFormazo(trimmed_tartalom, is_syn_genus, false)
108. sor: 118. sor:
                 local nemz_link = "[[:Kategória:" .. nemz .. "|'''''" .. nemz .. "''''']]"
                 local nemz_link = "[[:Kategória:" .. nemz .. "|'''''" .. nemz .. "''''']]"
                 local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                 local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                 table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | " .. nemz_link .. "\n| " .. formazSzinonimak(maradek))
                -- Itt átadjuk, hogy ez egy 1-es szintű sor (true)
                 table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | " .. nemz_link .. "\n| " .. formazSzinonimak(maradek, true))
             end
             end
         elseif szint == "2" and isVisible then
         elseif szint == "2" and isVisible then
115. sor: 126. sor:
                 counter = counter + 1
                 counter = counter + 1
                 local tiszta = mw.text.trim(fajnev)
                 local tiszta = mw.text.trim(fajnev)
                 table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | [[" .. tiszta .. "|''" .. tiszta .. "'']]\n| " .. formazSzinonimak(maradek))
                -- Itt átadjuk, hogy ez egy 2-es szintű sor (false)
                 table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | [[" .. tiszta .. "|''" .. tiszta .. "'']]\n| " .. formazSzinonimak(maradek, false))
             end
             end
         end
         end

A lap 2026. január 10., 08:01-kori változata

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

local p = {}

-- Speciális formázó a taxonómiai nevekhez + Linkelés
local function taxonFormazo(szoveg, isGenus, isTypeLink)
    if not szoveg or szoveg == "" then return "" end
    
    local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
    
    -- Sallangok eltávolítása a tiszta névhez
    local tiszta_nev = tiszta_szoveg:gsub("['\"'\"„”@?]", "")
    tiszta_nev = mw.text.trim(tiszta_nev)

    -- Link jelző (@) kezelése
    local hasLinkMarker = tiszta_szoveg:find("@")
    local megjelenitendo = tiszta_szoveg:gsub("@", ""):gsub("'", "")

    -- 1. Típusfaj linkelés
    if isTypeLink then
        local nev_resz = tiszta_szoveg:match("Típusfaj:%s*(.*)")
        if nev_resz then
            local tiszta_t_nev = mw.text.trim(nev_resz:gsub("['\"'\"„”]", ""))
            megjelenitendo = "Típusfaj: [[" .. tiszta_t_nev .. "|''" .. tiszta_t_nev .. "'']]"
        else
            megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
        end
    elseif hasLinkMarker then
        megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
    end
    
    local s = ""
    -- HA nemzetség-szintű (isGenus) ÉS nem linkelt, akkor félkövér-dőlt
    if isGenus and not isTypeLink and not hasLinkMarker then
        s = "'''''" .. megjelenitendo .. "'''''"
    elseif not isTypeLink and not hasLinkMarker then
        s = "''" .. megjelenitendo .. "''"
    else
        s = megjelenitendo
    end
    
    -- Álló betűs kulcsszavak (subsp. és var. marad álló, de dőlt környezetben)
    -- A subg., sect. stb. kulcsszavaknál is biztosítjuk az álló betűt a vastag-dőltben
    local kulcsszavak = {"subgen%.", "subg%.", "sect%.", "subsect%.", "subsp%.", "var%.", "subvar%.", "f%.", "Típusfaj:"}
    for _, kulcs in ipairs(kulcsszavak) do
        local tiszta_kulcs = kulcs:gsub("%%", "")
        -- Kicseréljük álló betűsre (kivesszük a dőlt/vastag hatása alól)
        s = s:gsub(kulcs, "''" .. tiszta_kulcs .. "''")
    end
    
    -- Tisztítás a felesleges markup-tól
    s = s:gsub("''''''", ""):gsub("''''", "")
    return s
end

-- Szinonimák feldolgozása (szint-függő nemzetség-logikával)
local function formazSzinonimak(sor, isParentGenus)
    if not sor or sor == "" then return "" end
    local lista = {}

    -- 1. Típusfaj
    local nyers_resz = sor:match("^([^%d]+)1#")
    if nyers_resz then
        local tisztitott = mw.text.trim(nyers_resz:gsub("^::%s*", ""))
        if tisztitott ~= "" then
            table.insert(lista, "<li>" .. taxonFormazo(tisztitott, false, true) .. "</li>")
        end
    end

    -- 2. Szinonimák
    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)
            
            -- NEMZETSÉG-SZINTŰ FORMÁZÁS LOGIKA:
            -- 1. Ha az 1-es sorban vagyunk (isParentGenus)
            -- 2. VAGY ha nincs szóköz (pl. Tunilla)
            -- 3. VAGY ha tartalmazza a subg./sect./subsect. kulcsszavakat
            local subGenusKeywords = {"subgen%.", "subg%.", "sect%.", "subsect%."}
            local containsSubGenus = false
            for _, k in ipairs(subGenusKeywords) do
                if trimmed_tartalom:find(k) then containsSubGenus = true break end
            end
            
            local is_syn_genus = isParentGenus or (not trimmed_tartalom:gsub("@", ""):find(" ")) or containsSubGenus
            
            local formalt_nev = taxonFormazo(trimmed_tartalom, is_syn_genus, false)
            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
    return #lista > 0 and '<ul style="list-style-type:disc; padding:0; margin:0 0 0 1.5em;">' .. table.concat(lista) .. "</ul>" or ""
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: Adatmodul nem található." end
    local nyers = dataModul.getAdatok()

    local rows, counter, isVisible = {}, 0, 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:]+)")
            isVisible = (szuro == "" or nemz == szuro)
            if nemz and isVisible then
                counter = counter + 1
                local nemz_link = "[[:Kategória:" .. nemz .. "|'''''" .. nemz .. "''''']]"
                local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                -- Itt átadjuk, hogy ez egy 1-es szintű sor (true)
                table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | " .. nemz_link .. "\n| " .. formazSzinonimak(maradek, true))
            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 = mw.text.trim(fajnev)
                -- Itt átadjuk, hogy ez egy 2-es szintű sor (false)
                table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | [[" .. tiszta .. "|''" .. tiszta .. "'']]\n| " .. formazSzinonimak(maradek, false))
            end
        end
    end
    return frame:preprocess('{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonimák\n' .. table.concat(rows, "\n") .. "\n|}")
end

return p