Centers text. Does not work with wikitables. Use Template:Center top and Template:Center bottom instead.

See Template:Center/doc for usage.


local getArgs = require('Module:Arguments').getArgs

local p = {}

-- Nested div based on original Template:Center
-- Not used, available if there is a problem with the flexbox version
function _center_nested(args)
	local text = args[1] or ''

	local div = mw.html.create('div')
	div
		:css('text-align', 'center')

	local inner_div = div:tag('div')
	inner_div
		:css('display', 'inline-block')
		:cssText(args['style'])
		:wikitext('\n' .. text .. '\n')
	
	return tostring(div)
end

function _center(args)
	local text = args[1] or ''
	
	local div = mw.html.create('div')
	div
		:css('display', 'flex')				-- Use flexbox
		:css('align-items', 'center')		-- Center content vertically
		:css('justify-content', 'center')	-- Center content horizontally
		:css('text-align', 'center')		-- Align text content
		:cssText(args['style'])				-- Additional styles
		:wikitext('\n' .. text .. '\n')		-- Content

	return tostring(div)
end

function p.center_nested(frame)
	return _center_nested(getArgs(frame))
end

function p.center(frame)
	return _center(getArgs(frame))
end

return p