Jump to content

Module:Font/sandbox

From Wikiversity

Documentation for this module may be created at Module:Font/sandbox/doc

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

local p = {}

function _font(args)
	local html_size = {
		["0"] = "xx-small",
		["1"] = "x-small",
		["2"] = "small",
		["3"] = "medium",
		["4"] = "large",
		["5"] = "x-large",
		["6"] = "xx-large",
		["7"] = "xxx-large"
	}

	local font_family = args["font"] or args["family"] or args["face"] or "sans-serif"
	local font_size = html_size[args["size"]] or args["size"] or "100%"
	local font_weight = args["weight"] or "normal"
	local color = args["color"] or "black"
	local background_color = args["bgcolor"] or args["background"] or "transparent"
	local style = args["css"] or args["style"] or nil
	local class= args["class" or nil]
	local lang = args["lang"] or nil
	local title = args["title"] or nil
	local text = args["text"] or args[1] or ''
	local element = args["element"] or 'span'
	local span = mw.html.create(element)
	span
		:css('font-family', font_family)
		:css('font-size', font_size)
		:css('font-weight', font_weight)
		:css('color', color)
		:css('background-color', background_color)
		:cssText(style)
		:attr('class', class)
		:attr('lang', lang)
		:attr('title', title)
		:wikitext(text)

	return tostring(span)
end

function p.font(frame)
	return _font(getArgs(frame))
end

function p.font_block(frame)
	args = getArgs(frame);
	text= args["text"] or args[1] 
	local text ='\n'.. text ..'\n'
	args["text"] = text
	args["element"]='div'
 return _font(args);
end

return p