The above documentation is transcluded from Module:Text/doc. (edit | history)
local p = {}
local rframe = require( 'module:frame' )
local rtable = require( 'module:table' )
function p.pageName( f )
return mw.title.getCurrentTitle().text;
end
function p.rootPageName( f )
return mw.title.getCurrentTitle().rootText;
end
function p.subPageName( f )
return mw.title.getCurrentTitle().subpageText;
end
function p.test( f )
return type( f )
end
function p.toNumber( f )
local args = rframe.args( f )
return tonumber( args[1], args.base or 10 )
end
function p.itemTest( f )
local args = rtable.trimAll( rtable.getArgs( f ) )
local exceptions = {
["Ace of Spades 2"] = "Ace of Spades (Card)",
["Cancer 2"] = "Cancer (Trinket)",
["Gemini"] = "Gemini (Item)",
["Little Horn"] = "Little Horn (Item)",
["Money Power"] = "Money = Power",
["Steven"] = "Steven (Item)"
}
for i, j in pairs( exceptions ) do
if args[1] == i then
return j
end
end
return args[1]
end
function p.itemTest2( f )
local args = rtable.trimAll( rtable.getArgs( f ) )
local exceptions = {
["Ace of Spades 2"] = "Ace of Spades (Card)",
["Cancer 2"] = "Cancer (Trinket)",
["Gemini"] = "Gemini (Item)",
["Little Horn"] = "Little Horn (Item)",
["Money Power"] = "Money = Power",
["Steven"] = "Steven (Item)"
}
local name = args[1]
for i, j in pairs( exceptions ) do
if args[1] == i then
name = j
end
end
local mode = args[2] == 'a' and 'link-a' or args[2] == 'a+' and 'link-a+' or args[2] == 'n' and 'link-a+' or args[2] or 'link'
return f:expandTemplate{ title = ':' .. name, args = { 'itemα' .. name .. 'β' .. mode } }
end
p.specialCharacters = {
['"'] = "oquote",
["“"] = "oquote",
["”"] = "cquote",
["*"] = "star",
["+"] = "plus",
["±"] = "pm",
["="] = "equal",
["~"] = "tilde",
[":"] = "colon",
[";"] = "scolon",
["."] = "point",
["!"] = "emark",
["?"] = "qmark",
["/"] = "slash",
["|"] = "vbar",
["\\"] = "bslash",
["("] = "oparen",
[")"] = "cparen",
["["] = "obrkt",
["]"] = "cbrkt",
["{"] = "obrace",
["}"] = "cbrace",
["<"] = "lthan",
[">"] = "gthan",
["¶"] = "pilcrow",
["&"] = "and",
["§"] = "ss",
["%"] = "percent",
["†"] = "dagger",
["‡"] = "diesis",
["#"] = "hash",
["°"] = "degree",
["$"] = "dol",
["€"] = "euro",
["¢"] = "cent",
["£"] = "pound",
["@"] = "at",
["©"] = "copy",
["®"] = "regtm",
["¤"] = "curren",
}
-- Replace a text with div(s), with a special font on background
-- Available: TeamMeat (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat.png)
-- TeamMeat-Bold (https://bindingofisaacrebirth.gamepedia.com/File:Font_TeamMeat_Bold.png)
function p.font( f )
local args = rtable.trimAll( rtable.getArgs( f ) )
local _t = '<span style="white-space:nowrap">'
-- Get custom characters
local char = {}
if args.var1 then
local i = 1
repeat
char[i] = mw.text.split( args['var'..i], '-' )
i = i + 1
until not args['var'..i]
end
-- Split string
local characters = {}
args[2]:gsub( ".", function(c) table.insert( characters, c ) end )
local j = 1
while characters[j] do
-- Is a space ?
if characters[j] == ' ' then
_t = _t .. '</span> <span style="white-space:nowrap">'
else
-- Replace custom character
for k, l in pairs( char ) do
if characters[j] == l[1] then
characters[j] = l[2]
break
end
end
-- Is a special character ?
characters[j] = p.specialCharacters[characters[j]] or characters[j]
-- Replace character with a div
_t = _t .. '<div ' .. ( args.title and 'title="' .. args.title .. '"' or '' ) .. ' class="font-' .. args[1] .. ' font-' .. args[1] .. '-' .. characters[j] .. '"></div>'
end
j = j + 1
end
return _t .. '</span>'
end
p.filesWidth = {
["("] = 9,
["“"] = 7,
["."] = 7,
["§"] = 11,
["'"] = 8,
["-"] = 12,
["&"] = 14,
["@"] = 17,
["¤"] = 11,
["©"] = 14,
[")"] = 9,
["°"] = 10,
["$"] = 13,
["%"] = 22,
["£"] = 15,
["®"] = 14,
["~"] = 13,
["!"] = 7,
["¢"] = 11,
["="] = 11,
["¶"] = 11,
["±"] = 18,
["{"] = 13,
["1"] = 8,
["2"] = 12,
["4"] = 11,
["6"] = 13,
["7"] = 13,
["D"] = 13,
["G"] = 15,
["K"] = 15,
["M"] = 17,
["P"] = 14,
["Q"] = 19,
["S"] = 14,
["U"] = 14,
["b"] = 10,
["e"] = 11,
["f"] = 11,
["m"] = 12,
["o"] = 12,
["}"] = 10,
["0"] = 11,
["8"] = 13,
["9"] = 12,
["I"] = 11,
["J"] = 13,
["L"] = 14,
["O"] = 17,
["V"] = 13,
["Z"] = 15,
["a"] = 10,
["g"] = 12,
["h"] = 11,
["i"] = 5,
["k"] = 11,
["t"] = 12,
["w"] = 14,
["x"] = 10,
["z"] = 13,
["\\"] = 8,
[">"] = 13,
["#"] = 17,
["["] = 9,
[";"] = 7,
["A"] = 14,
["B"] = 14,
["C"] = 12,
["E"] = 12,
["F"] = 13,
["H"] = 14,
["N"] = 17,
["R"] = 15,
["T"] = 15,
["W"] = 19,
["X"] = 16,
["Y"] = 15,
["c"] = 11,
["d"] = 11,
["j"] = 10,
["l"] = 7,
["n"] = 10,
["p"] = 10,
["q"] = 12,
["r"] = 11,
["s"] = 11,
["u"] = 11,
["v"] = 12,
["y"] = 9,
["]"] = 10,
[":"] = 5,
["?"] = 13,
["<"] = 13,
["+"] = 12,
["/"] = 10,
["*"] = 10,
["3"] = 13,
["5"] = 13,
}
function p.title( f )
local args = rtable.trimAll( rtable.getArgs( f ) )
local _t = '<span style="white-space:nowrap">'
-- Get custom characters
local char = {}
if args.var1 then
local i = 1
repeat
char[i] = mw.text.split( args['var'..i], '-' )
i = i + 1
until not args['var'..i]
end
-- Split string
local characters = {}
args[2]:gsub( ".", function(c) table.insert( characters, c ) end )
local j = 1
while characters[j] do
-- Is a space ?
if characters[j] == ' ' then
_t = _t .. '</span> ' .. ( tonumber( args[3] or 1 ) > 1.5 and ' ' or '' ) .. ' <span style="white-space:nowrap">'
else
-- Replace custom character
for k, l in pairs( char ) do
if characters[j] == l[1] then
characters[j] = l[2]
break
end
end
-- Replace character with an image
local fileName = 'Font_' .. args[1] .. '_' .. ( p.specialCharacters[characters[j]] or characters[j] ) .. '.png'
local width = math.floor( p.filesWidth[characters[j]] * ( args[3] or 1 ) )
_t = _t .. '[[Image:' .. fileName .. '|' .. tostring( width ) .. 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
end
j = j + 1
end
return _t .. '</span>'
end
return p