Module:ST
From ENDLESS Legend 2 Official Wiki
See https://darkestdungeon.wiki.gg/wiki/Module:ST
local getArgs = require("Module:Arguments").getArgs
--
-- Basic utilities for formatting text
--
local span_fmt = '<span class="%s">%s</span>'
local nowrap_fmt = span_fmt:format("nowrap", "%s")
local dash = string.byte("-")
local img_fmt = "[[File:%s|%s|link=%s|alt=%s]]"
local size_normal = "16px"
local size_large = "35px"
local link_fmt = "[[%s|%s]]"
local function span(txt, class)
return (class ~= nil) and span_fmt:format(class, txt) or txt
end
-- This is necessary to ensure that symbols and text are grouped together on
-- one line instead of spilling over.
local function nowrap(txt)
return nowrap_fmt:format(txt)
end
local function img(args)
local size_fmt = (args.size == "large") and size_large or size_normal
return img_fmt:format(
args.image, size_fmt, args.link, args.alt or args.name)
end
local function link(args)
if #args.link > 0 then
return link_fmt:format(args.link, args.name)
else
return args.name
end
end
--
-- Define argument patterns
--
local function icon(args)
if args[1] == nil then
return img(args)
elseif args[1] == "-" then
return nowrap(img(args) .. " " .. link(args))
end
end
local function icon_fallback(args)
return nowrap(img(args) .. span(args[1], args.class))
end
--
-- Match argument patterns to determine what variant we should render
--
local renderers_by_type = {
icon={icon, icon_fallback},
}
local function _render(args)
for _, f in ipairs(renderers_by_type[args.type]) do
local result = f(args)
if result ~= nil then
return result
end
end
end
local function render(frame)
return _render(getArgs(frame, {
parentFirst=true,
removeBlanks=false
}))
end
return {
_render=_render,
render=render
}


