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ó
(20 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ólumok és HTML lista kezeléséhez
-- Szupergyors tisztító: csak sima string műveleteket használ
local function formazSzinonimak(szoveg)
local function gyorsTisztitas(szoveg)
     if not szoveg or szoveg == "" then return "" end
     if not szoveg or szoveg == "" then return "" end
    -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
    -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
    local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
    tiszta = tiszta:gsub(">%-", "−"):gsub(">≡", "≡"):gsub(">=", "=")
    return tiszta
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;'>Hiba: Adj meg egy nemzetséget!</div>"
    end


    -- 1. Felesleges karakterek törlése
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local tiszta = szoveg:gsub("[đ÷]", ""):gsub("¤+", "")
    if not status then return "Hiba: Adatmodul hiányzik." end
    local nyers = dataModul.getAdatok()


     -- 2. Átalakítások jelölőkké (ideiglenes elválasztó karaktert használunk: | )
     local rows = {}
    tiszta = tiszta:gsub("≡≡", ", ≡")
     local counter = 0
    tiszta = tiszta:gsub("==", "|=")
     local isVisible = false
    tiszta = tiszta:gsub("−−", "|−")
    tiszta = tiszta:gsub("%-%-", "|−")
     tiszta = tiszta:gsub(">≡", ", >≡")
     tiszta = tiszta:gsub(">−", ", >−")
      
      
     -- 3. Darabolás az elválasztó mentén és HTML lista építése
     -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
    local res = ""
     for sor in nyers:gmatch("[^\r\n]+") do
    local elso = true
         local b1 = sor:byte(1)
   
       
    -- A string elosztása a '|' mentén (ahol új listapontot kértél)
        -- ß karakter (195 159)
     for resz in mw.text.gsplit(tiszta, "|", true) do
         if b1 == 195 and sor:byte(2) == 159 then
         local tiszta_resz = mw.text.trim(resz)
             if sor:find(szuro, 1, true) then
         if tiszta_resz ~= "" then
                local nemz = sor:match("ß%s*([^:]+)")
             -- Botanikai nevek dőltetése a részleten belül
                 if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
            local szavak = {}
                    isVisible = true
            for szo in tiszta_resz:gmatch("%S+") do
                    counter = counter + 1
                 if szo:match("[≡=>−,]") or szo == "var." or szo == "subsp." or szo == "f." or szo == "Type:" then
                    local tip = sor:match("::%s*(.+)") or ""
                     table.insert(szavak, szo)
                     table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                else
                 else isVisible = false end
                    table.insert(szavak, "''" .. szo .. "''")
             else isVisible = false end
                 end
             end
            local formazott_resz = table.concat(szavak, " "):gsub("^,%s*", "")
              
              
            if elso then
        -- Ł karakter (197 129)
                res = formazott_resz
        elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
                elso = false
             local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
             else
            if t then
                -- Ha már a második elemnél járunk, listát kezdünk/folytatunk
                counter = counter + 1
                if not res:find("<ul") then
                table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
                    res = res .. '<ul style="margin-left: 1.5em; list-style-type: disc;">'
                end
                res = res .. "<li>" .. formazott_resz .. "</li>"
             end
             end
         end
         end
        if counter >= 1000 then break end
     end
     end
   
    if res:find("<ul") then res = res .. "</ul>" end
   
    return res
end
function p.tablazat(frame)
    local status, adatModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: A 'Modul:CactaceaeTaxonokData' nem található!" end
   
    local nyers_adat = adatModul.getAdatok()


     local res = '{| class="wikitable sortable datatable-hook stripe hover compact" data-page-length="50" style="width:100%; font-size:90%;"\n'
     if #rows == 0 then return "Nincs találat: " .. szuro end
    res = res .. "! # !! Taxonnév !! Típusfaj, szinonima\n"


     local sorszam = 0
    -- TÁBLÁZAT ÖSSZEÁLLÍTÁSA (Csak itt formázunk, hogy spóroljunk a CPU-val)
     for sor in nyers_adat:gmatch("[^\r\n]+") do
     local finalRows = {}
        local taxon = ""
     for i, data in ipairs(rows) do
         local szinonimak = ""
         local szinonimak = ""
 
         if data[3] ~= "" then
         if sor:match("") then
            local t = gyorsTisztitas(data[3])
             local nemzettseg, tipus = sor:match("^ß%s*([^:]+)::%s*(.+)")
             local lista = {}
            if nemzettseg then
            -- Egyszerű darabolás
                taxon = "'''" .. mw.text.trim(nemzettseg) .. "'''"
            for r in t:gmatch("[^|≡=−]+") do
                 szinonimak = tipus
                local tr = mw.text.trim(r)
                if tr ~= "" and tr ~= "''" then
                    table.insert(lista, "<li>''" .. tr .. "''</li>")
                 end
             end
             end
        elseif sor:match("^Ł") then
             if #lista > 0 then
            local tiszta = sor:gsub("^Ł%s*", "")
                 szinonimak = '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
            local t, sz = tiszta:match("([^¤]+)¤¤¤(.*)")
             if t then
                 taxon = "''" .. mw.text.trim(t) .. "''"
                szinonimak = sz
             end
             end
         end
         end
 
         table.insert(finalRows, "|-\n| " .. data[1] .. "\n| " .. data[2] .. "\n| " .. szinonimak)
         if taxon ~= "" then
            sorszam = sorszam + 1
            res = res .. "|-\n"
            res = res .. "| " .. sorszam .. "\n"
            res = res .. '| style="white-space: nowrap;" | ' .. taxon .. "\n"
            -- Itt hívjuk meg a formázót
            res = res .. "| " .. formazSzinonimak(szinonimak) .. "\n"
        end
     end
     end


     res = res .. "|}"
     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(finalRows, "\n") .. "\n|}")
     return frame:preprocess(res)
end
end


return p
return p

A lap 2026. január 7., 10:36-kori változata

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

local p = {}

-- Szupergyors tisztító: csak sima string műveleteket használ
local function gyorsTisztitas(szoveg)
    if not szoveg or szoveg == "" then return "" end
    -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
    -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
    local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
    tiszta = tiszta:gsub(">%-", "−"):gsub(">≡", "≡"):gsub(">=", "=")
    return tiszta
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;'>Hiba: Adj meg egy nemzetséget!</div>"
    end

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

    local rows = {}
    local counter = 0
    local isVisible = false
    
    -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
    for sor in nyers:gmatch("[^\r\n]+") do
        local b1 = sor:byte(1)
        
        -- ß karakter (195 159)
        if b1 == 195 and sor:byte(2) == 159 then
            if sor:find(szuro, 1, true) then
                local nemz = sor:match("ß%s*([^:]+)")
                if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
                    isVisible = true
                    counter = counter + 1
                    local tip = sor:match("::%s*(.+)") or ""
                    table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                else isVisible = false end
            else isVisible = false end
            
        -- Ł karakter (197 129)
        elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
            local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
            if t then
                counter = counter + 1
                table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
            end
        end
        if counter >= 1000 then break end
    end

    if #rows == 0 then return "Nincs találat: " .. szuro end

    -- TÁBLÁZAT ÖSSZEÁLLÍTÁSA (Csak itt formázunk, hogy spóroljunk a CPU-val)
    local finalRows = {}
    for i, data in ipairs(rows) do
        local szinonimak = ""
        if data[3] ~= "" then
            local t = gyorsTisztitas(data[3])
            local lista = {}
            -- Egyszerű darabolás
            for r in t:gmatch("[^|≡=−]+") do
                local tr = mw.text.trim(r)
                if tr ~= "" and tr ~= "''" then
                    table.insert(lista, "<li>''" .. tr .. "''</li>")
                end
            end
            if #lista > 0 then
                szinonimak = '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
            end
        end
        table.insert(finalRows, "|-\n| " .. data[1] .. "\n| " .. data[2] .. "\n| " .. szinonimak)
    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(finalRows, "\n") .. "\n|}")
end

return p