local getArgs = require('Module:Arguments').getArgs
local str = require('Module:String')
local p = {}
local function handleArgs(val, pref, suff, split)
local pick, color, css, url = nil, nil, nil, nil
local out = ''
local firstChar = str.pos(val, 1)
if firstChar == '-' then
local nextChar = str.pos(val, 2)
if nextChar == '@' then
local seg = str.sub(val, 3, str.find(val, '-@css-'))
if seg == 'css' then
css = str.replace(val, '-@css-', '')
elseif seg == 'url' then
url = str.replace(val, '-@url-', '')
end
elseif nextChar == '#' then
color = str.sub(val, 3, str.len(val))
else
pick = str.sub(val, 2, str.len(val))
end
elseif val == 'end' then
out = ''
else
local link = ''
if url == nil then
link = (pref or '') .. val .. (suff or '')
else
link = url
end
local style = ''
if color ~= nil then
style = 'color:' .. color .. ';'
end
if css ~= nil then
style = style .. css .. ';'
end
out = '[[' .. link .. '|<span style="' .. style .. '">' .. (pick or val) .. '</span>]]' .. (split or " • ")
end
pick, color, css, url = nil, nil, nil, nil
return out
end
function p.main(frame)
local args = getArgs(frame)
local content = ''
for _, val in ipairs(args) do
content = content .. handleArgs(val, args['prefix'], args['suffix'], args['split'])
end
return mw.text.trim(content):gsub(args['split'] .. "$", "")
end
return p