Module:Color: Difference between revisions
ReisuDesign (talk | contribs) Created page with "local p = {} local lib = require('Module:Feature') local aliases = { bz = 'buzz', buzzword = 'buzz', event = 'bp', action = 'menu', tutorial = 'help' } local colors = { buzz = 'text-buzz', bp = 'text-bp', menu = 'text-menu', new = 'text-new', old = 'text-old', help = 'text-help', citlali = 'text-citlali' } -- Main function for wiki usage. -- If 2 arguments are present, treats t..." |
this SHOULD fix Uncommon getting picked up as Common. |
||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 5: | Line 5: | ||
bz = 'buzz', | bz = 'buzz', | ||
buzzword = 'buzz', | buzzword = 'buzz', | ||
neighbor = 'highlight', | |||
neighbour = 'highlight', | |||
tutorial = 'help' | green = 'new', | ||
red = 'old', | |||
tutorial = 'help', | |||
item = 'help', | |||
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', | |||
menu = 'text-menu', | menu = 'text-menu', | ||
new = 'text-new', | new = 'text-new', | ||
old = 'text-old', | old = 'text-old', | ||
help = 'text-help', | help = 'text-help', | ||
catch = 'text-catch', | |||
whisper = 'text-whisper', | |||
common = 'text-common', | |||
uncommon = 'text-uncommon', | |||
rare = 'text-rare', | |||
stellar = 'text-stellar', | |||
miracle = 'text-miracle', | |||
} | } | ||
| Line 53: | 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 83: | 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 | ||