본문으로 이동

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

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


local lines = mw.text.gsplit(args.items or '', '\n')
return items
local items = {}


for line in lines do
-- local lines = mw.text.gsplit(args.items or '', '\n')
line = mw.text.trim(line)
-- local items = {}


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


-- HTML
-- if line == '' then
local nav = mw.html.create('nav')
-- table.insert(items, {})
:addClass('kawa-deck-grid')
-- else
-- local key, value = line:gmatch('([^=]+)=([^=]+)')
-- if key and value then
-- key = mw.text.trim(key):lower()
-- value = mw.text.trim(value)
-- if key ~= '' then
-- items[#items][key] = value
-- end
-- end
-- end
-- end


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


local anchor = mw.html.create('a')
-- for _, item in ipairs(items) do
:addClass('kawa-deck-item')
-- 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


anchor:attr('href', url)
-- local anchor = mw.html.create('a')
if url:match('^(https?:)?//') then
-- :addClass('kawa-deck-item')
anchor:attr('target', '_blank')
anchor:attr('rel', 'noopener noreferrer')
end


local iconSpan = mw.html.create('span')
-- anchor:attr('href', url)
:addClass('kawa-deck-icon')
-- if url:match('^(https?:)?//') then
:attr('aria-hidden', 'true')
-- anchor:attr('target', '_blank')
-- anchor:attr('rel', 'noopener noreferrer')
-- end


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


local titleSpan = mw.html.create('span')
-- if icon:match('^(https?:)?//') then
:addClass('kawa-deck-title')
-- iconSpan:tag('img'):attr('src', icon):attr('alt', '')
:wikitext(title)
-- else
local contentSpan = mw.html.create('span')
-- iconSpan:wikitext(icon)
:addClass('kawa-deck-content')
-- end
contentSpan:node(titleSpan)
 
-- 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)
anchor:node(iconSpan)
-- anchor:node(iconSpan)
anchor:node(contentSpan)
-- anchor:node(contentSpan)
nav:node(anchor)
-- nav:node(anchor)
end
-- end


    return tostring(nav)
--    return tostring(nav)
end
end


return p
return p

2026년 5월 26일 (화) 19:23 판

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

local p = {}

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

	return items

	-- local lines = mw.text.gsplit(args.items or '', '\n')
	-- local items = {}

	-- for line in lines do
	-- 	line = mw.text.trim(line)

	-- 	if line == '' then
	-- 		table.insert(items, {})
	-- 	else
	-- 		local key, value = line:gmatch('([^=]+)=([^=]+)')
	-- 		if key and value then
	-- 			key = mw.text.trim(key):lower()
	-- 			value = mw.text.trim(value)
	-- 			if key ~= '' then
	-- 				items[#items][key] = value
	-- 			end
	-- 		end
	-- 	end
	-- end

	-- -- HTML
	-- local nav = mw.html.create('nav')
	-- 	:addClass('kawa-deck-grid')

	-- 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 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')
	-- 		:addClass('kawa-deck-icon')
	-- 		: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')
	-- 		:addClass('kawa-deck-title')
	-- 		:wikitext(title)
	-- 	local contentSpan = mw.html.create('span')
	-- 		:addClass('kawa-deck-content')
	-- 	contentSpan:node(titleSpan)
		
	-- 	anchor:node(iconSpan)
	-- 	anchor:node(contentSpan)
	-- 	nav:node(anchor)
	-- end

 --    return tostring(nav)
end

return p