본문으로 이동

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

Kawa
잔글편집 요약 없음
잔글편집 요약 없음
8번째 줄: 8번째 줄:


local lines = (args['items'] or ''):gmatch("([^\n]+)")
local lines = (args['items'] or ''):gmatch("([^\n]+)")
local items = {{}}
local items = {}


for line in lines do
for line in lines do
line = mw.text.trim(line)
line = mw.text.trim(line)
 
if line == '' then
if line ~= '' then
table.insert(items, {})
else
local key, value = line:match('^([^=]+)=(.+)$')
local key, value = line:match('^([^=]+)=(.+)$')
if key and value then
if key and value then
23번째 줄: 21번째 줄:
items[#items][key] = value
items[#items][key] = value
end
end
else
table.insert(items, {url = line})
end
end
end
end
37번째 줄: 37번째 줄:
title = url:match("^%a+://([^/:]+)") or url
title = url:match("^%a+://([^/:]+)") or url
end
end
-- local anchor = mw.html.create('a')
-- :addClass('kawa-deck-item')
-- anchor:attr('href', url)
-- if url:match('^(https?:)?//') then
-- anchor:attr('target', '_blank')
-- anchor:attr('rel', 'noopener noreferrer')
-- end


local iconSpan = mw.html.create('span')
local iconSpan = mw.html.create('span')
:addClass('kawa-deck-icon')
:addClass('kawa-deck-icon')
:attr('aria-hidden', 'true')
:attr('aria-hidden', 'true')
if icon:match('^(https?:)?//') then
iconSpan:tag('img'):attr('src', icon):attr('alt', '')
else
iconSpan:wikitext(icon)
end


local titleSpan = mw.html.create('span')
local titleSpan = mw.html.create('span')
64번째 줄: 49번째 줄:
contentSpan:node(titleSpan)
contentSpan:node(titleSpan)


html = html .. '[' .. url .. ' ' .. tostring(iconSpan) .. tostring(contentSpan) .. ']'
html = html .. '[' .. url .. ' ' .. icon .. tostring(contentSpan) .. ']'
end
end



2026년 5월 26일 (화) 20:17 판

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

local p = {}

function p.render(f)
    local args = f:getParent().args
    if args['items'] == nil then
        args = f.args
    end

	local lines = (args['items'] or ''):gmatch("([^\n]+)")
	local items = {}

	for line in lines do
		line = mw.text.trim(line)
		
		if line ~= '' then
			local key, value = line:match('^([^=]+)=(.+)$')
			if key and value then
				key = mw.text.trim(key):lower()
				value = mw.text.trim(value)
				if key ~= '' then
					items[#items][key] = value
				end
			else
				table.insert(items, {url = line})
			end
		end
	end

	-- HTML
	local html = ''
	
	for _, item in ipairs(items) do
		local url = item.url or '#'
		local icon = item.icon or '🔗'
		local title = mw.text.trim(item.title or '')
		if title == '' then
			title = url:match("^%a+://([^/:]+)") or url
		end

		local iconSpan = mw.html.create('span')
			:addClass('kawa-deck-icon')
			:attr('aria-hidden', 'true')

		local titleSpan = mw.html.create('span')
			:addClass('kawa-deck-title')
			:wikitext(title)
		local contentSpan = mw.html.create('span')
			:addClass('kawa-deck-content')
		contentSpan:node(titleSpan)

		html = html .. '[' .. url .. ' ' .. icon .. tostring(contentSpan) .. ']'
	end

	return f:preprocess('<div class="kawa-deck-grid">' .. html .. '</div>')
end

return p