이 모듈에 대한 설명문서는 모듈:ImageSwitch/설명문서에서 만들 수 있습니다
local p = {}
function p.main(frame)
local args = frame:getParent().args
local light = args[1] or ''
if light == '' then
return '<strong class="error">라이트모드 이미지가 필요합니다.</strong>'
end
local dark = args[2] or ''
local function inject_class(wikitext, class_name)
if wikitext:find('|%s*class%s*=') then
return wikitext:gsub('|%s*class%s*=%s*([^|]*)', function(existing)
return '|class=' .. existing .. ' ' .. class_name
end)
else
return wikitext .. '|class=' .. class_name
end
end
local light_img = inject_class(light, 'light-mode-img')
local dark_img = dark ~= '' and inject_class(dark, 'dark-mode-img') or ''
local html = {}
table.insert(html, '<span class="image-switch-wrapper">')
table.insert(html, light_img)
if dark_img ~= '' then
table.insert(html, dark_img)
end
table.insert(html, '</span>')
return table.concat(html)
end
return p