Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Logoform: Difference between revisions

From Neodyland Wiki
m Reverted edits by 197.120.162.43 (talk) to last revision by Sarang
m Undo revision 1051453348 by 187.161.18.9 (talk) vandalism
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}  --  Module for: Formatting Logo
--  Module for: Formatting Logo
local p = {}


function p.format (frame)
local concat = table.concat
local gpar = frame.args -- global
local split = mw.text.split
local file = 'F' -- assume file
local trim = mw.text.trim
local size = gpar[2] or '0' -- "0" for "unspecified"
local upper = mw.ustring.upper
local styl = ';'..gpar[3] or '-' -- "unspecified"
local sub = mw.ustring.sub
local titl = '">' -- no title
 
if mw.ustring.sub(size, -2) == 'px' then
local function ucfirst(s)
size = mw.ustring.sub(size, 1, #size-2 )
return upper(sub(s, 1, 1)) .. sub(s, 2)
end
end
if not mw.ustring.find( gpar[1], '.', 1, true ) then
 
if mw.ustring.sub ( gpar[1], 1, 2 ) == 'U+' or
function p.format(frame)
mw.ustring.sub ( gpar[1], 1, 2 ) == '&#' then
local gpar = frame.args -- global
file = 'U'
 
if mw.ustring.sub( gpar[1], 1, 2 ) == 'U+' then -- standardize:
local fname = ucfirst(trim(gpar[1] or ''))
titl = '" title='..gpar[1]..'>'
if fname == '' then return '' end -- if file name is "unspecified"
gpar[1] = mw.ustring.gsub( gpar[1]..';', 'U%+', '&#x' ),_
 
elseif
local size = trim(gpar[2] or '') -- or '0' for "unspecified"
mw.ustring.sub( gpar[1], 1, 3 ) == '&#;' then -- textstring:
if size:sub(-2) == 'px' then size = size:sub(1, -3) end -- discard 'px' unit if present
gpar[1] = mw.ustring.sub( gpar[1], 4 )
size = split(size, 'x') -- {width, height} or {height}
end
size = size[2] and size[2] or size[1] -- keep only the specified height (in px)
if styl == ';-' then styl = ';' end -- not specified
 
if size ~= '0' then
local style = trim(gpar[3] or '') -- or '-' for "unspecified"
local stab = mw.text.split( size, 'x' )
if style == '-' then style = '' end
size = stab[1]
 
if stab[2] then size = stab[2] end -- height
local title = trim(gpar[4] or '') -- or '' for "unspecified"
else
local what = split(fname, '.', true--[[plain, not regexp]]) --[[detect a filename extension]]
size = '33' -- Unicode default size
--[[if there's a non-empty part before a supported extension, with 1 to 4 characters: 'jpg', 'jpeg', 'gif', 'png', 'svg', 'webp', 'djvu', 'tif', 'tiff'...]]
end
if #what > 1 and #(what[#what]) > 0 and #(what[#what]) < 5 then
if title == '' then
title = concat(what, '.', 1, -2):gsub('_', ' ') --[[default title from fname without this extension, underscores replaced by spaces]]
end
what = 'F' -- displaying a file
if size == '' or size == '0' then
size = '36' -- default file size (in px)
end
elseif fname:sub(1, 2) == 'U+' or fname:sub(1, 2) == '&#' then
what = 'U' -- displaying an Unicode code point instead of a file
if size == '' or size == '0' then
size = '15' -- Unicode default font-size (in px)
end
end
else
if title == '' then
if size == '0' then
title = fname--[[default title]]
size = '36x22' -- File default size
end
end
title = trim(title
:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return 'U+' .. upper(x) .. ' ' end)
:gsub('&#([0-9A-Fa-f]+);?', function(x) return 'U+' .. upper(x) .. ' ' end))
fname = fname
:gsub('&#([0-9A-Fa-f]+);?', function(x) return '&#x' .. upper(x) .. ';' end)
:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return '&#x' .. upper(x) .. ';' end) .. '&#xFE0F;'--[[Emoji-style variation selector 16]]
end
end


if file == 'F' then  
if what == 'F' then -- displaying a file
return '[[File:'..gpar[1]..'|'..size..'px]]' -- allow linking
if style ~= '' then
else
style = '|' .. style
return '<span style="font-size:'..size..'px;vertical-align:middle'..styl..titl..gpar[1]..'</span>'
end
if title ~= '' then
title = '|' .. title
:gsub('%[', '&#91;')
:gsub('%]', '&#93;')
:gsub('%|', '&#123;')
end
return concat{ '[[File:', fname, '|', size, 'x22px', style--[[allow linking]], title, ']]' }
else -- displaying an Unicode code point
if title ~= '' then
title = concat{ ' title="', title:gsub('"', '&#34;'), '"' }
end
return concat{ '<div style="display:inline-block;position:relative;font-size:', size, 'px;line-height:22px;vertical-align:middle;top:-1px', style, '"', title, '>', fname, '</div>' }
end
end
end -- function format
end -- function format


return p
return p

Latest revision as of 11:22, 2 July 2025

Module documentation[ create · purge ]
This documentation is transcluded from Module:Logoform/doc.
--  Module for: Formatting Logo
local p = {}

local concat = table.concat
local split = mw.text.split
local trim = mw.text.trim
local upper = mw.ustring.upper
local sub = mw.ustring.sub

local function ucfirst(s)
	return upper(sub(s, 1, 1)) .. sub(s, 2)
end

function p.format(frame)
	local gpar = frame.args -- global

	local fname = ucfirst(trim(gpar[1] or ''))
	if fname == '' then return '' end -- if file name is "unspecified"

	local size = trim(gpar[2] or '') -- or '0' for "unspecified"
	if size:sub(-2) == 'px' then size = size:sub(1, -3) end -- discard 'px' unit if present
	size = split(size, 'x') -- {width, height} or {height}
	size = size[2] and size[2] or size[1] -- keep only the specified height (in px)

	local style = trim(gpar[3] or '') -- or '-' for "unspecified"
	if	style == '-' then style = '' end

	local title = trim(gpar[4] or '') -- or '' for "unspecified"
	local what = split(fname, '.', true--[[plain, not regexp]]) --[[detect a filename extension]]
	--[[if there's a non-empty part before a supported extension, with 1 to 4 characters: 'jpg', 'jpeg', 'gif', 'png', 'svg', 'webp', 'djvu', 'tif', 'tiff'...]]
	if #what > 1 and #(what[#what]) > 0 and #(what[#what]) < 5 then
		if title == '' then
			title = concat(what, '.', 1, -2):gsub('_', ' ') --[[default title from fname without this extension, underscores replaced by spaces]]
		end
		what = 'F' -- displaying a file
		if size == '' or size == '0' then
			size = '36' --	default file size (in px)
		end
	elseif fname:sub(1, 2) == 'U+' or fname:sub(1, 2) == '&#' then
		what = 'U' -- displaying an Unicode code point instead of a file
		if	size == '' or size == '0' then
			size = '15' -- Unicode default font-size (in px)
		end
		if title == '' then
			title = fname--[[default title]]
		end
		title = trim(title
			:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return 'U+' .. upper(x) .. ' ' end)
			:gsub('&#([0-9A-Fa-f]+);?', function(x) return 'U+' .. upper(x) .. ' ' end))
		fname = fname
			:gsub('&#([0-9A-Fa-f]+);?', function(x) return '&#x' .. upper(x) .. ';' end)
			:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return '&#x' .. upper(x) .. ';' end) .. '&#xFE0F;'--[[Emoji-style variation selector 16]]
	end

	if what == 'F' then -- displaying a file
		if style ~= '' then
			style = '|' .. style
		end
		if title ~= '' then
			title = '|' .. title
				:gsub('%[', '&#91;')
				:gsub('%]', '&#93;')
				:gsub('%|', '&#123;')
		end
		return concat{ '[[File:', fname, '|', size, 'x22px', style--[[allow linking]], title, ']]' }
	else -- displaying an Unicode code point
		if title ~= '' then
			title = concat{ ' title="', title:gsub('"', '&#34;'), '"' }
		end
		return concat{ '<div style="display:inline-block;position:relative;font-size:', size, 'px;line-height:22px;vertical-align:middle;top:-1px', style, '"', title, '>', fname, '</div>' }
	end	
end -- function format

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.