편집 요약 없음 |
편집 요약 없음 |
||
1번째 줄: | 1번째 줄: | ||
local p = {} | local p = {} | ||
local function escape_html(text) | local function escape_html(text) | ||
return text | return text | ||
14번째 줄: | 13번째 줄: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local light = args[1] or '' | local light = args[1] or '' | ||
if light == '' then | if light == '' then | ||
20번째 줄: | 18번째 줄: | ||
end | end | ||
local dark = args[2] or '' | local dark = args[2] or '' | ||
local width = escape_html(args[3] or '') | local width = escape_html(args[3] or '') | ||
local alt = escape_html(args['alt'] or '') | local alt = escape_html(args['alt'] or '') | ||
local raw_link = args['link'] | local raw_link = args['link'] | ||
29번째 줄: | 25번째 줄: | ||
local style = escape_html(args['style'] or '') | local style = escape_html(args['style'] or '') | ||
local lighturl = escape_html(frame:callParserFunction('filepath', light)) | local lighturl = escape_html(frame:callParserFunction('filepath', light)) | ||
local darkurl = | local darkurl = dark ~= '' and escape_html(frame:callParserFunction('filepath', dark)) or '' | ||
-- 링크 | -- 기본 링크 설정 | ||
local link = nil | local link = nil | ||
if raw_link ~= nil then | if raw_link ~= nil then | ||
42번째 줄: | 34번째 줄: | ||
link = '/wiki/index.php/' .. mw.uri.encode(raw_link, 'WIKI') | link = '/wiki/index.php/' .. mw.uri.encode(raw_link, 'WIKI') | ||
else | else | ||
link = '' | link = '' | ||
end | end | ||
else | else | ||
48번째 줄: | 40번째 줄: | ||
end | end | ||
local function make_img(src, img_class) | local function make_img(src, img_class) | ||
local tag = '<img src="' .. src .. '" class="' .. img_class | local tag = '<img src="' .. src .. '" class="' .. img_class | ||
63번째 줄: | 54번째 줄: | ||
local dark_img = darkurl ~= '' and make_img(darkurl, 'dark-mode-img') or '' | local dark_img = darkurl ~= '' and make_img(darkurl, 'dark-mode-img') or '' | ||
local html = {} | local html = {} | ||
table.insert(html, '<div class="image-switch-wrapper">') | table.insert(html, '<div class="image-switch-wrapper">') | ||
if link ~= '' then | if link ~= '' then | ||
table.insert(html, '<a href="' .. link .. '">' .. light_img .. dark_img .. '</a>') | table.insert(html, '<a href="' .. link .. '" class="auto-image-link" data-light="' .. light .. '" data-dark="' .. dark .. '">' .. light_img .. dark_img .. '</a>') | ||
else | else | ||
table.insert(html, light_img .. dark_img) | table.insert(html, light_img .. dark_img) |
2025년 4월 8일 (화) 10:35 판
이 모듈에 대한 설명문서는 모듈:ImageSwitch/설명문서에서 만들 수 있습니다
local p = {}
local function escape_html(text)
return text
:gsub("&", "&")
:gsub("<", "<")
:gsub(">", ">")
:gsub("\"", """)
:gsub("'", "'")
end
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 width = escape_html(args[3] or '')
local alt = escape_html(args['alt'] or '')
local raw_link = args['link']
local class = escape_html(args['class'] or '')
local style = escape_html(args['style'] or '')
local lighturl = escape_html(frame:callParserFunction('filepath', light))
local darkurl = dark ~= '' and escape_html(frame:callParserFunction('filepath', dark)) or ''
-- 기본 링크 설정
local link = nil
if raw_link ~= nil then
if raw_link ~= '' then
link = '/wiki/index.php/' .. mw.uri.encode(raw_link, 'WIKI')
else
link = ''
end
else
link = '/wiki/index.php/파일:' .. mw.uri.encode(light, 'WIKI')
end
local function make_img(src, img_class)
local tag = '<img src="' .. src .. '" class="' .. img_class
if class ~= '' then tag = tag .. ' ' .. class end
tag = tag .. '"'
if width ~= '' then tag = tag .. ' width="' .. width .. '"' end
if alt ~= '' then tag = tag .. ' alt="' .. alt .. '"' end
if style ~= '' then tag = tag .. ' style="' .. style .. '"' end
tag = tag .. '>'
return tag
end
local light_img = make_img(lighturl, 'light-mode-img')
local dark_img = darkurl ~= '' and make_img(darkurl, 'dark-mode-img') or ''
local html = {}
table.insert(html, '<div class="image-switch-wrapper">')
if link ~= '' then
table.insert(html, '<a href="' .. link .. '" class="auto-image-link" data-light="' .. light .. '" data-dark="' .. dark .. '">' .. light_img .. dark_img .. '</a>')
else
table.insert(html, light_img .. dark_img)
end
table.insert(html, '</div>')
return table.concat(html)
end
return p