Jump to content

Module:Slideshow

From Adaris

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

local p = {}

local function trim(s)
	return mw.text.trim(s or "")
end

function p.render(frame)
	local args = frame.args
	local items = args.items or args[1] or ""

	if trim(items) == "" then
		return ""
	end

	local output = {}
	table.insert(output, '<gallery mode="slideshow">')

	for line in mw.text.gsplit(items, "\n", true) do
		line = trim(line)

		if line ~= "" then
			local filename, caption = line:match("^(.-)%s*::%s*(.*)$")

			if filename then
				filename = trim(filename)
				caption = trim(caption)

				if not filename:match("^File:") and not filename:match("^Image:") then
					filename = "File:" .. filename
				end

				table.insert(output, filename .. "|" .. caption)
			else
				if not line:match("^File:") and not line:match("^Image:") then
					line = "File:" .. line
				end

				table.insert(output, line)
			end
		end
	end

	table.insert(output, "</gallery>")

	return table.concat(output, "\n")
end

return p