386
edits
m>Frietjes (add option for greatercontrast to form inline css string) |
m (2 revisions imported from wikipedia:Module:Color_contrast: see Topic:Vtixlm0q28eo6jtf) |
||
(7 intermediate revisions by 7 users not shown) | |||
Line 63: | Line 63: | ||
return '' | return '' | ||
end | end | ||
-- html '#' entity | |||
c = c:gsub("#", "#") | |||
-- whitespace | -- whitespace | ||
c = c:match( '^%s*(.-)[%s;]*$' ) | c = c:match( '^%s*(.-)[%s;]*$' ) | ||
Line 139: | Line 143: | ||
if css then | if css then | ||
if mw.ustring.match( | local c1 = args[1] or '' | ||
mw.ustring.match( | if mw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or | ||
mw.ustring.match(c1, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then | |||
c1 = '#' .. c1 | |||
end | end | ||
if mw.ustring.match( | if mw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or | ||
mw.ustring.match( | mw.ustring.match(c2, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then | ||
c2 = '#' .. c2 | |||
end | end | ||
if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or | if mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') or | ||
mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then | mw.ustring.match(v3, '^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]$') then | ||
c3 = '#' .. c3 | |||
end | end | ||
return 'background-color:' .. | return 'background-color:' .. c1 .. '; color:' .. ((ratio1 > 0) and (ratio2 > 0) and ((ratio1 + bias > ratio2) and c2 or c3) or '') .. ';' | ||
end | end | ||