local getArgs = require('Module:Arguments').getArgs
local p = {}
local function contains(t, val)
for _, v in ipairs(t) do
if v == val then
return true
end
end
return false
end
function p.main(frame)
local args = getArgs(frame)
local result = {}
local types = {'png', 'gif', 'jpg', 'jpeg', 'webp', 'svg'}
for _, source in ipairs(args) do
local parts = {}
local iter = mw.ustring.gmatch(source .. ',', '([^,]*),')
for val in iter do
table.insert(parts, val)
end
local color, chara, disp, img, size = parts[1], parts[2], parts[3], parts[4], parts[5]
if disp and contains(types, mw.ustring.match(disp:lower(), '%.(%w+)$')) then
size = img
img = disp
disp = chara
end
local block_part = ''
local text_part = ''
if img and img ~= '' then
block_part = '[[File:' .. img .. '|' .. (size or 'x15px') .. '|link=' .. (chara or '') .. ']]'
else
block_part = frame:expandTemplate{ title = 'color_block', args = { color } }
end
if chara and chara ~= '' then
text_part = '[[' .. chara .. '|' .. frame:expandTemplate{ title = 'color', args = { color, (disp or chara) } } .. '</span>]]'
else
text_part = frame:expandTemplate{ title = 'color', args = { color, disp } }
end
local content = block_part .. ' ' .. text_part
table.insert(result,
content .. '<span style="cursor:default; '
.. frame:expandTemplate{ title = 'prefix', args = { 'user-select:none' } }
.. '"> </span>')
end
table.insert(result, '<br>')
return table.concat(result)
end
return p