Jump to content

Module:FlexGallery: Difference between revisions

From Climbopedia
No edit summary
Cleanup + sanitization based on chatgpt
Line 1: Line 1:
local p = {}
local p = {}
local width
 
local images = {}
 
local thumbnails = {}
local gallery
local gallery


-- frame.args
-- frame.args


p.hi = function(frame)
p.gallery = function(frame)
    local mwText = mw.text
   
    local width = mwText.trim(tostring(frame.args[1] or ""))
    if not mw.ustring.match(width, "^%d+px$") then
        width = "120px"
    end
    local images = {}
    local thumbnails = {}
 
     for k, v in pairs(frame.args) do
     for k, v in pairs(frame.args) do
         v = v:gsub("[\n\r\]", "")
         v = mwText.trim(tostring(v or ""))
        v = tostring(v)
         if k ~= 1 then
         if k == 1 then
             if (k % 2) == 0 then
             width = tonumber(v)
                local image = mw.ustring.match(v, "^File:[%w%s%-%._()%',]+$") or ""
        elseif (k % 2) == 0 then
                table.insert(images, image)
            table.insert(images, tostring(v))
            else
        else
                table.insert(thumbnails, tostring(v))
            table.insert(thumbnails, tostring(v))
            end
         end
         end
     end
     end
     local gallery = "<div><ul>"
     local gallery = mw.html.create("div")
     for k, v in pairs(images) do
    local ul = gallery.tag("ul")
 
     for i, images in pairs(images) do
        local caption = thumbnails[i] or ""
         local line = string.format("[[%s|thumb|none|%spx|%s]]",
         local line = string.format("[[%s|thumb|none|%spx|%s]]",
                                  v, width, thumbnails[k])
                                    image, width, caption)
         local li = mw.html.create('li')
         ul:tag("li")
        li
          :css("display", "inline-block")
            :css("display", "inline-block")
          :css("vertical-align", "top")
            :css("vertical-align", "top")
          :wikitext(frame:preprocess(line))
            :wikitext(frame:preprocess(line))
        gallery = gallery .. tostring(li) .. "\n"
     end
     end
    gallery = gallery .. "</ul></div>"
     return gallery
    -- return frame:preprocess(gallery)
     return(gallery)
end
end


return p
return p

Revision as of 04:17, 21 August 2025

Documentation for this module may be created at Module:FlexGallery/doc

local p = {}


local gallery

-- frame.args

p.gallery = function(frame)
    local mwText = mw.text
    
    local width = mwText.trim(tostring(frame.args[1] or ""))
    if not mw.ustring.match(width, "^%d+px$") then
        width = "120px"
    end
    local images = {}
    local thumbnails = {}

    for k, v in pairs(frame.args) do
        v = mwText.trim(tostring(v or ""))
        if k ~= 1 then
            if (k % 2) == 0 then
                local image = mw.ustring.match(v, "^File:[%w%s%-%._()%',]+$") or ""
                table.insert(images, image)
            else
                table.insert(thumbnails, tostring(v))
            end
        end
    end
    local gallery = mw.html.create("div")
    local ul = gallery.tag("ul")

    for i, images in pairs(images) do
        local caption = thumbnails[i] or ""
        local line = string.format("[[%s|thumb|none|%spx|%s]]",
                                    image, width, caption)
        ul:tag("li")
          :css("display", "inline-block")
          :css("vertical-align", "top")
          :wikitext(frame:preprocess(line))
     end
     return gallery
end

return p