yoohoo! hot sauce please

10:27, 7 September 2026 (UTC)

Module:CatMark

From 2swagg wiki
Revision as of 01:35, 11 October 2026 by Bulgogi2 (talk | contribs) (Created page with "local p = {} p.prefix = 'data-cat-' -- earmark for modules to identify local function trim(value) if value == nil then return '' end return mw.text.trim(tostring(value)) end function p._build(name, value) name = string.lower(trim(name)) if not string.match(name, '^[%w%-]+$') then return '' end local marker = mw.html.create('span'):attr(p.prefix .. name, trim(value)) return tostring(marker) end function p.mark(frame) local parent = frame:getParent() if not pa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This module copies a template's parameter into an "invisible" HTML marker, so that categorizer modules can read the value later easily. It is meant for values that can't be reliably detected from prose, such as the country code in {{Nationality}} or post count given in {{Boorusearch}}. it just saves a whole lot of time from writing annoying regex and patterning when the template can just report its code with an earmark phrase

Usage[edit source]

Place this inside the template somewhere:

<syntaxhighlight lang='wikitext'>

</syntaxhighlight>

For example, in {{Nationality}}:

<syntaxhighlight lang='wikitext>

</syntaxhighlight>

if the template uses "DE", it will report "DE" in the mark.

The marker renders nothing visible to the reader and is harmless. Markers will generate in the order they are in wikitext.


local p = {}

p.prefix = 'data-cat-'
-- earmark for modules to identify
local function trim(value)
	if value == nil then return '' end
	return mw.text.trim(tostring(value))
end

function p._build(name, value)
	name = string.lower(trim(name))
	if not string.match(name, '^[%w%-]+$') then return '' end

	local marker = mw.html.create('span'):attr(p.prefix .. name, trim(value))

	return tostring(marker)
end

function p.mark(frame)
	local parent = frame:getParent()
	if not parent then return '' end

	local param = trim(frame.args[2])
	if param == '' then return '' end

	return p._build(frame.args[1], parent.args[tonumber(param) or param])
end

return p