Module:Capitalize

From MiMoText
Jump to navigation Jump to search

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

local p = {}

function p.cap(str)
	lang = mw.getContentLanguage()
	if lang:ucfirst(str) ~= str then
		return lang:ucfirst(str)
	else
		local substr = mw.ustring.sub 
		b, e = mw.ustring.find(str, ">%s*%a")
		while e ~= nil do
			if mw.ustring.find(">", substr(str, b,e)) == nil then 
				return substr(str, 1, e-1) .. lang:ucfirst(substr(str,e,e)) ..substr(str, e+1)
			end
			b, e = mw.ustring.find(str, ">%s*%a", e)
		end
		return str
	end
end

function p.capitalize(frame) return p.cap(frame.args[1]) end

return p