btw this Wiki is not meant for a wider audience yet
Module:ImageTabber: Difference between revisions
Jump to navigation
Jump to search
Revert to working state before arrow styling |
(No difference)
|
Latest revision as of 01:12, 6 December 2025
This Module is used in at least Template:YYMMDD Infobox and can be invoked as needed.
local p = {}
function p.format(frame)
local imageParam = frame.args[1] or ""
local width = frame.args.width or "350px"
-- Return empty if no image provided
if imageParam == "" then
return ""
end
-- Check if multiple images (contains comma)
if not imageParam:find(",") then
-- Single image - check for and strip optional tab title prefix
local content = imageParam:match("^.-%s*:%s*(.+)$")
if content and not imageParam:match("^yt[:%-%s]") and not imageParam:match("^File:") and not imageParam:match("^{{") then
-- Has a colon AND doesn't start with content syntax, so strip the tab title
return p.processContent(content, width)
else
-- No tab title to strip, process as-is
return p.processContent(imageParam, width)
end
end
-- Multiple images - build tabber syntax
local images = {}
for item in imageParam:gmatch("[^,]+") do
table.insert(images, item:match("^%s*(.-)%s*$")) -- trim whitespace
end
local tabs = {}
for i, item in ipairs(images) do
-- Parse "tab title:content" using : as delimiter
local tabTitle, content = item:match("^(.-)%s*:%s*(.+)$")
if not tabTitle then
-- No : delimiter found, use entire item as content
content = item
tabTitle = "Tab " .. i
end
-- Trim whitespace
content = content:match("^%s*(.-)%s*$")
tabTitle = tabTitle:match("^%s*(.-)%s*$")
-- Process the content
content = p.processContent(content, width)
-- Build tab entry
table.insert(tabs, "|-|" .. tabTitle .. "=\n" .. content)
end
-- Generate tabber content
local tabberContent = table.concat(tabs, "\n")
-- Use frame:extensionTag to properly invoke the tabber extension
local tabberOutput = frame:extensionTag("tabber", tabberContent)
return tabberOutput
end
function p.processContent(content, width)
-- Trim whitespace
content = content:match("^%s*(.-)%s*$")
-- Extract numeric width value from "350px" format
local widthNum = width:match("(%d+)")
if not widthNum then
widthNum = "350"
end
-- Check for shorthand YouTube syntax: yt:VIDEO_ID or yt-VIDEO_ID
local videoId = content:match("^yt:(.+)$") or content:match("^yt%-(.+)$")
if videoId then
videoId = videoId:match("^%s*(.-)%s*$") -- trim
return "{{#ev:youtube|" .. videoId .. "|" .. widthNum .. "}}"
end
-- Check for YouTube embed that needs width added/replaced
if content:match("{{#ev:youtube") then
-- Check if it already has a width parameter
if content:match("{{#ev:youtube|[^}]+|%d+") then
-- Has width, replace it
content = content:gsub("({{#ev:youtube|[^|]+)|%d+", "%1|" .. widthNum)
else
-- No width, add it before the closing braces
content = content:gsub("({{#ev:youtube|[^}]+)(}})", "%1|" .. widthNum .. "%2")
end
return content
end
-- Check if content is a parser function/extension or HTML (not a plain filename)
if content:find("<") or content:find("#ev:") or content:find("#tag:") or content:find("UNIQ") or content:find("{{") then
-- It's special content, return as-is
return content
else
-- Plain filename, wrap in File syntax with frameless to remove spacing
return "<div style='line-height: 0;'>[[File:" .. content .. "|frameless|" .. width .. "]]</div>"
end
end
return p