Mòdul:columns

De Viccionari

La documentació d'ús d'aquest mòdul es pot crear a Mòdul:columns/ús

local p = {}

local function plainText(text)
	text = mw.text.killMarkers(text)
		:gsub('<span.->(.-)</span>', '%1') --remove spans while keeping text inside
		:gsub('<i.->(.-)</i>', '%1') --remove italics while keeping text inside
		:gsub('<.->', '') --remove any other tag markup
		:gsub('%[%[[^%]]-|', '') --strip out piped link text
		:gsub('[%[%]]', '') --then strip out remaining [ and ]
		:gsub("'''?", "") --strip out bold and italic markup
		:gsub("^%s+", "") --strip leading spaces
		:gsub("%s+$", "") --and trailing spaces
	return text
end

function p.colauto(frame)
	local args = frame.args and frame:getParent().args or frame
	local max_len = 1
	for item in mw.text.gsplit(args[1], '*', true) do
		max_len = math.max(max_len, #plainText(item))
	end
	max_len = max_len + 2
	local ret = mw.html.create('div')
	ret:cssText("-moz-column-width: " .. max_len .. "ch; "
		.. "-ms-column-width: " .. max_len .. "ch; "
		.. "-webkit-column-width: " .. max_len .. "ch; "
		.. "column-width: ".. max_len .. "ch; "
		.. "vertical-align: top;"
		)
	ret:wikitext(args[1])
	ret:allDone()
	return ret
end

return p