The above documentation is transcluded from Module:Text/doc. (edit | history)
local p = {}
local rtable = require( 'Module:Table' )
p.specialCharacters = {
["“"] = "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.specialCharactersTitle = {
["%+"] = "plus",
[":"] = "colon",
[";"] = "scolon",
["?"] = "qmark",
["/"] = "slash",
["|"] = "vbar",
["\\"] = "bslash",
["%["] = "obrkt",
["%]"] = "cbrkt",
["{"] = "obrace",
["}"] = "cbrace",
["<"] = "lthan",
[">"] = "gthan",
["#"] = "hash"
}
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
-- Is a special character ?
characters[j] = p.specialCharactersTitle[characters[j]] or characters[j]
-- 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] .. '_' .. characters[j] .. '.png'
local width = math.floor( mw.getCurrentFrame():callParserFunction( '#imgw', fileName ) * ( args[3] or 1 ) )
local height = math.floor( mw.getCurrentFrame():callParserFunction( '#imgh', fileName ) * ( args[3] or 1 ) )
_t = _t .. '[[Image:' .. fileName .. '|' .. tostring( width ) .. 'x' .. tostring( height ) .. 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
end
j = j + 1
end
return _t .. '</span>'
end
return p