Module:Color contrast: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
No edit summary
(new styleratio for parsing css style statements)
Line 148: Line 148:
return args['error'] or '?'
return args['error'] or '?'
end
end
end

function p._styleratio(args)
local style = (args[1] or ''):lower()
local bg, fg = (args[2] or 'white'), (args[3] or 'black')

local slist = mw.text.split(s or '', ';')
for k = 1,#slist do
s = slist[k]
local k,v = s:match( '^[%s*]([^:]-):([^:]-)[%s;]*$' )
k = k or ''
v = v or ''
if (k:match('^[%s]*(background)[%s]*$') or k:match('^[%s]*(background-color)[%s]*$')) then
bg = v
elseif (k:match('^[%s]*(color)[%s]*$')) then
fg = v
end
end

return p._ratio({bg, fg, ['error'] = args['error']})
end
end


Line 157: Line 177:
local args = frame.args[1] and frame.args or frame:getParent().args
local args = frame.args[1] and frame.args or frame:getParent().args
return p._ratio(args)
return p._ratio(args)
end

function p.styleratio(frame)
local args = frame.args[1] and frame.args or frame:getParent().args
return p._styleratio(args)
end
end