Module:ColorText: Difference between revisions
From He is Coming Official Wiki
Benjiminio (talk | contribs) No edit summary |
Benjiminio (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
-- Module:ColorText | -- Module:ColorText | ||
-- Returns inline colored spans for keywords, links if page exists | |||
local p = {} | local p = {} | ||
-- Keyword-to-color mapping | |||
local colors = { | local colors = { | ||
attack = "#e74444", | attack = "#e74444", | ||
| Line 19: | Line 22: | ||
function p.main(frame) | function p.main(frame) | ||
local keyword = frame.args[1] or "" | local keyword = frame.args[1] or "" | ||
local color = colors[keyword:lower()] or "#888888" | local color = colors[keyword:lower()] or "#888888" -- default gray | ||
local text = keyword | local text = keyword | ||
local title = mw.title.new(keyword) | local title = mw.title.new(keyword) | ||
| Line 26: | Line 29: | ||
text = string.format('[[%s]]', keyword) | text = string.format('[[%s]]', keyword) | ||
end | end | ||
return string.format('<span style="color:%s;">%s</span>', color, text) | return string.format('<span style="color:%s !important;">%s</span>', color, text) | ||
end | end | ||
return p | return p | ||
Revision as of 12:22, 7 November 2025
Documentation for this module may be created at Module:ColorText/doc
-- Module:ColorText
-- Returns inline colored spans for keywords, links if page exists
local p = {}
-- Keyword-to-color mapping
local colors = {
attack = "#e74444",
armor = "#4179ab",
health = "#93c13e",
speed = "#ffd569",
acid = "#ccf61f",
freeze = "#62abd4",
poison = "#bbc44e",
purity = "#62abd4",
regeneration = "#9b4c51",
riptide = "#5880cc",
stun = "#ffd569",
thorns = "#8a961f"
}
function p.main(frame)
local keyword = frame.args[1] or ""
local color = colors[keyword:lower()] or "#888888" -- default gray
local text = keyword
local title = mw.title.new(keyword)
if title and title.exists then
text = string.format('[[%s]]', keyword)
end
return string.format('<span style="color:%s !important;">%s</span>', color, text)
end
return p


