Module:character simple list

From Wiktionary, the free dictionary
Jump to navigation Jump to search


local export = {}

local function contains(table, val)
	for i = 1, #table do
		if table[i] == val then 
			return true
		end
	end
	return false
end

function export.show(frame)
	local result = {}
	local args = frame.args
	local text = args[1] or ''
	local sc_code = args['sc'] or 'Zyyy'
	local prefix = args['prefix'] or ''
	local separator = args['sep'] or ', '
	local size = args['size'] or 'large'
	local mark = args['mark'] or '⁕'
	local marklist = args['marklist'] or ''

	marklist = mw.text.split(marklist, '')
	for term in mw.text.gsplit(text, '') do
		if prefix == '' then
			table.insert(result, '[[' .. term .. ']]' .. (contains(marklist, term) and mark or ''))
		else
			table.insert(result, '[[' .. prefix .. term .. '|' .. term .. ']]' .. (contains(marklist, term) and mark or ''))
		end
	end
	return '<span class="' .. sc_code .. '" style="font-size:' .. size .. '">' .. table.concat(result, separator) .. '</span>'
end

return export