모듈:ImageSwitch: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
 
(같은 사용자의 중간 판 7개는 보이지 않습니다)
1번째 줄: 1번째 줄:
local p = {}
local p = {}
function escape_html(text)
    return text
        :gsub("&", "&")
        :gsub("<", "&lt;")
        :gsub(">", "&gt;")
        :gsub("\"", "&quot;")
        :gsub("'", "&#39;")
end


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local light = args[1] or ''
     local light = args[1] or ''
    local dark = args[2] or ''
    local width = escape_html(args[3] or '')
    local alt = escape_html(args['alt'] or '')
    local link = escape_html(args['link'] or '')
    local class = escape_html(args['class'] or '')
    local style = escape_html(args['style'] or '')
     if light == '' then
     if light == '' then
         return '<strong class="error">라이트모드 이미지가 필요합니다.</strong>'
         return '<strong class="error">라이트모드 이미지가 필요합니다.</strong>'
     end
     end


     local lighturl = escape_html(frame:callParserFunction('filepath', light))
     local dark = args[2] or ''
    local darkurl = ''
 
    if dark and mw.text.trim(dark) ~= '' then
    local function wrap_img(img_code, class)
        darkurl = escape_html(frame:callParserFunction('filepath', dark))
        return '<span class="' .. class .. '">' .. img_code .. '</span>'
     end
     end


     local html = {}
     local html = {}
     table.insert(html, '<div class="image-switch-wrapper">')
     table.insert(html, '<div class="image-switch-wrapper">')
 
     table.insert(html, wrap_img(light, 'light-mode-img'))
     -- 라이트모드 이미지
     if dark ~= '' then
    local img1 = '<img src="' .. lighturl .. '" class="light-mode-img'
         table.insert(html, wrap_img(dark, 'dark-mode-img'))
     if class ~= '' then img1 = img1 .. ' ' .. class end
    img1 = img1 .. '"'
    if width ~= '' then img1 = img1 .. ' width="' .. width .. '"' end
    if alt ~= '' then img1 = img1 .. ' alt="' .. alt .. '"' end
    if style ~= '' then img1 = img1 .. ' style="' .. style .. '"' end
    img1 = img1 .. '>'
 
    -- 다크모드 이미지
    local img2 = ''
    if darkurl ~= '' then
        img2 = '<img src="' .. darkurl .. '" class="dark-mode-img'
        if class ~= '' then img2 = img2 .. ' ' .. class end
        img2 = img2 .. '"'
        if width ~= '' then img2 = img2 .. ' width="' .. width .. '"' end
        if alt ~= '' then img2 = img2 .. ' alt="' .. alt .. '"' end
        if style ~= '' then img2 = img2 .. ' style="' .. style .. '"' end
        img2 = img2 .. '>'
    end
 
    if link ~= '' then
         table.insert(html, '<a href="/wiki/' .. link .. '">' .. img1 .. img2 .. '</a>')
    else
        table.insert(html, img1 .. img2)
     end
     end
    table.insert(html, '</div>')


    table.insert(html, '</div>')
     return table.concat(html)
     return table.concat(html)
end
end


return p
return p

2025년 4월 17일 (목) 14:54 기준 최신판

이 모듈에 대한 설명문서는 모듈: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 wrap_img(img_code, class)
        return '<span class="' .. class .. '">' .. img_code .. '</span>'
    end

    local html = {}
    table.insert(html, '<div class="image-switch-wrapper">')
    table.insert(html, wrap_img(light, 'light-mode-img'))
    if dark ~= '' then
        table.insert(html, wrap_img(dark, 'dark-mode-img'))
    end
    table.insert(html, '</div>')

    return table.concat(html)
end

return p