Module:Color: Difference between revisions
Added missing colors and aliases |
this SHOULD fix Uncommon getting picked up as Common. |
||
| (4 intermediate revisions by 2 users not shown) | |||
| Line 10: | Line 10: | ||
red = 'old', | red = 'old', | ||
tutorial = 'help', | tutorial = 'help', | ||
item = 'help', | |||
wp = 'whisper', | wp = 'whisper', | ||
common = 'common', | |||
gray = 'common', | |||
uncommon = 'uncommon', | |||
blue = 'uncommon', | |||
rare = 'rare', | |||
purple = 'rare', | |||
stellar = 'stellar', | |||
gold = 'stellar', | |||
yellow = 'stellar', | |||
miracle = 'miracle', | |||
rainbow = 'miracle' | |||
} | } | ||
local colors = { | local colors = { | ||
accent = 'text-accent', | |||
buzz = 'text-buzz', | buzz = 'text-buzz', | ||
highlight = 'text-highlight', | highlight = 'text-highlight', | ||
| Line 22: | Line 35: | ||
catch = 'text-catch', | catch = 'text-catch', | ||
whisper = 'text-whisper', | whisper = 'text-whisper', | ||
common = 'text-common', | |||
uncommon = 'text-uncommon', | |||
rare = 'text-rare', | |||
stellar = 'text-stellar', | |||
miracle = 'text-miracle', | |||
} | } | ||
| Line 57: | Line 75: | ||
end | end | ||
if (args. | if (args.no_bold and lib.isNotEmpty(class)) then | ||
return '<span class="' .. class .. '">' .. text .. '</span>' | return '<span class="' .. class .. '">' .. text .. '</span>' | ||
elseif (args. | elseif (args.no_bold and lib.isNotEmpty(span)) then | ||
return '<span style="color:' .. span .. '">' .. text .. '</span>' | return '<span style="color:' .. span .. '">' .. text .. '</span>' | ||
elseif lib.isNotEmpty(span) then | elseif lib.isNotEmpty(span) then | ||
| Line 87: | Line 105: | ||
-- Helper method to search given text for the keys of given table t. | -- Helper method to search given text for the keys of given table t. | ||
-- If a key is found, returns its value; returns nil otherwise. | -- If a key is found, returns its value; returns nil otherwise. | ||
-- Checks longer keys first to avoid matching partial keywords (Uncommon getting detected as Common.) | |||
local function searchTextForKeys(text, t) | local function searchTextForKeys(text, t) | ||
local keys = {} | |||
for key in pairs(t) do | |||
keys[#keys + 1] = key | |||
end | |||
table.sort(keys, function(a, b) | |||
return #a > #b | |||
end) | |||
for _, key in ipairs(keys) do | |||
if mw.ustring.find(text, key, 1, true) ~= nil then | |||
return t[key] | |||
end | |||
end | end | ||
end | end | ||