Module:Logoform
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
- global function "format"
is invoked from e.g. Created with/layout when
- either the name of the
logo
starts with U+ or &# - and/or an
iconsize
is specified.
- analize
logo
: when it contains a dot, it cannot be a codepoint
no further checks are performed whether is is a valid file name, e.g. "U+2861.svg";
without a dot it is assumed to be a codepoint, as e.g. ⡡
no further checks are performed whether is is a valid codepoint,
but the notation U+ is converted to &#x... and the display becomes tooltipped - analize
iconsize
: when it is missing, useful defaults are set: 33px for Unicode, 36x22px for files
when it is specified, the absence/presence of thepx
dimension is verified - either the file, or the codepoint is displayed
With other file names and no iconsize, no invocation occurs
Code
local p = {} -- Module for: Formatting Logo
function p.format (frame)
local gpar = frame.args -- global
local file = 'F' -- assume file
local size = gpar[2] or '0' -- "0" for "unspecified"
local styl = ';'..gpar[3] or '-' -- "unspecified"
local titl = '">' -- no title
if mw.ustring.sub(size, -2) == 'px' then
size = mw.ustring.sub(size, 1, #size-2 )
end
if not mw.ustring.find( gpar[1], '.', 1, true ) then
if mw.ustring.sub ( gpar[1], 1, 2 ) == 'U+' or
mw.ustring.sub ( gpar[1], 1, 2 ) == '&#' then
file = 'U'
if mw.ustring.sub( gpar[1], 1, 2 ) == 'U+' then -- standardize:
titl = '" title='..gpar[1]..'>'
gpar[1] = mw.ustring.gsub( gpar[1]..';', 'U%+', '&#x' ),_
elseif
mw.ustring.sub( gpar[1], 1, 3 ) == '&#;' then -- textstring:
gpar[1] = mw.ustring.sub( gpar[1], 4 )
end
if styl == ';-' then styl = ';' end -- not specified
if size ~= '0' then
local stab = mw.text.split( size, 'x' )
size = stab[1]
if stab[2] then size = stab[2] end -- height
else
size = '33' -- Unicode default size
end
end
else
if size == '0' then
size = '36x22' -- File default size
end
end
if file == 'F' then
return '[[File:'..gpar[1]..'|'..size..'px]]' -- allow linking
else
return '<span style="font-size:'..size..'px;vertical-align:middle'..styl..titl..gpar[1]..'</span>'
end
end -- function format
return p