Ugrás a tartalomhoz

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

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Címke: Visszaállítva
Nincs szerkesztési összefoglaló
 
(28 közbenső módosítás ugyanattól a felhasználótól nincs mutatva)
1. sor: 1. sor:
local p = {}
local p = {}


-- Segédfüggvény a szimbólumokhoz (Unicode-biztos)
-- Speciális formázó a taxonómiai nevekhez + Linkelés
local function formazSzinonimak(szoveg)
local function taxonFormazo(szoveg, isGenus, isTypeLink)
     if not szoveg or szoveg == "" then return "" end
     if not szoveg or szoveg == "" then return "" end
     local tiszta = mw.ustring.gsub(szoveg, "[đ÷]", "")
   
     tiszta = mw.ustring.gsub(tiszta, "¤+", "")
     local tiszta_szoveg = szoveg:gsub("Type:", "Típusfaj:")
     tiszta = mw.ustring.gsub(tiszta, ">−", "")
   
     tiszta = mw.ustring.gsub(tiszta, ">≡", "")
    -- Ellenőrizzük, hogy van-e benne link jelző (@)
     tiszta = mw.ustring.gsub(tiszta, ">=", "=")
    local hasLinkMarker = tiszta_szoveg:find("@")
     tiszta = mw.ustring.gsub(tiszta, "≡≡", "|≡")
     if hasLinkMarker then
    tiszta = mw.ustring.gsub(tiszta, "==", "|=")
        tiszta_szoveg = tiszta_szoveg:gsub("@", "")
    tiszta = mw.ustring.gsub(tiszta, "−−", "|−")
     end
     tiszta = mw.ustring.gsub(tiszta, "%-%-", "|−")
 
    local megjelenitendo = tiszta_szoveg
   
    -- 1. Típusfaj linkelés
    if isTypeLink then
        local nev_resz = tiszta_szoveg:match("Típusfaj:%s*(.*)")
        if nev_resz then
            local tiszta_nev = mw.text.trim(nev_resz)
            megjelenitendo = "Típusfaj: [[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
        else
            megjelenitendo = "[[" .. tiszta_szoveg .. "|''" .. tiszta_szoveg .. "'']]"
        end
    -- 2. Jelölt szinonima linkelés (@ karakter esetén)
     elseif hasLinkMarker then
        local tiszta_nev = mw.text.trim(tiszta_szoveg)
        megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
    end
   
    local s = ""
    -- Formázás (félkövér a nemzetségeknek, ha nem típusfaj link)
     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
     local kulcsszavak = {
        "subgen%.", "subg%.", "sect%.", "subsect%.",
        "subsp%.", "var%.", "subvar%.", "f%.", "Típusfaj:"
    }
   
    for _, kulcs in ipairs(kulcsszavak) do
        local tiszta_kulcs = kulcs:gsub("%%", "")
        -- Itt ügyelünk rá, hogy a linkelt részen belül is javítsuk a dőlteket
        s = s:gsub(kulcs, "''" .. tiszta_kulcs .. "''")
     end
   
    s = s:gsub("''''''", ""):gsub("''''", "")
    return s
end
 
-- Szinonimák feldolgozása
local function formazSzinonimak(sor)
    if not sor or sor == "" then return "" end


     local lista_elemek = {}
     local lista = {}
     for resz in mw.text.gsplit(tiszta, "|", true) do
 
         local tiszta_resz = mw.text.trim(resz)
     -- 1. Típusfaj kinyerése
         if tiszta_resz ~= "" then
    local nyers_resz = sor:match("^([^%d]+)1#")
             local szavak = {}
    if nyers_resz then
            for szo in mw.ustring.gmatch(tiszta_resz, "%S+") do
         local tisztitott = mw.text.trim(nyers_resz:gsub("^::%s*", ""))
                if mw.ustring.find(szo, "[≡=−,]") or szo == "var." or szo == "subsp." or szo == "f." or szo == "Type:" then
         if tisztitott ~= "" then
                    table.insert(szavak, szo)
             table.insert(lista, "<li>" .. taxonFormazo(tisztitott, false, true) .. "</li>")
                 else
        end
                    table.insert(szavak, "''" .. szo .. "''")
    end
                 end
 
    -- 2. Számozott blokkok (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)
           
            -- Ha van @ jel, linkeljük, függetlenül attól, hogy nemzetség vagy faj
            local formalt_nev = taxonFormazo(trimmed_tartalom, not trimmed_tartalom:find(" "), 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
            table.insert(lista_elemek, "<li>" .. table.concat(szavak, " ") .. "</li>")
         end
         end
     end
     end
   
 
     if #lista_elemek > 0 then
     if aktualis_sor ~= "" then
         return '<ul style="margin-left: 1.1em; list-style-type: disc; padding: 0; margin: 0;">' .. table.concat(lista_elemek) .. "</ul>"
         table.insert(lista, "<li>" .. aktualis_sor .. "</li>")
     end
     end
     return ""
 
     return #lista > 0 and '<ul style="list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>" or ""
end
end


function p.tablazat(frame)
function p.tablazat(frame)
     local status, adatModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local args = frame:getParent().args
     if not status then return "Hiba: A 'Modul:CactaceaeTaxonokData' nem található!" end
     local szuro = args[1] and mw.text.trim(args[1]) or ""
      
      
     local nyers_adat = adatModul.getAdatok()
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: Modul:CactaceaeTaxonokData nem található." end
    local nyers = dataModul.getAdatok()


    -- 1. Keresés vezérlő (Checkboxok)
     local rows = {}
     local controls = [[
     local counter = 0
<div style="margin-bottom: 10px; padding: 8px; background: #f8f9fa; border: 1px solid #a2a9b1; border-radius: 2px; font-size: 90%;">
     local isVisible = false
     <strong>Keresés itt:</strong>
    <label style="margin-right: 15px;"><input type="checkbox" id="search-taxon" checked> Taxonnév</label>
     <label><input type="checkbox" id="search-szinonima" checked> Szinonimák</label>
</div>
]]


     -- 2. Táblázat generálása
     for sor in nyers:gmatch("[^\r\n]+") do
    local res = '{| class="wikitable sortable datatable-hook stripe hover compact" id="cactus-table" data-page-length="50" style="width:100%; font-size:90%;"\n'
        local szint = sor:sub(1, 1)
    res = res .. "! # !! Taxonnév !! Típusfaj, szinonima\n"


    local sorszam = 0
        if szint == "1" then
    for sor in mw.ustring.gmatch(nyers_adat, "[^\r\n]+") do
            local nemz = sor:match("^1%s+([^%s:]+)")
        local taxon, szinonimak = "", ""
            if nemz then
        if mw.ustring.match(sor, "") then
                if szuro == "" or nemz == szuro then
            local nemzettseg, tipus = mw.ustring.match(sor, "^ß%s*([^:]+)::%s*(.+)")
                    isVisible = true
            if nemzettseg then
                    counter = counter + 1
                taxon = "'''" .. mw.text.trim(nemzettseg):gsub("¤+", "") .. "'''"
                    local nemz_display = "'''''" .. nemz .. "'''''"
                 szinonimak = tipus
                    local nemz_link = "[[:Kategória:" .. nemz .. "|" .. nemz_display .. "]]"
                    local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                    table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | " .. nemz_link .. "\n| " .. formazSzinonimak(maradek))
                 else
                    isVisible = false
                end
             end
             end
         elseif mw.ustring.match(sor, "") then
         elseif szint == "2" and isVisible then
             local tiszta_sor = mw.ustring.gsub(sor, "^Ł%s*", "")
             local fajnev, maradek = sor:match("^2%s+([^2#]+)2#%s*(.*)")
            local t, sz = mw.ustring.match(tiszta_sor, "([^¤]+)¤¤¤(.*)")
             if fajnev then
             if t then
                 counter = counter + 1
                 taxon = "''" .. mw.text.trim(t) .. "''"
                local tiszta_fajnev = mw.text.trim(fajnev)
                szinonimak = sz
                table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | [[" .. tiszta_fajnev .. "|''" .. tiszta_fajnev .. "'']]\n| " .. formazSzinonimak(maradek))
             end
             end
        end
        if taxon ~= "" then
            sorszam = sorszam + 1
            res = res .. "|-\n| " .. sorszam .. '\n| style="white-space: nowrap;" | ' .. taxon .. "\n| " .. formazSzinonimak(szinonimak) .. "\n"
         end
         end
     end
     end
    res = res .. "|}"
    -- 3. JavaScript a szűréshez
    -- Ez a kód figyeli a checkboxokat és módosítja a DataTable keresési logikáját
    local script = [[
<script>
document.addEventListener('DOMContentLoaded', function() {
    var table = $('#cactus-table').DataTable();
   
    // Alapértelmezett keresőmező elrejtése vagy átvétele
    $('.dataTables_filter input').on('keyup', function() {
        var term = this.value;
        var searchTaxon = document.getElementById('search-taxon').checked;
        var searchSzin = document.getElementById('search-szinonima').checked;
       
        // Összes keresés törlése
        table.columns().search('');
       
        if (searchTaxon && searchSzin) {
            table.search(term).draw(); // Globális keresés
        } else if (searchTaxon) {
            table.column(1).search(term).draw(); // Csak Taxonnév (2. oszlop)
            table.column(2).search('');
        } else if (searchSzin) {
            table.column(2).search(term).draw(); // Csak Szinonima (3. oszlop)
            table.column(1).search('');
        } else {
            table.search('^$', true, false).draw(); // Semmi (üres keresés)
        }
    });
});
</script>
]]


     return frame:preprocess(controls .. res .. script)
    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
end


return p
return p

A lap jelenlegi, 2026. január 10., 00:58-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:")
    
    -- Ellenőrizzük, hogy van-e benne link jelző (@)
    local hasLinkMarker = tiszta_szoveg:find("@")
    if hasLinkMarker then
        tiszta_szoveg = tiszta_szoveg:gsub("@", "")
    end

    local megjelenitendo = tiszta_szoveg
    
    -- 1. Típusfaj linkelés
    if isTypeLink then
        local nev_resz = tiszta_szoveg:match("Típusfaj:%s*(.*)")
        if nev_resz then
            local tiszta_nev = mw.text.trim(nev_resz)
            megjelenitendo = "Típusfaj: [[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
        else
            megjelenitendo = "[[" .. tiszta_szoveg .. "|''" .. tiszta_szoveg .. "'']]"
        end
    -- 2. Jelölt szinonima linkelés (@ karakter esetén)
    elseif hasLinkMarker then
        local tiszta_nev = mw.text.trim(tiszta_szoveg)
        megjelenitendo = "[[" .. tiszta_nev .. "|''" .. tiszta_nev .. "'']]"
    end
    
    local s = ""
    -- Formázás (félkövér a nemzetségeknek, ha nem típusfaj link)
    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
    local kulcsszavak = {
        "subgen%.", "subg%.", "sect%.", "subsect%.", 
        "subsp%.", "var%.", "subvar%.", "f%.", "Típusfaj:"
    }
    
    for _, kulcs in ipairs(kulcsszavak) do
        local tiszta_kulcs = kulcs:gsub("%%", "")
        -- Itt ügyelünk rá, hogy a linkelt részen belül is javítsuk a dőlteket
        s = s:gsub(kulcs, "''" .. tiszta_kulcs .. "''")
    end
    
    s = s:gsub("''''''", ""):gsub("''''", "")
    return s
end

-- Szinonimák feldolgozása
local function formazSzinonimak(sor)
    if not sor or sor == "" then return "" end

    local lista = {}

    -- 1. Típusfaj kinyerése
    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. Számozott blokkok (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)
            
            -- Ha van @ jel, linkeljük, függetlenül attól, hogy nemzetség vagy faj
            local formalt_nev = taxonFormazo(trimmed_tartalom, not trimmed_tartalom:find(" "), 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;">' .. 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: 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 .. "]]"
                    local maradek = sor:match("^1%s+[^%s:]+%s*(.*)$") or ""
                    table.insert(rows, "|-\n| " .. counter .. "\n| style=\"white-space:nowrap\" | " .. 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| style=\"white-space:nowrap\" | [[" .. 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