m (Remove old versions) |
mNo edit summary |
||
Line 69: | Line 69: | ||
end |
end |
||
return text .. '</span>' |
return text .. '</span>' |
||
+ | end |
||
+ | |||
+ | |||
+ | function p.font2( 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 |
end |
||
Revision as of 20:27, 13 March 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' )
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
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",
}
function p.font( f )
local args = w_frame.args( f )
local font = 'font-' .. args[ 1 ]
local intro = '<div' .. ( args.title and ' title="' .. args.title .. '"' or '' ) .. ' class="' .. font .. ' ' .. font .. '-'
local text = '<span style="white-space:nowrap">'
for c in mw.text.gsplit( args[ 2 ], '' ) do
text = text .. ( c == ' ' and '</span> <span style="white-space:nowrap">' or intro .. ( p.specialCharacters[c] or c ) .. '"></div>' )
end
return text .. '</span>'
end
function p.font2( 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">'
for c in mw.text.gsplit( args[ 2 ], '' ) do
text = text .. ( c == ' ' and space or intro .. ( p.specialCharacters[ c ] or c ) .. '.png|' .. math.floor( width[ c ] * scale ) .. outro )
end
return text .. '</span>'
end
return p