Module:Color contrast: Difference between revisions

new styleratio for parsing css style statements
No edit summary
(new styleratio for parsing css style statements)
Line 148:
return args['error'] or '?'
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
 
Line 157 ⟶ 177:
local args = frame.args[1] and frame.args or frame:getParent().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
 
Anonymous user