No edit summary |
mNo edit summary |
||
(38 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | local w_title = require( 'module:title' ) |
|
− | 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 |
||
⚫ | |||
⚫ | |||
− | return args[1] |
||
− | end |
||
⚫ | |||
− | 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 |
||
− | 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", |
||
− | ["”"] = "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", |
||
− | } |
||
+ | -- DEPRECATED |
||
+ | p.pageName = w_title.main |
||
+ | p.rootPageName = w_title.root |
||
+ | p.subPageName = w_title.subpage |
||
+ | |||
− | -- 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) |
||
+ | return tonumber( args[1], args.base or 10 ) |
||
− | function p.font( f ) |
||
− | local args = rtable.trimAll( rtable.getArgs( f ) ) |
||
⚫ | |||
− | |||
− | -- 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 |
||
⚫ | |||
− | 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 |
||
− | |||
⚫ | |||
end |
end |
||
+ | -- DEPRECATED : Use "template:font" instead |
||
− | p.specialCharactersTitle = { |
||
⚫ | |||
− | ["+"] = "plus", |
||
+ | local args = w_frame.args( f ) |
||
− | [":"] = "colon", |
||
+ | return '<span class="custom-font custom-font-' .. args[ 1 ] .. ( args.title and '" title="' .. args.title or '' ) .. '">' .. args[ 2 ] .. '</span>' |
||
− | [";"] = "scolon", |
||
⚫ | |||
− | ["?"] = "qmark", |
||
− | ["/"] = "slash", |
||
− | ["|"] = "vbar", |
||
− | ["\\"] = "bslash", |
||
− | ["["] = "obrkt", |
||
− | ["]"] = "cbrkt", |
||
− | ["{"] = "obrace", |
||
− | ["}"] = "cbrace", |
||
− | ["<"] = "lthan", |
||
− | [">"] = "gthan", |
||
− | ["#"] = "hash" |
||
− | } |
||
function p.title( f ) |
function p.title( f ) |
||
− | + | local args = w_frame.args( f ) |
|
+ | local scale = tonumber( args[ 3 ] or 1 ) |
||
− | local _t = '<span style="white-space:nowrap">' |
||
⚫ | |||
− | |||
+ | local width = mw.loadData( 'module:text/' .. args[ 1 ] ) |
||
− | -- Get custom characters |
||
+ | local intro = '[[file:font_' .. args[ 1 ] .. '_' |
||
− | local char = {} |
||
⚫ | |||
− | if args.var1 then |
||
⚫ | |||
− | local i = 1 |
||
+ | local specialCharacters = mw.loadData( 'module:text/special' ) |
||
− | repeat |
||
− | + | for c in mw.text.gsplit( args[ 2 ], '' ) do |
|
+ | text = text .. ( c == ' ' and space or intro .. ( specialCharacters[ c ] or c ) .. '.png|alt=' .. c .. '|' .. math.floor( width[ c ] * scale ) .. outro ) |
||
− | 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 ) ) |
||
⚫ | |||
− | end |
||
− | j = j + 1 |
||
− | end |
||
− | |||
− | return _t .. '</span>' |
||
end |
end |
||
+ | |||
return p |
return p |
Revision as of 22:48, 8 April 2021
The above documentation is transcluded from Module:Text/doc. (edit | history)
local p = {}
local w_frame = require( 'module:frame' )
local w_title = require( 'module:title' )
-- DEPRECATED
p.pageName = w_title.main
p.rootPageName = w_title.root
p.subPageName = w_title.subpage
function p.toNumber( f )
local args = w_frame.args( f )
return tonumber( args[1], args.base or 10 )
end
-- DEPRECATED : Use "template:font" instead
function p.font( f )
local args = w_frame.args( f )
return '<span class="custom-font custom-font-' .. args[ 1 ] .. ( args.title and '" title="' .. args.title or '' ) .. '">' .. args[ 2 ] .. '</span>'
end
function p.title( f )
local args = w_frame.args( f )
local scale = tonumber( args[ 3 ] or 1 )
local space = '</span> ' .. ( scale > 1.5 and ' ' or '' ) .. ' <span style="white-space: nowrap">'
local width = mw.loadData( 'module:text/' .. args[ 1 ] )
local intro = '[[file:font_' .. args[ 1 ] .. '_'
local outro = 'px|link=' .. ( args.link or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
local text = '<span style="white-space:nowrap">'
local specialCharacters = mw.loadData( 'module:text/special' )
for c in mw.text.gsplit( args[ 2 ], '' ) do
text = text .. ( c == ' ' and space or intro .. ( specialCharacters[ c ] or c ) .. '.png|alt=' .. c .. '|' .. math.floor( width[ c ] * scale ) .. outro )
end
return text .. '</span>'
end
return p