Editing Module:Color contrast

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. Read the Privacy Policy to learn what information we collect about you and how we use it.

If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 228: Line 228:
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._greatercontrast(args)
return p._greatercontrast(args)
end
-- warning: crude! may be fooled by sufficientry tricky CSS
function p.extract_css_colors(css, e)
local fgcolor, bgcolor
css = css:gsub("/%*.-%*/", "")
for name, value in string.gmatch(css, "([a-z-]*)%s*:%s*([^;]*)") do
value = mw.text.trim(value)
if name == 'color' then
fgcolor = value
elseif name == 'background-color' then
bgcolor = value
elseif name == 'background' then
value = value:gsub("url%((['\"]?).-%1%)", "")
bgcolor = value:match("#[0-9A-Fa-f]*") or value:match("rgba?%([0-9.%, ]*%)") or value:match("hsla?%([0-9.%, ]*%)")
if not bgcolor then
value = value:gsub("[0-9.][0-9.]*[%%a-z][a-z]?[a-z]?", "")
value = value:gsub("auto", ""):gsub("cover", ""):gsub("contain", "")
value = value:gsub("scroll", ""):gsub("fixed", ""):gsub("local", "")
value = value:gsub("left", ""):gsub("right", ""):gsub("top", ""):gsub("bottom", ""):gsub("center", "")
value = value:gsub("no%-repeat", ""):gsub("repeat", ""):gsub("repeat%-[xy]", ""):gsub("space", ""):gsub("round", "")
value = value:gsub("border%-box", ""):gsub("padding%-box", ""):gsub("content%-box", "")
bgcolor = mw.text.trim(value)
end
end
end
return fgcolor, bgcolor
end
end


return p
return p
Please note that all contributions to Nonbinary Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Nonbinary Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Template used on this page: