모듈:ImageSwitch

모니터링 (토론 | 기여)님의 2025년 4월 8일 (화) 09:06 판 (새 문서: local p = {} function p.main(frame) local args = frame:getParent().args local light = args[1] or '' local dark = args[2] or '' local width = args[3] or '' local alt = args['alt'] or '' local link = args['link'] or '' local classes = args['class'] or '' local style = args['style'] or '' -- 파일 경로 가져오기 local lighturl = frame:callParserFunction('filepath', light) local darkurl = '' if dark and dark ~= '' then...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

이 모듈에 대한 설명문서는 모듈:ImageSwitch/설명문서에서 만들 수 있습니다

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local light = args[1] or ''
    local dark = args[2] or ''
    local width = args[3] or ''
    local alt = args['alt'] or ''
    local link = args['link'] or ''
    local classes = args['class'] or ''
    local style = args['style'] or ''

    -- 파일 경로 가져오기
    local lighturl = frame:callParserFunction('filepath', light)
    local darkurl = ''
    if dark and dark ~= '' then
        darkurl = frame:callParserFunction('filepath', dark)
    end

    -- 링크 처리
    local imgTag = '<img src="' .. lighturl .. '"'
    if width ~= '' then imgTag = imgTag .. ' width="' .. width .. '"' end
    if alt ~= '' then imgTag = imgTag .. ' alt="' .. alt .. '"' end
    if classes ~= '' then imgTag = imgTag .. ' class="' .. classes .. '"' end
    if style ~= '' then imgTag = imgTag .. ' style="' .. style .. '"' end
    imgTag = imgTag .. '>'

    if link ~= '' then
        imgTag = '<a href="/wiki/' .. mw.uri.encode(link, "WIKI") .. '">' .. imgTag .. '</a>'
    end

    -- HTML 출력
    local html = '<div class="image-switch-wrapper"><picture>'
    if darkurl ~= '' then
        html = html .. '<source srcset="' .. darkurl .. '" media="(prefers-color-scheme: dark)">'
    end
    html = html .. imgTag
    html = html .. '</picture></div>'

    return html
end

return p